1. Go to this page and download the library: Download smgladkovskiy/querier library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use SMGladkovskiy\Querier\QuerierTrait;
class AdvertisementsController extends \BaseController {
use QuerierTrait;
/**
* Build a report of job advertisements.
*
* @return Response
*/
public function getAdvertisementsList()
{
}
}
use SMGladkovskiy\Querier\QuerierTrait;
use Acme\Queries\AdvertisementsListQuery;
class AdvertisementsController extends \BaseController {
use QuerierTrait;
/**
* Build a report of job advertisements.
*
* @return Response
*/
public function getAdvertisementsList()
{
$advertisements = $this->executeQuery(AdvertisementsListQuery::class);
return View::make('reports.advertisements', compact('advertisements'));
}
namespace Acme\Queries;
class AdvertisementsListQuery {
public $title;
public $position_id;
public function __construct($title = null, $position = null)
{
$this->title = $title;
$this->position_id = $position;
}
}
namespace Acme\Queries;
use SMGladkovskiy\Querier\QueryBus;
class AdvertisementSanitizer implements QueryBus {
public function executeQuery($query)
{
// sanitize the job data
}
}
namespace Acme\Queries;
use SMGladkovskiy\Querier\QueryHandler;
class AdvertisementsListQueryHandler implements QueryHandler {
public function handle($query)
{
$advertisements = Advertisement::where(function($query) use ($query as $filterData)
{
$query->where('title', $filterData->title);
$query->where('position_id', $filterData->position_id);
})->paginate(15);
return $advertisements;
}
}
namespace Acme\Core;
use SMGladkovskiy\Querier\QueryTranslator;
class MyQueryTranslator implements QueryTranslator {
/**
* Translate a query to its handler counterpart
*
* @param $query
* @return mixed
* @throws HandlerNotRegisteredException
*/
public function toQueryHandler($query)
{
$handler = str_replace('Query', 'Handler', get_class($query));
if ( ! class_exists($handler))
{
$message = "Query handler [$handler] does not exist.";
throw new HandlerNotRegisteredException($message);
}
return $handler;
}
/**
* Translate a query to its validator counterpart
*
* @param $query
* @return mixed
*/
public function toValidator($query)
{
$segments = explode('\\', get_class($query));
array_splice($segments, -1, false, 'Validators');
return str_replace('Query', 'Validator', implode('\\', $segments));
}
}
// We want to use our own custom translator class
App::bind(
'SMGladkovskiy\Querier\QueryTranslator',
'Acme\Core\MyQueryTranslator'
);
namespace Acme\Bar;
class UsersQuery {
/**
* Constructor
*/
public function __construct()
{
}
}
namespace Acme\Bar;
use SMGladkovskiy\Querier\QueryHandler;
class UsersQueryHandler implements QueryHandler {
/**
* Handle the command.
*
* @param object $command
* @return void
*/
public function handle($command)
{
}
}
namespace Acme\Bar;
class UsersQuery {
/**
* @var string
*/
public $first;
/**
* @var string
*/
public $last;
/**
* Constructor
*
* @param string first
* @param string last
*/
public function __construct($first, $last)
{
$this->first = $first;
$this->last = $last;
}
}