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
1
vote
1 answer

Composer autoloading namespace error

I have been playing around with Slim 3 and Doctrine but haven't made much progress as I can't for the life of me work out why this isn't working. Project Structure: -src |-App |-index.php |-Entity |-User.php …
cosmicsafari
  • 3,949
  • 11
  • 37
  • 56
1
vote
1 answer

psr-4 how to load files without class / namespace

I have a bunch of php files each file contains one function no class no namespace just global functions. How can I load those files easily with composer? with psr-4 autoloader or any similar option so I don't have to require() all the time all…
Toskan
  • 13,911
  • 14
  • 95
  • 185
1
vote
0 answers

PHP Singleton class with PSR standards

I need your help. I create Singleton class to manipulate with multidimensional arrays. So I want you to review my class and add some recomendations about it. The logic is working good, but now I am learning how to write a clear code with PSR…
1
vote
1 answer

How to use the PSR-4 autoload in my /Classes/ folder?

I've tried multiple PSR-4 loaders, but they either don't work or I can't access the classes from another folder. My current folder structure: -Classes --Config.php --Session.php --Frontend (folder) ---Login.php PSR-4 Autoloader: I tried to load…
Stefan R
  • 404
  • 2
  • 8
  • 30
1
vote
2 answers

PSR4 Composer Autoload Fatal error: Trait not found

I'm attempting to implement this error handling class into my php website https://github.com/niteshapte/advanced-error-exception-handler-logger-php but I keep getting the error PHP Fatal error: Trait 'SingletonTrait' not found in…
Damian
  • 1,652
  • 4
  • 26
  • 44
1
vote
0 answers

Composer autoloader doesn't load class when I use variable

I've used autoloader from composer. Everything is fine when I set class name directly object; $method = $router->method; $id = $router->id; $action = new Accounts(); It…
Piotr
  • 11
  • 3
1
vote
2 answers

How to have "dashes" in filenames in ZendFramework 1.12

I have seen a few posts regarding this question but none were answered to the topic on which they were asked. I have a ZendFramework project (v 1.12) and I want to do some changes in the file naming conventions. The files and folders are named in…
Ashish Ranjan
  • 12,760
  • 5
  • 27
  • 51
1
vote
1 answer

Composer PSR-4 for php file

In my project I have a folder lib\custom which contains Web folder and functions.php file. In my functions.php I have some functions which I need to use in another classes and in this file on the first line I have a defined namespace look like…
Yur Gasparyan
  • 664
  • 5
  • 20
1
vote
1 answer

class not found : recursive reflection to inject dependency

I am trying to understand some advanced concept of mvc architecture in php,like autoload with psr-4 and dependency injection container.I made a dependency injection container and load classes using composer autoload. Whenever i run this code i get…
AL-zami
  • 8,902
  • 15
  • 71
  • 130
1
vote
1 answer

Class not being autoloaded

I've made a little library for myself and I'm trying to autoload it into my laravel project, it installs fine but whenever I try to use the class it simply says it's not found. I've checked all the classmap files in vendor/composer and it doesn't…
Nathan
  • 534
  • 1
  • 5
  • 13
1
vote
1 answer

PSR-4 autoloading trouble

I want to load HomeController class from lib directory: root/ -lib/ --/HomeController.php -vendor/ -composer.json -index.php Composer.json "autoload": { "psr-4": { "Lib\\": "lib/" } } HomeController.php namespace Lib; class…
Doc999tor
  • 190
  • 3
  • 15
1
vote
1 answer

Slim3 - Container: Class not found

My source code structure: src controllers controller.php Auth AuthController.php User UserController.php models composer.json: "autoload": { "psr-4": { "App\\": "src/" } }, AuthController.php:
Jurid
  • 35
  • 5
1
vote
1 answer

Composer specifying 'in development' packages?

I am working on a project with multiple local git repositories that tie together into a single app. Pretty much like Symfony has different components our app is split up similarly. My question is, what is the proper way to link to these packages? I…
Stephan-v
  • 19,255
  • 31
  • 115
  • 201
1
vote
2 answers

require_once can't load existing file on Windows 10 (works on Linux)

There is a mysterious problem with our autoloader: function psr4_default_autoload( $class ) { // project-specific namespace prefix $prefix = 'basefolder\\'; // base directory for the namespace prefix $base_dir = SOURCE_DIR . '/'; …
Tekay37
  • 467
  • 5
  • 18
1
vote
1 answer

How, if possible, to configure PHPSpec with no namespace and psr-4

I'm adding composer and PHPSpec to an established proprietary framework but I am unable to get PHPSpec to work with the global namespace when the classes to be tested reside in a non-standard directory which must be defined using psr-4. The file…
ThisLeeNoble
  • 150
  • 9