+ All Categories
Home > Technology > Usnadněte si soužití s Doctrine

Usnadněte si soužití s Doctrine

Date post: 04-Jun-2015
Category:
Upload: filip-prochazka
View: 1,580 times
Download: 0 times
Share this document with a friend
24
Usnadněte si soužití s Doctrine Filip Procházka
Transcript
Page 1: Usnadněte si soužití s Doctrine

Usnadněte sisoužití s Doctrine

Filip Procházka

Page 2: Usnadněte si soužití s Doctrine

Co si ukážeme?

+ Kdyby/Doctrine+ Kdyby/Console+ Kdyby/Events

Page 3: Usnadněte si soužití s Doctrine

Proč Kdyby?

- Doctrine má spoustu skvělých vlastností- Doctrine má spoustu otravných vlastností

- Kdyby je plug&play (convention over configuration), tedy konfigurace na pár řádků a hned můžete pracovat

Page 4: Usnadněte si soužití s Doctrine

Instalace

$ composer require \kdyby/doctrine

$ composer create-project \hosiplan/project

Page 5: Usnadněte si soužití s Doctrine

Konfiguraceextensions: annotations: Kdyby\Annotations\DI\AnnotationsExtension console: Kdyby\Console\DI\ConsoleExtension events: Kdyby\Events\DI\EventsExtension doctrine: Kdyby\Doctrine\DI\OrmExtension

Page 6: Usnadněte si soužití s Doctrine

Konfigurace

doctrine: user: foo password: bar dbname: sandbox metadata: App: %appDir%

Page 7: Usnadněte si soužití s Doctrine

Entitause Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity() */

class Article extends \Kdyby\Doctrine\Entities\IdentifiedEntity {

/** @ORM\Column(type="string") */

protected $title;

}

Page 8: Usnadněte si soužití s Doctrine

BaseEntity? Ta je přece fuj!

class Article extends BaseEntity {

private $one;

protected $two;

public $three;

}

Page 9: Usnadněte si soužití s Doctrine

Skvělé na prototypování

$article->getOne(); $article->one;$article->getTwo(); $article->two; $article->getThree(); $article->three;

$article->addComment($comment);

$article->removeComment($comment);

Page 10: Usnadněte si soužití s Doctrine

Striktní validace schématu

$ php www/index.php \orm:validate

Page 11: Usnadněte si soužití s Doctrine

Entity potřebují tabulky...

$ php www/index.php \orm:schema:up --dump-sql

Page 12: Usnadněte si soužití s Doctrine

Proxy třídy kvůli lazy loadingu

$ php www/index.php \orm:generate:proxies

Page 13: Usnadněte si soužití s Doctrine

Repository DAO

$articles = $entityManager

->getDao(App\Article::getClassName());

$articles = $entityManager

->getDao(App\Article::class);

Page 14: Usnadněte si soužití s Doctrine

Ne, repository nestačí...

$article = new Article();

$article->title = "The Tigger Movie";

$articles->save($article);

$article = $articles->find(1);

echo $article->title; // "The Tigger Movie"

Page 15: Usnadněte si soužití s Doctrine

Repozitář umí hezky nabobtnat

class ArticlesDao extends EntityDao

{

function findByTitle($title);

function findByStepmothersBrothersEyeColor();

function findBy...();

}

Page 16: Usnadněte si soužití s Doctrine

Hlavně žádné další dědění!

class ArticlesDao extends EntityDao

{

function findByTitle($title);

function findByStepmothersBrothersEyeColor();

function findBy...();

}

Page 17: Usnadněte si soužití s Doctrine

Krocení repozitářů

http://www.whitewashing.de http://www.whitewashing.de/2013/03/04/doctrine_repositories.htmlhttp://filip-prochazka.com/blog/doctrine-a-service-vrstva-aneb-takto-mi-to-dava-smysl

Page 18: Usnadněte si soužití s Doctrine

Tak třeba objednávky...

OrderModel - Order\UserOpening- Order\Dispatching- Order\Delivery- ….

Page 19: Usnadněte si soužití s Doctrine

Eventy: systémové listenery

class EditLogger implements Kdyby\Events\Subscriber {

function getSubscribedEvents() {

return array('postUpdate');

}

function postUpdate() { }

}

Page 20: Usnadněte si soužití s Doctrine

Eventy: systémové listenery

services:something:

class: App\EditLoggertags: [kdyby.subscriber]

Page 21: Usnadněte si soužití s Doctrine

ResultSet

$dql = $articles->createQuery("SELECT a FROM Articles a");

$articles = new Kdyby\Doctrine\ResultSet($dql);

$articles->applyPaginator($this['vp']->paginator);

Page 22: Usnadněte si soužití s Doctrine

Utilitky

Helpers::loadFromFile()Tools\NonLockingUniqueInserter

Page 23: Usnadněte si soužití s Doctrine

Dotazy?

Page 24: Usnadněte si soužití s Doctrine

Filip Procházkahttp://filip-prochazka.com

http://www.kdyby.org


Recommended