Created
July 23, 2012 08:45
-
-
Save yiseli/3162659 to your computer and use it in GitHub Desktop.
Doctrine - Empty proxy object values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Model\Entities; | |
| use Doctrine\Common\Collections\ArrayCollection; | |
| class Client extends Entreprise | |
| { | |
| function __construct($id = null, $nom = null) { | |
| parent::__construct($id, $nom); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Model\Entities; | |
| abstract class Entity | |
| { | |
| private function processToArray($attributes, $maxDepth, $depth = 0) | |
| { | |
| //.... | |
| } | |
| private function processArray($array, $maxDepth, $depth) | |
| { | |
| //... | |
| } | |
| public function toArray($attributes = null, $maxDepth = 1) | |
| { | |
| //... | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Model\Entities; | |
| class Entreprise extends Entity | |
| { | |
| /** | |
| * Identifiant de l'entreprise. | |
| * @var int | |
| * @Id @Column(type="integer") @GeneratedValue | |
| */ | |
| protected $id; | |
| /** | |
| * Nom de l'entreprise. | |
| * @var string | |
| * @Column(type="string") | |
| */ | |
| protected $nom; | |
| function __construct($id = null, $nom = null) { | |
| if (!empty($id)) $this->setId($id); | |
| if (!empty($nom)) $this->setNom($nom); | |
| } | |
| public function getId() | |
| { | |
| return $this->id; | |
| } | |
| public function getNom() | |
| { | |
| return $this->nom; | |
| } | |
| public function setId($id) | |
| { | |
| if ($id === null || is_int($id)) { | |
| $this->id = $id; | |
| } else { | |
| throw new \Lib\ParameterException('identifiant d\'entreprise est un int'); | |
| } | |
| } | |
| public function setNom($nom) | |
| { | |
| if ($nom === null || is_string($nom)) { | |
| $this->nom = $nom; | |
| } else { | |
| throw new \Lib\ParameterException('nom d\'entreprise est une string'); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Proxies; | |
| /** | |
| * THIS CLASS WAS GENERATED BY THE DOCTRINE ORM. DO NOT EDIT THIS FILE. | |
| */ | |
| class ModelEntitiesClientProxy extends \Model\Entities\Client implements \Doctrine\ORM\Proxy\Proxy | |
| { | |
| private $_entityPersister; | |
| private $_identifier; | |
| public $__isInitialized__ = false; | |
| public function __construct($entityPersister, $identifier) | |
| { | |
| $this->_entityPersister = $entityPersister; | |
| $this->_identifier = $identifier; | |
| } | |
| private function _load() | |
| { | |
| if (!$this->__isInitialized__ && $this->_entityPersister) { | |
| $this->__isInitialized__ = true; | |
| if ($this->_entityPersister->load($this->_identifier, $this) === null) { | |
| throw new \Doctrine\ORM\EntityNotFoundException(); | |
| } | |
| unset($this->_entityPersister, $this->_identifier); | |
| } | |
| } | |
| public function setId($id) | |
| { | |
| $this->_load(); | |
| return parent::setId($id); | |
| } | |
| public function setNom($nom) | |
| { | |
| $this->_load(); | |
| return parent::setNom($nom); | |
| } | |
| public function getId() | |
| { | |
| $this->_load(); | |
| return parent::getId(); | |
| } | |
| public function getNom() | |
| { | |
| $this->_load(); | |
| return parent::getNom(); | |
| } | |
| public function setId($id) | |
| { | |
| $this->_load(); | |
| return parent::setId($id); | |
| } | |
| public function setNom($nom) | |
| { | |
| $this->_load(); | |
| return parent::setNom($nom); | |
| } | |
| public function __toString() | |
| { | |
| $this->_load(); | |
| return parent::__toString(); | |
| } | |
| public function toArray($attributes = NULL, $maxDepth = 1) | |
| { | |
| $this->_load(); | |
| return parent::toArray($attributes, $maxDepth); | |
| } | |
| public function __sleep() | |
| { | |
| return array('__isInitialized__', 'id', 'nom'); | |
| } | |
| public function __clone() | |
| { | |
| if (!$this->__isInitialized__ && $this->_entityPersister) { | |
| $this->__isInitialized__ = true; | |
| $class = $this->_entityPersister->getClassMetadata(); | |
| $original = $this->_entityPersister->load($this->_identifier); | |
| if ($original === null) { | |
| throw new \Doctrine\ORM\EntityNotFoundException(); | |
| } | |
| foreach ($class->reflFields AS $field => $reflProperty) { | |
| $reflProperty->setValue($this, $reflProperty->getValue($original)); | |
| } | |
| unset($this->_entityPersister, $this->_identifier); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Model\Entities; | |
| use Doctrine\Common\Collections\ArrayCollection; | |
| class Projet extends Entity | |
| { | |
| /** | |
| * Identifiant du projet. | |
| * @var int | |
| * @Id @Column(type="integer") @GeneratedValue | |
| */ | |
| protected $id; | |
| /** | |
| * Client du projet. | |
| * @var \Model\Entities\Client | |
| * @ManyToOne(targetEntity="Client") | |
| */ | |
| protected $client; | |
| /** | |
| * Titre du projet. | |
| * @var string | |
| * @Column(type="string") | |
| */ | |
| protected $titre; | |
| function __construct($id = null, Client $client = null, $titre = null) | |
| { | |
| if (!empty($id)) $this->setId($id); | |
| if (!empty($client)) $this->setClient($client); | |
| if (!empty($titre)) $this->setTitre($titre); | |
| } | |
| public function setVals($projet) | |
| { | |
| die('>'.$projet.'<'); // -- (B) | |
| } | |
| public function getId() | |
| { | |
| return $this->id; | |
| } | |
| public function getClient() | |
| { | |
| return $this->client; | |
| } | |
| public function getTitre() | |
| { | |
| return $this->titre; | |
| } | |
| public function setId($id) | |
| { | |
| if ($id === null || is_int($id)) { | |
| $this->id = $id; | |
| } else { | |
| throw new \Lib\ParameterException('identifiant de personne est un int'); | |
| } | |
| } | |
| public function setClient($client) | |
| { | |
| if ($client === null || $client instanceof Client) { | |
| $this->client = $client; | |
| } else { | |
| throw new \Lib\ParameterException('client de projet est un \Model\Entities\Client'); | |
| } | |
| } | |
| public function setTitre($titre) | |
| { | |
| if ($titre === null || is_string($titre)) { | |
| $this->titre = $titre; | |
| } else { | |
| throw new \Lib\ParameterException('titre de projet est une string'); | |
| } | |
| } | |
| public function __toString() { | |
| return get_class($this) . " || Id: " . $this->getId() . ", Clientid: " . $this->getClient()->getId(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Model\Managers; | |
| class ProjetManager extends \Doctrine\ORM\EntityRepository | |
| { | |
| public function modifier($guid, \Model\Entities\Projet $projet) | |
| { | |
| $em = $this->getEntityManager(); | |
| $projetAModifier = $em->find('\Model\Entities\Projet', $guid); | |
| // die($projet); --- (A) | |
| $projetAModifier->setVals($projet); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment