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
8
votes
5 answers

Composer autoload - load class from parent directory

I'm currently working on a Laravel project that needs to access classes from its parent directory. composer.json > PSR-4: "psr-4": { ... "ModuleA\\": "../ModuleA/baseObjects", "ModuleB\\": "../ModuleB/baseObjects" …
davidvnog
  • 654
  • 2
  • 11
  • 33
8
votes
1 answer

Composer Gives Error, "Class Not Found"

I'm using Windows 10. After making a folder src in the root directory I created two files in it. Directory Structure (Before running composer install): │ ├── composer.json ├── run.php │ └── src ├── childclass.php └── parentclass.php Two…
Omar Tariq
  • 7,536
  • 10
  • 38
  • 57
7
votes
2 answers

How to use composer psr-4 fallback correctly

I have one directory that is going to keep all "helper" classes and functions. Let's call the directory helpers. I want to configure PSR-4 fallback directory to point to this helpers directory: "autoload": { "psr-4": { …
7
votes
2 answers

Make PhpStorm perform case sensitivity consistency check for namespaces and paths?

I am developing a web application using PhpStorm on OSx. I'm using Composer and have PSR-4 autoloading configured in composer.json. Everything is working fine on my development machine, but autoloading breaks when I upload to the production server…
Magnus
  • 17,157
  • 19
  • 104
  • 189
7
votes
1 answer

PHP - PSR-4: Autoloader (composer) and multiple namespaces with the same root

Currently all my classes are in one folder and are under one namespace: "psr-4": { "RootNamespace\\": "lib/" }, This is working well. As I'm adding more and more classes, I would like to put some logically related classes into deeper namespace…
kkochanski
  • 2,178
  • 23
  • 28
7
votes
3 answers

Why specify the namespace when using psr-4 autoloading with Composer?

I'm a little confused with how I should be using psr-4 autoloading in Composer. Let's say I've got a folder structure like this: / |- Core/ | - Router.php |- App/ | - Models | User.php |- composer.json Basically, in the project root:…
Dave Hollingworth
  • 3,670
  • 6
  • 29
  • 43
7
votes
2 answers

Call to undefined method Composer\\Autoload\\ClassLoader::setPsr4()

I have a project that have multiple subfolders. In one of the folders they are some "addons". All of these addons have a composer.json and a vendor-folder. I now wanted to build my own addon and created a new folder and put a composer.json into that…
Musterknabe
  • 5,763
  • 14
  • 61
  • 117
7
votes
1 answer

Namespaces not working with Codeception (Yii2)

Im using Codeception in Yii2 to make acceptance tests and there's no way to access my models because namespaces are not working into these tests. I have this in my tests/_bootstrap.php require(__DIR__ . '/../vendor/autoload.php'); require(__DIR__…
VictorArcas
  • 630
  • 2
  • 7
  • 23
6
votes
1 answer

Need to dump autoload to everytime I add a new class

I need to dump my autoloader every time I add a new class. I am using psr-4. I don't really know why I need to do so. In psr-4 it should automatically load the classes. Where am I going wrong? Here's my composer.json file {"autoload": {"psr-4":…
Pritam Bohra
  • 3,912
  • 8
  • 41
  • 72
6
votes
2 answers

PSR-4 directory structure and namespacing for a set of functions?

I have a set of PHP functions that I find useful. I want to create a PSR-4 compliant repository for them, but the guides I have found (1,2,3) seem to talk only about classes for autoloading. For instance, my files are as follows, with one function…
user151841
  • 17,377
  • 29
  • 109
  • 171
6
votes
1 answer

Composer autoloading psr-4 not adding namespace to autoload_psr4.php

I am using in a project a custom repository in github that contains my set of instruments. The project correctly imports the package inside the /vendor directory,but i cannot use any of the class, because it is not autoloading the contents of the…
Stormsson
  • 1,391
  • 2
  • 16
  • 29
6
votes
2 answers

PSR-4 autoloading not working

I have created an app/modules directory and autoloaded it using PSR-4 like this: "psr-4": { "Modules\\": "app/modules" } And I also did composer dumpautoload. I have the following directory structure: app - ... - modules -- ModuleName ---…
SUB0DH
  • 5,130
  • 4
  • 29
  • 46
5
votes
1 answer

Composer optimization level 1

On Composer's autoload optimization page: Note: You should not enable any of these optimizations in development as they all will cause various problems when adding/removing classes. The performance gains are not worth the trouble in a development…
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
5
votes
2 answers

Composer psr-4 autoload not working after deployment

I have my own little MVC framework and I use composer psr-4 autoloading. On my own computer it works perfectly fine, but when I deployed it to my Ubuntu server it did not work anymore. (it doesn't find any classes anymore) I have tried a lot of…
Luuk Wuijster
  • 6,678
  • 8
  • 30
  • 58
5
votes
1 answer

Composer PSR-4 Autoload class not found

I have been beating my head for a couple hours trying to figure out why the autoload is not working for "Authentication\auth()". The "dBase\db()" class is loading just fine, but i'm getting: Error: Class 'Authentication\auth' not found in …
Jaxchief
  • 146
  • 3
  • 10
1
2
3
20 21