Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of PharIo\Manifest.
4
 *
5
 * (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PharIo\Manifest;
11
 
12
class ApplicationName {
13
    /** @var string */
14
    private $name;
15
 
16
    public function __construct(string $name) {
17
        $this->ensureValidFormat($name);
18
        $this->name = $name;
19
    }
20
 
21
    public function asString(): string {
22
        return $this->name;
23
    }
24
 
25
    public function isEqual(ApplicationName $name): bool {
26
        return $this->name === $name->name;
27
    }
28
 
29
    private function ensureValidFormat(string $name): void {
30
        if (!\preg_match('#\w/\w#', $name)) {
31
            throw new InvalidApplicationNameException(
32
                \sprintf('Format of name "%s" is not valid - expected: vendor/packagename', $name),
33
                InvalidApplicationNameException::InvalidFormat
34
            );
35
        }
36
    }
37
}