Overview

Namespaces

  • DSchoenbauer
    • Orm
      • Builder
      • Entity
      • Enum
      • Events
        • Persistence
        • Validate
          • DataType
          • Schema
      • Exception
      • Framework

Classes

  • DSchoenbauer\Orm\Builder\ModelDirector
  • DSchoenbauer\Orm\Builder\PdoModelBuilder
  • DSchoenbauer\Orm\CrudModel
  • DSchoenbauer\Orm\Entity\AbstractEntity
  • DSchoenbauer\Orm\Enum\ModelEvents
  • DSchoenbauer\Orm\Events\AbstractEvent
  • DSchoenbauer\Orm\Events\Persistence\PdoCreate
  • DSchoenbauer\Orm\Events\Persistence\PdoDelete
  • DSchoenbauer\Orm\Events\Persistence\PdoSelect
  • DSchoenbauer\Orm\Events\Persistence\PdoUpdate
  • DSchoenbauer\Orm\Events\Validate\AbstractValidate
  • DSchoenbauer\Orm\Events\Validate\DataType\AbstractDataType
  • DSchoenbauer\Orm\Events\Validate\DataType\DataTypeBoolean
  • DSchoenbauer\Orm\Events\Validate\DataType\DataTypeDate
  • DSchoenbauer\Orm\Events\Validate\DataType\DataTypeNumber
  • DSchoenbauer\Orm\Events\Validate\DataType\DataTypeString
  • DSchoenbauer\Orm\Events\Validate\Schema\DefaultValue
  • DSchoenbauer\Orm\Events\Validate\Schema\RequiredFields
  • DSchoenbauer\Orm\Events\Validate\Schema\ValidFields
  • DSchoenbauer\Orm\Exception\InvalidDataTypeException
  • DSchoenbauer\Orm\Exception\RequiredFieldMissingException
  • DSchoenbauer\Orm\Framework\Attribute
  • DSchoenbauer\Orm\Framework\AttributeCollection
  • DSchoenbauer\Orm\Model

Interfaces

  • DSchoenbauer\Orm\Builder\BuilderInterface
  • DSchoenbauer\Orm\Builder\DirectorInterface
  • DSchoenbauer\Orm\Entity\EntityInterface
  • DSchoenbauer\Orm\Entity\HasBoolFieldsInterface
  • DSchoenbauer\Orm\Entity\HasDateFieldsInterface
  • DSchoenbauer\Orm\Entity\HasDateWithCustomFormatInterface
  • DSchoenbauer\Orm\Entity\HasDefaultValuesInterface
  • DSchoenbauer\Orm\Entity\HasFilterInterface
  • DSchoenbauer\Orm\Entity\HasNumericFieldsInterface
  • DSchoenbauer\Orm\Entity\HasRequiredFieldsInterface
  • DSchoenbauer\Orm\Entity\HasStaticValuesInterface
  • DSchoenbauer\Orm\Entity\HasStringFieldsInterface
  • DSchoenbauer\Orm\Entity\IsSortableInterface
  • DSchoenbauer\Orm\Exception\OrmExceptionInterface
  • DSchoenbauer\Orm\VisitorInterface
  • Overview
  • Namespace
  • Class
  1: <?php
  2: /**
  3:  * The MIT License
  4:  *
  5:  * Copyright 2017 David Schoenbauer.
  6:  *
  7:  * Permission is hereby granted, free of charge, to any person obtaining a copy
  8:  * of this software and associated documentation files (the "Software"), to deal
  9:  * in the Software without restriction, including without limitation the rights
 10:  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 11:  * copies of the Software, and to permit persons to whom the Software is
 12:  * furnished to do so, subject to the following conditions:
 13:  *
 14:  * The above copyright notice and this permission notice shall be included in
 15:  * all copies or substantial portions of the Software.
 16:  *
 17:  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18:  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19:  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20:  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21:  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 22:  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 23:  * THE SOFTWARE.
 24:  */
 25: namespace DSchoenbauer\Orm;
 26: 
 27: use DSchoenbauer\Orm\Entity\EntityInterface;
 28: use DSchoenbauer\Orm\Framework\AttributeCollection;
 29: use Zend\EventManager\EventManagerAwareTrait;
 30: 
 31: /**
 32:  * An object that represents business logic and is available for general consumption
 33:  *
 34:  * @author David Schoenbauer
 35:  */
 36: class Model
 37: {
 38: 
 39:     private $id;
 40:     private $data;
 41:     private $attributes;
 42:     private $entity;
 43: 
 44:     use EventManagerAwareTrait;
 45: 
 46:     /**
 47:      * @param EntityInterface $entity an entity object houses specific
 48:      * information about a given model
 49:      */
 50:     public function __construct(EntityInterface $entity)
 51:     {
 52:         $this->setAttributes(new AttributeCollection())->setEntity($entity);
 53:     }
 54: 
 55:     /**
 56:      * provides the entity of the model
 57:      * @return EntityInterface
 58:      * @since v1.0.0
 59:      */
 60:     public function getEntity()
 61:     {
 62:         return $this->entity;
 63:     }
 64: 
 65:     /**
 66:      * sets the entity of the model
 67:      * @param EntityInterface $entity
 68:      * @return Model
 69:      * @since v1.0.0
 70:      */
 71:     public function setEntity(EntityInterface $entity)
 72:     {
 73:         $this->entity = $entity;
 74:         return $this;
 75:     }
 76: 
 77:     /**
 78:      * Allows the visitor pattern to expand the functionality of the object
 79:      * @param \DSchoenbauer\Orm\VisitorInterface $visitor
 80:      * @return Model
 81:      * @since v1.0.0
 82:      */
 83:     public function accept(VisitorInterface $visitor)
 84:     {
 85:         $visitor->visitModel($this);
 86:         return $this;
 87:     }
 88: 
 89:     /**
 90:      * provides a unique identifier value for a given record
 91:      * @return integer
 92:      * @since v1.0.0
 93:      */
 94:     public function getId()
 95:     {
 96:         return $this->id;
 97:     }
 98: 
 99:     /**
100:      * provides the current record
101:      * @return mixed
102:      * @since v1.0.0
103:      */
104:     public function getData()
105:     {
106:         return $this->data;
107:     }
108: 
109:     /**
110:      * sets a unique identifier value for a given record
111:      * @param integer $id
112:      * @return Model
113:      * @since v1.0.0
114:      */
115:     public function setId($id)
116:     {
117:         $this->id = $id;
118:         return $this;
119:     }
120: 
121:     /**
122:      * sets the current record
123:      * @param mixed $data current
124:      * @return Model
125:      * @since v1.0.0
126:      */
127:     public function setData($data)
128:     {
129:         $this->data = $data;
130:         return $this;
131:     }
132: 
133: 
134:     /**
135:      * provides a collection of key value pairs that are specific to a given model
136:      * @return AttributeCollection
137:      * @since v1.0.0
138:      */
139:     public function getAttributes()
140:     {
141:         return $this->attributes;
142:     }
143: 
144:     /**
145:      * sets a collection of key value pairs that are specific to a given model
146:      * @param AttributeCollection $attributes
147:      * @return Model
148:      * @since v1.0.0
149:      */
150:     public function setAttributes(AttributeCollection $attributes)
151:     {
152:         $this->attributes = $attributes;
153:         return $this;
154:     }
155: }
156: 
API documentation generated by ApiGen