psr-4

PSR-4 autoloader Fatal error: Class not found

百般思念 提交于 2019-12-05 16:36:53
问题 I have my project structure like so: src/ ├─ Model/ └─ User.php My User.php file looks like this: <?php namespace Bix\Model; class User { And my composer.json autoloader is this: "autoload": { "psr-4": { "Bix\\": "src/" } } Finally my bootstrap.php is this: use Bix\Model\User; // PSR-4 Autoloader. require_once "vendor/autoload.php"; However if I try and create a new User() , I get the error Fatal error: Class 'User' not found in /var/www/public/api/v1/index.php on line 8 Looking at the

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

亡梦爱人 提交于 2019-12-05 12:54:11
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 usually typo problems The problem is in the usage of the PSR-4 Since Laravel default is PSR-0 it assumes that the resources (views etc) of a package will be 2 levels up from where the package service provider is. Ex: src ├── config ├── lang ├── migrations ├── Ghunti │ └── Subby │ └── SubbyServiceProvider.php ├── routes.php └── views └── user └── login

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

我的梦境 提交于 2019-12-05 12:16:56
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 per file: my_cool_function1.php my_cool_function2.php ... etc. How can I create a PSR-4 compliant library from them? The reason you're not able to find any documentation for PSR-4 autoloading files which aren't classes, that's because as the specification states - it's designed for autoloading classes. Taken directly from the official specs:

怎样开发一个满足 psr-4 规范的php 类库

亡梦爱人 提交于 2019-12-05 07:12:17
在网上找了很多文章了解 psr-4 ,却很难找到教你怎么去写一个符合 psr-4 规范的类库。也许是他们都比较了解之前的规范,所以基本都在讲其它方面的内容,唯独没有教你怎么写代码。 经过自己的摸索加实践,再参考别人的 类库,终于算是弄明白了这个事。 我发布了一个名为 "tansuo19/test" 的安装包,你可以直接通过 composer 来安装。它包括最基本的结构。 文件目录: test 文件夹 --src 文件夹,类文件放到这里 --log.php 类文件 -- composer.json 文件 composer.json 的内容: ( 建议通过 composer init 来生成 ) { "name": "tansuo19/test", "description": "just test", "license": "mit", "version":"0.1.2", "authors": [ { "name": "tansuo1989", "email": "huangui9@qq.com" } ], "autoload": { "psr-4": { "tansuo19test\\": "src/" } } } 这里需要注意的是把根命名空间定义到 src 所在目录,则 log.php 所在的命名空间就应该是 tansuo19test 。 并注意在 composer.json

Laravel psr-4 not autoloading

廉价感情. 提交于 2019-12-04 09:31:59
I have a Laravel project that works fine locally (Mavericks), but classes under psr-4 aren't loading on our stage server (CentOS). I'm getting a Reflection "class not found" error every time I try composer update, or run an artisan command. All my app-specific classes are stored in my Laravel project under app/heatherland, eg: app/heatherland/import/ImportJob.php (file contains HeatherLand\Import\ImportJob) My composer.json contains this entry: "autoload": { "classmap": [ "app/commands", ... "app/database/seeds", ], "psr-4": { "HeatherLand\\": "app/heatherland" } }, Locally, the psr-4 classes

PSR4 Composer Autoloading namespaces

会有一股神秘感。 提交于 2019-12-02 16:58:56
问题 I've been having a little play around with some Composer autoloading and i'm getting some issues so the directory structure is index.php app/ helpers/ router.php vendor/ composer/ /*usual files*/ autoload.php Inside my composer.json I have the following "autoload": { "psr-4": { "App\\": "app/" } } Inside my index.php I have <?php // Autoload our namespaces require __DIR__.'/vendor/autoload.php'; use App\Helpers\Router; $route = new Router; Getting the following error Fatal error: Class 'App

PSR4 Composer Autoloading namespaces

家住魔仙堡 提交于 2019-12-02 08:26:39
I've been having a little play around with some Composer autoloading and i'm getting some issues so the directory structure is index.php app/ helpers/ router.php vendor/ composer/ /*usual files*/ autoload.php Inside my composer.json I have the following "autoload": { "psr-4": { "App\\": "app/" } } Inside my index.php I have <?php // Autoload our namespaces require __DIR__.'/vendor/autoload.php'; use App\Helpers\Router; $route = new Router; Getting the following error Fatal error: Class 'App\Helpers\Router' not found in /var/www/public/index.php on line 6 I have tried a few different things to

Composer classmap and loading files with non-standard extensions

别说谁变了你拦得住时间么 提交于 2019-12-02 05:40:35
问题 When loading files through the composer classmap functionality is it possible to load PHP files that have non-standard extensions such as myFileName.stub or myFileName.foo ? At present it seems not to be loading them. 回答1: Composer will currently include files with the following extensions: .php .inc .hh The last one is for HHVM stuff. Relevant lines from the class map generator here: https://github.com/composer/composer/blob/master/src/Composer/Autoload/ClassMapGenerator.php#L62 https:/

Composer Gives Error, “Class Not Found”

青春壹個敷衍的年華 提交于 2019-12-02 00:26:42
问题 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 files in the root directory: composer.json: { "name": "myvendor/mypackage", "description": "nothing", "authors": [ { "name": "Omar Tariq", "email": "XXXXX@gmail.com" } ], "require": {}, "autoload": { "psr-4": { "myns\\": "src/" } } } run.php: <?php require

Composer Gives Error, “Class Not Found”

让人想犯罪 __ 提交于 2019-12-01 21:15:12
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 files in the root directory: composer.json: { "name": "myvendor/mypackage", "description": "nothing", "authors": [ { "name": "Omar Tariq", "email": "XXXXX@gmail.com" } ], "require": {}, "autoload": { "psr-4": { "myns\\": "src/" } } } run.php: <?php require_once __DIR__ . '/vendor/autoload.php'; use myns\childclass as childclass; $childclass = new childclass();