Skip to content

Instantly share code, notes, and snippets.

@Raistlfiren
Created August 4, 2016 15:07
Show Gist options
  • Save Raistlfiren/e34293e92f77ac6cb3bec7fcb49ede76 to your computer and use it in GitHub Desktop.
Save Raistlfiren/e34293e92f77ac6cb3bec7fcb49ede76 to your computer and use it in GitHub Desktop.
<?php
namespace Bolt\Extension\Test\ExtensionA\Storage\Repository;
class ContentRepository extends \Bolt\Storage\Repository\ContentRepository
{
public function getPublishedContent()
{
return $this->findBy(['status' => 'published']);
}
}
<?php
namespace Bolt\Extension\Bolt\JsonApi\Storage;
use Bolt\Storage\Query\QueryInterface;
use Bolt\Storage\Repository\ContentRepository;
use Doctrine\DBAL\Query\QueryBuilder;
/**
* Class Repository
* @package Bolt\Extension\Bolt\JsonApi\Storage
*/
class Repository extends ContentRepository
{
/**
* This method is used to load all of the default query builder information and return
* a query builder back to manipulate the query. This allows for easier pagination and
* manipulating queries before fetching.
* @param QueryInterface $query
* @return QueryInterface
*/
public function getQueryBuilderAfterMappings(QueryInterface $query)
{
$this->query($query);
$queryBuilder = $query->build();
$this->load($queryBuilder);
return $query;
}
/**
* Since the queries are built already, we don't need to run all of the other mappings
* before. Now we can just fetch the results of the query instead of running everything else.
* @param QueryBuilder $query
* @return bool|mixed
*/
public function findResults(QueryBuilder $query)
{
$result = $query->execute()->fetchAll();
if ($result) {
return $this->hydrateAll($result, $query);
} else {
return false;
}
}
}
<?php
namespace Bolt\Extension\Test\ExtensionA\Provider;
use Silex\ServiceProviderInterface;
use Silex\Application;
class TaxonomyListProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
// TODO: Implement register() method.
/**
* Add repository and query parsers to handle pagination to DI
*/
$app['storage.content_repository'] = $app->protect(
function ($classMetadata) use ($app) {
$repoClass = 'Bolt\Extension\Test\ExtensionA\Storage\Repository\ContentRepository';
$repo = new $repoClass($app['storage'], $classMetadata);
$repo->setLegacyService($app['storage.legacy_service']);
return $repo;
}
);
}
public function boot(Application $app)
{
// TODO: Implement boot() method.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment