whitestone / xpl
Whitestone 扩展 PHP 库
1.0.2
2019-10-29 12:00 UTC
Requires
- php: ^7.0
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-09-29 05:02:46 UTC
README
Whitestone\Xpl 包含一些 PHP7+ 的辅助特性和类。许可协议:MIT
安装与需求
需求
- PHP 7
您可以使用 composer
安装 Xpl。
composer require whitestone\xpl
运行测试
使用 phpunit
或 composer run test
运行 PHPUnit。
trait Whitestone\Xpl\Runkit
包含一个方法,用于在类上下文中执行闭包,并简单传递参数。
示例 1a (Foo.php)
class Foo { use Whitestone\Xpl\Runkit; public function print($x) { echo "{$x}\n"; } }
示例 1b (index.php)
$foo = new Foo; $foo->with(function($time) { $this->print($time); $this->print('OK'); }, time());
预期输出 1
1572350237\n OK\n
trait Whitestone\Xpl\Pathkit
在类上下文中检测当前文件位置的辅助工具。
示例 1a (Bar.php)
abstract class Bar { use Pathkit; public function add() { $filePath = $this->myFilename(); error_log("Deprecated method Bar->add() called in '{$filePath}'!"); } }
示例 1b (Foobar.php)
class FooBar extends Bar { }
预期输出 1
Deprecated method Bar->add() called in '.*/Foobar.php'
trait Whitestone\Xpl\Renderer
在当前作用域上使用输出缓冲区渲染文件的帮助工具(不会溢出变量)
示例 1a (View.php)
class View { use Renderer; }
示例 1b (template.phtml)
<?= $foo; ?>\n <?= get_class($this); ?>
示例 1c (index.php)
$view = new View; echo $view->scopedRender('template.phtml', ['foo' => 'bar']);
预期输出 1
bar\n View