00f100/fcphp-service

There is no license information available for the latest version (0.1.1) of this package.

Package to manipulate services of application

0.1.1 2018-08-17 03:06 UTC

This package is auto-updated.

Last update: 2024-11-18 06:44:34 UTC


README

Abstract class to Service FcPhp

Build Status codecov

PHP Version Packagist Version Total Downloads

How to install

Composer:

$ composer require 00f100/fcphp-service

or add in composer.json

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

How to use

Extends your service from FcPhp Service and add your repositories into Service using contruct method. After call to repository using "getRepository()" method.

namespace Example
{
    use FcPhp\Service\Service;

    class ExampleService extends Service
    {
        public function __construct($userRepository, $profileRepository, $addressRepository)
        {
            $this->setRepository('user', $userRepository);
            $this->setRepository('profile', $profileRepository);
            $this->setRepository('address', $addressRepository);
        }

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

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

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

Service Callback

use Example\ExampleService;

$instance = new ExampleService();

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

    // Your code here...

});