Skip to content

Commit

Permalink
Adjust to router changes (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
rustamwin committed Aug 18, 2021
1 parent 63ad622 commit ade3079
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions resources/views/layout/main.php
Expand Up @@ -16,7 +16,7 @@
* @var string|null $csrf
* @var Locale $locale
* @var Yiisoft\View\WebView $this
* @var Yiisoft\Router\UrlMatcherInterface $urlMatcher
* @var Yiisoft\Router\CurrentRoute $currentRoute
*/

$assetManager->register([
Expand Down Expand Up @@ -53,8 +53,8 @@

<?= Nav::widget()
->currentPath(
$urlMatcher->getCurrentUri() !== null
? $urlMatcher->getCurrentUri()->getPath()
$currentRoute->getUri() !== null
? $currentRoute->getUri()->getPath()
: ''
)
->items([]) ?>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/site/404.php
Expand Up @@ -4,7 +4,7 @@

/** @var Yiisoft\View\WebView $this */
/** @var Yiisoft\Router\UrlGeneratorInterface $urlGenerator */
/** @var Yiisoft\Router\UrlMatcherInterface $urlMatcher */
/** @var Yiisoft\Router\CurrentRoute $currentRoute */

$this->setTitle('404');
?>
Expand All @@ -15,7 +15,7 @@

<p class="has-text-danger">
The page
<strong><?= Html::encode($urlMatcher->getCurrentUri()->getPath()) ?></strong>
<strong><?= Html::encode($currentRoute->getUri()->getPath()) ?></strong>
not found.
</p>

Expand Down
10 changes: 5 additions & 5 deletions src/Handler/NotFoundHandler.php
Expand Up @@ -9,29 +9,29 @@
use Psr\Http\Server\RequestHandlerInterface;
use Yiisoft\Http\Status;
use Yiisoft\Router\UrlGeneratorInterface;
use Yiisoft\Router\UrlMatcherInterface;
use Yiisoft\Router\CurrentRoute;
use Yiisoft\Yii\View\ViewRenderer;

final class NotFoundHandler implements RequestHandlerInterface
{
private UrlGeneratorInterface $urlGenerator;
private UrlMatcherInterface $urlMatcher;
private CurrentRoute $currentRoute;
private ViewRenderer $viewRenderer;

public function __construct(
UrlGeneratorInterface $urlGenerator,
UrlMatcherInterface $urlMatcher,
CurrentRoute $currentRoute,
ViewRenderer $viewRenderer
) {
$this->urlGenerator = $urlGenerator;
$this->urlMatcher = $urlMatcher;
$this->currentRoute = $currentRoute;
$this->viewRenderer = $viewRenderer->withControllerName('site');
}

public function handle(ServerRequestInterface $request): ResponseInterface
{
return $this->viewRenderer
->render('404', ['urlGenerator' => $this->urlGenerator, 'urlMatcher' => $this->urlMatcher])
->render('404', ['urlGenerator' => $this->urlGenerator, 'currentRoute' => $this->currentRoute])
->withStatus(Status::NOT_FOUND);
}
}
10 changes: 5 additions & 5 deletions src/ViewInjection/LayoutViewInjection.php
Expand Up @@ -8,7 +8,7 @@
use Yiisoft\Assets\AssetManager;
use Yiisoft\I18n\Locale;
use Yiisoft\Router\UrlGeneratorInterface;
use Yiisoft\Router\UrlMatcherInterface;
use Yiisoft\Router\CurrentRoute;
use Yiisoft\Yii\View\LayoutParametersInjectionInterface;

final class LayoutViewInjection implements LayoutParametersInjectionInterface
Expand All @@ -17,20 +17,20 @@ final class LayoutViewInjection implements LayoutParametersInjectionInterface
private AssetManager $assetManager;
private Locale $locale;
private UrlGeneratorInterface $urlGenerator;
private UrlMatcherInterface $urlMatcher;
private CurrentRoute $currentRoute;

public function __construct(
ApplicationParameters $applicationParameters,
AssetManager $assetManager,
Locale $locale,
UrlGeneratorInterface $urlGenerator,
UrlMatcherInterface $urlMatcher
CurrentRoute $currentRoute
) {
$this->applicationParameters = $applicationParameters;
$this->assetManager = $assetManager;
$this->locale = $locale;
$this->urlGenerator = $urlGenerator;
$this->urlMatcher = $urlMatcher;
$this->currentRoute = $currentRoute;
}

public function getLayoutParameters(): array
Expand All @@ -40,7 +40,7 @@ public function getLayoutParameters(): array
'assetManager' => $this->assetManager,
'locale' => $this->locale,
'urlGenerator' => $this->urlGenerator,
'urlMatcher' => $this->urlMatcher,
'currentRoute' => $this->currentRoute,
];
}
}

0 comments on commit ade3079

Please sign in to comment.