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

Slim Framework PSR 4 with Controllers

I am making an application based on Slim Framework. I am following PSR 4 pattern. This application is basically dealing with RESTful services. To make it more flexible for future we have adopted to use a different approach than conventional slim…
2
votes
1 answer

Composer not composing - saying file not found

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":…
StudioTime
  • 22,603
  • 38
  • 120
  • 207
2
votes
0 answers

How to structure directory for PSR-4 autoloading?

According to PSR-4 autoloading, a fully qualified class name has the following form: \(\)*\ So this could be my class, namespace MyNamespace\Controller; class Foo { public $message = 'hello…
oasis
  • 197
  • 2
  • 13
2
votes
1 answer

How to use Composer to load php classes from local repository?

I am new to Php and composer, I want to access a Php class to another module using composer, This is my basic project structure (two modules common and worker) index.php TestLocalRepository --/Souce Files --/common --/vendor …
Aditya Kamat
  • 149
  • 1
  • 9
2
votes
3 answers

How do I call Validator from a namespace with an already existing Validator class

I'm trying to test a function in phpspec which calls Laravel's Validator::make function (http://laravel.com/docs/4.2/validation) However, I'm trying to call that same function from a namespace where the Validator class name is already taken. How can…
A F
  • 7,424
  • 8
  • 40
  • 52
2
votes
1 answer

ReflectionException Class does not exist psr-4

I'm fairly new to laravel and have encountered a problem with the psr-4 autoloading in my application. My folder structure: -app -config -controllers -UsersController -Mynamespace -User.php My composer.json file: "autoload": { …
WaffleBoy
  • 51
  • 1
  • 1
  • 3
1
vote
0 answers

Laravel Factory and Model relation when models have specific path

I have a project where laravel was migrated from 7 to 9 version Models are stored in app/v2/ folder Factories are stored in database/factories/v2 folder In my composer I have "psr-4": { "MyApi\\": "app/", "Database\\Factories\\":…
1
vote
0 answers

Fallback location for a namespace Laravel

I have a library that I am autoloading in my Laravel project and I want to have a fallback for that library. The reason is that on some systems, the library will be on a different location (depending on the development/production mode) For e.g. this…
M.Imran Mamda
  • 394
  • 1
  • 2
  • 13
1
vote
0 answers

PHP: Class not found despite autoloading

I am using the ps-4 autoloader using Composer. "autoload": { "psr-4": { "App\\":"app/", "Database\\":"database/" } }, So, I have the main index.php file in the root directory like this require 'vendor/autoload.php'; use…
Saeesh Tendulkar
  • 638
  • 12
  • 30
1
vote
1 answer

Symfony's vendors causing autoloader psr-4 warnings when running composer

For years, I have been getting these warning whenever I run composer install: Generating optimized autoload files (authoritative) Class Sensio\Bundle\FrameworkExtraBundle\Tests\DependencyInjection\AddParamConverterPassTest located…
Ignas Damunskis
  • 1,515
  • 1
  • 17
  • 44
1
vote
1 answer

Laravel package development - Target class [ControllerName] does not exist

I'm following a tutorial on how to create laravel packages. I'm using Laravel v8.42.1 (PHP v7.4.3) and jetstream package. I'm stuck on creating a controller for my package, I always get following error when trying to connect to my url via the…
bramdc
  • 580
  • 1
  • 5
  • 21
1
vote
2 answers

"does not comply with psr-4 autoloading standard." What am i doing wrong in this case?

Class Database\Factories\Tasks\UserFactory located in ./database/factories/tasks/UserFactory.php does not comply with psr-4 autoloading standard. Skipping. This is my php file:
João Hamerski
  • 461
  • 1
  • 5
  • 22
1
vote
1 answer

Plugin loaded but category in dropdown not loaded

I am using Shopware 6. I would like to add a category in the dropdown of the Shopping Experiences and save my custom elements there. So I've made a plugin and added the corresponding code. My composer.json { "name": "company/company-elements", …
wpwa_pg
  • 31
  • 5
1
vote
0 answers

Symfony 5 Bundle namespace autoload failed

I create a bundle like this
1
vote
0 answers

Get Userfrosting / Slim to work with Controller Class

I'm completly new to the MVC pattern and I find it really hard to understand without programming, so I set up the Userfrosting Framework which is based on Slim. I followed this tutorial and I could see the default starting page, log in, etc. Now I…
Standard
  • 1,450
  • 17
  • 35