Skip to content

Instantly share code, notes, and snippets.

@devmatheus
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devmatheus/10668172 to your computer and use it in GitHub Desktop.
Save devmatheus/10668172 to your computer and use it in GitHub Desktop.
<?php
namespace Sessao\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zend\Stdlib\Hydrator;
/**
* @ORM\Entity
* @ORM\Table(name="sessao")
* @ORM\Entity(repositoryClass="Doctrine\ORM\EntityRepository")
*/
class Sessao {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
* @var int
*/
protected $id;
/**
* @ORM\Column(type="text", length=150)
* @var string
*/
protected $titulo;
/**
* @ORM\Column(type="text")
* @var int
*/
protected $slug;
/**
* @ORM\Column(type="text")
* @var string
*/
protected $texto;
public function __construct($options = null) {
$hydrator = new Hydrator\ClassMethods;
$hydrator->hydrate($options, $this);
}
public function __toString() {
return $this->titulo;
}
public function __call ($methodName, $params = null) {
$methodPrefix = substr($methodName, 0, 3);
$property = strtolower(substr($methodName, 3));
if ($methodPrefix == 'set' && count($params) == 1) {
$this->$property = $params[0];
return $this;
} elseif ($methodPrefix == 'get' && property_exists($this, $property)) {
return $this->$property;
}
throw new \Exception($methodName . ' não definido em ' . get_class($this));
}
public function toArray () {
$reflect = new \ReflectionClass($this);
$props = $reflect->getProperties();
$data = array();
foreach ($props as $property) {
$property = $property->getName();
$data[$property] = $this->$property;
}
return $data;
}
}
<?php
namespace Sessao\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zend\Stdlib\Hydrator;
/**
* @ORM\Entity
* @ORM\Table(name="sessao")
* @ORM\Entity(repositoryClass="Doctrine\ORM\EntityRepository")
*/
class Sessao {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
* @var int
*/
protected $id;
/**
* @ORM\Column(type="text", length=150)
* @var string
*/
protected $titulo;
/**
* @ORM\Column(type="text")
* @var int
*/
protected $slug;
/**
* @ORM\Column(type="text")
* @var string
*/
protected $texto;
public function __construct($options = null) {
$hydrator = new Hydrator\ClassMethods;
$hydrator->hydrate($options, $this);
}
public function getId() {
return $this->id;
}
public function setId($id) {
$this->id = $id;
return $this;
}
public function getTitulo() {
return $this->titulo;
}
public function setTitulo($titulo) {
$this->titulo = $titulo;
return $this;
}
public function getSlug() {
return $this->slug;
}
public function setSlug($slug) {
$this->slug = $slug;
return $this;
}
public function getTexto() {
return $this->texto;
}
public function setTexto($texto) {
$this->texto = $texto;
return $this;
}
public function __toString() {
return $this->titulo;
}
public function toArray() {
$hydrator = new Hydrator\ClassMethods;
return $hydrator->extract($this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment