00f100/fcphp-controller

此软件包最新版本(0.1.0)没有提供许可证信息。

FcPhp的抽象控制器类

安装: 82

依赖: 1

建议者: 0

安全: 0

星标: 0

关注者: 2

分叉: 1

开放问题: 0

类型:软件包

0.1.0 2018-08-13 01:53 UTC

This package is auto-updated.

Last update: 2024-09-18 06:09:32 UTC


README

控制器FcPhp的抽象类

Build Status codecov

PHP Version Packagist Version Total Downloads

如何安装

Composer

$ composer require 00f100/fcphp-controller

或在composer.json中添加

{
    "require": {
        "00f100/fcphp-controller": "*"
    }
}

如何使用

FcPhp 控制器扩展你的控制器,并使用构造方法将你的服务添加到控制器中。之后,使用"getService()"方法调用服务。

namespace Example
{
    use FcPhp\Controller\Controller;

    class ExampleController extends Controller
    {
        public function __construct($userService, $profileService, $addressService)
        {
            $this->setService('user', $userService);
            $this->setService('profile', $profileService);
            $this->setService('address', $addressService);
        }

        public function findUsers()
        {
            return $this->getService('user')->findAll();
        }

        public function findProfiles()
        {
            return $this->getService('profile')->findAll();
        }

        public function findAddresses()
        {
            return $this->getService('address')->findAll();
        }
    }
}

控制器回调

use Example\ExampleController;

$instance = new ExampleController(UserService(), ProfileService(), AddressService());

// Callback on find service using "getService()"...
$instance->callback('callbackService', function(string $service, $instance) {

    // Your code here...

});