FAQ Database Discussion Community


PHP Composer Autoloader Simple Structure

php,composer-php,autoloader,psr-4
I have Composer working and I'd like to use its autoloader to load my classes, but it's not working. Here's my directory structure. I'm keeping it really simple to start with. index.php composer.json Vendor controllers/webgl.php Inside webgl.php I have: namespace controllers; class webgl { public function lesson1() { } }...

Is it possible use multiple classes under the same namespace, in the same file

php,oop,namespaces,psr-4
Is it possible use multiple classes under the same namespace, in the same file? I want to do something like this: <?php namespace MyNamespace\Helpers\Exceptions use Exception; class CustomException1 extends Exception{} class CustomException2 extends Exception{} class CustomException3 extends Exception{} to avoid using one single file for each custom exception class. The...

How to add Twig in namespaced project with psr-4 autoloader

twig,composer-php,psr-4
Here is my project's structure: app/ Life/ Forms Formhandler.php Page Pagehandler.php start.php vendor/ composer/ autoload.php index.php The index.php requires start.php which then requires the composer autoload.php: //start.php <?php require_once __DIR__ . '/../vendor/autoload.php'; This is a working structure, until I added Twig into the composer. Here's is what my composer.json looks...

Composer not composing - saying file not found

php,composer-php,psr-4
I'm using the excellent phpwkhtmltopdf library and want to update to latest version and for this I need to use composer. File structure: vendor --mikehaertl --php-shellcommand --php-tmpfile autoload.php Composer.json file: { "name": "mikehaertl/phpwkhtmltopdf", "description": "A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface", "keywords":...

autoloading nested classes with composer

php,namespaces,psr-0,psr-4
I have created a very basic validator class. My base code is in a my src/ folder, which gets autoloader with "kevdotbadger\\Validator\\": "src/" this works fine, so that when I instantiate a new "kevdotbadger\Validator\ Validator is gives me src/Validator.php My Validator.php class then loads a bunch of sub-classes in my...

psr-4 autoloading not working in Laravel 4

php,laravel,laravel-4,psr-4
I'm trying to create a directory to store custom classes, so I create the directory app/ArgumentClub/Transformers, and the class UserTransformer.php in that folder. I then autoload with: "autoload": { "classmap": [ "app/commands", "app/controllers", "app/models", "app/database/migrations", "app/database/seeds", "app/tests/TestCase.php" ], "psr-4": { "ArgumentClub\\": "app/ArgumentClub" } }, And run composer dump-autoload. And namespace...

PSR 4 autoload not finding class

php,composer-php,psr-4
I'm not sure why my PSR-4 auotloader isn't working. My composer.json file is simply { "require" : { "abraham/twitteroauth" : "*" }, "autoload" : { "psr-4" : {"Filters\\" : "src"} } } My PHP file, which is located in src/Filters namespace Filters; class BlogFilter { public function __construct() { return...