Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 796

Přidáno uživatelem Ondřej Fibich před téměř 14 roky(ů)

Pocatecni integrace Doctrine 2 ORM.

Zobrazit rozdíly:

freenetis/branches/doctrine2_integration/application/libraries/Base_Entity.php
<?php
/*
*
*/
use \Doctrine\ORM\EntityManager;
/**
* Parent of all doctrine entities.
* Enable quicker work with Entity Manager.
*
* @author Ondřej Fibich
*
* @see http://www.doctrine-project.org/docs/orm/2.0/en/reference/annotations-reference.html
*/
abstract class Base_Entity
{
/**
* @var \Doctrine\ORM\EntityManager Local copy of Entity Manager
*/
protected $em;
/**
* Constructor of Entity
* Copies Entity Manager from Controller
*/
public function __construct()
{
$this->em = Controller::getEntityManager();
}
public static function factory($modelName, $rowId = NULL)
{
}
/**
* Persist entity (add)
*/
public function persist()
{
Controller::getEntityManager()->persist($this);
}
/**
* Flush - make pernament changes
*/
public function flush()
{
Controller::getEntityManager()->flush();
}
/**
* Delete entity
*/
public function delete()
{
Controller::getEntityManager()->remove($this);
}
public function find($rowId)
{
}
public function find_all()
{
}
/**
* Execute DQL query
*
* @param string $dql DQL query
* @return mixed
* @see http://www.doctrine-project.org/docs/orm/2.0/en/reference/dql-doctrine-query-language.html
*/
public function dqlExecute($dql)
{
return Controller::getEntityManager()->createQuery($dql)->execute();
}
/**
* Create DQL query
*
* @example
* $q = $entity->dqlQuery('select u from MyProject\Model\User u');
* $iterableResult = $q->iterate();
* foreach($iterableResult AS $row) {
* $user = $row[0];
* }
* @example
* $q = $entity->dqlQuery('select u from MyProject\Model\User u');
* $result = $q->getResult(); // array of Users
*
* @param string $dql DQL query
* @return \Doctrine\ORM\Query
* @see http://www.doctrine-project.org/docs/orm/2.0/en/reference/dql-doctrine-query-language.html
*/
public function dqlQuery($dql)
{
return Controller::getEntityManager()->createQuery($dql);
}
/**
* Create Query Builder
*
* @return Doctrine\ORM\QueryBuilder
* @see http://www.doctrine-project.org/docs/orm/2.0/en/reference/query-builder.html
*/
public function qb()
{
return Controller::getEntityManager()->createQueryBuilder();
}
/**
* Perform start transaction
*/
public function transactionBegin()
{
Controller::getEntityManager()->getConnection()->beginTransaction();
}
/**
* Perform transaction commit
* @throws Kohana_Database_Exception If commit failed
*/
public function transactionCommit()
{
try
{
Controller::getEntityManager()->getConnection()->commit();
}
catch (Doctrine\DBAL\ConnectionException $cex)
{
throw new Kohana_Database_Exception($cex->__toString());
}
}
/**
* Perform transaction rollback
* @throws Kohana_Database_Exception If rollback failed
*/
public function transactionRollback()
{
try
{
Controller::getEntityManager()->getConnection()->rollback();
}
catch (Doctrine\DBAL\ConnectionException $cex)
{
throw new Kohana_Database_Exception($cex->__toString());
}
}
}
freenetis/branches/doctrine2_integration/application/libraries/MY_Controller.php
// for example when programmer misleads error and warning
define("PARAMETER", "1001");
use \Doctrine\ORM\EntityManager,
\Doctrine\DBAL\Event\Listeners\MysqlSessionInit;
/**
* Main controller creates menu, handles changes in svn repository (database upgrade), ...
......
/** @staticvar Controller Controller singleton */
private static $instance;
/** @var \Doctrine\ORM\EntityManager Entity manager */
private static $doctrineEntityManager = NULL;
/** @var gacl PHP GACL class */
public $gacl_class;
......
// This part only needs to be run once
if (self::$instance === NULL)
{
self::getEntityManager();
$this->session = Session::instance();
$this->settings = new Settings();
......
return self::$instance;
}
/**
* Return entity manager of Doctrine ORM.
* If it is not exists, mentod will create it.
* @return \Doctrine\ORM\EntityManager
*/
public static function & getEntityManager()
{
if (self::$doctrineEntityManager === NULL)
{
////////////////////////////////////////////////////////
// DOCTRINE SETUP --->
////////////////////////////////////////////////////////
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
// using annotations
$driverImpl = $config->newDefaultAnnotationDriver(array(
APPPATH . '/entities'
));
$config->setMetadataDriverImpl($driverImpl);
// proxy settings
$config->setProxyDir(APPPATH . '/proxies');
$config->setProxyNamespace('Freenetis\Proxies');
$config->setAutoGenerateProxyClasses(TRUE);
// config settings
$connectionOptions = array
(
'driver' => 'pdo_' . Config::get('db_type'),
'host' => 'localhost',
'user' => Config::get('db_user'),
'password' => Config::get('db_password'),
'dbname' => Config::get('db_name')
);
// encoding of mysql set to utf8_czech_ci
$eventManager = new Doctrine\Common\EventManager();
$eventManager->addEventSubscriber(new MysqlSessionInit(
'utf8', 'utf8_czech_ci'
));
// database connection
self::$doctrineEntityManager = EntityManager::create(
$connectionOptions, $config, $eventManager
);
////////////////////////////////////////////////////////
// <--- DOCTRINE SETUP
////////////////////////////////////////////////////////
}
return self::$doctrineEntityManager;
}
/**
* Function shows error of given message number.
freenetis/branches/doctrine2_integration/system/core/Kohana.php
// Lowercase filename
$file = strtolower(substr($class, 0, -6));
break;
case 'Entity':
$type = 'entities';
// Lowercase filename
$file = strtolower(substr($class, 0, -7));
break;
case 'Driver':
$type = 'libraries/drivers';
$file = str_replace('_', '/', substr($class, 0, -7));
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/OrmTestCase.php
<?php
namespace Doctrine\Tests;
/**
* Base testcase class for all ORM testcases.
*/
abstract class OrmTestCase extends DoctrineTestCase
{
/** The metadata cache that is shared between all ORM tests (except functional tests). */
private static $_metadataCacheImpl = null;
/** The query cache that is shared between all ORM tests (except functional tests). */
private static $_queryCacheImpl = null;
/**
* Creates an EntityManager for testing purposes.
*
* NOTE: The created EntityManager will have its dependant DBAL parts completely
* mocked out using a DriverMock, ConnectionMock, etc. These mocks can then
* be configured in the tests to simulate the DBAL behavior that is desired
* for a particular test,
*
* @return Doctrine\ORM\EntityManager
*/
protected function _getTestEntityManager($conn = null, $conf = null, $eventManager = null, $withSharedMetadata = true)
{
$config = new \Doctrine\ORM\Configuration();
if($withSharedMetadata) {
$config->setMetadataCacheImpl(self::getSharedMetadataCacheImpl());
} else {
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
}
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
$config->setQueryCacheImpl(self::getSharedQueryCacheImpl());
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
$eventManager = new \Doctrine\Common\EventManager();
if ($conn === null) {
$conn = array(
'driverClass' => 'Doctrine\Tests\Mocks\DriverMock',
'wrapperClass' => 'Doctrine\Tests\Mocks\ConnectionMock',
'user' => 'john',
'password' => 'wayne'
);
}
if (is_array($conn)) {
$conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager);
}
return \Doctrine\Tests\Mocks\EntityManagerMock::create($conn, $config, $eventManager);
}
private static function getSharedMetadataCacheImpl()
{
if (self::$_metadataCacheImpl === null) {
self::$_metadataCacheImpl = new \Doctrine\Common\Cache\ArrayCache;
}
return self::$_metadataCacheImpl;
}
private static function getSharedQueryCacheImpl()
{
if (self::$_queryCacheImpl === null) {
self::$_queryCacheImpl = new \Doctrine\Common\Cache\ArrayCache;
}
return self::$_queryCacheImpl;
}
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/OrmFunctionalTestSuite.php
<?php
namespace Doctrine\Tests;
/**
* The outermost test suite for all orm related testcases & suites.
*
* Currently the orm suite uses a normal connection object.
* Upon separation of the DBAL and ORM package this suite should just use a orm
* connection/session/manager instance as the shared fixture.
*/
class OrmFunctionalTestSuite extends OrmTestSuite
{
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/AllTests.php
<?php
namespace Doctrine\Tests;
use Doctrine\Tests\Common;
use Doctrine\Tests\ORM;
use Doctrine\Tests\DBAL;
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'AllTests::main');
}
require_once __DIR__ . '/TestInit.php';
class AllTests
{
public static function main()
{
\PHPUnit_TextUI_TestRunner::run(self::suite());
}
public static function suite()
{
$suite = new DoctrineTestSuite('Doctrine Tests');
$suite->addTest(ORM\AllTests::suite());
return $suite;
}
}
if (PHPUnit_MAIN_METHOD == 'AllTests::main') {
AllTests::main();
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php
<?php
namespace Doctrine\Tests\Models\ECommerce;
use Doctrine\Common\Collections\ArrayCollection;
/**
* ECommerceCart
* Represents a typical cart of a shopping application.
*
* @author Giorgio Sironi
* @Entity
* @Table(name="ecommerce_carts")
*/
class ECommerceCart
{
/**
* @Column(type="integer")
* @Id
* @GeneratedValue
*/
private $id;
/**
* @Column(length=50, nullable=true)
*/
private $payment;
/**
* @OneToOne(targetEntity="ECommerceCustomer", inversedBy="cart")
* @JoinColumn(name="customer_id", referencedColumnName="id")
*/
private $customer;
/**
* @ManyToMany(targetEntity="ECommerceProduct", cascade={"persist"})
* @JoinTable(name="ecommerce_carts_products",
joinColumns={@JoinColumn(name="cart_id", referencedColumnName="id")},
inverseJoinColumns={@JoinColumn(name="product_id", referencedColumnName="id")})
*/
private $products;
public function __construct()
{
$this->products = new ArrayCollection;
}
public function getId() {
return $this->id;
}
public function getPayment() {
return $this->payment;
}
public function setPayment($payment) {
$this->payment = $payment;
}
public function setCustomer(ECommerceCustomer $customer) {
if ($this->customer !== $customer) {
$this->customer = $customer;
$customer->setCart($this);
}
}
public function removeCustomer() {
if ($this->customer !== null) {
$customer = $this->customer;
$this->customer = null;
$customer->removeCart();
}
}
public function getCustomer() {
return $this->customer;
}
public function getProducts()
{
return $this->products;
}
public function addProduct(ECommerceProduct $product) {
$this->products[] = $product;
}
public function removeProduct(ECommerceProduct $product) {
return $this->products->removeElement($product);
}
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/Models/ECommerce/ECommerceFeature.php
<?php
namespace Doctrine\Tests\Models\ECommerce;
/**
* Describes a product feature.
*
* @author Giorgio Sironi
* @Entity
* @Table(name="ecommerce_features")
*/
class ECommerceFeature
{
/**
* @Column(type="integer")
* @Id
* @GeneratedValue
*/
private $id;
/**
* @Column(length=50)
*/
private $description;
/**
* @ManyToOne(targetEntity="ECommerceProduct", inversedBy="features")
* @JoinColumn(name="product_id", referencedColumnName="id")
*/
private $product;
public function getId() {
return $this->id;
}
public function getDescription() {
return $this->description;
}
public function setDescription($description) {
$this->description = $description;
}
public function setProduct(ECommerceProduct $product) {
$this->product = $product;
}
public function removeProduct() {
if ($this->product !== null) {
$product = $this->product;
$this->product = null;
$product->removeFeature($this);
}
}
public function getProduct() {
return $this->product;
}
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/Models/ECommerce/ECommerceCategory.php
<?php
namespace Doctrine\Tests\Models\ECommerce;
use Doctrine\Common\Collections\ArrayCollection;
/**
* ECommerceCategory
* Represents a tag applied on particular products.
*
* @author Giorgio Sironi
* @Entity
* @Table(name="ecommerce_categories")
*/
class ECommerceCategory
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Column(type="string", length=50)
*/
private $name;
/**
* @ManyToMany(targetEntity="ECommerceProduct", mappedBy="categories")
*/
private $products;
/**
* @OneToMany(targetEntity="ECommerceCategory", mappedBy="parent", cascade={"persist"})
*/
private $children;
/**
* @ManyToOne(targetEntity="ECommerceCategory", inversedBy="children")
* @JoinColumn(name="parent_id", referencedColumnName="id")
*/
private $parent;
public function __construct()
{
$this->products = new ArrayCollection();
$this->children = new ArrayCollection();
}
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
public function addProduct(ECommerceProduct $product)
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->addCategory($this);
}
}
public function removeProduct(ECommerceProduct $product)
{
$removed = $this->products->removeElement($product);
if ($removed) {
$product->removeCategory($this);
}
}
public function getProducts()
{
return $this->products;
}
private function setParent(ECommerceCategory $parent)
{
$this->parent = $parent;
}
public function getChildren()
{
return $this->children;
}
public function getParent()
{
return $this->parent;
}
public function addChild(ECommerceCategory $child)
{
$this->children[] = $child;
$child->setParent($this);
}
/** does not set the owning side. */
public function brokenAddChild(ECommerceCategory $child)
{
$this->children[] = $child;
}
public function removeChild(ECommerceCategory $child)
{
$removed = $this->children->removeElement($child);
if ($removed) {
$child->removeParent();
}
}
private function removeParent()
{
$this->parent = null;
}
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php
<?php
namespace Doctrine\Tests\Models\ECommerce;
use Doctrine\Common\Collections\ArrayCollection;
/**
* ECommerceProduct
* Represents a type of product of a shopping application.
*
* @author Giorgio Sironi
* @Entity
* @Table(name="ecommerce_products",indexes={@Index(name="name_idx", columns={"name"})})
*/
class ECommerceProduct
{
/**
* @Column(type="integer")
* @Id
* @GeneratedValue
*/
private $id;
/**
* @Column(type="string", length=50, nullable="true")
*/
private $name;
/**
* @OneToOne(targetEntity="ECommerceShipping", cascade={"persist"})
* @JoinColumn(name="shipping_id", referencedColumnName="id")
*/
private $shipping;
/**
* @OneToMany(targetEntity="ECommerceFeature", mappedBy="product", cascade={"persist"})
*/
private $features;
/**
* @ManyToMany(targetEntity="ECommerceCategory", cascade={"persist"}, inversedBy="products")
* @JoinTable(name="ecommerce_products_categories",
* joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="category_id", referencedColumnName="id")})
*/
private $categories;
/**
* This relation is saved with two records in the association table for
* simplicity.
* @ManyToMany(targetEntity="ECommerceProduct", cascade={"persist"})
* @JoinTable(name="ecommerce_products_related",
* joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="related_id", referencedColumnName="id")})
*/
private $related;
public function __construct()
{
$this->features = new ArrayCollection;
$this->categories = new ArrayCollection;
$this->related = new ArrayCollection;
}
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
public function getShipping()
{
return $this->shipping;
}
public function setShipping(ECommerceShipping $shipping)
{
$this->shipping = $shipping;
}
public function removeShipping()
{
$this->shipping = null;
}
public function getFeatures()
{
return $this->features;
}
public function addFeature(ECommerceFeature $feature)
{
$this->features[] = $feature;
$feature->setProduct($this);
}
/** does not set the owning side */
public function brokenAddFeature(ECommerceFeature $feature)
{
$this->features[] = $feature;
}
public function removeFeature(ECommerceFeature $feature)
{
$removed = $this->features->removeElement($feature);
if ($removed) {
$feature->removeProduct();
}
return $removed;
}
public function addCategory(ECommerceCategory $category)
{
if (!$this->categories->contains($category)) {
$this->categories[] = $category;
$category->addProduct($this);
}
}
public function removeCategory(ECommerceCategory $category)
{
$removed = $this->categories->removeElement($category);
if ($removed) {
$category->removeProduct($this);
}
}
public function getCategories()
{
return $this->categories;
}
public function getRelated()
{
return $this->related;
}
public function addRelated(ECommerceProduct $related)
{
if (!$this->related->contains($related)) {
$this->related[] = $related;
$related->addRelated($this);
}
}
public function removeRelated(ECommerceProduct $related)
{
$removed = $this->related->removeElement($related);
if ($removed) {
$related->removeRelated($this);
}
}
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php
<?php
namespace Doctrine\Tests\Models\ECommerce;
/**
* ECommerceCustomer
* Represents a registered user of a shopping application.
*
* @author Giorgio Sironi
* @Entity
* @Table(name="ecommerce_customers")
*/
class ECommerceCustomer
{
/**
* @Column(type="integer")
* @Id
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Column(type="string", length=50)
*/
private $name;
/**
* @OneToOne(targetEntity="ECommerceCart", mappedBy="customer", cascade={"persist"})
*/
private $cart;
/**
* Example of a one-one self referential association. A mentor can follow
* only one customer at the time, while a customer can choose only one
* mentor. Not properly appropriate but it works.
*
* @OneToOne(targetEntity="ECommerceCustomer", cascade={"persist"})
* @JoinColumn(name="mentor_id", referencedColumnName="id")
*/
private $mentor;
public function getId() {
return $this->id;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function setCart(ECommerceCart $cart)
{
if ($this->cart !== $cart) {
$this->cart = $cart;
$cart->setCustomer($this);
}
}
/* Does not properly maintain the bidirectional association! */
public function brokenSetCart(ECommerceCart $cart) {
$this->cart = $cart;
}
public function getCart() {
return $this->cart;
}
public function removeCart()
{
if ($this->cart !== null) {
$cart = $this->cart;
$this->cart = null;
$cart->removeCustomer();
}
}
public function setMentor(ECommerceCustomer $mentor)
{
$this->mentor = $mentor;
}
public function removeMentor()
{
$this->mentor = null;
}
public function getMentor()
{
return $this->mentor;
}
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/Models/ECommerce/ECommerceShipping.php
<?php
namespace Doctrine\Tests\Models\ECommerce;
/**
* ECommerceShipping
* Represents a shipping method.
*
* @author Giorgio Sironi
* @Entity
* @Table(name="ecommerce_shippings")
*/
class ECommerceShipping
{
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @Column(type="integer")
*/
private $days;
public function getId()
{
return $this->id;
}
public function getDays()
{
return $this->days;
}
public function setDays($days)
{
$this->days = $days;
}
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/Models/Navigation/NavTour.php
<?php
namespace Doctrine\Tests\Models\Navigation;
/**
* @Entity
* @Table(name="navigation_tours")
*/
class NavTour
{
/**
* @Id
* @Column(type="integer")
* @generatedValue
*/
private $id;
/**
* @column(type="string")
*/
private $name;
/**
* @ManyToMany(targetEntity="NavPointOfInterest")
* @JoinTable(name="navigation_tour_pois",
* joinColumns={@JoinColumn(name="tour_id", referencedColumnName="id")},
* inverseJoinColumns={
* @JoinColumn(name="poi_long", referencedColumnName="nav_long"),
* @JoinColumn(name="poi_lat", referencedColumnName="nav_lat")
* }
* )
*
*/
private $pois;
public function __construct($name)
{
$this->name = $name;
$this->pois = new \Doctrine\Common\Collections\ArrayCollection;
}
public function addPointOfInterest(NavPointOfInterest $poi)
{
$this->pois[] = $poi;
}
public function getPointOfInterests()
{
return $this->pois;
}
public function getName()
{
return $this->name;
}
public function getId()
{
return $this->id;
}
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/Models/Navigation/NavPhotos.php
<?php
namespace Doctrine\Tests\Models\Navigation;
/**
* @Entity
* @Table(name="navigation_photos")
*/
class NavPhotos
{
/**
* @Id
* @column(type="integer")
* @generatedValue
*/
private $id;
/**
* @ManyToOne(targetEntity="NavPointOfInterest")
* @JoinColumns({
* @JoinColumn(name="poi_long", referencedColumnName="nav_long"),
* @JoinColumn(name="poi_lat", referencedColumnName="nav_lat")
* })
*/
private $poi;
/**
* @column(type="string", name="file_name")
*/
private $file;
function __construct($poi, $file) {
$this->poi = $poi;
$this->file = $file;
}
public function getId() {
return $this->id;
}
public function getPointOfInterest() {
return $this->poi;
}
public function getFile() {
return $this->file;
}
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/Models/Navigation/NavPointOfInterest.php
<?php
namespace Doctrine\Tests\Models\Navigation;
/**
* @Entity
* @Table(name="navigation_pois")
*/
class NavPointOfInterest
{
/**
* @Id
* @Column(type="integer", name="nav_long")
*/
private $long;
/**
* @Id
* @Column(type="integer", name="nav_lat")
*/
private $lat;
/**
* @Column(type="string")
*/
private $name;
/**
* @ManyToOne(targetEntity="NavCountry")
*/
private $country;
public function __construct($lat, $long, $name, $country)
{
$this->lat = $lat;
$this->long = $long;
$this->name = $name;
$this->country = $country;
}
public function getLong() {
return $this->long;
}
public function getLat() {
return $this->lat;
}
public function getName() {
return $this->name;
}
public function getCountry() {
return $this->country;
}
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/Models/Navigation/NavCountry.php
<?php
namespace Doctrine\Tests\Models\Navigation;
/**
* @Entity
* @Table(name="navigation_countries")
*/
class NavCountry
{
/**
* @Id
* @Column(type="integer")
* @generatedValue
*/
private $id;
/**
* @Column(type="string")
*/
private $name;
/**
* @OneToMany(targetEntity="NavPointOfInterest", mappedBy="country")
*/
private $pois;
function __construct($name) {
$this->name = $name;
}
public function getId() {
return $this->id;
}
public function getName() {
return $this->name;
}
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/Models/Global/GlobalNamespaceModel.php
<?php
/**
* @entity
* @table(name="articles")
*/
class DoctrineGlobal_Article
{
/**
* @id
* @column(type="int")
*/
protected $id;
/**
* @column(type="string")
*/
protected $headline;
/**
* @column(type="text")
*/
protected $text;
/**
* @ManyToMany(targetEntity="DoctrineGlobal_User")
* @JoinTable(name="author_articles",
* joinColumns={@JoinColumn(name="article_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="author_id", referencedColumnName="id", unique=true)}
* )
*/
protected $author;
/**
* @ManyToMany(targetEntity="\DoctrineGlobal_User")
* @JoinTable(name="editor_articles",
* joinColumns={@JoinColumn(name="article_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="editor_id", referencedColumnName="id", unique=true)}
* )
*/
protected $editor;
}
/**
* @Entity
* @Table(name="users")
*/
class DoctrineGlobal_User
{
/**
* @Id
* @column(type="integer")
* @var int
*/
private $id;
/**
* @column(type="string", length=64)
* @var string
*/
private $username;
/**
* @column(type="string", length=128)
* @var string
*/
private $email;
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/Models/CMS/CmsGroup.php
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
namespace Doctrine\Tests\Models\CMS;
/**
* Description of CmsGroup
*
* @author robo
* @Entity
* @Table(name="cms_groups")
*/
class CmsGroup
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
public $id;
/**
* @Column(length=50)
*/
public $name;
/**
* @ManyToMany(targetEntity="CmsUser", mappedBy="groups")
*/
public $users;
public function setName($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
public function addUser(CmsUser $user) {
$this->users[] = $user;
}
public function getUsers() {
return $this->users;
}
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/Models/CMS/CmsUser.php
<?php
namespace Doctrine\Tests\Models\CMS;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity
* @Table(name="cms_users")
*/
class CmsUser
{
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
public $id;
/**
* @Column(type="string", length=50)
*/
public $status;
/**
* @Column(type="string", length=255, unique=true)
*/
public $username;
/**
* @Column(type="string", length=255)
*/
public $name;
/**
* @OneToMany(targetEntity="CmsPhonenumber", mappedBy="user", cascade={"persist", "remove", "merge"}, orphanRemoval=true)
*/
public $phonenumbers;
/**
* @OneToMany(targetEntity="CmsArticle", mappedBy="user")
*/
public $articles;
/**
* @OneToOne(targetEntity="CmsAddress", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
*/
public $address;
/**
* @ManyToMany(targetEntity="CmsGroup", inversedBy="users", cascade={"persist", "merge"})
* @JoinTable(name="cms_users_groups",
* joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")}
* )
*/
public $groups;
public function __construct() {
$this->phonenumbers = new ArrayCollection;
$this->articles = new ArrayCollection;
$this->groups = new ArrayCollection;
}
public function getId() {
return $this->id;
}
public function getStatus() {
return $this->status;
}
public function getUsername() {
return $this->username;
}
public function getName() {
return $this->name;
}
/**
* Adds a phonenumber to the user.
*
* @param CmsPhonenumber $phone
*/
public function addPhonenumber(CmsPhonenumber $phone) {
$this->phonenumbers[] = $phone;
$phone->setUser($this);
}
public function getPhonenumbers() {
return $this->phonenumbers;
}
public function addArticle(CmsArticle $article) {
$this->articles[] = $article;
$article->setAuthor($this);
}
public function addGroup(CmsGroup $group) {
$this->groups[] = $group;
$group->addUser($this);
}
public function getGroups() {
return $this->groups;
}
public function removePhonenumber($index) {
if (isset($this->phonenumbers[$index])) {
$ph = $this->phonenumbers[$index];
unset($this->phonenumbers[$index]);
$ph->user = null;
return true;
}
return false;
}
public function getAddress() { return $this->address; }
public function setAddress(CmsAddress $address) {
if ($this->address !== $address) {
$this->address = $address;
$address->setUser($this);
}
}
}
freenetis/branches/doctrine2_integration/modules/doctrine/tests/Doctrine/Tests/Models/CMS/CmsEmployee.php
<?php
namespace Doctrine\Tests\Models\CMS;
/**
* Description of CmsEmployee
*
* @author robo
* @Entity
* @Table(name="cms_employees")
*/
class CmsEmployee
{
/**
* @Id
* @Column(type="integer")
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff