yiisoft /
demo
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace App\Blog; |
||
| 6 | |||
| 7 | use App\Blog\Archive\ArchiveRepository; |
||
| 8 | use App\Blog\Post\PostRepository; |
||
|
0 ignored issues
–
show
|
|||
| 9 | use App\Blog\Tag\TagRepository; |
||
| 10 | use Psr\Http\Message\ResponseInterface as Response; |
||
|
0 ignored issues
–
show
The type
Psr\Http\Message\ResponseInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 11 | use Yiisoft\Data\Paginator\OffsetPaginator; |
||
|
0 ignored issues
–
show
The type
Yiisoft\Data\Paginator\OffsetPaginator was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 12 | use Yiisoft\Router\HydratorAttribute\RouteArgument; |
||
|
0 ignored issues
–
show
The type
Yiisoft\Router\HydratorAttribute\RouteArgument was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 13 | use Yiisoft\User\CurrentUser; |
||
|
0 ignored issues
–
show
The type
Yiisoft\User\CurrentUser was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 14 | use Yiisoft\Yii\View\Renderer\ViewRenderer; |
||
|
0 ignored issues
–
show
The type
Yiisoft\Yii\View\Renderer\ViewRenderer was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 15 | |||
| 16 | final class BlogController |
||
| 17 | { |
||
| 18 | private const POSTS_PER_PAGE = 3; |
||
| 19 | private const POPULAR_TAGS_COUNT = 10; |
||
| 20 | private const ARCHIVE_MONTHS_COUNT = 12; |
||
| 21 | |||
| 22 | private ViewRenderer $viewRenderer; |
||
| 23 | |||
| 24 | public function __construct(ViewRenderer $viewRenderer) |
||
| 25 | { |
||
| 26 | $this->viewRenderer = $viewRenderer->withControllerName('blog'); |
||
| 27 | } |
||
| 28 | |||
| 29 | public function index( |
||
| 30 | PostRepository $postRepository, |
||
| 31 | TagRepository $tagRepository, |
||
| 32 | ArchiveRepository $archiveRepo, |
||
| 33 | CurrentUser $currentUser, |
||
| 34 | #[RouteArgument('page')] $pageNum = 1, |
||
| 35 | ): Response { |
||
| 36 | $dataReader = $postRepository->findAllPreloaded(); |
||
| 37 | $paginator = (new OffsetPaginator($dataReader)) |
||
| 38 | ->withPageSize(self::POSTS_PER_PAGE) |
||
| 39 | ->withCurrentPage((int)$pageNum); |
||
| 40 | |||
| 41 | $data = [ |
||
| 42 | 'paginator' => $paginator, |
||
| 43 | 'archive' => $archiveRepo |
||
| 44 | ->getFullArchive() |
||
| 45 | ->withLimit(self::ARCHIVE_MONTHS_COUNT), |
||
| 46 | 'tags' => $tagRepository->getTagMentions(self::POPULAR_TAGS_COUNT), |
||
| 47 | 'isGuest' => $currentUser->isGuest(), |
||
| 48 | ]; |
||
| 49 | |||
| 50 | return $this->viewRenderer->render('index', $data); |
||
| 51 | } |
||
| 52 | } |
||
| 53 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: