psr-4

How does PSR-4 autoloading work in composer for custom libraries?

故事扮演 提交于 2019-12-01 15:11:16
问题 I use the following directory structure based on my understanding of how namespaces in PHP work: project_root app/ | lib/ | | MyCompany/ | | | Utility/ | | | | Logger.php | | | Core/ | | | | User.php vendor/ composer/ symfony/ guzzle/ bootstrap.php composer.json According to the PSR-4 specification, a fully qualified class name has the following form: \<NamespaceName>(\<SubNamespaceNames>)*\<ClassName> Question 1: From my directory structure above, is the assumption below correct?

How to change app folder name in laravel 5

僤鯓⒐⒋嵵緔 提交于 2019-12-01 14:38:39
I want to change main folder [app] to author name in laravel 5 how can I do that can I do that without change anything in autoloader or composer ? You will have an entry on your composer.json file named "psr-4", inside change it to your new renamed directory. "autoload": { "classmap": [ "database" ], "psr-4": { "App\\": "your_new_directory/" } }, Then in command line run: $ composer dump-autoload Or $ php composer.phar dump-autoload 来源: https://stackoverflow.com/questions/34180918/how-to-change-app-folder-name-in-laravel-5

How to change app folder name in laravel 5

落花浮王杯 提交于 2019-12-01 12:28:02
问题 I want to change main folder [app] to author name in laravel 5 how can I do that can I do that without change anything in autoloader or composer ? 回答1: You will have an entry on your composer.json file named "psr-4", inside change it to your new renamed directory. "autoload": { "classmap": [ "database" ], "psr-4": { "App\\": "your_new_directory/" } }, Then in command line run: $ composer dump-autoload Or $ php composer.phar dump-autoload 来源: https://stackoverflow.com/questions/34180918/how-to

PHP PSR-4 Autoloader 自动加载(中文版)

霸气de小男生 提交于 2019-12-01 00:30:51
Autoloader 关键词 “必须”("MUST")、“一定不可/一定不能”("MUST NOT")、“需要”("REQUIRED")、 “将会”("SHALL")、“不会”("SHALL NOT")、“应该”("SHOULD")、“不该”("SHOULD NOT")、 “推荐”("RECOMMENDED")、“可以”("MAY")和”可选“("OPTIONAL")的详细描述可参见 [RFC 2119][] 。 1. 概述 本 PSR 是关于由文件路径 自动载入 对应类的相关规范, 本规范是可互操作的,可以作为任一自动载入规范的补充,其中包括 PSR-0 ,此外, 本 PSR 还包括自动载入的类对应的文件存放路径规范。 2. 详细说明 此处的“类”泛指所有的class类、接口、traits可复用代码块以及其它类似结构。 一个完整的类名需具有以下结构: \<命名空间>(\<子命名空间>)*\<类名> 完整的类名 必须 要有一个顶级命名空间,被称为 "vendor namespace"; 完整的类名 可以 有一个或多个子命名空间; 完整的类名 必须 有一个最终的类名; 完整的类名中任意一部分中的下滑线都是没有特殊含义的; 完整的类名 可以 由任意大小写字母组成; 所有类名都 必须 是大小写敏感的。 当根据完整的类名载入相应的文件…… 完整的类名中,去掉最前面的命名空间分隔符

Is it possible use multiple classes under the same namespace, in the same file

跟風遠走 提交于 2019-11-30 17:40:30
Is it possible use multiple classes under the same namespace, in the same file? I want to do something like this: <?php namespace MyNamespace\Helpers\Exceptions use Exception; class CustomException1 extends Exception{} class CustomException2 extends Exception{} class CustomException3 extends Exception{} to avoid using one single file for each custom exception class. The problem is, when I try to use, in another class, one of the custom exceptions, use MyNamespace\Helpers\Exceptions\CustomException1; the CustomException1 class is not found. Any ideas? I don't think there's anything

Using classes without namespace with Yii2

倾然丶 夕夏残阳落幕 提交于 2019-11-30 08:57:42
问题 I want to use Checkout SDK with Yii2 but since this library does not support PSR-4 standards (namespaces) I am having trouble to integrate it. How can I use this library for my purpose? EDIT As suggested I tried to use class as $sale = new \Twocheckout_Sale(); but still I am unable to make it work. 回答1: When the class does not have namespace it means it's in the root namespace. Option 1: use Twocheckout; ... Twocheckout::format('json'); Option 2: \Twocheckout::format('json'); For example,

PSR-4 autoloading with Composer

允我心安 提交于 2019-11-30 08:34:27
I run a portail with composer's autoloading class system: "autoload": { "psr-4": { "Portal\\": "src/" } } It works when I run composer.phar dump -o , for instance my class Boostrap is well referenced into vendor/composer/autoload_classmap.php file: 'Portal\\Core\\Bootstrap' => $baseDir . '/src/core/Bootstrap.php', But when I don't run the optimized option on autoload dumping, the autoloading system doesn't works anymore: Fatal error: Class 'Portal\Core\Bootstrap' not found in /var/www/portail/prod/web/index.php on line 7 How can I make autoloading works without -o option? sectus There are two

PSR-4 autoloading with Composer

我怕爱的太早我们不能终老 提交于 2019-11-29 11:54:53
问题 I run a portail with composer's autoloading class system: "autoload": { "psr-4": { "Portal\\": "src/" } } It works when I run composer.phar dump -o , for instance my class Boostrap is well referenced into vendor/composer/autoload_classmap.php file: 'Portal\\Core\\Bootstrap' => $baseDir . '/src/core/Bootstrap.php', But when I don't run the optimized option on autoload dumping, the autoloading system doesn't works anymore: Fatal error: Class 'Portal\Core\Bootstrap' not found in /var/www/portail

Using classes without namespace with Yii2

旧街凉风 提交于 2019-11-29 09:33:45
I want to use Checkout SDK with Yii2 but since this library does not support PSR-4 standards (namespaces) I am having trouble to integrate it. How can I use this library for my purpose? EDIT As suggested I tried to use class as $sale = new \Twocheckout_Sale(); but still I am unable to make it work. arogachev When the class does not have namespace it means it's in the root namespace. Option 1: use Twocheckout; ... Twocheckout::format('json'); Option 2: \Twocheckout::format('json'); For example, PHPExcel extension also doesn't have namespaces, similar question was answered on official forum .

Why use a PSR-0 or PSR-4 autoload in composer if classmap is actually faster?

大憨熊 提交于 2019-11-26 15:12:06
I understand that you can use either a PSR standard to locate files, or tell composer a directory to scan for classes. The documentation recommends using the PSR-4 standard. There is also an option for composer to create an optimized autoloader, which basically generates a full classmap . So why should one use PSR-4 at all if the best way to load is with a classmap? It makes sense to me to keep the directory structure, since that is a good way to organize anyway. However, it seems like the logical option would be to use PSR-4 loading on development machines, and then classmap for the