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
0
votes
1 answer

Namespacing not working, using composer psr-4

I am using slim framework, composer, and psr-4 autoload. This is in composer: "Shorty\\":"app/Shorty" Note: I tried the above also with "Shorty\\":"app/Shorty/Models" directorry structure: app/Shorty/Models/Trap.php Inside Trap.php: namespace…
TDawg
  • 833
  • 2
  • 8
  • 24
0
votes
2 answers

CakePHP3 Plugin autoload class

I'm making a CakePHP3 plugin and I'm using a library that I wrote that uses PSR-4 autoloading. If I require the library in the application's composer.json it autoloads correctly and I can use it anywhere in my app including the plugin. When I try…
Devin Crossman
  • 7,454
  • 11
  • 64
  • 102
0
votes
1 answer

autoloading nested classes with composer

I have created a very basic validator class. My base code is in a my src/ folder, which gets autoloader with "kevdotbadger\\Validator\\": "src/" this works fine, so that when I instantiate a new "kevdotbadger\Validator\ Validator is gives me…
dotty
  • 40,405
  • 66
  • 150
  • 195
0
votes
0 answers

PHP Include class by using "use" with PSR-4

I'm using PSR-4, I defined the psr-4 section on composer.json "autoload": { "classmap":[ ], "psr-4": { "App\\": "app/" } }, When I tried to import a class by using "use"…
0
votes
2 answers

PHP Composer Autoloader Simple Structure

I have Composer working and I'd like to use its autoloader to load my classes, but it's not working. Here's my directory structure. I'm keeping it really simple to start with. index.php composer.json Vendor controllers/webgl.php Inside webgl.php I…
tobuslieven
  • 1,474
  • 2
  • 14
  • 21
0
votes
0 answers

php composer reuse of modify package

Using composer, I have come across a package that does what I want, if I modify the constant values and some of the code in private methods. What I've been trying to do is create my own package and extend the other package that I've found and try to…
user9418
  • 395
  • 2
  • 4
  • 13
0
votes
0 answers

How to load controller / create router for php mvc framework

I am writing a light weight php mvc framework for my portfolio and as a barebone setup for my future developments. I am stuck now because I am trying to use PSR-4 autoloader through composer. I understand the concept of PSR-4 etc but I am wondering…
user2302045
0
votes
1 answer

psr-4 changes to working examples do not work

I have to achieve that all sources are inclueded like this $instance = new \d1\d2\d3\app\MyClass(); Where d1\d2\d3\ points to the root directory. I have read the basics on https://getcomposer.org/doc/04-schema.md#psr-4 and on…
Juri Sinitson
  • 1,445
  • 1
  • 14
  • 18
0
votes
1 answer

Best way to define path in PHP

This is my piece of code define('BASE_PATH', realpath(__DIR__) . DIRECTORY_SEPARATOR); define('LIB', BASE_PATH . 'lib' . DIRECTORY_SEPARATOR); define('FRAMEWORK', LIB . 'framework' . DIRECTORY_SEPARATOR); define('DATABASE', FRAMEWORK .…
Terry Djony
  • 1,975
  • 4
  • 23
  • 41
0
votes
1 answer

Using Composer Autoloader with PSR-4

I'm looking at examples, and I cannot get my code to work. Directory Structure app src company FileExport FileExport.php FileExportInterface.php Validator vendor ... My…
nobrandheroes
  • 748
  • 1
  • 10
  • 17
0
votes
2 answers

How to use PSR-4 in methods with PHP

Excuse me guys I am trying to use PSR-4 into my PHP project until now I have only one problem; If I only use classes
user4727469
0
votes
1 answer

How to add Twig in namespaced project with psr-4 autoloader

Here is my project's structure: app/ Life/ Forms Formhandler.php Page Pagehandler.php start.php vendor/ composer/ autoload.php index.php The index.php requires start.php which then requires the…
shaNnex
  • 1,043
  • 2
  • 19
  • 34
0
votes
1 answer

psr-4 autoloading not working in Laravel 4

I'm trying to create a directory to store custom classes, so I create the directory app/ArgumentClub/Transformers, and the class UserTransformer.php in that folder. I then autoload with: "autoload": { "classmap": [ "app/commands", …
babbaggeii
  • 7,577
  • 20
  • 64
  • 118
0
votes
1 answer

Autoloading with PSR4 naming in php

I have following library structure C:\WWW\WEBS | users.php | \---lib | Api.php | Server.php | TimeSync.php | \---TimeSync Ntp.php Protocol.php Sntp.php In server.php I have…
alwaysLearn
  • 6,882
  • 7
  • 39
  • 67
0
votes
1 answer

PSR-4 autoloading not working - cannot find class

I'm trying to split up a long file into smaller chunks, so I created an src folder, and am trying to reference it from the main Extension.php file (which loads and works fine, by the way). So, I add the src folder to the psr-4 autoloading…
babbaggeii
  • 7,577
  • 20
  • 64
  • 118