Created
January 31, 2010 11:21
-
-
Save marijn/291024 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
namespace Entities; | |
/** | |
* @MappedSuperclass | |
*/ | |
abstract class EntityAbstract | |
{ | |
/** | |
* @Id | |
* @Column(name="id", type="smallint") | |
* @GeneratedValue(strategy="AUTO") | |
*/ | |
private $_id; | |
final public function getId () | |
{ | |
if ( ! $this->hasId()) | |
{ | |
throw new \OutOfBoundsException(sprintf('No id was set for this %s instance', get_class($this))); | |
} | |
return $this->_id; | |
} | |
final public function setId ($arg_id) | |
{ | |
if ($this->hasId()) | |
{ | |
throw new \BadMethodCallException(sprintf('The %s#setId method can not be called when an id is already set', get_class($this))); | |
} | |
$this->_id = $arg_id; | |
} | |
final public function hasId () | |
{ | |
return NULL !== $this->_id; | |
} | |
final public function voidId () | |
{ | |
if ( ! $this->hasId()) | |
{ | |
throw new \BadMethodCallException('Cannot void the id for this %s intance since no id is set'); | |
} | |
$this->_id = NULL; | |
} | |
public function __get ($arg_key) | |
{ | |
$method = 'get' . ucfirst($arg_key); | |
if ( ! method_exists($this, $method)) | |
{ | |
throw new \OutOfBoundsException(sprintf('The %s object does not have a field getter named %s.', get_class($this), $method)); | |
} | |
return call_user_func(array($this, $method)); | |
} | |
public function __set ($arg_key, $arg_value) | |
{ | |
$method = 'set' . ucfirst($arg_key); | |
if ( ! method_exists($this, $method)) | |
{ | |
throw new \OutOfBoundsException(sprintf('The %s object does not have a field setter named %s.', get_class($this), $method)); | |
} | |
return call_user_func(array($this, $method), $arg_value); | |
} | |
} |
This file contains 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
<?php | |
namespace Entities; | |
/** | |
* @Entity | |
* @Table(name="users") | |
* @InheritanceType("SINGLE_TABLE") | |
* @DiscriminatorColumn(name="type", type="string") | |
* @DiscriminatorMap({"idol" = "Entities\Idol", "fan" = "Entities\Fan"}) | |
*/ | |
class Fan extends EntityAbstract | |
{ | |
// /** | |
// * @ManyToMany(targetEntity="Entities\Idol", mappedBy="_idols") | |
// */ | |
// private $_idols; | |
public function __construct () | |
{ | |
parent::__construct(); | |
// $this->_idols = new \Doctrine\Common\Collections\ArrayCollection(); | |
} | |
} |
This file contains 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
<?php | |
namespace Entities; | |
/** | |
* @Entity | |
*/ | |
class Idol extends Fan | |
{ | |
/** | |
* @ManyToMany(targetEntity="Entities\Fan") | |
* @JoinTable(name="idol_fans" | |
* ,joinColumns={@JoinColumn(name="idol_id", referencedColumnName="id")} | |
* ,inverseJoinColumns={@JoinColumn(name="fan_id", referencedColumnName="id")} | |
* ) | |
*/ | |
private $_fans; | |
public function __construct () | |
{ | |
parent::__construct(); | |
$this->_fans = new \Doctrine\Common\Collections\ArrayCollection(); | |
} | |
public function getFans () | |
{ | |
return $this->_fans; | |
} | |
public function setFans (array $arg_fans) | |
{ | |
$this->_fans = new \Doctrine\Common\Collections\ArrayCollection(array_filter($arg_fans, array($this, '_filterFan'))); | |
} | |
private function _filterFan (UserHyvesXfactorFan $arg_fan) | |
{ | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment