library multiexception
This is a simple package for education purposes, that implements the concept of 'multiexceptions'
customer41/multiexception
This is a simple package for education purposes, that implements the concept of 'multiexceptions'
- Wednesday, April 12, 2017
- by customer41
- Repository
- 1 Watchers
- 0 Stars
- 1 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 1 Versions
- 0 % Grown
MultiException
MultiException - это простой контейнер для ваших исключений, который сам по себе является исключением, (*1)
Требования
Установка
composer require customer41/multiexception, (*2)
Использование
setTitle($title);
$this->setDescription($description);
if (count($errors) > 0) {
throw $errors;
}
}
private function setTitle(string $title): void
{
if (!empty($title)) {
$this->title = $title;
} else {
$errors->add(new \Exception('Пустой заголовок'));
}
}
private function setDescription(string $description): void
{
if (!empty($description)) {
$this->description = $description;
} else {
$errors->add(new \Exception('Пустое описание'));
}
}
}
```
В контроллере:
```php
class ArticleController
{
public function createArticle(): void
{
try {
$article = new Article($_POST['title'], $_POST['description']);
} catch (MultiException $errors) {
...
}
}
}
```
В шаблоне:
```php
<div class="alert alert-danger">
<?php echo $error->getMessage(); ?>
</div>
dev-master
9999999-dev
This is a simple package for education purposes, that implements the concept of 'multiexceptions'
Sources
Download