Skip to content

Instantly share code, notes, and snippets.

@devmatheus
Last active August 29, 2015 13:59
Show Gist options
  • Select an option

  • Save devmatheus/10668172 to your computer and use it in GitHub Desktop.

Select an option

Save devmatheus/10668172 to your computer and use it in GitHub Desktop.

Revisions

  1. devmatheus revised this gist Apr 14, 2014. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Sessao1.php
    Original file line number Diff line number Diff line change
    @@ -42,6 +42,10 @@ 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);
  2. devmatheus created this gist Apr 14, 2014.
    72 changes: 72 additions & 0 deletions Sessao1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    <?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 __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;
    }

    }
    91 changes: 91 additions & 0 deletions Sessao2.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,91 @@
    <?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);
    }

    }