定制 dawid-daweb/components 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dawid-daweb/components

Composer 安装命令:

composer require dawid-daweb/components

包简介

modules for help development

README 文档

README

require PHP >= 5.4

Install

in your composer.json

{
   require: {
     "dawid-daweb/components" "dev-master"
   }
}

Mixin

is the simple way on add additional properties and methods to your object. Simple example:

<?php
 use daweb\mixin\MixinTrait;
                
        class object { // your object 

            use MixinTrait; // use trait or implemments MixinInterface and create your own logic managment
        }

        $object = new Object;

        $object->mixinAttach('additional_params', [ //attach your additional properties
            'prop' => 'Hello ',
            'prop2' => 'World',
            'callback' => function($name) {return $name;}
        ]);

        echo $object->prop; //Hello
        echo $object->callback('Beautiful'); //Beautiful
        echo $object->prop2; //World

When we need mix some class

          class MyObject { //for mixin with Object

            private $prop;

            public function getProp() {
                return $this->prop;
            }
        }

        $object->mixinAttach('additional_methods', [//add all public methods to $object
            'class' => 'MyObject', //if you need use constructor pass new MyObject
            'prop' => 'work'
        ]);
        echo $object->getProp2(); //work

Mixins can be defined in method mixins()

        class object { 

            use MixinTrait; 

            public function mixins() {
              
                 return [
                   ['someProp' => 'value'],
                   'additional_params' => [ 
                      'prop' => 'Hello ',
                      'prop2' => 'World',
                      'callback' => function($name) {return $name;}
                   ],
                   'additional_methods' => [
                       'class' => 'MyObject', //if you need use constructor pass new MyObject
                        'prop' => 'work'
                    ]
                 ]
            }
        }

Helper methods

        $object->hasMixin('additional_params'); 
        $object->mixinDetach('additional_params');
        $object->issetProperty('prop'); //check whether $objec has mixed property

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD
  • 更新时间: 2014-12-08