}
// If an exception occurs when attempting to run a query, we'll format the error
// message to include the bindings with SQL, which will make this exception a
// lot more helpful to the developer instead of just the database's errors.
catch (\Exception $e)
{
throw new QueryException(
$query, $this->prepareBindings($bindings), $e
);
return $this->run($query, $bindings, function($me, $query, $bindings) use ($useReadPdo)
{
if ($me->pretending()) return array();
// For select statements, we'll simply execute the query and return an array
// of the database result set. Each element in the array will be a single
// row from the database table, and will either be an array or objects.
$statement = $this->getPdoForSelect($useReadPdo)->prepare($query);
$statement->execute($me->prepareBindings($bindings));
return $this->run($query, $bindings, function($me, $query, $bindings) use ($useReadPdo)
{
if ($me->pretending()) return array();
// For select statements, we'll simply execute the query and return an array
// of the database result set. Each element in the array will be a single
// row from the database table, and will either be an array or objects.
$statement = $this->getPdoForSelect($useReadPdo)->prepare($query);
$statement->execute($me->prepareBindings($bindings));
protected function runQueryCallback($query, $bindings, Closure $callback)
{
// To execute the statement, we'll simply call the callback, which will actually
// run the SQL against the PDO connection. Then we can calculate the time it
// took to execute and log the query SQL, bindings and time in our memory.
try
{
$result = $callback($this, $query, $bindings);
}
$start = microtime(true);
// Here we will run this query. If an exception occurs we'll determine if it was
// caused by a connection that has been lost. If that is the cause, we'll try
// to re-establish connection and re-run the query with a fresh connection.
try
{
$result = $this->runQueryCallback($query, $bindings, $callback);
}
catch (QueryException $e)
// of the database result set. Each element in the array will be a single
// row from the database table, and will either be an array or objects.
$statement = $this->getPdoForSelect($useReadPdo)->prepare($query);
$statement->execute($me->prepareBindings($bindings));
return $statement->fetchAll($me->getFetchMode());
});
}
protected function runSelect()
{
if ($this->useWritePdo)
{
return $this->connection->select($this->toSql(), $this->getBindings(), false);
}
return $this->connection->select($this->toSql(), $this->getBindings());
}
* @param array $columns
* @return array|static[]
*/
public function getFresh($columns = array('*'))
{
if (is_null($this->columns)) $this->columns = $columns;
return $this->processor->processSelect($this, $this->runSelect());
}
* @param array $columns
* @return array|static[]
*/
public function get($columns = array('*'))
{
if ( ! is_null($this->cacheMinutes)) return $this->getCached($columns);
return $this->getFresh($columns);
}
* @return \Illuminate\Database\Eloquent\Model[]
*/
public function getModels($columns = array('*'))
{
// First, we will simply get the raw results from the query builders which we
// can use to populate an array with Eloquent models. We will pass columns
// that should be selected as well, which are typically just everything.
$results = $this->query->get($columns);
$connection = $this->model->getConnectionName();
* Execute the query as a "select" statement.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public function get($columns = array('*'))
{
$models = $this->getModels($columns);
// If we actually found models we will also eager load any relationships that
} else {
if (array_key_exists('take', $parameters)) { //Paginate
//Get all or first model
$selectModel = ($oneOrAll == 2) ? $selectModel->take($parameters['take'])->get($fields) : $selectModel->first($fields);
} else {
//Get all or first model
$selectModel = ($oneOrAll == 2) ? $selectModel->get($fields) : $selectModel->first($fields);
}
// echo $cache_index;
if ($predis->exists($cache_index)) {
$model = json_decode($predis->get($cache_index), true);
} else {
//Select models
$model = $this->select($fields, $where_clause, 2, $parameters);
try {
* @param array $parameters
* @return \Symfony\Component\HttpFoundation\Response
*/
public function callAction($method, $parameters)
{
$this->setupLayout();
$response = call_user_func_array(array($this, $method), $parameters);
// If no response is returned from the controller action and a layout is being
* Call another controller
*/
public function callController($controller, $action, $parameters = array())
{
$app = app();
$controller = $app->make($controller);
return $controller->callAction($action, $parameters);
}
* @author Edwin Mugendi
* Inject data source. This are mainly select
*
* @param array $dataSource Data source
*/
public function injectDataSources() {
//Get this organization category id
$this->view_data['dataSource']['category_id'] = $this->callController(\Util::buildNamespace('blogs', 'category', 1), 'getOrganizationsHtmlSelect', array($this->org['id'], 'id', array('name'), \Lang::get('common.select')));
//Get and set published options to data source
$this->callController(\Util::buildNamespace('accounts', 'user', 1), 'sessionUser', array($this->view_data['user'], false));
}
\Session::put('user', $this->view_data['user']);
} //E# if statement
//Inject data sources
$this->injectDataSources();
//Make controller_model an array because of buildSingleList need an array
* @param array $parameters
* @return \Symfony\Component\HttpFoundation\Response
*/
public function callAction($method, $parameters)
{
$this->setupLayout();
$response = call_user_func_array(array($this, $method), $parameters);
// If no response is returned from the controller action and a layout is being
* @param string $method
* @return mixed
*/
protected function call($instance, $route, $method)
{
$parameters = $route->parametersWithoutNulls();
return $instance->callAction($method, $parameters);
}
$response = $this->before($instance, $route, $request, $method);
// If no before filters returned a response we'll call the method on the controller
// to get the response to be returned to the router. We will then return it back
// out for processing by this router and the after filters can be called then.
if (is_null($response))
{
$response = $this->call($instance, $route, $method);
}
$request = $this->getCurrentRequest();
// Now we can split the controller and method out of the action string so that we
// can call them appropriately on the class. This controller and method are in
// in the Class@method format and we need to explode them out then use them.
list($class, $method) = explode('@', $controller);
return $d->dispatch($route, $request, $class, $method);
};
}
*
* @return mixed
*/
public function run()
{
$parameters = array_filter($this->parameters(), function($p) { return isset($p); });
return call_user_func_array($this->action['uses'], $parameters);
}
// Once we have successfully matched the incoming request to a given route we
// can call the before filters on that route. This works similar to global
// filters in that if a response is returned we will not call the route.
$response = $this->callRouteBefore($route, $request);
if (is_null($response))
{
$response = $route->run($request);
}
// If no response was returned from the before filter, we will call the proper
// route instance to get the response. If no route is found a response will
// still get returned based on why no routes were found for this request.
$response = $this->callFilter('before', $request);
if (is_null($response))
{
$response = $this->dispatchToRoute($request);
}
}
if ($this->runningUnitTests() && ! $this['session']->isStarted())
{
$this['session']->start();
}
return $this['router']->dispatch($this->prepareRequest($request));
}
{
try
{
$this->refreshRequest($request = Request::createFromBase($request));
$this->boot();
return $this->dispatch($request);
}
catch (\Exception $e)
if ($this->sessionConfigured())
{
$session = $this->startSession($request);
$request->setSession($session);
}
$response = $this->app->handle($request, $type, $catch);
// Again, if the session has been configured we will need to close out the session
* @param \Symfony\Component\HttpFoundation\Request $request
* @param int $type
* @param bool $catch
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
$response = $this->app->handle($request, $type, $catch);
foreach ($this->cookies->getQueuedCookies() as $cookie)
* @param \Symfony\Component\HttpFoundation\Request $request
* @param int $type
* @param bool $catch
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
return $this->encrypt($this->app->handle($this->decrypt($request), $type, $catch));
}
{
$this->app = $app;
$this->middlewares = $middlewares;
}
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
return $this->app->handle($request, $type, $catch);
}
* @param \Symfony\Component\HttpFoundation\Request $request
* @return void
*/
public function run(SymfonyRequest $request = null)
{
$request = $request ?: $this['request'];
$response = with($stack = $this->getStackedClient())->handle($request);
$response->send();
| Once we have the application, we can simply call the run method,
| which will execute the request and send the response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have whipped up for them.
|
*/
$app->run();