PHP Autoloading with Composer using Namespaces -


i had pretty simple autoload script working nicely, i've noticed doctrine2 using composer this, thought might nice streamline everything. unfortunately, composer not seem working understood to.

here relevant part of composer.json

"autoload": {     "psr-0": {        "": "models/",        "catalog2\\config": "class/"     } } 

note "": "models/" line used doctrine2 has been working fine. after ran composer update , bottom part of vendor/composer/autoload_namespaces.php looks so:

'doctrine\\common\\' => array($vendordir . '/doctrine/common/lib'), 'catalog2\\config' => array($basedir . '/class'), '' => array($basedir . '/models'), 

so far good, think. in routes.php file (basically front-controller) have following:

<?php use catalog2\config;  //autoload classes require_once __dir__.'/vendor/autoload.php';  try {     $router = new router; } catch(exception $e ) {     echo "<strong>can't create router object</strong><br/>"; } 

here catalog2\config\router should calling class/router.php, begins follows:

<?php namespace catalog2\config;  class router {     protected $resource; //what manipulating? product? order?     protected $action; //what doing resource? 

when go page this:

fatal error: class 'router' not found in /home/tom/code/productcatalog2/routes.php on line 14 

what going wrong here? repeat doctrine2 able autoload model code /models, why aren't changes working?

according psr-0 namespace prefix included path.

so complete filename class must be:

class/catalog2/config/router.php 

meanwhile psr-4 behave expected: match namespace prefix , not append additionally given path.

references:

ps: want namespace prefix "catalog2\\config\\" (see trailing slash)


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -