Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-30-2008, 07:13 AM
Junior Member
 
Join Date: Jan 2008
Posts: 5
Default Verify component exists

I have a interesting question for anyone that can answer it.

I want to create function that verifies that a requested component exists. For example:

function isComponent($componentName)
{
// Code to verify component exists
}

My question being is there a way to do this or would have just have to do it with a switch. Any help is appreciated.

Xistins
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-30-2008, 08:31 AM
Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 52
Send a message via MSN to Leif.Högberg
Default

More information is needed in order to answer this question.
What exactly do you mean by component?

If it's a class like any other then class_exists might be what you are looking for.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-30-2008, 07:28 PM
Junior Member
 
Join Date: Jan 2008
Posts: 5
Default

Okay to clarify...

If say using the above example:

isComponent('form') <--- should return true as there is a Zend_Form
isComponent('shazbot') <--- would return false because there isn't one.

I'm currently doing this with a switch for the different components but I guess I was hoping there was a "prettier" way to do it as this way is rather ugly and a lot of code.

As for a little bit more of information I need the ability to also instantiate the component as well. I.E.

if(isComponent($requested))
{
$this->services[$requested] = new Zend_$requested;
}

I may have to keep doing this with a switch and that is okay, but I was hoping there was an easier way to do it.

Any help is appreciated.

X
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-30-2008, 10:49 PM
Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 52
Send a message via MSN to Leif.Högberg
Default

Still sounds to me like you should take a look at the php built-in function class_exists.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-18-2008, 07:58 AM
Junior Member
 
Join Date: Feb 2008
Posts: 1
Default

Quote:
Originally Posted by xistins View Post
I have a interesting question for anyone that can answer it.

I want to create function that verifies that a requested component exists. For example:

function isComponent($componentName)
{
// Code to verify component exists
}

My question being is there a way to do this or would have just have to do it with a switch. Any help is appreciated.

Xistins
function isComponent($componentName)
{
// Code to verify component exists
$filename = '/zend/$componentName'; // suppose your ZendFramwork library dir is /zend/
if (file_exists($filename)) {
return true;
} else {
return false;
}
}

I think if this dir "/zend/form" exists, the component exists
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-19-2008, 02:31 PM
Senior Member
 
Join Date: Jan 2008
Location: chicago
Posts: 101
Default

I don't want to question what you are trying to do, but I am guessing that it is a waste of time if you are trying to detect if a Zend_Class has been loaded or not. If you are worried about loading a class more than once, just use
PHP Code:
require_once 'XXXX.php'
.

You can just set up the autoloader and not even have to worry about this:

PHP Code:
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload(); 

If you are trying to load a class in the library and it isn't even there, then your app should be breaking so that you know you have to fix it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 02:06 PM.