gooh / interface-distiller
此包已被废弃,不再维护。未建议替代包。
从类API中推导接口
dev-master
2014-11-01 12:08 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2019-09-05 09:53:31 UTC
README
InterfaceDistiller 允许您从类的API中推导接口。
基本用法示例
Interface Distiller 可以通过以下方式使用:a) 程序化,b) 通过Builder或c) 通过命令行。程序化使用提供最大的灵活性,但通常不需要。Builder提供了配置接口蒸馏的方便方式。命令行界面是Builder的包装,提供了相同的功能。
示例 1 - 使用Builder
<?php $distiller = new InterfaceDistiller; $distiller ->methodsWithModifiers(\ReflectionMethod::IS_PUBLIC) ->extendInterfaceFrom('Iterator, SeekableIterator') ->excludeImplementedMethods() ->excludeInheritedMethods() ->excludeMagicMethods() ->excludeOldStyleConstructors() ->filterMethodsByPattern('(^get)') ->saveAs(new SplFileObject('MyInterface.php')) ->distill('SomeFoo', 'MyInterface');
除了distill
和reset
方法外,所有其他公共方法都提供了流畅的接口。调用distill
将根据指定的类和配置创建一个新的接口。源类不会以任何方式改变(不是提取)。随后的distill
调用将使用相同的配置,除非调用了reset
。
示例 2 - 使用命令行界面
要使用命令行界面,您必须先运行build/create_phar.php
来构建之前的phar文件。
Usage: phpdistill [options] <classname> <interfacename>
--bootstrap Path to File containing your bootstrap and autoloader
--methodsWithModifiers <number> A ReflectionMethod Visibility BitMask. Defaults to Public.
--extendInterfaceFrom <name,...> Comma-separated list of Interfaces to extend.
--excludeImplementedMethods Will exclude all implemented methods.
--excludeInheritedMethods Will exclude all inherited methods.
--excludeMagicMethods Will exclude all magic methods.
--excludeOldStyleConstructors Will exclude Legacy Constructors.
--filterMethodsByPattern <pattern> Only include methods matching PCRE pattern.
--saveAs Filename to save new Interface to. STDOUT if omitted.
命令行界面要求您在--bootstrap
选项中设置引导文件的路径。您的引导文件应包含所有必要的逻辑,包括您希望从中推导接口的任何类,例如自动加载器、包含路径等。如果没有这些,您将只能从原生类中蒸馏。
如果您通过Composer包管理器安装了InterfaceDistiller,命令行工具将尝试在vendor目录中包含自动加载器。
命令行界面将在每次调用之间重置配置。这意味着您需要为每个要从中蒸馏接口的类指定完整的配置。
示例 3 - 使用程序化方法
可以在示例文件夹中找到一个程序化示例。一般来说,您只有在需要添加、修改或替换内部组件时才需要这种方法。