From d8d64043ebaee409c331128e8917316031b7e01b Mon Sep 17 00:00:00 2001 From: Adam Engebretson Date: Mon, 28 Jul 2014 20:33:37 -0700 Subject: [PATCH] Fixing compatability issue with Prismic's PHP Kit Signed-off-by: Adam Engebretson --- .gitignore | 3 +- composer.json | 4 +- src/Adamgoose/PrismicIo/Model.php | 14 ++++--- src/Adamgoose/PrismicIo/Query.php | 63 +++++++++++++++++++------------ 4 files changed, 50 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 2c1fc0c..38cdbd7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /vendor composer.phar composer.lock -.DS_Store \ No newline at end of file +.DS_Store +.idea \ No newline at end of file diff --git a/composer.json b/composer.json index 270c845..7f36668 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": ">=5.3.0", + "php": ">=5.4.0", "illuminate/support": "~4.0", "prismic/php-sdk": "dev-master" }, @@ -19,5 +19,5 @@ "Adamgoose\\PrismicIo": "src/" } }, - "minimum-stability": "dev" + "minimum-stability": "stable" } \ No newline at end of file diff --git a/src/Adamgoose/PrismicIo/Model.php b/src/Adamgoose/PrismicIo/Model.php index fba3295..8ef7ecc 100644 --- a/src/Adamgoose/PrismicIo/Model.php +++ b/src/Adamgoose/PrismicIo/Model.php @@ -7,13 +7,13 @@ abstract class Model { protected $endpoint; protected $token; - protected $ref; + public $ref; public $collection; public $mask; public $tags; - public $conditions = array(); + public $conditions = []; public $pageSize = 20; public $page = 1; @@ -23,7 +23,9 @@ abstract class Model { /** * Grab variables from config * - * @return void + * @param Document $document + * + * @return \Adamgoose\PrismicIo\Model */ public function __construct(Document $document = null) { @@ -57,10 +59,10 @@ public function newQuery() public function __call($method, $parameters) { if($this->document instanceof Document) { - return call_user_func_array(array($this->document, $method), $parameters); + return call_user_func_array([$this->document, $method], $parameters); } else { $query = $this->newQuery(); - return call_user_func_array(array($query, $method), $parameters); + return call_user_func_array([$query, $method], $parameters); } } @@ -75,7 +77,7 @@ public static function __callStatic($method, $parameters) { $instance = new static; - return call_user_func_array(array($instance, $method), $parameters); + return call_user_func_array([$instance, $method], $parameters); } /** diff --git a/src/Adamgoose/PrismicIo/Query.php b/src/Adamgoose/PrismicIo/Query.php index 3fc0008..5ace9e0 100644 --- a/src/Adamgoose/PrismicIo/Query.php +++ b/src/Adamgoose/PrismicIo/Query.php @@ -11,7 +11,8 @@ class Query { * Creates a new Query instance. * * @param \Adamgoose\PrismicIo\Model $model - * @return void + * + * @return \Adamgoose\PrismicIo\Query */ public function __construct(Model $model) { @@ -21,7 +22,8 @@ public function __construct(Model $model) /** * Sets the ref of the query * - * @param string $ref + * @param string $ref + * * @return \Adamgoose\PrismicIo\Query */ public function ref($ref) @@ -34,7 +36,8 @@ public function ref($ref) /** * Sets the collection of the query * - * @param string $collection + * @param string $collection + * * @return \Adamgoose\PrismicIo\Query */ public function collection($collection) @@ -47,7 +50,8 @@ public function collection($collection) /** * Sets the mask of the query * - * @param string $mask + * @param string $mask + * * @return \Adamgoose\PrismicIo\Query */ public function mask($mask) @@ -60,7 +64,8 @@ public function mask($mask) /** * Sets the tags of the query * - * @param array $tags + * @param array $tags + * * @return \Adamgoose\PrismicIo\Query */ public function tags(array $tags) @@ -75,7 +80,8 @@ public function tags(array $tags) * * @param string $key * @param string $value - * @return \Adamgoose\Prismic\Query + * + * @return \Adamgoose\PrismicIo\Query */ public function at($key, $value) { @@ -89,7 +95,8 @@ public function at($key, $value) * * @param string $key * @param array $values - * @return \Adamgoose\Prismic\Query + * + * @return \Adamgoose\PrismicIo\Query */ public function any($key, array $values) { @@ -103,7 +110,8 @@ public function any($key, array $values) * * @param string $key * @param string $value - * @return \Adamgoose\Prismic\Query + * + * @return \Adamgoose\PrismicIo\Query */ public function fulltext($key, $value) { @@ -116,7 +124,8 @@ public function fulltext($key, $value) * Define the pageSize for the query * * @param int $pageSize - * @return \Adamgoose\Prismic\Query + * + * @return \Adamgoose\PrismicIo\Query */ public function pageSize($pageSize) { @@ -129,7 +138,8 @@ public function pageSize($pageSize) * Define which page to return * * @param int $page - * @return \Adamgoose\Prismic\Query + * + * @return \Adamgoose\PrismicIo\Query */ public function page($page) { @@ -142,13 +152,14 @@ public function page($page) * Alias for at('document.id', $id) * * @param string $id + * * @return \Prismic\Document */ public function find($id) { $collection = $this->get(); - $collection = $collection->filter(function($document) use ($id) + $collection = $collection->filter(function ($document) use ($id) { if($document->id == $id) return true; }); @@ -160,13 +171,14 @@ public function find($id) * Return the document with matching slug * * @param string $slug + * * @return \Prismic\Document */ public function findSlug($slug) { $collection = $this->get(); - $collection = $collection->filter(function($document) use ($slug) + $collection = $collection->filter(function ($document) use ($slug) { if($document->containsSlug($slug)) return true; }); @@ -176,7 +188,6 @@ public function findSlug($slug) /** * Alias for get()->first(); - * * @return \Prismic\Document */ public function first() @@ -186,7 +197,6 @@ public function first() /** * Execute the query - * * @return \Illuminate\Support\Collection */ public function get() @@ -197,28 +207,31 @@ public function get() // Set mask using predicated query if($this->model->mask != null) - $query .= '[:d = at(document.type, "'.$this->model->mask.'")]'; + $query .= '[:d = at(document.type, "' . $this->model->mask . '")]'; // Set tags using predicated query if($this->model->tags != null) - $query .= '[:d = any(document.tags, ["'.implode('","', $this->model->tags).'"])]'; + $query .= '[:d = any(document.tags, ["' . implode('","', $this->model->tags) . '"])]'; // Set "at" predicated queries if(array_key_exists('at', $this->model->conditions)) - foreach($this->model->conditions['at'] as $at) { - $query .= '[:d = at('.$at['key'].', "'.$at['value'].'")]'; + foreach($this->model->conditions['at'] as $at) + { + $query .= '[:d = at(' . $at['key'] . ', "' . $at['value'] . '")]'; } // Set "any" predicated queries if(array_key_exists('any', $this->model->conditions)) - foreach($this->model->conditions['any'] as $any) { - $query .= '[:d = any('.$any['key'].', ["'.implode('","', $any['values']).'"])]'; + foreach($this->model->conditions['any'] as $any) + { + $query .= '[:d = any(' . $any['key'] . ', ["' . implode('","', $any['values']) . '"])]'; } // Set "fulltext" predicated queries if(array_key_exists('fulltext', $this->model->conditions)) - foreach($this->model->conditions['fulltext'] as $fulltext) { - $query .= '[:d = fulltext('.$fulltext['key'].', "'.$fulltext['value'].'")]'; + foreach($this->model->conditions['fulltext'] as $fulltext) + { + $query .= '[:d = fulltext(' . $fulltext['key'] . ', "' . $fulltext['value'] . '")]'; } // Determine which API form to use @@ -243,7 +256,7 @@ public function get() $class = get_class($this->model); $models = []; - foreach($results as $result) + foreach($results->getResults() as $result) $models[] = new $class($result); return new Collection($models); @@ -251,7 +264,6 @@ public function get() /** * Prepare API for calls - * * @return \Prismic\Api */ private function prepareApi() @@ -265,6 +277,8 @@ private function prepareApi() /** * Returns either the master ref, or the defined ref * + * @param Api $api + * * @return string */ private function getRef(Api $api) @@ -274,5 +288,4 @@ private function getRef(Api $api) return $api->master()->getRef(); } - } \ No newline at end of file