manuwhat/shortcut

Shortcut - 类实例化快捷设计器

v1.0.1 2019-04-06 16:57 UTC

This package is auto-updated.

Last update: 2024-09-19 10:40:13 UTC


README

Build Status Scrutinizer Code Quality Build Status Code Intelligence Status

创建类实例化自定义快捷的库。

要求: PHP 5.3+

为什么要为 PHP 类实例化创建快捷方式?

通常您会为类实例化创建快捷方式,如果

  1. 您需要更定制化的功能,就像 PHP 使用 array() 函数创建数组一样。
  2. 您想提高生产力,避免使用 "new" 关键字,同时避免重复使用过长的类名。
  3. 除了提高生产力,您只是怀念使用 Python 或旧式的 JavaScript 时代,那时您不需要使用 "new" 关键字来实例化新对象。
  4. 只是为了好玩。
  5. 因为您只是疯狂地爱上函数 -:).

如何使用它

通过执行此命令安装库

composer require manuwhat/Shortcut

require 'vendor/autoload.php'; 添加到脚本的顶部。

接下来,创建一个快捷方式,就像这样

use ezama/Shortcut;

create_Shortcut('fullQualifiedclassname'[,'chosen_Shortcut_name']);
create_Shortcut('ArrayIterator');

Shortcut 只创建一次,直到缓存被抑制并代码包含在内,然后您可以在脚本中使用它

$obj=chosen_Shortcut_name(); // ==> ### if no chosen name has been specified then you may use!
$obj=fullQualifiedclassname();// of course you must pass the arguments if the constructor require them at instantiation
$iterator=ArrayIterator([1,1,2,3,3]);

默认情况下,快捷方式将缓存到默认目录,但您可以使用以下方式指定自定义目录路径,快捷方式将被保存:

use ezama/Shortcut;
Shortcut::setDir('your/path/here');
create_Shortcut('fullQualifiedclassname'[,'chosen_Shortcut_name']);
create_Shortcut('ArrayIterator','AI');

请注意,每个类只能定义一个自定义快捷方式,并且只能使用可实例化的类。

要运行单元测试

phpunit  ./tests