-
Notifications
You must be signed in to change notification settings - Fork 46
Introdce a safe_class_exists #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Http\Discovery; | ||
|
||
/** | ||
* We want to do a "safe" version of PHP's "class_exists" because Magento has a bug | ||
* (or they call it a "feature"). Magento is throwing an exception if you do class_exists() | ||
* on a class that ends with "Factory" and if that file does not exits. | ||
* | ||
* This function will catch all potential exceptions and make sure it returns a boolean. | ||
* | ||
* @param string $class | ||
* @param bool $autoload | ||
* | ||
* @return bool | ||
*/ | ||
function safe_class_exists($class, $autoload = true) | ||
{ | ||
try { | ||
return class_exists($class, $autoload); | ||
} catch (\Exception $e) { | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
// Don't redefine the functions if included multiple times. | ||
if (!function_exists('Http\Discovery\safe_class_exists')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not require_once? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this allows you to override... Im not sure. I just did it the "guzzle" way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah that allows to override by hijacking the namespace. sounds like either horrible situations or really bad design but i guess it does not hurt too much. also will be quite some issue with having things loaded in the right order. but if its helpful to people to have it, i guess the overhad is insignificant so lets do it this way. |
||
require __DIR__.'/functions.php'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there no autoloading for functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think only classes are autoloaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, otherwise we would need a naming scheme for function to filename...