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
4
votes
2 answers

PSR-2. When to capitalize directories?

As I understood according to PSR-2 standard we should capitalize directory names which contain classes. But how to do if the directory also contains some other files, for example styles and scripts? Say I have a plugin directory, each plugin can…
ymakux
  • 3,415
  • 1
  • 34
  • 43
4
votes
1 answer

PSR 4 autoload not finding class

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…
user9418
  • 395
  • 2
  • 4
  • 13
4
votes
1 answer

autoload psr-4 gets lost during install

this is the composer.json of my bundle (shortened) { "name": "acme/my-bundle", "type": "library", "version": "0.5.0", "autoload": { "psr-4": { "Acme\\MyBundle\\": "" } } } and in my…
auipga
  • 300
  • 3
  • 10
4
votes
1 answer

Laravel, using packages with PSR-4 gives message "No hint path defined for"

Im using Laravel 4.1 and starting a package (subby) that is using PSR-4 standard. When I try to render any view with: return View::make('subby::user.login'); I get the message: No hint path defined for [subby] I've red many things, but those were…
Gonçalo Queirós
  • 1,193
  • 2
  • 9
  • 19
3
votes
1 answer

php+symfony 5.0.x autoload issue when extending abstract class and implementing interface simultaneously

I have a symfony 5 project. And I faced a problem with autoloading. I use default autoloading configuration, provided by the framework. I have class, abstract class and interface defined in the same directory under the same namespace. The problem…
Sergej
  • 2,030
  • 1
  • 18
  • 28
3
votes
2 answers

Composer PSR-4 autoloading "class not found" debug

Yes another question about the "class not found" error. Either I am missing something, or I misunderstood the PSR-4 logic. My composer library directory sturcture: "Scanner" => "src" => "Test.php" Test.php namespace MyNS; class…
Digital Human
  • 1,599
  • 1
  • 16
  • 26
3
votes
1 answer

Class not found when using PSR-4 Autoload in Linux, works in Windows

Introduction Hello, I moved my files from my local pc, running WAMP to my webserver, which is a Linux machine. I work with composer to use its autoload functionality to load my MVC structure, more about that later. The error that I receive on my…
GodOfNeoN
  • 45
  • 7
3
votes
1 answer

Disambiguating a PHP namespace used by two vendors

I have two composer packages in my app that are creating a namespace collision in a third party module. I'm trying to determine the least disruptive way to disambiguate within the third party module so that I don't have to fork the packages. First…
Ryan
  • 53
  • 4
3
votes
3 answers

Avoid to require vendor/autoload.php in every file

I'm currently learning about autoload in php using composer and psr-4. i have successfully configured my composer.json and i can access classes using namespaces. Now, the problem is that i have to include vendor/autoload.php in every file that i…
3
votes
1 answer

How to autoload from root namespace?

Trying the following config to load my models from root namespace failed. any alternative? "autoload": { "psr-4": { "\\": "app/Models" } }, The following works but I have to run dumpautoload each time I create a new…
Handsome Nerd
  • 17,114
  • 22
  • 95
  • 173
3
votes
2 answers

Validate PSR-4 file/class structure (painless migrate to PSR-4)

I have a composer package that is used in internal projects. Historically all classes in this package were autoloaded via "autoload": { "classmap": ... } and have not been structured. Now I want to migrate to PSR-4. I reordered all files and…
cronfy
  • 1,001
  • 1
  • 15
  • 32
3
votes
0 answers

Laravel - Class not found in Package (only on Linux)

I created a package of name Getbit\Emojione and set in composer.json, from Laravel root project. In package folder I added some classes and defined the psr-4 This is the Client Class The problem happens in the line 19, I get a Class Not Found,…
Michel Andrade
  • 4,056
  • 5
  • 27
  • 28
3
votes
0 answers

how to use composer in opencart 2.2.0

So, based on Opencart 2.2.0 installation guide : From version 2.2 composer has been added to aid developers who want to use composer libraries. 2 versions of OpenCart will become available, one compiled and one non-compiled (composer.json only…
Fatimah Wulandari
  • 307
  • 2
  • 5
  • 16
3
votes
1 answer

How do you properly test a Composer package during development?

Update / My Solution: I accidentally didn't remove the VCS require from my composer.json before testing with the "autoload" key. It's now my understanding (based on what just happened) that the autoload section of composer.json is processed at…
Eric Dubé
  • 472
  • 1
  • 4
  • 12
3
votes
1 answer

Laravel custom package loading issue

I have a small problem. I'm trying to make a Laravel package , but it won't load. Whenever I try adding it's provider in the config/app.php, I get: Error class 'Something\HttpRequest\HttpRequestServiceProvider' not found At the moment it has just…
overburn
  • 1,194
  • 9
  • 27