delboy1978uk / common
Stuff that winds up in every project
Installs: 2 795
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- delboy1978uk/barnacle: ^2.2
- doctrine/migrations: 2.2
- doctrine/orm: ^2.6.3
- symfony/console: ^5.0
Requires (Dev)
- codeception/codeception: 4.0
- codeception/module-asserts: ^1.1
- roave/security-advisories: dev-master
- dev-master
- v4.1.2
- v4.1.1
- v4.1.0
- v4.0.9
- v4.0.8
- v4.0.7
- v4.0.6
- v4.0.5
- v4.0.4
- v4.0.3
- v4.0.2
- v4.0.1
- v4.0.0
- v3.1.1
- v3.1.0
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.21
- v2.3.20
- v2.3.19
- v2.3.18
- v2.3.17
- v2.3.16
- v2.3.15
- v2.3.14
- v2.3.13
- v2.3.12
- v2.3.10
- v2.3.9
- v2.3.8
- v2.3.7
- v2.3.6
- v2.3.5
- v2.3.4
- v2.3.3
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.12
- v2.2.11
- v2.2.10
- v2.2.9
- v2.2.8
- v2.2.7
- v2.2.6
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.1
- v2.0.0
- v1.0.1a
- v1.0.0
- dev-dev-master
This package is auto-updated.
Last update: 2024-11-29 05:20:46 UTC
README
Stuff that winds up in every project.
Db Credentials
Set the db credentials by passing an array
use Del\Common\Config\DbCredentials; $credentials = new DbCredentials([ 'driver' => 'pdo_mysql', 'dbname' => 'delboy1978uk', 'user' => 'dbuser', 'password' => '[123456]', ]);
DIC Container Factory Service
use Del\Common\ContainerService; $containerSvc = ContainerService::getInstance();
Service Methods
$containerSvc->setDbCredentials($credentials); // Do this before getContainer() to configure the DBAL Connection $containerSvc->addEntityPath('path/to/entities'); // You can add multiple paths to get Entities from different packages $containerSvc->registerToContainer($registrationInterface); // See below
Container Registration Interface
You can create a class in your own packages that will register any definitions that go in the container. Just implement Barnacle\RegistrationInterface. E.g.
namespace My\Config\Container; use Barnacle\Container; use Barnacle\RegistrationInterface; use Doctrine\ORM\EntityManager; use My\Repository\Dog as DogRepository; class DogPackage implements RegistrationInterface { /** * @param Container $c */ public function addToContainer(Container $c) { $c['repository.dog'] = $c->factory(function ($c) { /** @var EntityManager $em */ $em = $c['doctrine.entity_manager']; /** @var DogRepository $repo */ $repo = $em->getRepository('My\Entity\Dog'); return $repo; }); } }
Pimple Container
A Dependency Injection container. Which now contains a configured Doctrine 2 Entity Manager
$container = $containerSvc->getContainer();
$em = $container['doctrine.entity_manager'];
$dogRepo = $container['repository.dog'];
Value Objects
There have several value objects which extend Del\Common\Value\AbstractValue.
use Del\Common\Value\DecimalValue; use Del\Common\Value\IntValue; use Del\Common\Value\StringValue; $money = new DecimalValue(123.45); $text = new StringValue('Hooray'); $int = new IntValue(500); echo $money->getValue(); echo $text->getValue(); echo $int->getValue();