Overview

Namespaces

  • rsanchez
    • Deep
      • App
        • EE
        • Laravel
          • Facade
      • Collection
      • Hydrator
      • Model
      • Plugin
      • Relations
      • Repository

Classes

  • AbstractHydrator
  • AssetsHydrator
  • DateHydrator
  • ExplodeHydrator
  • FileHydrator
  • GridHydrator
  • HydratorFactory
  • MatrixHydrator
  • ParentsHydrator
  • PipeHydrator
  • PlayaHydrator
  • RelationshipHydrator
  • SiblingsHydrator
  • WysiwygHydrator

Interfaces

  • HydratorInterface
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * Deep
  5:  *
  6:  * @package      rsanchez\Deep
  7:  * @author       Rob Sanchez <info@robsanchez.com>
  8:  */
  9: 
 10: namespace rsanchez\Deep\Hydrator;
 11: 
 12: use rsanchez\Deep\Collection\EntryCollection;
 13: use rsanchez\Deep\Collection\AbstractTitleCollection;
 14: use rsanchez\Deep\Hydrator\DefaultHydrator;
 15: use rsanchez\Deep\Repository\SiteRepository;
 16: use rsanchez\Deep\Repository\UploadPrefRepositoryInterface;
 17: use rsanchez\Deep\Model\Asset;
 18: use rsanchez\Deep\Model\File;
 19: use rsanchez\Deep\Model\GridCol;
 20: use rsanchez\Deep\Model\GridRow;
 21: use rsanchez\Deep\Model\MatrixCol;
 22: use rsanchez\Deep\Model\MatrixRow;
 23: use rsanchez\Deep\Model\PlayaEntry;
 24: use rsanchez\Deep\Model\RelationshipEntry;
 25: 
 26: /**
 27:  * Factory for building new Hydrators
 28:  */
 29: class HydratorFactory
 30: {
 31:     /**
 32:      * Array of fieldtype => hydrator class name
 33:      * @var array
 34:      */
 35:     protected $hydrators = array(
 36:         'matrix'                => '\\rsanchez\\Deep\\Hydrator\\MatrixHydrator',
 37:         'grid'                  => '\\rsanchez\\Deep\\Hydrator\\GridHydrator',
 38:         'playa'                 => '\\rsanchez\\Deep\\Hydrator\\PlayaHydrator',
 39:         'relationship'          => '\\rsanchez\\Deep\\Hydrator\\RelationshipHydrator',
 40:         'assets'                => '\\rsanchez\\Deep\\Hydrator\\AssetsHydrator',
 41:         'file'                  => '\\rsanchez\\Deep\\Hydrator\\FileHydrator',
 42:         'date'                  => '\\rsanchez\\Deep\\Hydrator\\DateHydrator',
 43:         'multi_select'          => '\\rsanchez\\Deep\\Hydrator\\PipeHydrator',
 44:         'checkboxes'            => '\\rsanchez\\Deep\\Hydrator\\PipeHydrator',
 45:         'fieldpack_checkboxes'  => '\\rsanchez\\Deep\\Hydrator\\ExplodeHydrator',
 46:         'fieldpack_multiselect' => '\\rsanchez\\Deep\\Hydrator\\ExplodeHydrator',
 47:         'fieldpack_list'        => '\\rsanchez\\Deep\\Hydrator\\ExplodeHydrator',
 48:         'wygwam'                => '\\rsanchez\\Deep\\Hydrator\\WysiwygHydrator',
 49:         'parents'               => '\\rsanchez\\Deep\\Hydrator\\ParentsHydrator',
 50:         'siblings'              => '\\rsanchez\\Deep\\Hydrator\\SiblingsHydrator',
 51:     );
 52: 
 53:     /**
 54:      * Site model repository
 55:      * @var \rsanchez\Deep\Repository\SiteRepository
 56:      */
 57:     protected $siteRepository;
 58: 
 59:     /**
 60:      * UploadPref model repository
 61:      * @var \rsanchez\Deep\Repository\UploadPrefRepository
 62:      */
 63:     protected $uploadPrefRepository;
 64: 
 65:     /**
 66:      * Constructor
 67:      *
 68:      * @var \rsanchez\Deep\Repository\SiteRepository                $siteRepository
 69:      * @var \rsanchez\Deep\Repository\UploadPrefRepositoryInterface $uploadPrefRepository
 70:      */
 71:     public function __construct(
 72:         SiteRepository $siteRepository,
 73:         UploadPrefRepositoryInterface $uploadPrefRepository,
 74:         Asset $asset,
 75:         File $file,
 76:         GridCol $gridCol,
 77:         GridRow $gridRow,
 78:         MatrixCol $matrixCol,
 79:         MatrixRow $matrixRow,
 80:         PlayaEntry $playaEntry,
 81:         RelationshipEntry $relationshipEntry
 82:     ) {
 83:         $this->siteRepository = $siteRepository;
 84:         $this->uploadPrefRepository = $uploadPrefRepository;
 85:         $this->asset = $asset;
 86:         $this->file =  $file;
 87:         $this->gridCol = $gridCol;
 88:         $this->gridRow = $gridRow;
 89:         $this->matrixCol = $matrixCol;
 90:         $this->matrixRow = $matrixRow;
 91:         $this->playaEntry = $playaEntry;
 92:         $this->relationshipEntry = $relationshipEntry;
 93:     }
 94: 
 95:     /**
 96:      * Get an array of Hydrators needed by the specified collection
 97:      *    'field_name' => AbstractHydrator
 98:      * @param  \rsanchez\Deep\Collection\AbstractTitleCollection $collection
 99:      * @return array                                             AbstractHydrator[]
100:      */
101:     public function getHydrators(AbstractTitleCollection $collection, array $extraHydrators = array())
102:     {
103:         $hydrators = array();
104: 
105:         if ($collection->hasCustomFields()) {
106:             // add the built-in ones
107:             foreach ($this->hydrators as $type => $class) {
108:                 if ($collection->hasFieldtype($type)) {
109:                     $hydrators[$type] = $this->newHydrator($collection, $type);
110:                 }
111:             }
112:         }
113: 
114:         foreach ($extraHydrators as $type) {
115:             if (isset($this->hydrators[$type])) {
116:                 $hydrators[$type] = $this->newHydrator($collection, $type);
117:             }
118:         }
119: 
120:         return $hydrators;
121:     }
122: 
123:     /**
124:      * Create a new Hydrator object
125:      * @param  \rsanchez\Deep\Collection\EntryCollection $collection
126:      * @param  string                                    $fieldtype
127:      * @return \rsanchez\Deep\Hydrator\AbstractHydrator
128:      */
129:     public function newHydrator(EntryCollection $collection, $fieldtype)
130:     {
131:         $class = $this->hydrators[$fieldtype];
132: 
133:         $baseClass = basename(str_replace('\\', DIRECTORY_SEPARATOR, $class));
134: 
135:         $method = 'new'.$baseClass;
136: 
137:         // some hydrators may have dependencies to be injected
138:         if (method_exists($this, $method)) {
139:             return $this->$method($collection, $fieldtype);
140:         }
141: 
142:         return new $class($collection, $fieldtype);
143:     }
144: 
145:     /**
146:      * Create a new AssetsHydrator object
147:      * @param  \rsanchez\Deep\Collection\EntryCollection $collection
148:      * @param  string                                    $fieldtype
149:      * @return \rsanchez\Deep\Hydrator\AssetsHydrator
150:      */
151:     public function newAssetsHydrator(EntryCollection $collection, $fieldtype)
152:     {
153:         return new AssetsHydrator($collection, $fieldtype, $this->asset, $this->uploadPrefRepository);
154:     }
155: 
156:     /**
157:      * Create a new FileHydrator object
158:      * @param  \rsanchez\Deep\Collection\EntryCollection $collection
159:      * @param  string                                    $fieldtype
160:      * @return \rsanchez\Deep\Hydrator\FileHydrator
161:      */
162:     public function newFileHydrator(EntryCollection $collection, $fieldtype)
163:     {
164:         return new FileHydrator($collection, $fieldtype, $this->file, $this->uploadPrefRepository);
165:     }
166: 
167:     /**
168:      * Create a new GridHydrator object
169:      * @param  \rsanchez\Deep\Collection\EntryCollection $collection
170:      * @param  string                                    $fieldtype
171:      * @return \rsanchez\Deep\Hydrator\GridHydrator
172:      */
173:     public function newGridHydrator(EntryCollection $collection, $fieldtype)
174:     {
175:         return new GridHydrator($collection, $fieldtype, $this->gridCol, $this->gridRow);
176:     }
177: 
178:     /**
179:      * Create a new MatrixHydrator object
180:      * @param  \rsanchez\Deep\Collection\EntryCollection $collection
181:      * @param  string                                    $fieldtype
182:      * @return \rsanchez\Deep\Hydrator\MatrixHydrator
183:      */
184:     public function newMatrixHydrator(EntryCollection $collection, $fieldtype)
185:     {
186:         return new MatrixHydrator($collection, $fieldtype, $this->matrixCol, $this->matrixRow);
187:     }
188: 
189:     /**
190:      * Create a new PlayaHydrator object
191:      * @param  \rsanchez\Deep\Collection\EntryCollection $collection
192:      * @param  string                                    $fieldtype
193:      * @return \rsanchez\Deep\Hydrator\PlayaHydrator
194:      */
195:     public function newPlayaHydrator(EntryCollection $collection, $fieldtype)
196:     {
197:         return new PlayaHydrator($collection, $fieldtype, $this->playaEntry);
198:     }
199: 
200:     /**
201:      * Create a new RelationshipHydrator object
202:      * @param  \rsanchez\Deep\Collection\EntryCollection    $collection
203:      * @param  string                                       $fieldtype
204:      * @return \rsanchez\Deep\Hydrator\RelationshipHydrator
205:      */
206:     public function newRelationshipHydrator(EntryCollection $collection, $fieldtype)
207:     {
208:         return new RelationshipHydrator($collection, $fieldtype, $this->relationshipEntry);
209:     }
210: 
211:     /**
212:      * Create a new ParentsHydrator object
213:      * @param  \rsanchez\Deep\Collection\EntryCollection    $collection
214:      * @param  string                                       $fieldtype
215:      * @return \rsanchez\Deep\Hydrator\ParentsHydrator
216:      */
217:     public function newParentsHydrator(EntryCollection $collection, $fieldtype)
218:     {
219:         return new ParentsHydrator($collection, $fieldtype, $this->relationshipEntry);
220:     }
221: 
222:     /**
223:      * Create a new SIblingsHydrator object
224:      * @param  \rsanchez\Deep\Collection\EntryCollection    $collection
225:      * @param  string                                       $fieldtype
226:      * @return \rsanchez\Deep\Hydrator\SiblingsHydrator
227:      */
228:     public function newSiblingsHydrator(EntryCollection $collection, $fieldtype)
229:     {
230:         return new SiblingsHydrator($collection, $fieldtype, $this->relationshipEntry);
231:     }
232: 
233:     /**
234:      * Create a new WysiwygHydrator object
235:      * @param  \rsanchez\Deep\Collection\EntryCollection $collection
236:      * @param  string                                    $fieldtype
237:      * @return \rsanchez\Deep\Hydrator\WysiwygHydrator
238:      */
239:     public function newWysiwygHydrator(EntryCollection $collection, $fieldtype)
240:     {
241:         return new WysiwygHydrator($collection, $fieldtype, $this->siteRepository, $this->uploadPrefRepository);
242:     }
243: }
244: 
API documentation generated by ApiGen 2.8.0