I want to use a css parser that uses namespaces. I put the files in vendors and app imported it. but the script itself does not seem to find its classes
At the top of my class I import the file:
App::import('Vendor', 'Sabberworm', array('file' => 'Sabberworm/CSS/Parser.php'));
which is in /root/vendors/Sabberworm/CSS/ (all files are in this namespace)
Inside my class method I create a new instance:
public function parse($content) {
$oParser = new Sabberworm\CSS\Parser($content);
...
}
So far so good. But if I now want to call $oCss = $oParser->parse();
it fatal errors:
"Fatal error: Class 'Sabberworm\CSS\CSSList\Document'"
it fails then because it requires the other files (which should be loaded using namespaces). the root vendors folder is in the include path and the foreign script seems to set the namespace to "namespace Sabberworm\CSS;". what am I missing? I am kinda new to namespaces.
Add this to bootstrap
spl_autoload_register(function($class) {
foreach(App::path('Vendor') as $base) {
$path = $base . str_replace('\\', DS, $class) . '.php';
if (file_exists($path)) {
return include $path;
}
}
});
Or just this inside the function:
$path = APP . 'Vendor' . DS . str_replace('\\', DS, $class) . '.php';
if (file_exists($path)) {
include $path;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With