if ($book->slug == $slug) {
$chosen = $book;
break;
}
}
return $chosen;
}
/**
* Gives an array of book objects which match a given category
*
*
* @return array
*/
public function getObjectsByIdentifier($identifier): array {
$parts = self::parseIdentifier($identifier);
$book = $this->getBookBySlug($parts['bookSlug']);
$language = $book->getLanguageByCode($parts['languageCode']);
$version = $language->getVersionByDescriptor($parts['versionDescriptor']);
return [
'book' => $book,
'language' => $language,
* @param string $requestUri
*
* @return null|string
*/
private function lookupVersionRedirect($requestUri): ?string {
$objects = $this->library->getObjectsByIdentifier($requestUri);
$requestParts = Library::parseIdentifier($requestUri);
/* @var \App\Model\Version $version */
$version = $objects['version'];
if (!$version) {
return null;
public function lookupRedirect($requestUri): ?string {
// Give up right away if the request contains two dots (for security)
if (strstr($requestUri, '..')) {
return null;
}
return $this->lookupVersionRedirect($requestUri) ?? $this->lookupPageRedirect($requestUri);
}
/**
* Try to find a redirect for the page by looking to see if the version
* supplied in the request is actually one of the redirects for the versions
public function onExceptionEvent(ExceptionEvent $event): void {
$exception = $event->getThrowable();
if ($exception instanceof NotFoundHttpException) {
$requestUri = $event->getRequest()->getRequestUri();
$redirect = $this->redirecter->lookupRedirect($requestUri);
if ($redirect) {
$response = new RedirectResponse($redirect);
$event->setResponse($response);
} else {
throw new NotFoundHttpException(
$this->called = true;
$this->priority = $dispatcher->getListenerPriority($eventName, $this->listener);
$e = $this->stopwatch->start($this->name, 'event_listener');
($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher);
if ($e->isStarted()) {
$e->stop();
}
foreach ($listeners as $listener) {
if ($stoppable && $event->isPropagationStopped()) {
break;
}
$listener($event, $eventName, $this);
}
}
/**
* Sorts the internal list of listeners for the given event by priority.
} else {
$listeners = $this->getListeners($eventName);
}
if ($listeners) {
$this->callListeners($listeners, $eventName, $event);
}
return $event;
}
try {
$this->beforeDispatch($eventName, $event);
try {
$e = $this->stopwatch->start($eventName, 'section');
try {
$this->dispatcher->dispatch($event, $eventName);
} finally {
if ($e->isStarted()) {
$e->stop();
}
}
* @throws \Exception
*/
private function handleThrowable(\Throwable $e, Request $request, int $type): Response
{
$event = new ExceptionEvent($this, $request, $type, $e);
$this->dispatcher->dispatch($event, KernelEvents::EXCEPTION);
// a listener might have replaced the exception
$e = $event->getThrowable();
if (!$event->hasResponse()) {
$this->finishRequest($request, $type);
throw $e;
}
return $this->handleThrowable($e, $request, $type);
}
}
/**
* {@inheritdoc}
$this->boot();
++$this->requestStackSize;
$this->resetServices = true;
try {
return $this->getHttpKernel()->handle($request, $type, $catch);
} finally {
--$this->requestStackSize;
}
}
$this->request = $request;
}
public function run(): int
{
$response = $this->kernel->handle($this->request);
$response->send();
if ($this->kernel instanceof TerminableInterface) {
$this->kernel->terminate($this->request, $response);
}
$app = $app(...$args);
exit(
$runtime
->getRunner($app)
->run()
);
<?php
use App\Kernel;
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
No log messages
TypeError
|
---|
TypeError: App\Model\Library::getBookBySlug(): Return value must be of type App\Model\Book, null returned at src/Model/Library.php:101 at App\Model\Library->getBookBySlug() (src/Model/Library.php:268) at App\Model\Library->getObjectsByIdentifier() (src/Utils/Redirecter.php:56) at App\Utils\Redirecter->lookupVersionRedirect() (src/Utils/Redirecter.php:43) at App\Utils\Redirecter->lookupRedirect() (src/EventSubscriber/ExceptionSubscriber.php:26) at App\EventSubscriber\ExceptionSubscriber->onExceptionEvent() (vendor/symfony/event-dispatcher/Debug/WrappedListener.php:111) at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke() (vendor/symfony/event-dispatcher/EventDispatcher.php:230) at Symfony\Component\EventDispatcher\EventDispatcher->callListeners() (vendor/symfony/event-dispatcher/EventDispatcher.php:59) at Symfony\Component\EventDispatcher\EventDispatcher->dispatch() (vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:152) at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch() (vendor/symfony/http-kernel/HttpKernel.php:213) at Symfony\Component\HttpKernel\HttpKernel->handleThrowable() (vendor/symfony/http-kernel/HttpKernel.php:85) at Symfony\Component\HttpKernel\HttpKernel->handle() (vendor/symfony/http-kernel/Kernel.php:202) at Symfony\Component\HttpKernel\Kernel->handle() (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35) at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run() (vendor/autoload_runtime.php:29) at require_once('/var/www/civicrm-docs/vendor/autoload_runtime.php') (public/index.php:5) |