|
$message = "The `{$name}` association is not defined on `{$this->getAlias()}`."; |
|
if ($assocations) { |
|
$message .= "\nValid associations are: " . implode(', ', $assocations); |
|
} |
|
throw new InvalidArgumentException($message); |
|
} |
|
|
|
return $association; |
|
} |
Arguments
|
*/ |
|
protected function _normalizeContain(Table $parent, string $alias, array $options, array $paths): EagerLoadable |
|
{ |
|
$defaults = $this->_containOptions; |
|
$instance = $parent->getAssociation($alias); |
|
|
|
$paths += ['aliasPath' => '', 'propertyPath' => '', 'root' => $alias]; |
|
$paths['aliasPath'] .= '.' . $alias; |
|
|
|
$contain[$alias] = $this->_normalizeContain( |
|
$repository, |
|
$alias, |
|
$options, |
|
['root' => null] |
|
); |
|
} |
|
|
|
return $this->_normalized = $contain; |
|
* @return array<\Cake\ORM\EagerLoadable> |
|
*/ |
|
public function attachableAssociations(Table $repository): array |
|
{ |
|
$contain = $this->normalized($repository); |
|
$matching = $this->_matching ? $this->_matching->normalized($repository) : []; |
|
$this->_fixStrategies(); |
|
$this->_loadExternal = []; |
|
|
|
if (empty($this->_containments) && $this->_matching === null) { |
|
return; |
|
} |
|
|
|
$attachable = $this->attachableAssociations($repository); |
|
$processed = []; |
|
do { |
|
foreach ($attachable as $alias => $loadable) { |
|
$config = $loadable->getConfig() + [ |
|
if (empty($this->_parts['from'])) { |
|
$this->from([$repository->getAlias() => $repository->getTable()]); |
|
} |
|
$this->_addDefaultFields(); |
|
$this->getEagerLoader()->attachAssociations($this, $repository, !$this->_hasFields); |
|
$this->_addDefaultSelectTypes(); |
|
} |
|
|
|
/** |
|
public function sql(?ValueBinder $binder = null): string |
|
{ |
|
$this->triggerBeforeFind(); |
|
|
|
$this->_transformQuery(); |
|
|
|
return parent::sql($binder); |
|
} |
|
|
|
/** |
|
* @psalm-suppress PossiblyInvalidMethodCall |
|
* @psalm-suppress PossiblyInvalidArgument |
|
*/ |
|
$statement = $this->_connection->prepare($isObject ? $query->sql() : $query); |
|
$result = new MysqlStatement($statement, $this); |
|
/** @psalm-suppress PossiblyInvalidMethodCall */ |
|
if ($isObject && $query->isBufferedResultsEnabled() === false) { |
|
$result->bufferResults(false); |
|
*/ |
|
public function prepare($query): StatementInterface |
|
{ |
|
return $this->getDisconnectRetry()->run(function () use ($query) { |
|
$statement = $this->_driver->prepare($query); |
|
|
|
if ($this->_logQueries) { |
|
$statement = $this->_newLogger($statement); |
|
} |
|
{ |
|
$this->numRetries = 0; |
|
while (true) { |
|
try { |
|
return $action(); |
|
} catch (Exception $e) { |
|
if ( |
|
$this->numRetries < $this->maxRetries && |
|
$this->strategy->shouldRetry($e, $this->numRetries) |
|
$statement = $this->_newLogger($statement); |
|
} |
|
|
|
return $statement; |
|
}); |
|
} |
|
|
|
/** |
|
* Executes a query using $params for interpolating values and $types as a hint for each |
|
*/ |
|
public function run(Query $query): StatementInterface |
|
{ |
|
return $this->getDisconnectRetry()->run(function () use ($query) { |
|
$statement = $this->prepare($query); |
|
$query->getValueBinder()->attachTo($statement); |
|
$statement->execute(); |
|
|
|
return $statement; |
|
{ |
|
$this->numRetries = 0; |
|
while (true) { |
|
try { |
|
return $action(); |
|
} catch (Exception $e) { |
|
if ( |
|
$this->numRetries < $this->maxRetries && |
|
$this->strategy->shouldRetry($e, $this->numRetries) |
|
$query->getValueBinder()->attachTo($statement); |
|
$statement->execute(); |
|
|
|
return $statement; |
|
}); |
|
} |
|
|
|
/** |
|
* Executes a SQL statement and returns the Statement object as result. |
|
* @return \Cake\Database\StatementInterface |
|
*/ |
|
public function execute(): StatementInterface |
|
{ |
|
$statement = $this->_connection->run($this); |
|
$this->_iterator = $this->_decorateStatement($statement); |
|
$this->_dirty = false; |
|
|
|
return $this->_iterator; |
|
|
|
return new $decorator($this->_results); |
|
} |
|
|
|
$statement = $this->getEagerLoader()->loadExternal($this, $this->execute()); |
|
|
|
return new ResultSet($this, $statement); |
|
} |
|
|
|
if ($this->_cache) { |
|
$results = $this->_cache->fetch($this); |
|
} |
|
if ($results === null) { |
|
$results = $this->_decorateResults($this->_execute()); |
|
if ($this->_cache) { |
|
$this->_cache->store($this, $results); |
|
} |
|
} |
|
'You cannot call all() on a non-select query. Use execute() instead.' |
|
); |
|
} |
|
|
|
return $this->_all(); |
|
} |
|
|
|
/** |
|
* Trigger the beforeFind event on the query's repository object. |
|
if ($this->_dirty) { |
|
$this->limit(1); |
|
} |
|
|
|
return $this->all()->first(); |
|
} |
|
|
|
/** |
|
* Get the first result from the executing query or raise an exception. |
|
* @return \Cake\Datasource\EntityInterface|array The first result from the ResultSet. |
|
*/ |
|
public function firstOrFail() |
|
{ |
|
$entity = $this->first(); |
|
if (!$entity) { |
|
$table = $this->getRepository(); |
|
throw new RecordNotFoundException(sprintf( |
|
'Record not found in table "%s"', |
|
$query->cache($cacheKey, $cacheConfig); |
|
} |
|
|
|
/** @psalm-suppress InvalidReturnStatement */ |
|
return $query->firstOrFail(); |
|
} |
|
|
|
/** |
|
* Handles the logic executing of a worker inside a transaction. |
|
*/ |
|
public function view($id = null) |
|
{ |
|
$watermarkSheet = $this->WatermarkSheets->get($id, [ |
|
'contain' => ['Facts', 'WatermarkSheetsFolios', 'WatermarkFolios'], |
|
]); |
|
|
|
$this->set(compact('watermarkSheet')); |
|
} |
|
* @throws \UnexpectedValueException If return value of action is not `null` or `ResponseInterface` instance. |
|
*/ |
|
public function invokeAction(Closure $action, array $args): void |
|
{ |
|
$result = $action(...$args); |
|
if ($result !== null && !$result instanceof ResponseInterface) { |
|
throw new UnexpectedValueException(sprintf( |
|
'Controller actions can only return ResponseInterface instance or null. ' |
|
. 'Got %s instead.', |
|
$args = $this->getActionArgs( |
|
$action, |
|
array_values((array)$controller->getRequest()->getParam('pass')) |
|
); |
|
$controller->invokeAction($action, $args); |
|
|
|
$result = $controller->shutdownProcess(); |
|
if ($result instanceof ResponseInterface) { |
|
return $result; |
|
|
|
return $runner->run($middlewareQueue, $controller->getRequest(), $this); |
|
} |
|
|
|
return $this->handle($controller->getRequest()); |
|
} |
|
|
|
/** |
|
* Invoke the action. |
|
} |
|
|
|
$controller = $this->controllerFactory->create($request); |
|
|
|
return $this->controllerFactory->invoke($controller); |
|
} |
|
} |
|
|
|
return $middleware->process($request, $this); |
|
} |
|
|
|
if ($this->fallbackHandler) { |
|
return $this->fallbackHandler->handle($request); |
|
} |
|
|
|
$response = new Response([ |
|
'body' => 'Middleware queue was exhausted without returning a response ' |
|
$request = $request->withAttribute('authentication', $service); |
|
$request = $request->withAttribute('authenticationResult', $result); |
|
|
|
try { |
|
$response = $handler->handle($request); |
|
$authenticator = $service->getAuthenticationProvider(); |
|
|
|
if ($authenticator !== null && !$authenticator instanceof StatelessInterface) { |
|
$return = $service->persistIdentity($request, $response, $result->getData()); |
|
if ($this->queue->valid()) { |
|
$middleware = $this->queue->current(); |
|
$this->queue->next(); |
|
|
|
return $middleware->process($request, $this); |
|
} |
|
|
|
if ($this->fallbackHandler) { |
|
return $this->fallbackHandler->handle($request); |
|
); |
|
} |
|
$matching = Router::getRouteCollection()->getMiddleware($middleware); |
|
if (!$matching) { |
|
return $handler->handle($request); |
|
} |
|
|
|
$middleware = new MiddlewareQueue($matching); |
|
$runner = new Runner(); |
|
if ($this->queue->valid()) { |
|
$middleware = $this->queue->current(); |
|
$this->queue->next(); |
|
|
|
return $middleware->process($request, $this); |
|
} |
|
|
|
if ($this->fallbackHandler) { |
|
return $this->fallbackHandler->handle($request); |
|
$this->queue = $queue; |
|
$this->queue->rewind(); |
|
$this->fallbackHandler = $fallbackHandler; |
|
|
|
return $this->handle($request); |
|
} |
|
|
|
/** |
|
* Handle incoming server request and return a response. |
|
} |
|
|
|
$this->dispatchEvent('Server.buildMiddleware', ['middleware' => $middleware]); |
|
|
|
$response = $this->runner->run($middleware, $request, $this->app); |
|
|
|
if ($request instanceof ServerRequest) { |
|
$request->getSession()->close(); |
|
} |
|
// Bind your application to the server. |
|
$server = new Server(new Application(dirname(__DIR__) . '/config')); |
|
|
|
// Run the request/response through the application and emit the response. |
|
$server->emit($server->run()); |
|
|
If you want to customize this error message, create
templates/Error/error500.php