Questions tagged [psr-4]

PSR-4 describes requirements that must be adhered to for autoloader interoperability in PHP. PSR-4 is an alternative to PSR-0 that corrects problems discovered in real-world use.

Specification link:

Code and test samples:

308 questions
2
votes
1 answer

PSR4 not working

I have setup a folder structure like this for a package of legacy classes vendorname/legacy/src/ClassA.php namespace Vendorname\Legacy; class ClassA{} vendorname/legacy/src/Folder/Class2.php namespace Vendorname\Legacy\Folder; class…
jdog
  • 2,465
  • 6
  • 40
  • 74
2
votes
2 answers

How to keep seeder files separate and clean in laravel?

I want to keep my seeder files separate. for example UsersTableSeeder.php , PostsTableSeeder.php and then call them in main seeder file (DatabaseSeeder.php) : Example: use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder { …
Ahmad Mobaraki
  • 7,426
  • 5
  • 48
  • 69
2
votes
0 answers

PSR-4 Autoloading Class

I am adding some custom classes to a project. I am struggling to get psr-4 autoloading to work. I am placing my custom classes in a folder at [project root]/lib Here is the autoload bit from my composer.json: "autoload": { "psr-4": { …
Roger Creasy
  • 1,419
  • 2
  • 19
  • 35
2
votes
1 answer

How do I set up Doctrine 2 with multiple Entity Managers in one Project? (without Symfony/Zend)

Current Situation I am using Doctrine 2 (without Zend and Symfony) for accessing two different MySQL databases in my Project. I tried to create two EntityManager for each database one. The two bootstrap files are set up to use their own classes,…
h.kenny
  • 31
  • 8
2
votes
3 answers

PSR-4: Autoloader (composer) and extending namespaces ensuring fallback php

I am having a problem with my namespace fallbacks and using PSR-4 loader in Composer. What I am trying to do is this: Have a core which can overwritten / extended. The core is based off an interface. The directory structure is like…
2
votes
1 answer

How to implement a default routing behaviour with Lumen or Slim framework

I'm looking into using Lumen or possibly Slim for a project and wondered whether it was possible to autoload controllers based on directory structure rather than having to register all routes. This is how I would like the autoloading to work…
TarranJones
  • 4,084
  • 2
  • 38
  • 55
2
votes
1 answer

Composer PSR4 weird behavior

A while ago I created a twig extension. Recently I added a namespace so I could use it with composer more easily. I've done this a few times and it works fine with other files/classes. The problem is that it only autoloads properly if I use the -o…
Crecket
  • 718
  • 2
  • 7
  • 24
2
votes
1 answer

how can i include phpmailer 5.2 using composer?

I'm trying to instantiate the PHP mailer class which i've installed using composer. The class is located in vendor\phpmailer\phpmailer\class.phpmailer.php -Project -src -SmtpHandler.php -vendor -phpmailer -phpmailer …
Juakali92
  • 1,155
  • 8
  • 20
2
votes
1 answer

Php psr-4 Class not Found Error using Composer

I'm trying to exercise MVC concepts with php on "wamp-server" At local directory i have the index.php page for basic routing with alto-router package and a routes.php file: map('GET','/test', 'Acme\Controllers\PageController@test'…
user4412122
2
votes
1 answer

phpspec creates files in wrong folders per psr-4 namespace specification

I scrapped the earlier form of my question because it was too convoluted. Here's the new version. I want to use phpspec with my psr-4 formatted projects. Here's the way I tried to set up a test project: Created a new folder for the project: cd…
Chris Schmitz
  • 20,160
  • 30
  • 81
  • 137
2
votes
1 answer

PHP tests pass locally but fail on Travis CI using Composer, PSR-4 autoload

Could anyone help me understand the reasons that why these unit tests are failing at CI while they pass on local setup. The repository is at https://github.com/jabranr/test-ci The tests are at https://travis-ci.org/jabranr/test-ci The tests fail in…
Jabran Rafique
  • 335
  • 1
  • 4
  • 18
2
votes
1 answer

PSR-4 autoloading and namespace import not finding classes

I am trying to autoload the contents of src folder and use them in some unit tests . Here is the autoloading part of composer.json "autoload": { "psr-0": { "Meetup\\Login\\": "src/" } } There is a class called users in src/core…
Swaraj Giri
  • 4,007
  • 2
  • 27
  • 44
2
votes
2 answers

Making Legacy Application PSR-4 Compatible

I have a question with regards to refactoring a legacy PHP application to be compatible with PHP's PSR-4 standards. I have some classes located at app/classes/ folder which are not yet namespaced properly and I want them to be autoloaded directly…
2
votes
5 answers

Drupal Class not found

I'm trying to create a new module with a routing file pointing to a controller. But i get the following error in my logs ReflectionException: Class \Drupal\glue\Controller\GlueController does not exist in ReflectionMethod->__construct() (line 128…
Ian Droogmans
  • 65
  • 1
  • 8
2
votes
1 answer

Zend 1 not working with psr-4 namespaces

I am working on zend framework 1 But I want to use \ instead of _ Like class IndexController extends Zend_Controller_Action This is working fine but when I changed this by class IndexController extends \Zend\Controller\Action Then its giving me…
Kuldeep Raj
  • 791
  • 1
  • 7
  • 29