generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add friendly exceptions + support Link and Meta tag objects + adopt t…
…o new yiisoft/view (#30)
- Loading branch information
Showing
10 changed files
with
305 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
<?xml version="1.0"?> | ||
<psalm | ||
errorLevel="2" | ||
errorLevel="1" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="https://getpsalm.org/schema/config" | ||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" | ||
> | ||
<projectFiles> | ||
<directory name="src" /> | ||
<ignoreFiles> | ||
<directory name="vendor" /> | ||
</ignoreFiles> | ||
</projectFiles> | ||
</psalm> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Yii\View\Exception; | ||
|
||
use RuntimeException; | ||
use Yiisoft\FriendlyException\FriendlyExceptionInterface; | ||
|
||
final class InvalidLinkTagException extends RuntimeException implements FriendlyExceptionInterface | ||
{ | ||
/** | ||
* @var mixed | ||
*/ | ||
private $tag; | ||
|
||
/** | ||
* @param mixed $tag | ||
*/ | ||
public function __construct(string $message, $tag) | ||
{ | ||
$this->tag = $tag; | ||
|
||
parent::__construct($message); | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'Invalid link tag configuration in injection'; | ||
} | ||
|
||
public function getSolution(): ?string | ||
{ | ||
$solution = 'Got link tag:' . "\n" . var_export($this->tag, true); | ||
$solution .= <<<SOLUTION | ||
In injection that implements `Yiisoft\Yii\View\LinkTagsInjectionInterface` defined link tags in the method `getLinkTags()`. | ||
The link tag can be define in the following ways: | ||
- as array of attributes: `['rel' => 'stylesheet', 'href' => '/user.css']`, | ||
- as instance of `Yiisoft\Html\Tag\Link`: `Html::link()->toCssFile('/main.css')`. | ||
Optionally: | ||
- use array format and set the position in a page via `__position`. | ||
- use string keys of array as identifies the link tag. | ||
Example: | ||
```php | ||
public function getLinkTags(): array | ||
{ | ||
return [ | ||
'favicon' => Html::link('/myicon.png', [ | ||
'rel' => 'icon', | ||
'type' => 'image/png', | ||
]), | ||
'themeCss' => [ | ||
'__position' => \Yiisoft\View\WebView::POSITION_END, | ||
Html::link()->toCssFile('/theme.css'), | ||
], | ||
'userCss' => [ | ||
'__position' => \Yiisoft\View\WebView::POSITION_BEGIN, | ||
'rel' => 'stylesheet', | ||
'href' => '/user.css', | ||
], | ||
]; | ||
} | ||
``` | ||
SOLUTION; | ||
return $solution; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Yii\View\Exception; | ||
|
||
use RuntimeException; | ||
use Yiisoft\FriendlyException\FriendlyExceptionInterface; | ||
|
||
final class InvalidMetaTagException extends RuntimeException implements FriendlyExceptionInterface | ||
{ | ||
/** | ||
* @var mixed | ||
*/ | ||
private $tag; | ||
|
||
/** | ||
* @param mixed $tag | ||
*/ | ||
public function __construct(string $message, $tag) | ||
{ | ||
$this->tag = $tag; | ||
|
||
parent::__construct($message); | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'Invalid meta tag configuration in injection'; | ||
} | ||
|
||
public function getSolution(): ?string | ||
{ | ||
$solution = 'Got meta tag:' . "\n" . var_export($this->tag, true); | ||
$solution .= <<<SOLUTION | ||
In injection that implements `Yiisoft\Yii\View\MetaTagsInjectionInterface` defined meta tags in the method `getMetaTags()`. | ||
The meta tag can be define in the following ways: | ||
- as array of attributes: `['name' => 'keywords', 'content' => 'yii,framework']`, | ||
- as instance of `Yiisoft\Html\Tag\Meta`: `Html::meta()->name('keywords')->content('yii,framework')`. | ||
Optionally, you may use string keys of array as identifies the meta tag. | ||
Example: | ||
```php | ||
public function getMetaTags(): array | ||
{ | ||
return [ | ||
'seo-keywords' => [ | ||
'name' => 'keywords', | ||
'content' => 'yii,framework', | ||
], | ||
Html::meta()->name('description')->content('Yii is a fast, secure, and efficient PHP framework.'), | ||
]; | ||
} | ||
``` | ||
SOLUTION; | ||
return $solution; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.