Esempio n. 1
0
 /**
  * Constructor.
  *
  * @param Illuminate\Database\Eloquent\Collection $collection - a collection to present.
  * @access public
  * @throws InvalidArgumentException
  */
 public function __construct($data)
 {
     if (is_object($data)) {
         if ($data instanceof Collection || $data instanceof Model) {
             $data = $data->toArray();
         } else {
             $data = (array) $data;
         }
     } else {
         if (!is_array($data)) {
             throw new \InvalidArgumentException('Data must only be an object or array. ' . gettype($data) . ' was given.');
         }
     }
     parent::__construct($data);
 }
Esempio n. 2
0
<?php

use AlephTools\Data\Presenters\ArrayPresenter;
require_once __DIR__ . '/../src/ArrayPresenter.php';
$a = (require __DIR__ . '/data.php');
echo '<b>The original array:</b><pre>' . print_r($a, true) . '</pre>';
$presenter = new ArrayPresenter($a);
$presenter->mode = ArrayPresenter::MODE_REDUCE;
$presenter->schema = ['$.id', '$.name', '$.date|date_string:m/d/Y', '$.tags|ignore|array'];
echo '<b>The transformaton schema (REDUCE mode):</b><pre>' . print_r($presenter->schema, true) . '</pre>';
$res = $presenter->toArray();
echo '<b>The result:</b><pre>' . print_r($res, true) . '</pre>';
 /**
  * Constructor.
  *
  * @param Illuminate\Database\Eloquent\Collection $collection - a collection to present.
  * @access public
  */
 public function __construct(Collection $collection)
 {
     parent::__construct($collection->toArray());
 }
Esempio n. 4
0
 /**
  * Constructor.
  *
  * @param Illuminate\Database\Eloquent\Model $model - a model to present.
  * @access public
  */
 public function __construct(Model $model)
 {
     parent::__construct($model->toArray());
 }