PHP code example of delboy1978uk / common

1. Go to this page and download the library: Download delboy1978uk/common library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

delboy1978uk / common example snippets


use Del\Common\Config\DbCredentials;

$credentials = new DbCredentials([
    'driver' => 'pdo_mysql',
    'dbname' => 'delboy1978uk',
    'user' => 'dbuser',
    'password' => '[123456]',
]);

use Del\Common\ContainerService;

$containerSvc = ContainerService::getInstance();

$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

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; 
        });
    }
}

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();