当前位置:K88软件开发文章中心编程工具Composer → 文章内容

Composer 架构

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-24 10:15:07

", "acme/foo": "@dev" }}如果你的依赖之一,有对另一个不稳定包的依赖,你最好在 require 中显示的定义它,并带上足够详细的稳定性标识。实例:{ "require": { "doctrine/doctrine-fixtures-bundle": "dev-master", "doctrine/data-fixtures": "@dev" }}require 和 require-dev 还支持对 dev(开发)版本的明确引用(即:版本控制系统中的提交编号 commit),以确保它们被锁定到一个给定的状态,即使你运行了更新命令。你只需要明确一个开发版本号,并带上诸如 #<ref> 的标识。实例:{ "require": { "monolog/monolog": "dev-master#2eb0c0978d290a1c45346a1955188929cb4e5db7", "acme/foo": "1.0.x-dev#abc123" }}注意: 虽然这有时很方便,但不应该长期在你的包中使用,因为它有一个技术上的限制。 composer.json 将仍然在哈希值之前指定的分支名称读取元数据, 正因为如此,在某些情况下,它不会是一个实用的解决方法, 如果可能,你应该总是尝试切换到拥有标签的版本。它也可以应用于行内别名,这样它将匹配一个约束,否则不会。更多信息请参考 别名。require必须的软件包列表,除非这些依赖被满足,否则不会完成安装。require-dev (root-only)这个列表是为开发或测试等目的,额外列出的依赖。“root 包”的 require-dev 默认是会被安装的。然而 install 或 update 支持使用 --no-dev 参数来跳过 require-dev 字段中列出的包。conflict此列表中的包与当前包的这个版本冲突。它们将不允许同时被安装。请注意,在 conflict 中指定类似于 <1.0, >= 1.1 的版本范围时,这表示它与小于1.0 并且 同时大等于1.1的版本冲突,这很可能不是你想要的。在这种情况下你可能想要表达的是 <1.0 | >= 1.1 。replace这个列表中的包将被当前包取代。这使你可以 fork 一个包,以不同的名称和版本号发布,同时要求依赖于原包的其它包,在这之后依赖于你 fork 的这个包,因为它取代了原来的包。这对于创建一个内部包含子包的主包也非常的有用。例如 symfony/symfony 这个主包,包含了所有 Symfony 的组件,而这些组件又可以作为单独的包进行发布。如果你 require 了主包,那么它就会自动完成其下各个组件的任务,因为主包取代了子包。注意,在使用上述方法取代子包时,通常你应该只对子包使用 self.version 这一个版本约束,以确保主包仅替换掉子包的准确版本,而不是任何其他版本。provideList of other packages that are provided by this package. This is mostly useful for common interfaces. A package could depend on some virtual logger package, any library that implements this logger interface would simply list it in provide.suggest建议安装的包,它们增强或能够与当前包良好的工作。这些只是信息,并显示在依赖包安装完成之后,给你的用户一个建议,他们可以添加更多的包。格式如下,版本约束变成了描述信息。实例:{ "suggest": { "monolog/monolog": "Allows more advanced logging of the application flow" }}autoloadPHP autoloader 的自动加载映射。Currently PSR-0 autoloading, PSR-4 autoloading, classmap generation and files includes are supported. PSR-4 is the recommended way though since it offers greater ease of use (no need to regenerate the autoloader when you add classes).PSR-4Under the psr-4 key you define a mapping from namespaces to paths, relative to the package root. When autoloading a class like Foo\\Bar\\Baz a namespace prefix Foo\\ pointing to a directory src/ means that the autoloader will look for a file named src/Bar/Baz.php and include it if present. Note that as opposed to the older PSR-0 style, the prefix (Foo\\) is not present in the file path.Namespace prefixes must end in \\ to avoid conflicts between similar prefixes. For example Foo would match classes in the FooBar namespace so the trailing backslashes solve the problem: Foo\\ and FooBar\\ are distinct.The PSR-4 references are all combined, during install/update, into a single key => value array which may be found in the generated file vendor/composer/autoload_psr4.php.Example:{ "autoload": { "psr-4": { "Monolog\\": "src/", "Vendor\\Namespace\\": "" } }}If you need to search for a same prefix in multiple directories, you can specify them as an array as such:{ "autoload": { "psr-4": { "Monolog\\": ["src/", "lib/"] } }}If you want to have a fallback directory where any namespace will be looked for, you can use an empty prefix like:{ "autoload": { "psr-4": { "": "src/" } }}PSR-0在 psr-0 key 下你定义了一个命名空间到实际路径的映射(相对于包的根目录)。注意,这里同样支持 PEAR-style 方式的约定(与命名空间不同,PEAR 类库在类名上采用了下划线分隔)。请注意,命名空间的申明应该以 \\ 结束,以确保 autoloader 能够准确响应。例: Foo 将会与 FooBar 匹配,然而以反斜杠结束就可以解决这样的问题, Foo\\ 和 FooBar\\ 将会被区分开来。在 install/update 过程中,PSR-0 引用都将被结合为一个单一的键值对数组,存储至 vendor/composer/autoload_namespaces.php 文件中。实例:{ "autoload": { "psr-0": { "Monolog\\": "src/", "Vendor\\Namespace\\": "src/", "Vendor_Namespace_": "src/" } }}如果你需要搜索多个目录中一个相同的前缀,你可以将它们指定为一个数组,例:{ "autoload": { "psr-0": { "Monolog\\": ["src/", "lib/"] } }}PSR-0 方式并不仅限于申明命名空间,也可以是精确到类级别的指定。这对于只有一个类在全局命名空间的类库是非常有用的(如果 php 源文件也位于包的根目录)。例如,可以这样申明:{ "autoload": { "psr-0": { "UniqueGlobalClass": "" } }}如果你想设置一个目录作为任何命名空间的备用目录,你

上一页  [1] [2] [3] [4]  下一页


Composer 架构