/fcphp-service

Package to manipulate services of application FcPhp

Primary LanguagePHPMIT LicenseMIT

FcPhp Service

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...

});