2017 © Pedro Peláez
 

library slim-doctrine

Service provider para integrar Doctrine y DBAL en proyectos basados en Slim 3

image

restyphp/slim-doctrine

Service provider para integrar Doctrine y DBAL en proyectos basados en Slim 3

  • Wednesday, April 11, 2018
  • by mostofreddy
  • Repository
  • 0 Watchers
  • 1 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 4 % Grown

The README.md

Deprecated, (*1)

Resty-Doctrine

Build Status, (*2)

Service provider para integrar Doctrine y DBAL en proyectos basados en Slim 3., (*3)

Versión estable

0.2.1, (*4)

License

The MIT License (MIT). Ver el archivo LICENSE para más información, (*5)

Features

  • Entidad base
  • Provider para instanciar DBAL
  • Provider para instanciar Doctrine

Requisitos

  • PHP >= 7
  • restyphp/slim-service-provider

Instalación

{
    require: {
        "restyphp/slim-doctrine": "*"
    }

}

Documentación

Entidad base

Clase base para entidades de doctrine que permite transformar la entidad en json o array, (*6)

use Resty\Slim\Doctrine\Entity;
/**
 * @Entity @Table(name="clients")
 **/
class Client extends Entity
{
    /** @Id @Column(type="integer") @GeneratedValue **/
    protected $id;
    /** @Column(type="string") **/
    protected $name;

    public function getId()
    {
        return $this->id;
    }
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }
    public function getName()
    {
        return $this->name;
    }
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }
}

$e = new Client();
$e->setName("John");

// transformar a array
var_dump($e->toArray());

// transformar a json
var_dump($e->jsonSerialize());

// internamente invoca al metodo jsonSerialize
var_dump(json_encode($e));

DBAL

use Slim\App;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Resty\ServiceProviderMiddleware;

$config = [];
$config['settings'] = [
    // slim config
];
$config['services'] = [
    '\Resty\Slim\Doctrine\Providers\DbalServiceProvider'
];
$config['dbal'] = [
    'connection' => [
        'url' => 'mysql://root:root@127.0.0.1/points'
    ],
    'debug' => true
];
$api = new App($config);
$api->add('\Resty\Slim\ServiceProviderMiddleware');

$api->get('/dbal', function (ServerRequestInterface $request, ResponseInterface $response) {

    $db = $this->get('db');
    $clients = $db->fetchAll('SELECT * FROM clients');

    $body = $response->getBody();
    return $body->write(json_encode($clients));
});

$api->run();

Doctrine

use Slim\App;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Resty\ServiceProviderMiddleware;

$config = [];
$config['settings'] = [
    // slim config
];
$config['services'] = [
    '\Resty\Slim\Doctrine\Providers\DbalServiceProvider'
];
$config['doctrine'] = [
    'meta' => [
        'paths' => [],
        'isDevMode' => false,
        'proxyDir' => null,
        'cache' => null,
        'useSimpleAnnotationReader' => true
    ],
    'connection' => [
        'url' => 'mysql://root:root@127.0.0.1/points'
    ]
];
$api = new App($config);
$api->add('\Resty\Slim\ServiceProviderMiddleware');

$api->get('/doctrine', function (ServerRequestInterface $request, ResponseInterface $response) {

    $em = $this->get('em');
    $query = $em->createQuery('SELECT c FROM \Client c');
    $clients = $query->getResult();

    $body = $response->getBody();
    return $body->write(json_encode($clients));
});

$api->run();

The Versions

11/04 2018

dev-master

9999999-dev https://github.com/mostofreddy/resty-doctrine

Service provider para integrar Doctrine y DBAL en proyectos basados en Slim 3

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database api framework rest doctrine dbal mysql slim

18/01 2017

0.2.1

0.2.1.0 https://github.com/mostofreddy/resty-doctrine

Service provider para integrar Doctrine y DBAL en proyectos basados en Slim 3

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database api framework rest doctrine dbal mysql slim

21/12 2016

0.2.0

0.2.0.0 https://github.com/mostofreddy/resty-doctrine

Service provider para integrar Doctrine y DBAL en proyectos basados en Slim 3

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database api framework rest doctrine dbal mysql slim

07/12 2016

0.1.0

0.1.0.0 https://github.com/mostofreddy/resty-doctrine

Service provider para integrar Doctrine y DBAL en proyectos basados en Slim 3

  Sources   Download

MIT

The Requires

 

The Development Requires

orm database api framework rest doctrine dbal mysql slim