Menu
  • HOME
  • TAGS

PHP autoloader class to load files from two or three different path

php,autoloader

I think your problem basically boils down to not checking if the file exists before requireing it... that will produce a fatal error if the file doesn't exist in the first folder that you attempt to include from. I don't know your use case, but here are some suggestions: Can...

spl_autoloader not loading any classes

php,namespaces,autoloader,spl-autoload-register,spl-autoloader

The problem here is, that you don't register a callback function with spl_autoload_register(). have a look at the official docs. To be more flexible, you can write your own class to register and autoload classes like this: class Autoloader { private $baseDir = null; private function __construct($baseDir = null) {...

How to load PHP config files with an autoloader

php,oop,autoloader

You are definitely on the right track. As with anything related to programming, there are 1 million + 1 ways to skin a cat, here a a few options /w some info. Yaml: Heavily used by frameworks such as Symfony. If you don't use the SF framework, you can easily...

Load git repo with composer - autoloading issue

php,git,composer-php,autoloader

Finaly, I have found out what was the problem. composer.json file in the project I was trying to load - UPS library -was invalid. I was able to download files when I ran: composer.phar install but it looks like composer.json file was ignored. I found it out when I ran...

Zend 1 3d party NameSpaces autoload don't working

php,zend-framework,amazon-web-services,namespaces,autoloader

In order to use $autoloader->registerNamespace('Aws'), the AWS lib you seek must be on your PHP include path, which probably includes your ./library directory. Instead, you have the AWS lib buried down in ./library/Eplan/AmazonCloudSearch, which almost certainly is not on your PHP include_path. Try moving the AWS library up two levels,...

Composer for autoloading php

php,composer-php,autoloader

namespaces need \\: "Apison\\": "../sdk" documentation: https://getcomposer.org/doc/04-schema.md#psr-4 Based on our chat, the solution is this: "autoload": { "psr-4": { "Apison\\Sdk\\": "sdk" } } Then the namespaces and file structure was changed to comply with the psr-4 standard...

Composer, the Autoloader, and VCS

php,composer-php,autoloader

While it's pretty clear to me to ignore the VENDOR dir, it is not clear to me whether the autoload.php file should be excluded also. Composer's autoload.php file should indeed be ignored, as it's part of the vendor directory. It's automatically generated as part of the composer install /...

phalcon load classes from directory

php,model-view-controller,model,phalcon,autoloader

Thanks for you Artamiel I found the problem! I had phalcon 1.3 and everything works fine, then I updated phalcon to 2.0 version, and don't test autoload. The difference is in Prefix for directory classes in 1.3 version I use 'Service_' in 2.0 works fine just 'Service' So, the solution...

symfony 2.3 add third party library

symfony2,autoloader

please dont do these kind of stuff, go on packagist and find the right package to install with composer command line interface. Class loader will be overwritten each time you'll use composer anyway,you shouldnt be touching it. https://packagist.org/search/?q=FPDF If you dont know how to use composer read its doc https://getcomposer.org...

PHPUnit can't find test class if it is auto/manually loaded in bootstrap

php,phpunit,autoloader

I haven't fixed this, but my build methods are now so long that it makes sense for them to appear in different classes anyway. I have a naming convention so that a test of *Test.php has a corresponding build class of *Build.php. I use PHPUnit's bootstrap system to scan for...

How to call this function for every controller in codeigniter

php,codeigniter,controller,autoloader

You can create a library for this purpose and autoload this library. Creating a library is explained in the given link codeigniter library Or you can refer to a somewhat same question asked in the stackoverflow Stack overflow post...

Classmap keyword doesn't insert classes

php,composer-php,autoloader

Your autoload definition is wrong. You are defining that you use PSR-0. You define that classes that start with the prefix "classmap" (all lowercase) are located in the directory "src/libraries". Then you try to use a class names "ClassName". This class does not start with the letters "classmap", so it...

Is module auto-loading meant to be reliable?

powershell,module,autoloader

I can't speak to whether module auto-loading is intended to be reliable, but I personally do not rely on it in finished code. If I'm writing a script or module, I always use Import-Module TheModule -ErrorAction Stop, and often use #Requires -Module AciveDirectory,TheModule,SQLPs to ensure that the modules are available....

