PHP code example of kassko / data-mapper-bundle

1. Go to this page and download the library: Download kassko/data-mapper-bundle 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/ */

    

kassko / data-mapper-bundle example snippets


composer 

public function registerBundles()
{
    $bundles = array(
        new Kassko\Bundle\DataMapperBundle\KasskoDataMapperBundle(),
        new Kassko\Bundle\ClassResolverBundle\KasskoClassResolverBundle(),
    );
}

$this->get('kassko_data_mapper');

use Kassko\DataMapper\Expression\ExpressionFunction;
use Kassko\DataMapper\Expression\ExpressionFunctionProviderInterface;

class ExpressionFunctionProvider implements ExpressionFunctionProviderInterface
{
    public function getFunctions()
    {
        return [
            new ExpressionFunction(
                'granted',
                function ($arg) {
                    return sprintf('container.get(%s)', $arg);
                }, 
                function (array $context, $value) {
                    return $context['container']->get($value);
                }
            ),
        ];
    }
}

trait LoggableTrait
{
    private function getLogger()
    {
        return Registry::getInstance()['logger'];
    }
}

class Person
{
    use LoggableTrait;

    private $id;
    private $name;
    private $address;

    public function getName()
    {
        if (! isset($this->address)) {
            $this->getLogger()->warning(sprintf('No address for %s', $this->name));
        }
    }
}