1. Go to this page and download the library: Download customer41/multiexception library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
customer41 / multiexception example snippets
class Article
{
public string $title;
public string $description;
public function __construct(string $title, string $description)
{
$errors = new MultiException();
$this->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('Пустое описание'));
}
}
}
class ArticleController
{
public function createArticle(): void
{
try {
$article = new Article($_POST['title'], $_POST['description']);
} catch (MultiException $errors) {
...
}
}
}
foreach ($errors as $error):
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.