How autoloader works in zend framework 2

php,zend-framework2,package,composer-php,autoloader

I think there's a problem with the composer.json file in your module. It says: "autoload": { "psr-0": { "Zf2auth": "./" } } and looking at the directory structure it should be: "autoload": { "psr-0": { "Zf2auth\\": "src" } } It works in your ./modules/ dir because of the getAutoloaderConfig you...

Swift Mailer ruins autolading

php,autoload,swiftmailer,autoloader

Instead of __autoload(), you should use spl_autoload_register. If there must be multiple autoload functions, spl_autoload_register() allows for this. It effectively creates a queue of autoload functions, and runs through each of them in the order they are defined. By contrast, __autoload() may only be defined once. http://php.net/manual/en/function.spl-autoload-register.php define("_DOCUMENT_ROOT", str_replace("//", "/",...

Composer autoloader + slim framework - atal error: Class 'Slim\Slim' not found?

php,composer-php,slim,autoloader

If you prefer to keep slim under ext (as you mentioned here Slim framework - How to autoload Slim/Slim.php instead of using require?) instead of using it as a composer package, I believe this will work: { "autoload": { "psr-0": { "": "ext/" } } } ...

Trouble using SplClassLoader

php,autoloader

All the SplClassLoader does is append your namespace path, as directories, to the supplied directory defined in the loader. so. given your example of: namespace: Worker1\Repositories Then the directory path defined in the loader should be: TestProject/BackgroundWorkers. Note: always supply the full disk path as the 'lookup' directory. Here is...

PHP Composer Autoloader Class not Found Exception

php,composer-php,autoloader

You need to include namespace when you are initializing a class: $mysql = new Database\Core\MySQL(); or use Database\Core\MySQL; $mysql = new MySQL(); See http://php.net/manual/en/language.namespaces.importing.php...

Getting development copy of ZF2 module

php,module,zend-framework2,composer-php,autoloader

For me I get the next solution: 1) Add somethink like that to "script"-section in composer.json: "devmodules": [ "mkdir devmodules", "git clone git://github.com/4orever/ppc-auth/ devmodules/ppc-auth", "git clone git://github.com/4orever/ppc-backend/ devmodules/ppc-backend", "git clone git://github.com/4orever/ppc-backend-client/ devmodules/ppc-backend-client", "git clone git://github.com/4orever/ppc-dev-mode/ devmodules/ppc-dev-mode", "git clone git://github.com/4orever/ppc-main-assets/ devmodules/ppc-main-assets", "rm -rf...

Composer autoload - How to fetch classes, traits, interfaces from different folders?

php,namespaces,composer-php,autoloader,spl-autoloader

You have to standardize your namespaces and folders structure. If you have the same namespace in different folders, it's harder to create a simple logic to autoload them all. Try to use another segment in your namespace like: namespace MyNamespace\Controller; class Foo { public $message = 'hello Foo'; } and:...

Slim framework - How to autoload Slim/Slim.php instead of using require?

php,slim,autoloader,zend-autoloader,spl-autoloader

With the way your autoloader handles namespaces, you'll need to use this: $SplAutoload->fetch([ 'ext/Slim/' // Slim/ is kept under ext/ ]); or change your autoloader so it includes the namespace as a directory....

PHP Composer Autoloader Simple Structure

php,composer-php,autoloader,psr-4

Did you define an autoload directive? You need to add this to your composer.json file: "autoload": { "psr-4": { "controllers\\": "controllers/" } } to point the autoloader in the right direction and then run composer update from the terminal in your project directory. Now the class will load without explicitly...

Will PHP Autoloader load when calling a class constant?

php,autoloader

In short, yes, autoloader is called for statics. You could test this yourself: /index.php <?php class Init { function __construct() { spl_autoload_register(array($this, 'loadClass')); echo MyThing::BORIS; } function loadClass($className) { $possible_file = 'classes/' . strtolower($className) . '.php'; echo 'Autoloader called for ' . $className . '<br />'; if(file_exists($possible_file)) { require_once($possible_file); }...