00f100 / fcphp-service
Package to manipulate services of application
Installs: 58
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Type:package
Requires
- php: >=7.2
Requires (Dev)
- 00f100/phpdbug: *
- phpunit/phpunit: 6.*
This package is auto-updated.
Last update: 2024-11-18 06:44:34 UTC
README
Abstract class to Service FcPhp
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... });