Abstract class to Service FcPhp
Composer:
$ composer require 00f100/fcphp-service
or add in composer.json
{
"require": {
"00f100/fcphp-service": "*"
}
}
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();
}
}
}
use Example\ExampleService;
$instance = new ExampleService();
// Callback on find service using "getService()"...
$instance->callback('callbackRepository', function(string $repository, $instance) {
// Your code here...
});