| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* This file is part of the Nette Framework (https://nette.org) |
| 5 |
* Copyright (c) 2004 David Grudl (https://davidgrudl.com) |
| 6 |
*/ |
| 7 |
declare (strict_types=1); |
| 8 |
namespace Packetery\Nette\DI\Definitions; |
| 9 |
|
| 10 |
use Packetery\Nette; |
| 11 |
/** |
| 12 |
* Reference to service. Either by name or by type or reference to the 'self' service. |
| 13 |
*/ |
| 14 |
final class Reference |
| 15 |
{ |
| 16 |
use \Packetery\Nette\SmartObject; |
| 17 |
public const Self = 'self'; |
| 18 |
/** @deprecated use Reference::Self */ |
| 19 |
public const SELF = self::Self; |
| 20 |
/** @var string */ |
| 21 |
private $value; |
| 22 |
public static function fromType(string $value) : self |
| 23 |
{ |
| 24 |
if (\strpos($value, '\\') === \false) { |
| 25 |
$value = '\\' . $value; |
| 26 |
} |
| 27 |
return new static($value); |
| 28 |
} |
| 29 |
public function __construct(string $value) |
| 30 |
{ |
| 31 |
$this->value = $value; |
| 32 |
} |
| 33 |
public function getValue() : string |
| 34 |
{ |
| 35 |
return $this->value; |
| 36 |
} |
| 37 |
public function isName() : bool |
| 38 |
{ |
| 39 |
return \strpos($this->value, '\\') === \false && $this->value !== self::Self; |
| 40 |
} |
| 41 |
public function isType() : bool |
| 42 |
{ |
| 43 |
return \strpos($this->value, '\\') !== \false; |
| 44 |
} |
| 45 |
public function isSelf() : bool |
| 46 |
{ |
| 47 |
return $this->value === self::Self; |
| 48 |
} |
| 49 |
} |
| 50 |
|