Пример #1
0
 /**
  * Find all characters based on the given $criteria.
  *
  * @param Api\Client $client   The API Client.
  * @param array      $criteria The criteria to search with.
  *
  * @return Api\Collection
  */
 public static function findAll(Api\Client $client, array $criteria = [])
 {
     $filters = ['name' => [['string']], 'modifiedSince' => [['date', true], ['formatDate']], 'comics' => [['ofScalars', [['uint']]], ['implode', ',']], 'series' => [['ofScalars', [['uint']]], ['implode', ',']], 'events' => [['ofScalars', [['uint']]], ['implode', ',']], 'stories' => [['ofScalars', [['uint']]], ['implode', ',']], 'orderBy' => [['in', ['name', 'modified', '-name', '-modified']]]];
     list($success, $filteredCriteria, $error) = Api\Filterer::filter($filters, $criteria);
     Util::ensure(true, $success, $error);
     return new Api\Collection($client, 'characters', $filteredCriteria);
 }
Пример #2
0
 /**
  * Create a new AbstractEntity based on the given $input array.
  *
  * @param array $input The data for the EntityInterface.
  */
 public function __construct(array $input = [])
 {
     list($success, $filtered, $error) = Filterer::filter($this->getFilters(), $input, ['allowUnknowns' => true]);
     Util::ensure(true, $success, '\\InvalidArgumentException', [$error]);
     foreach ($filtered as $key => $value) {
         $this->data[$key] = $value;
     }
 }
 /**
  * Create a new DataWrapper instance.
  *
  * @param array $input The data for the DataWrapper
  */
 public function __construct(array $input)
 {
     $filters = ['code' => [['int', true]], 'status' => [['string', true]], 'copyright' => [['string', true]], 'attributionText' => [['string', true]], 'attributionHTML' => [['string', true]], 'etag' => [['string', true]], 'data' => ['default' => [], ['array', 0]]];
     list($success, $filteredInput, $error) = Filterer::filter($filters, $input, ['allowUnknowns' => true]);
     Util::ensure(true, $success, $error);
     foreach ($filteredInput as $key => $value) {
         $this->{$key} = $value;
     }
     $this->data = new DataContainer($filteredInput['data']);
 }
 /**
  * Create a new DataContainer instance.
  *
  * @param array $input The data for the DataContainer
  */
 public function __construct(array $input)
 {
     $resourceFilter = self::deriveResourceFilter(Util\Arrays::get($input, 'results', []));
     $filters = ['offset' => ['default' => 0, ['int', true]], 'limit' => ['default' => 0, ['int', true]], 'total' => ['default' => 0, ['int', true]], 'count' => ['default' => 0, ['int', true]], 'results' => [[$resourceFilter]]];
     list($success, $filtered, $error) = Filterer::filter($filters, $input, ['allowUnknowns' => true]);
     Util::ensure(true, $success, $error);
     foreach ($filtered as $key => $value) {
         $this->{$key} = $value;
     }
 }
Пример #5
0
 /**
  * Returns a collection containing all Comics which match the given criteria.
  *
  * @param Api\Client $client   The API Client.
  * @param array      $criteria The criteria for searching.
  *
  * @return Api\Collection
  */
 public static final function findAll(Api\Client $client, array $criteria = [])
 {
     $filters = ['format' => [['in', ['comic', 'hardcover', 'trade paperback', 'magazine', 'digest', 'graphic novel', 'digital comic', 'infinite comic']]], 'formatType' => [['in', ['comic', 'collection']]], 'noVariants' => [['bool'], ['boolToString']], 'dateDescriptor' => [['in', ['lastWeek', 'thisWeek', 'nextWeek', 'thisMonth']]], 'fromDate' => [['date', true]], 'toDate' => [['date', true]], 'hasDigitalIssue' => [['bool'], ['boolToString']], 'modifiedSince' => [['date', true], ['formatDate']], 'creators' => [['ofScalars', [['uint']]], ['implode', ',']], 'characters' => [['ofScalars', [['uint']]], ['implode', ',']], 'series' => [['ofScalars', [['uint']]], ['implode', ',']], 'events' => [['ofScalars', [['uint']]], ['implode', ',']], 'stories' => [['ofScalars', [['uint']]], ['implode', ',']], 'sharedAppearances' => [['ofScalars', [['uint']]], ['implode', ',']], 'collaborators' => [['ofScalars', [['uint']]], ['implode', ',']], 'orderBy' => [['in', ['focDate', 'onsaleDate', 'title', 'issueNumber', 'modified', '-focDate', '-onsaleDate', '-title', '-issueNumber', '-modified']]]];
     list($success, $filteredCriteria, $error) = Api\Filterer::filter($filters, $criteria);
     Util::ensure(true, $success, $error);
     $toDate = Util\Arrays::get($filteredCriteria, 'toDate');
     $fromDate = Util\Arrays::get($filteredCriteria, 'fromDate');
     if ($toDate !== null && $fromDate !== null) {
         unset($filteredCriteria['toDate'], $filteredCriteria['fromDate']);
         $filteredCriteria['dateRange'] = "{$fromDate->format('c')},{$toDate->format('c')}";
     }
     return new Api\Collection($client, self::API_RESOURCE, $filteredCriteria);
 }