koine/decorator

PHP对象装饰器

0.9.2 2014-08-29 16:10 UTC

This package is not auto-updated.

Last update: 2024-09-14 12:44:34 UTC


README

PHP简单装饰器基类。

代码信息

Build Status Coverage Status Code Climate Scrutinizer Code Quality

包信息

Latest Stable Version Total Downloads Latest Unstable Version License Dependency Status

用法

创建一个扩展 Koine\Decorator 并仅覆盖其中更改的方法的类。

<?php
class Product
{
    public function getPrice()
    {
        return 123.99;
    }

    public function getName()
    {
        return "Product Name";
    }
}

class ProductDecorator extends \Koine\Decorator
{
    public function getPrice()
    {
        return 'US ' . $this->object->getPrice();
    }
}

$product   = new Product;
$decorator = new ProductDecorator($product);

$decorator->getName();  // Product Name
$decorator->getPrice(); // US 123.99

安装

通过 Composer

将库添加到您的 composer.json 中的 requirements 键。

{
    // composer.json
    // [..]
    require: {
        // append this line to your requirements
        "koine/decorator": "dev-master"
    }
}

替代安装

  • 学习 composer。您不应该寻找替代安装。这值得您花费时间。请相信我 ;-)
  • 遵循 这些说明

问题/功能建议

这里 是问题跟踪器

贡献

只有通过 TDD 编写的代码将被接受。请遵循 PSR-2 代码规范

  1. 分支它
  2. 创建您的功能分支 (git checkout -b my-new-feature)
  3. 提交您的更改 (git commit -am 'Add some feature')
  4. 推送到分支 (git push origin my-new-feature)
  5. 创建新的 Pull Request

如何运行测试

phpunit --configuration tests/phpunit.xml

要检查代码规范,请运行

phpcs --standard=PSR2 lib
phpcs --standard=PSR2 tests

许可

MIT

作者