namespaces - How to use a PHP library with namespacing without Composer as dependency (PSR-0)? -
i need use php libraries dependencies have restrictions on webserver of client. managed webserver , can not use console eg on ssh.
so how use these libraries without composer?
can create directories manually , directories or paths need create? also, need create autoloading , namespacing working?
can create autoload.php somehow manually , content of file?
it possible simple autoloader , not hard it:
function __autoload($classname) { $classname = ltrim($classname, '\\'); $filename = ''; $namespace = ''; if ($lastnspos = strripos($classname, '\\')) { $namespace = substr($classname, 0, $lastnspos); $classname = substr($classname, $lastnspos + 1); $filename = str_replace('\\', directory_separator, $namespace) . directory_separator; } $filename .= str_replace('_', directory_separator, $classname) . '.php'; // $filename .= $classname . '.php'; //sometimes need custom structure //require_once "library/class.php"; //or include class manually require $filename; } but have adjust $filename works libraries. depends on standard autoloading , how class names of libraries named. have split classname on _ , use first element direcotry name , add class name. had example second library class library_parser structure library/library-parser.php.
the first library worked directly above code , classes automatically loaded.
the code taken http://www.sitepoint.com/autoloading-and-the-psr-0-standard/ had correct code parts (additional underscores , backslashes). have used psr-0 standard solution.
Comments
Post a Comment