(codeigniter/Neo4j) PHP : namespace and autoloader -


as i'm trying install neo4jphp library in codeigniter (v2.2.x), i'm having annoying issues regarding namespaces. i've been searching 4 hours without success.

in short, there libraries directory in neo4jphp must copied. in 'libraries/', there directory 'everyman/neo4j/', contains neo4j php classes.

also, in same 'libraries' directory, there class autoloader function, aims @ loading neo4j classes (which in 'everyman/neo4j/').

inside of 'libraries'

- libraries/      |-- everyman/              |-- neo4j/                    |-- client.php                    |-- some_other_classes.php      |-- neo4j.php 

then, somewhere in code, in global namespace, try instantiate class client :

$client = new client(); 

but error class 'client' not found.

in class client, following namespace specified : everyman\neo4j.

i'm must admit found 2 workarounds issue :

from calling code, use qualified name :

new everyman\neo4j\client(); 

or, in client.php, remove namespace.

in these 2 cases, works. however, call client class these 2 condition : 1. don't want modify neo4jphp library. 2. don't want have use qualified name (everyman\neo4j\client). want use "new client()".

do guys have idea how achieve (yes, don't have deep understanding of namespaces, , loaders).

in neo4j.php (file loader)

 <?php     class everyman{      public function __construct()     {         spl_autoload_register(array($this,'autoload'));     }      public function autoload($sclass){             $slibpath = __dir__.directory_separator;     //below, modified instruction class file     //can found. however, class not found.             $sclassfile = 'everyman'.directory_separator.'neo4j'.str_replace('\\',directory_separator,$sclass).'.php';             $sclasspath = $slibpath.$sclassfile;             if (file_exists($sclasspath)) {                 require($sclasspath);             }         }     } 

so that's it. think i've given information have. if no 1 can me, i'll have use 'new everyman\ne4j\client();' (which works).

it may seem stupid ask help, have found 2 workarounds, want learn how handle issue (if possible).

thanks.

it seems code $client = new everyman\neo4j\client('localhost', 7474); offical usage: https://github.com/jadell/neo4jphp#connection-test

so not work around.

i don't want have use qualified name (everyman\neo4j\client). want use "new client()".

i don't know want. how putting code below in code use everyman\neo4j\client:

use everyman\neo4j\client;

and

$client = new client();

see http://php.net/manual/en/language.namespaces.importing.php


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -