Skip to content

Instantly share code, notes, and snippets.

@tommymarshall
Created January 18, 2017 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommymarshall/6839c3ecaec0af77782dd247655d08aa to your computer and use it in GitHub Desktop.
Save tommymarshall/6839c3ecaec0af77782dd247655d08aa to your computer and use it in GitHub Desktop.
Contentful Feed Builder
<?php
class ContentfulBuilder {
protected $query;
public function __construct() {
$this->query = new Query;
}
public function setContentType($content_type) {
$this->query->setContentType($content_type);
return $this;
}
public function where($query)
{
if (is_array($query)) {
foreach ($query as $key => $value) {
$this->query->where("fields.$key", $value);
}
}
return $this;
}
public function get()
{
return $this->query;
}
}
<?php
$query = (new ContentfulBuilder)->setContentType('gameAssetCarousel')->where([
'namespace' => 'foo',
'tags' => 'foo_index',
])->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment