new files

This commit is contained in:
panchengyong
2026-03-07 22:29:07 +08:00
parent cd7e80b502
commit 7acbf45ff7
12516 changed files with 1808447 additions and 194 deletions

View File

@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
/**
* Copyright (c) 2017-2022 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/classy
*/
namespace Ergebnis\Classy\Exception;
final class DirectoryDoesNotExist extends \InvalidArgumentException implements ExceptionInterface
{
private string $directory = '';
/**
* Returns a new exception from a directory.
*/
public static function fromDirectory(string $directory): self
{
$exception = new self(\sprintf(
'Directory "%s" does not exist.',
$directory,
));
$exception->directory = $directory;
return $exception;
}
/**
* Returns the directory.
*/
public function directory(): string
{
return $this->directory;
}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
/**
* Copyright (c) 2017-2022 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/classy
*/
namespace Ergebnis\Classy\Exception;
interface ExceptionInterface extends \Throwable
{
}

View File

@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
/**
* Copyright (c) 2017-2022 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/classy
*/
namespace Ergebnis\Classy\Exception;
use Ergebnis\Classy\Construct;
final class MultipleDefinitionsFound extends \RuntimeException implements ExceptionInterface
{
/**
* @var array<int, Construct>
*/
private array $constructs = [];
/**
* Returns a new exception from constructs.
*
* @param array<int, Construct> $constructs
*/
public static function fromConstructs(array $constructs): self
{
$exception = new self(\sprintf(
"Multiple definitions have been found for the following constructs:\n\n%s",
\implode("\n", \array_map(static function (Construct $construct): string {
return \sprintf(
' - "%s" defined in "%s"',
$construct->name(),
\implode('", "', $construct->fileNames()),
);
}, $constructs)),
));
$exception->constructs = $constructs;
return $exception;
}
/**
* Returns an array of constructs.
*
* @return array<int, Construct>
*/
public function constructs(): array
{
return $this->constructs;
}
}

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/**
* Copyright (c) 2017-2022 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/classy
*/
namespace Ergebnis\Classy\Exception;
final class ParseError extends \ParseError implements ExceptionInterface
{
public static function fromParseError(\ParseError $exception): self
{
return new self(
$exception->getMessage(),
0,
$exception,
);
}
public static function fromFileNameAndParseError(
string $fileName,
\ParseError $exception,
): self {
return new self(
\sprintf(
'A parse error occurred when parsing "%s": "%s".',
$fileName,
$exception->getMessage(),
),
0,
$exception,
);
}
}

View File

@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
/**
* Copyright (c) 2017-2022 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/classy
*/
namespace Ergebnis\Classy\Exception;
final class ShouldNotHappen extends \LogicException implements ExceptionInterface
{
public static function create(): self
{
return new self('This should not happen.');
}
}