@@ -26,56 +26,56 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | final class ExtensionManager |
| 28 | 28 | { |
| 29 | - use UninstanciableObjectTrait; |
|
| 29 | + use UninstanciableObjectTrait; |
|
| 30 | 30 | |
| 31 | - public const KNOWN_EXTENSION_NAMES = [ |
|
| 32 | - 'Arangodb', |
|
| 33 | - 'Couchbasev4', |
|
| 34 | - 'Couchdb', |
|
| 35 | - 'Dynamodb', |
|
| 36 | - 'Firestore', |
|
| 37 | - 'Mongodb', |
|
| 38 | - 'Ravendb', |
|
| 39 | - 'Solr' |
|
| 40 | - ]; |
|
| 31 | + public const KNOWN_EXTENSION_NAMES = [ |
|
| 32 | + 'Arangodb', |
|
| 33 | + 'Couchbasev4', |
|
| 34 | + 'Couchdb', |
|
| 35 | + 'Dynamodb', |
|
| 36 | + 'Firestore', |
|
| 37 | + 'Mongodb', |
|
| 38 | + 'Ravendb', |
|
| 39 | + 'Solr' |
|
| 40 | + ]; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var array<string, string> |
|
| 44 | - */ |
|
| 45 | - protected static array $registeredExtensions = []; |
|
| 42 | + /** |
|
| 43 | + * @var array<string, string> |
|
| 44 | + */ |
|
| 45 | + protected static array $registeredExtensions = []; |
|
| 46 | 46 | |
| 47 | - public static function registerExtension(string $extensionName, string $driverClassName): void |
|
| 48 | - { |
|
| 49 | - if (!str_starts_with($driverClassName, ltrim('Phpfastcache\\Extensions\\', '\\'))) { |
|
| 50 | - throw new PhpfastcacheInvalidArgumentException( |
|
| 51 | - 'Only extensions from "\\Phpfastcache\\Extensions\\" namespace are allowed. Use CacheManager::addCustomDriver() to create your own extensions.' |
|
| 52 | - ); |
|
| 53 | - } |
|
| 54 | - self::$registeredExtensions[$extensionName] = $driverClassName; |
|
| 55 | - } |
|
| 47 | + public static function registerExtension(string $extensionName, string $driverClassName): void |
|
| 48 | + { |
|
| 49 | + if (!str_starts_with($driverClassName, ltrim('Phpfastcache\\Extensions\\', '\\'))) { |
|
| 50 | + throw new PhpfastcacheInvalidArgumentException( |
|
| 51 | + 'Only extensions from "\\Phpfastcache\\Extensions\\" namespace are allowed. Use CacheManager::addCustomDriver() to create your own extensions.' |
|
| 52 | + ); |
|
| 53 | + } |
|
| 54 | + self::$registeredExtensions[$extensionName] = $driverClassName; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - public static function extensionExists(string $extensionName): bool |
|
| 58 | - { |
|
| 59 | - return isset(self::$registeredExtensions[$extensionName]); |
|
| 60 | - } |
|
| 57 | + public static function extensionExists(string $extensionName): bool |
|
| 58 | + { |
|
| 59 | + return isset(self::$registeredExtensions[$extensionName]); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @param string $name |
|
| 64 | - * @return string |
|
| 65 | - * @throws PhpfastcacheExtensionNotFoundException |
|
| 66 | - */ |
|
| 67 | - public static function getExtension(string $name): string |
|
| 68 | - { |
|
| 69 | - if (isset(self::$registeredExtensions[$name])) { |
|
| 70 | - return self::$registeredExtensions[$name]; |
|
| 71 | - } else { |
|
| 72 | - throw new PhpfastcacheExtensionNotFoundException( |
|
| 73 | - sprintf( |
|
| 74 | - 'Unable too find the %s extension. Make sure that you you added through composer: `composer require phpfastcache/%s-extension`', |
|
| 75 | - $name, |
|
| 76 | - strtolower($name) |
|
| 77 | - ) |
|
| 78 | - ); |
|
| 79 | - } |
|
| 80 | - } |
|
| 62 | + /** |
|
| 63 | + * @param string $name |
|
| 64 | + * @return string |
|
| 65 | + * @throws PhpfastcacheExtensionNotFoundException |
|
| 66 | + */ |
|
| 67 | + public static function getExtension(string $name): string |
|
| 68 | + { |
|
| 69 | + if (isset(self::$registeredExtensions[$name])) { |
|
| 70 | + return self::$registeredExtensions[$name]; |
|
| 71 | + } else { |
|
| 72 | + throw new PhpfastcacheExtensionNotFoundException( |
|
| 73 | + sprintf( |
|
| 74 | + 'Unable too find the %s extension. Make sure that you you added through composer: `composer require phpfastcache/%s-extension`', |
|
| 75 | + $name, |
|
| 76 | + strtolower($name) |
|
| 77 | + ) |
|
| 78 | + ); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -68,7 +68,8 @@ |
||
| 68 | 68 | { |
| 69 | 69 | if (isset(self::$registeredExtensions[$name])) { |
| 70 | 70 | return self::$registeredExtensions[$name]; |
| 71 | - } else { |
|
| 71 | + } |
|
| 72 | + else { |
|
| 72 | 73 | throw new PhpfastcacheExtensionNotFoundException( |
| 73 | 74 | sprintf( |
| 74 | 75 | 'Unable too find the %s extension. Make sure that you you added through composer: `composer require phpfastcache/%s-extension`', |
@@ -21,110 +21,110 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class DriverStatistic |
| 23 | 23 | { |
| 24 | - protected string $info = ''; |
|
| 25 | - |
|
| 26 | - protected ?int $size = 0; |
|
| 27 | - |
|
| 28 | - protected ?int $count = 0; |
|
| 29 | - |
|
| 30 | - protected string $data = ''; |
|
| 31 | - |
|
| 32 | - protected mixed $rawData; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Return quick information about the driver instance |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function getInfo(): string |
|
| 39 | - { |
|
| 40 | - return $this->info; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - public function setInfo(string $info): static |
|
| 44 | - { |
|
| 45 | - $this->info = $info; |
|
| 46 | - |
|
| 47 | - return $this; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Return the approximate size taken by the driver instance (in bytes) (null if unsupported by the driver) |
|
| 52 | - * @return int|null |
|
| 53 | - */ |
|
| 54 | - public function getSize(): ?int |
|
| 55 | - { |
|
| 56 | - return $this->size; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function setSize(?int $size): static |
|
| 60 | - { |
|
| 61 | - $this->size = $size; |
|
| 62 | - |
|
| 63 | - return $this; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Return the approximate count of elements stored in a driver database (or collection if applicable). Added in v9.2.3 |
|
| 68 | - * @since 9.2.3 |
|
| 69 | - * @return int|null |
|
| 70 | - */ |
|
| 71 | - public function getCount(): ?int |
|
| 72 | - { |
|
| 73 | - return $this->count; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public function setCount(?int $count): static |
|
| 77 | - { |
|
| 78 | - $this->count = $count; |
|
| 79 | - return $this; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Return an array of item keys used by this driver instance (deprecated as of v9.2.3, will be removed as of v10) |
|
| 84 | - * @deprecated as of phpfastcache 9.2.3, will be removed as of v10 |
|
| 85 | - */ |
|
| 86 | - public function getData(): string |
|
| 87 | - { |
|
| 88 | - return $this->data; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @deprecated as of phpfastcache 9.2.3, will be removed as of v10 |
|
| 93 | - */ |
|
| 94 | - public function setData(string $data): static |
|
| 95 | - { |
|
| 96 | - $this->data = ($data ?: ''); |
|
| 97 | - |
|
| 98 | - return $this; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Return a bunch of random data provided by the driver. Any type can be provided, usually an array |
|
| 103 | - * @return mixed |
|
| 104 | - */ |
|
| 105 | - public function getRawData(): mixed |
|
| 106 | - { |
|
| 107 | - return $this->rawData; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - public function setRawData(mixed $raw): static |
|
| 111 | - { |
|
| 112 | - $this->rawData = $raw; |
|
| 113 | - |
|
| 114 | - return $this; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @return array<string, string> |
|
| 119 | - */ |
|
| 120 | - public function getPublicDesc(): array |
|
| 121 | - { |
|
| 122 | - return [ |
|
| 123 | - 'Info' => 'Cache Information', |
|
| 124 | - 'Size' => 'Cache Size', |
|
| 125 | - 'Count' => 'Cache database/collection count', |
|
| 126 | - 'Data' => 'Cache items keys (Deprecated)', |
|
| 127 | - 'RawData' => 'Cache raw data', |
|
| 128 | - ]; |
|
| 129 | - } |
|
| 24 | + protected string $info = ''; |
|
| 25 | + |
|
| 26 | + protected ?int $size = 0; |
|
| 27 | + |
|
| 28 | + protected ?int $count = 0; |
|
| 29 | + |
|
| 30 | + protected string $data = ''; |
|
| 31 | + |
|
| 32 | + protected mixed $rawData; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Return quick information about the driver instance |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function getInfo(): string |
|
| 39 | + { |
|
| 40 | + return $this->info; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + public function setInfo(string $info): static |
|
| 44 | + { |
|
| 45 | + $this->info = $info; |
|
| 46 | + |
|
| 47 | + return $this; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Return the approximate size taken by the driver instance (in bytes) (null if unsupported by the driver) |
|
| 52 | + * @return int|null |
|
| 53 | + */ |
|
| 54 | + public function getSize(): ?int |
|
| 55 | + { |
|
| 56 | + return $this->size; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function setSize(?int $size): static |
|
| 60 | + { |
|
| 61 | + $this->size = $size; |
|
| 62 | + |
|
| 63 | + return $this; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Return the approximate count of elements stored in a driver database (or collection if applicable). Added in v9.2.3 |
|
| 68 | + * @since 9.2.3 |
|
| 69 | + * @return int|null |
|
| 70 | + */ |
|
| 71 | + public function getCount(): ?int |
|
| 72 | + { |
|
| 73 | + return $this->count; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public function setCount(?int $count): static |
|
| 77 | + { |
|
| 78 | + $this->count = $count; |
|
| 79 | + return $this; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Return an array of item keys used by this driver instance (deprecated as of v9.2.3, will be removed as of v10) |
|
| 84 | + * @deprecated as of phpfastcache 9.2.3, will be removed as of v10 |
|
| 85 | + */ |
|
| 86 | + public function getData(): string |
|
| 87 | + { |
|
| 88 | + return $this->data; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @deprecated as of phpfastcache 9.2.3, will be removed as of v10 |
|
| 93 | + */ |
|
| 94 | + public function setData(string $data): static |
|
| 95 | + { |
|
| 96 | + $this->data = ($data ?: ''); |
|
| 97 | + |
|
| 98 | + return $this; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Return a bunch of random data provided by the driver. Any type can be provided, usually an array |
|
| 103 | + * @return mixed |
|
| 104 | + */ |
|
| 105 | + public function getRawData(): mixed |
|
| 106 | + { |
|
| 107 | + return $this->rawData; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + public function setRawData(mixed $raw): static |
|
| 111 | + { |
|
| 112 | + $this->rawData = $raw; |
|
| 113 | + |
|
| 114 | + return $this; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @return array<string, string> |
|
| 119 | + */ |
|
| 120 | + public function getPublicDesc(): array |
|
| 121 | + { |
|
| 122 | + return [ |
|
| 123 | + 'Info' => 'Cache Information', |
|
| 124 | + 'Size' => 'Cache Size', |
|
| 125 | + 'Count' => 'Cache database/collection count', |
|
| 126 | + 'Data' => 'Cache items keys (Deprecated)', |
|
| 127 | + 'RawData' => 'Cache raw data', |
|
| 128 | + ]; |
|
| 129 | + } |
|
| 130 | 130 | } |
@@ -20,30 +20,30 @@ |
||
| 20 | 20 | |
| 21 | 21 | class ItemBatch |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * ItemBatch constructor. |
|
| 25 | - * @param string $itemKey |
|
| 26 | - * @param DateTimeInterface $itemDate |
|
| 27 | - */ |
|
| 28 | - public function __construct( |
|
| 29 | - protected string $itemKey, |
|
| 30 | - protected DateTimeInterface $itemDate |
|
| 31 | - ) { |
|
| 32 | - } |
|
| 23 | + /** |
|
| 24 | + * ItemBatch constructor. |
|
| 25 | + * @param string $itemKey |
|
| 26 | + * @param DateTimeInterface $itemDate |
|
| 27 | + */ |
|
| 28 | + public function __construct( |
|
| 29 | + protected string $itemKey, |
|
| 30 | + protected DateTimeInterface $itemDate |
|
| 31 | + ) { |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function getItemKey(): string |
|
| 38 | - { |
|
| 39 | - return $this->itemKey; |
|
| 40 | - } |
|
| 34 | + /** |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function getItemKey(): string |
|
| 38 | + { |
|
| 39 | + return $this->itemKey; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return DateTimeInterface |
|
| 44 | - */ |
|
| 45 | - public function getItemDate(): DateTimeInterface |
|
| 46 | - { |
|
| 47 | - return $this->itemDate; |
|
| 48 | - } |
|
| 42 | + /** |
|
| 43 | + * @return DateTimeInterface |
|
| 44 | + */ |
|
| 45 | + public function getItemDate(): DateTimeInterface |
|
| 46 | + { |
|
| 47 | + return $this->itemDate; |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -18,65 +18,65 @@ |
||
| 18 | 18 | |
| 19 | 19 | class DriverIO |
| 20 | 20 | { |
| 21 | - protected int $writeHit = 0; |
|
| 22 | - |
|
| 23 | - protected int $readHit = 0; |
|
| 24 | - |
|
| 25 | - protected int $readMiss = 0; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - public function getWriteHit(): int |
|
| 29 | - { |
|
| 30 | - return $this->writeHit; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @param int $writeHit |
|
| 35 | - * @return DriverIO |
|
| 36 | - */ |
|
| 37 | - public function setWriteHit(int $writeHit): DriverIO |
|
| 38 | - { |
|
| 39 | - $this->writeHit = $writeHit; |
|
| 40 | - return $this; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - public function incWriteHit(): DriverIO |
|
| 44 | - { |
|
| 45 | - $this->writeHit++; |
|
| 46 | - return $this; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public function getReadHit(): int |
|
| 50 | - { |
|
| 51 | - return $this->readHit; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public function setReadHit(int $readHit): DriverIO |
|
| 55 | - { |
|
| 56 | - $this->readHit = $readHit; |
|
| 57 | - return $this; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - public function incReadHit(): DriverIO |
|
| 61 | - { |
|
| 62 | - $this->readHit++; |
|
| 63 | - return $this; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - public function getReadMiss(): int |
|
| 67 | - { |
|
| 68 | - return $this->readMiss; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - public function setReadMiss(int $readMiss): DriverIO |
|
| 72 | - { |
|
| 73 | - $this->readMiss = $readMiss; |
|
| 74 | - return $this; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - public function incReadMiss(): DriverIO |
|
| 78 | - { |
|
| 79 | - $this->readMiss++; |
|
| 80 | - return $this; |
|
| 81 | - } |
|
| 21 | + protected int $writeHit = 0; |
|
| 22 | + |
|
| 23 | + protected int $readHit = 0; |
|
| 24 | + |
|
| 25 | + protected int $readMiss = 0; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + public function getWriteHit(): int |
|
| 29 | + { |
|
| 30 | + return $this->writeHit; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @param int $writeHit |
|
| 35 | + * @return DriverIO |
|
| 36 | + */ |
|
| 37 | + public function setWriteHit(int $writeHit): DriverIO |
|
| 38 | + { |
|
| 39 | + $this->writeHit = $writeHit; |
|
| 40 | + return $this; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + public function incWriteHit(): DriverIO |
|
| 44 | + { |
|
| 45 | + $this->writeHit++; |
|
| 46 | + return $this; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public function getReadHit(): int |
|
| 50 | + { |
|
| 51 | + return $this->readHit; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public function setReadHit(int $readHit): DriverIO |
|
| 55 | + { |
|
| 56 | + $this->readHit = $readHit; |
|
| 57 | + return $this; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + public function incReadHit(): DriverIO |
|
| 61 | + { |
|
| 62 | + $this->readHit++; |
|
| 63 | + return $this; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + public function getReadMiss(): int |
|
| 67 | + { |
|
| 68 | + return $this->readMiss; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + public function setReadMiss(int $readMiss): DriverIO |
|
| 72 | + { |
|
| 73 | + $this->readMiss = $readMiss; |
|
| 74 | + return $this; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + public function incReadMiss(): DriverIO |
|
| 78 | + { |
|
| 79 | + $this->readMiss++; |
|
| 80 | + return $this; |
|
| 81 | + } |
|
| 82 | 82 | } |
@@ -21,173 +21,173 @@ |
||
| 21 | 21 | |
| 22 | 22 | trait ClassNamespaceResolverTrait |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @var array<string, string> |
|
| 26 | - */ |
|
| 27 | - protected static array $namespaces = []; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Iterate over all files in the given directory searching for classes. |
|
| 31 | - * |
|
| 32 | - * NOTICE: This method has been borrowed from Symfony ClassLoader 3.4 since they |
|
| 33 | - * deprecated the whole component as of SF4. Our thanks to them. |
|
| 34 | - * |
|
| 35 | - * @param string $dir The directory to search in or an iterator |
|
| 36 | - * |
|
| 37 | - * @return array<string, string> A class map array |
|
| 38 | - */ |
|
| 39 | - protected static function createClassMap(string $dir): array |
|
| 40 | - { |
|
| 41 | - $dirIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); |
|
| 42 | - |
|
| 43 | - $map = []; |
|
| 44 | - |
|
| 45 | - foreach ($dirIterator as $file) { |
|
| 46 | - if (!$file->isFile()) { |
|
| 47 | - continue; |
|
| 48 | - } |
|
| 49 | - $path = $file->getRealPath() ?: $file->getPathname(); |
|
| 50 | - if ('php' !== pathinfo($path, PATHINFO_EXTENSION)) { |
|
| 51 | - continue; |
|
| 52 | - } |
|
| 53 | - $classes = self::findClasses($path); |
|
| 54 | - gc_mem_caches(); |
|
| 55 | - foreach ($classes as $class) { |
|
| 56 | - $map[$class] = $path; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - return $map; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Extract the classes in the given file. |
|
| 65 | - * |
|
| 66 | - * NOTICE: This method has been borrowed from Symfony ClassLoader 3.4 since they |
|
| 67 | - * deprecated the whole component as of SF4. Our thanks to them. |
|
| 68 | - * |
|
| 69 | - * @param string $path The file to check |
|
| 70 | - * |
|
| 71 | - * @return string[] The found classes |
|
| 72 | - * |
|
| 73 | - * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
|
| 74 | - */ |
|
| 75 | - protected static function findClasses(string $path): array |
|
| 76 | - { |
|
| 77 | - $contents = file_get_contents($path); |
|
| 78 | - $tokens = token_get_all($contents); |
|
| 79 | - $classes = []; |
|
| 80 | - $namespace = ''; |
|
| 81 | - for ($i = 0; isset($tokens[$i]); ++$i) { |
|
| 82 | - $token = $tokens[$i]; |
|
| 83 | - if (!isset($token[1])) { |
|
| 84 | - continue; |
|
| 85 | - } |
|
| 86 | - $class = ''; |
|
| 87 | - switch ($token[0]) { |
|
| 88 | - case T_NAMESPACE: |
|
| 89 | - $namespace = self::buildTokenNamespace($i, $tokens); |
|
| 90 | - break; |
|
| 91 | - case T_CLASS: |
|
| 92 | - case T_INTERFACE: |
|
| 93 | - case T_TRAIT: |
|
| 94 | - $classes = self::buildTokenClasses($namespace, $class, $classes, $i, $tokens); |
|
| 95 | - break; |
|
| 96 | - default: |
|
| 97 | - break; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $classes; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @param string $namespace |
|
| 106 | - * @param string $class |
|
| 107 | - * @param string[] $classes |
|
| 108 | - * @param int $index |
|
| 109 | - * @param array<array<mixed>|string> $tokens |
|
| 110 | - * @return string[] |
|
| 111 | - */ |
|
| 112 | - protected static function buildTokenClasses(string $namespace, string $class, array $classes, int $index, array $tokens): array |
|
| 113 | - { |
|
| 114 | - // Skip usage of ::class constant |
|
| 115 | - $isClassConstant = false; |
|
| 116 | - for ($j = $index - 1; $j > 0; --$j) { |
|
| 117 | - if (!isset($tokens[$j][1])) { |
|
| 118 | - break; |
|
| 119 | - } |
|
| 120 | - if (T_DOUBLE_COLON === $tokens[$j][0]) { |
|
| 121 | - $isClassConstant = true; |
|
| 122 | - break; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - if (!\in_array($tokens[$j][0], [T_WHITESPACE, T_DOC_COMMENT, T_COMMENT], false)) { |
|
| 126 | - break; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - if ($isClassConstant) { |
|
| 130 | - return $classes; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // Find the classname |
|
| 134 | - while (isset($tokens[++$index][1])) { |
|
| 135 | - $t = $tokens[$index]; |
|
| 136 | - if (T_STRING === $t[0]) { |
|
| 137 | - $class .= $t[1]; |
|
| 138 | - } elseif ('' !== $class && T_WHITESPACE === $t[0]) { |
|
| 139 | - break; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return \array_merge($classes, [\ltrim($namespace . $class, '\\')]); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @param int $index |
|
| 148 | - * @param array<array<mixed>|string> $tokens |
|
| 149 | - * @return string |
|
| 150 | - */ |
|
| 151 | - protected static function buildTokenNamespace(int $index, array $tokens): string |
|
| 152 | - { |
|
| 153 | - $namespace = ''; |
|
| 154 | - |
|
| 155 | - // If there is a namespace, extract it (PHP 8 test) |
|
| 156 | - if (\defined('T_NAME_QUALIFIED')) { |
|
| 157 | - while (isset($tokens[++$index][1])) { |
|
| 158 | - if ($tokens[$index][0] === T_NAME_QUALIFIED) { |
|
| 159 | - $namespace = $tokens[$index][1]; |
|
| 160 | - break; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } else { |
|
| 164 | - while (isset($tokens[++$index][1])) { |
|
| 165 | - if (\in_array($tokens[$index][0], [T_STRING, T_NS_SEPARATOR], true)) { |
|
| 166 | - $namespace .= $tokens[$index][1]; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - return $namespace . '\\'; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @return string |
|
| 176 | - */ |
|
| 177 | - public static function getClassNamespace(): string |
|
| 178 | - { |
|
| 179 | - if (!isset(self::$namespaces[static::class])) { |
|
| 180 | - self::$namespaces[static::class] = substr(static::class, 0, strrpos(static::class, '\\')); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - return self::$namespaces[static::class]; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public function getClassName(): string |
|
| 190 | - { |
|
| 191 | - return static::class; |
|
| 192 | - } |
|
| 24 | + /** |
|
| 25 | + * @var array<string, string> |
|
| 26 | + */ |
|
| 27 | + protected static array $namespaces = []; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Iterate over all files in the given directory searching for classes. |
|
| 31 | + * |
|
| 32 | + * NOTICE: This method has been borrowed from Symfony ClassLoader 3.4 since they |
|
| 33 | + * deprecated the whole component as of SF4. Our thanks to them. |
|
| 34 | + * |
|
| 35 | + * @param string $dir The directory to search in or an iterator |
|
| 36 | + * |
|
| 37 | + * @return array<string, string> A class map array |
|
| 38 | + */ |
|
| 39 | + protected static function createClassMap(string $dir): array |
|
| 40 | + { |
|
| 41 | + $dirIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); |
|
| 42 | + |
|
| 43 | + $map = []; |
|
| 44 | + |
|
| 45 | + foreach ($dirIterator as $file) { |
|
| 46 | + if (!$file->isFile()) { |
|
| 47 | + continue; |
|
| 48 | + } |
|
| 49 | + $path = $file->getRealPath() ?: $file->getPathname(); |
|
| 50 | + if ('php' !== pathinfo($path, PATHINFO_EXTENSION)) { |
|
| 51 | + continue; |
|
| 52 | + } |
|
| 53 | + $classes = self::findClasses($path); |
|
| 54 | + gc_mem_caches(); |
|
| 55 | + foreach ($classes as $class) { |
|
| 56 | + $map[$class] = $path; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + return $map; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Extract the classes in the given file. |
|
| 65 | + * |
|
| 66 | + * NOTICE: This method has been borrowed from Symfony ClassLoader 3.4 since they |
|
| 67 | + * deprecated the whole component as of SF4. Our thanks to them. |
|
| 68 | + * |
|
| 69 | + * @param string $path The file to check |
|
| 70 | + * |
|
| 71 | + * @return string[] The found classes |
|
| 72 | + * |
|
| 73 | + * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
|
| 74 | + */ |
|
| 75 | + protected static function findClasses(string $path): array |
|
| 76 | + { |
|
| 77 | + $contents = file_get_contents($path); |
|
| 78 | + $tokens = token_get_all($contents); |
|
| 79 | + $classes = []; |
|
| 80 | + $namespace = ''; |
|
| 81 | + for ($i = 0; isset($tokens[$i]); ++$i) { |
|
| 82 | + $token = $tokens[$i]; |
|
| 83 | + if (!isset($token[1])) { |
|
| 84 | + continue; |
|
| 85 | + } |
|
| 86 | + $class = ''; |
|
| 87 | + switch ($token[0]) { |
|
| 88 | + case T_NAMESPACE: |
|
| 89 | + $namespace = self::buildTokenNamespace($i, $tokens); |
|
| 90 | + break; |
|
| 91 | + case T_CLASS: |
|
| 92 | + case T_INTERFACE: |
|
| 93 | + case T_TRAIT: |
|
| 94 | + $classes = self::buildTokenClasses($namespace, $class, $classes, $i, $tokens); |
|
| 95 | + break; |
|
| 96 | + default: |
|
| 97 | + break; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $classes; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @param string $namespace |
|
| 106 | + * @param string $class |
|
| 107 | + * @param string[] $classes |
|
| 108 | + * @param int $index |
|
| 109 | + * @param array<array<mixed>|string> $tokens |
|
| 110 | + * @return string[] |
|
| 111 | + */ |
|
| 112 | + protected static function buildTokenClasses(string $namespace, string $class, array $classes, int $index, array $tokens): array |
|
| 113 | + { |
|
| 114 | + // Skip usage of ::class constant |
|
| 115 | + $isClassConstant = false; |
|
| 116 | + for ($j = $index - 1; $j > 0; --$j) { |
|
| 117 | + if (!isset($tokens[$j][1])) { |
|
| 118 | + break; |
|
| 119 | + } |
|
| 120 | + if (T_DOUBLE_COLON === $tokens[$j][0]) { |
|
| 121 | + $isClassConstant = true; |
|
| 122 | + break; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + if (!\in_array($tokens[$j][0], [T_WHITESPACE, T_DOC_COMMENT, T_COMMENT], false)) { |
|
| 126 | + break; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + if ($isClassConstant) { |
|
| 130 | + return $classes; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // Find the classname |
|
| 134 | + while (isset($tokens[++$index][1])) { |
|
| 135 | + $t = $tokens[$index]; |
|
| 136 | + if (T_STRING === $t[0]) { |
|
| 137 | + $class .= $t[1]; |
|
| 138 | + } elseif ('' !== $class && T_WHITESPACE === $t[0]) { |
|
| 139 | + break; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return \array_merge($classes, [\ltrim($namespace . $class, '\\')]); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @param int $index |
|
| 148 | + * @param array<array<mixed>|string> $tokens |
|
| 149 | + * @return string |
|
| 150 | + */ |
|
| 151 | + protected static function buildTokenNamespace(int $index, array $tokens): string |
|
| 152 | + { |
|
| 153 | + $namespace = ''; |
|
| 154 | + |
|
| 155 | + // If there is a namespace, extract it (PHP 8 test) |
|
| 156 | + if (\defined('T_NAME_QUALIFIED')) { |
|
| 157 | + while (isset($tokens[++$index][1])) { |
|
| 158 | + if ($tokens[$index][0] === T_NAME_QUALIFIED) { |
|
| 159 | + $namespace = $tokens[$index][1]; |
|
| 160 | + break; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } else { |
|
| 164 | + while (isset($tokens[++$index][1])) { |
|
| 165 | + if (\in_array($tokens[$index][0], [T_STRING, T_NS_SEPARATOR], true)) { |
|
| 166 | + $namespace .= $tokens[$index][1]; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + return $namespace . '\\'; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @return string |
|
| 176 | + */ |
|
| 177 | + public static function getClassNamespace(): string |
|
| 178 | + { |
|
| 179 | + if (!isset(self::$namespaces[static::class])) { |
|
| 180 | + self::$namespaces[static::class] = substr(static::class, 0, strrpos(static::class, '\\')); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + return self::$namespaces[static::class]; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public function getClassName(): string |
|
| 190 | + { |
|
| 191 | + return static::class; |
|
| 192 | + } |
|
| 193 | 193 | } |
@@ -135,7 +135,8 @@ discard block |
||
| 135 | 135 | $t = $tokens[$index]; |
| 136 | 136 | if (T_STRING === $t[0]) { |
| 137 | 137 | $class .= $t[1]; |
| 138 | - } elseif ('' !== $class && T_WHITESPACE === $t[0]) { |
|
| 138 | + } |
|
| 139 | + elseif ('' !== $class && T_WHITESPACE === $t[0]) { |
|
| 139 | 140 | break; |
| 140 | 141 | } |
| 141 | 142 | } |
@@ -160,7 +161,8 @@ discard block |
||
| 160 | 161 | break; |
| 161 | 162 | } |
| 162 | 163 | } |
| 163 | - } else { |
|
| 164 | + } |
|
| 165 | + else { |
|
| 164 | 166 | while (isset($tokens[++$index][1])) { |
| 165 | 167 | if (\in_array($tokens[$index][0], [T_STRING, T_NS_SEPARATOR], true)) { |
| 166 | 168 | $namespace .= $tokens[$index][1]; |
@@ -18,13 +18,13 @@ |
||
| 18 | 18 | |
| 19 | 19 | interface ClassNamespaceResolverInterface |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @return string |
|
| 23 | - */ |
|
| 24 | - public static function getClassNamespace(): string; |
|
| 21 | + /** |
|
| 22 | + * @return string |
|
| 23 | + */ |
|
| 24 | + public static function getClassNamespace(): string; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function getClassName(): string; |
|
| 26 | + /** |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function getClassName(): string; |
|
| 30 | 30 | } |
@@ -23,126 +23,126 @@ |
||
| 23 | 23 | |
| 24 | 24 | class Directory |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * Get the directory size |
|
| 28 | - * @param string $directory |
|
| 29 | - * @param bool $includeDirAllocSize |
|
| 30 | - * @return int |
|
| 31 | - */ |
|
| 32 | - public static function dirSize(string $directory, bool $includeDirAllocSize = false): int |
|
| 33 | - { |
|
| 34 | - $size = 0; |
|
| 35 | - foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) { |
|
| 36 | - /** |
|
| 37 | - * @var SplFileInfo $file |
|
| 38 | - */ |
|
| 39 | - if ($file->isFile()) { |
|
| 40 | - $size += filesize($file->getRealPath()); |
|
| 41 | - } elseif ($includeDirAllocSize) { |
|
| 42 | - $size += $file->getSize(); |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - return $size; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param string $path |
|
| 51 | - * @return int |
|
| 52 | - */ |
|
| 53 | - public static function getFileCount(string $path): int |
|
| 54 | - { |
|
| 55 | - $count = 0; |
|
| 56 | - $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); |
|
| 57 | - foreach ($objects as $object) { |
|
| 58 | - /** |
|
| 59 | - * @var SplFileInfo $object |
|
| 60 | - */ |
|
| 61 | - if ($object->isFile()) { |
|
| 62 | - $count++; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - return $count; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Recursively delete a directory and all of its contents - e.g.the equivalent of `rm -r` on the command-line. |
|
| 71 | - * Consistent with `rmdir()` and `unlink()`, an E_WARNING level error will be generated on failure. |
|
| 72 | - * |
|
| 73 | - * @param string $source absolute path to directory or file to delete. |
|
| 74 | - * @param bool $removeOnlyChildren set to true will only remove content inside directory. |
|
| 75 | - * |
|
| 76 | - * @return bool true on success; false on failure |
|
| 77 | - */ |
|
| 78 | - public static function rrmdir(string $source, bool $removeOnlyChildren = false): bool |
|
| 79 | - { |
|
| 80 | - if (empty($source) || file_exists($source) === false) { |
|
| 81 | - return false; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - if (is_file($source) || is_link($source)) { |
|
| 85 | - clearstatcache(true, $source); |
|
| 86 | - return unlink($source); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $files = new RecursiveIteratorIterator( |
|
| 90 | - new RecursiveDirectoryIterator($source, FilesystemIterator::SKIP_DOTS), |
|
| 91 | - RecursiveIteratorIterator::CHILD_FIRST |
|
| 92 | - ); |
|
| 93 | - |
|
| 94 | - foreach ($files as $fileInfo) { |
|
| 95 | - /** |
|
| 96 | - * @var SplFileInfo $fileInfo |
|
| 97 | - */ |
|
| 98 | - $realpath = $fileInfo->getRealPath(); |
|
| 99 | - if ($realpath) { |
|
| 100 | - if ($fileInfo->isDir()) { |
|
| 101 | - if (self::rrmdir($fileInfo->getRealPath()) === false) { |
|
| 102 | - return false; |
|
| 103 | - } |
|
| 104 | - } elseif (unlink($realpath) === false) { |
|
| 105 | - return false; |
|
| 106 | - } |
|
| 107 | - } else { |
|
| 108 | - return false; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - if ($removeOnlyChildren === false) { |
|
| 113 | - return rmdir($source); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - return true; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Alias of realpath() but work |
|
| 121 | - * on non-existing files |
|
| 122 | - * |
|
| 123 | - * @param string $path |
|
| 124 | - * @return string |
|
| 125 | - */ |
|
| 126 | - public static function getAbsolutePath(string $path): string |
|
| 127 | - { |
|
| 128 | - $parts = preg_split('~[/\\\\]+~', $path, 0, PREG_SPLIT_NO_EMPTY); |
|
| 129 | - $absolutes = []; |
|
| 130 | - foreach ($parts as $part) { |
|
| 131 | - if ('.' === $part) { |
|
| 132 | - continue; |
|
| 133 | - } |
|
| 134 | - if ('..' === $part) { |
|
| 135 | - array_pop($absolutes); |
|
| 136 | - } else { |
|
| 137 | - $absolutes[] = $part; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Allows dereferencing char |
|
| 143 | - */ |
|
| 144 | - $file = preg_replace('~^(([a-z0-9\-]+)://)~', '', __FILE__);// remove file protocols such as "phar://" etc. |
|
| 145 | - $prefix = $file[0] === DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : ''; |
|
| 146 | - return $prefix . implode(DIRECTORY_SEPARATOR, $absolutes); |
|
| 147 | - } |
|
| 26 | + /** |
|
| 27 | + * Get the directory size |
|
| 28 | + * @param string $directory |
|
| 29 | + * @param bool $includeDirAllocSize |
|
| 30 | + * @return int |
|
| 31 | + */ |
|
| 32 | + public static function dirSize(string $directory, bool $includeDirAllocSize = false): int |
|
| 33 | + { |
|
| 34 | + $size = 0; |
|
| 35 | + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) { |
|
| 36 | + /** |
|
| 37 | + * @var SplFileInfo $file |
|
| 38 | + */ |
|
| 39 | + if ($file->isFile()) { |
|
| 40 | + $size += filesize($file->getRealPath()); |
|
| 41 | + } elseif ($includeDirAllocSize) { |
|
| 42 | + $size += $file->getSize(); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + return $size; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param string $path |
|
| 51 | + * @return int |
|
| 52 | + */ |
|
| 53 | + public static function getFileCount(string $path): int |
|
| 54 | + { |
|
| 55 | + $count = 0; |
|
| 56 | + $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); |
|
| 57 | + foreach ($objects as $object) { |
|
| 58 | + /** |
|
| 59 | + * @var SplFileInfo $object |
|
| 60 | + */ |
|
| 61 | + if ($object->isFile()) { |
|
| 62 | + $count++; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + return $count; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Recursively delete a directory and all of its contents - e.g.the equivalent of `rm -r` on the command-line. |
|
| 71 | + * Consistent with `rmdir()` and `unlink()`, an E_WARNING level error will be generated on failure. |
|
| 72 | + * |
|
| 73 | + * @param string $source absolute path to directory or file to delete. |
|
| 74 | + * @param bool $removeOnlyChildren set to true will only remove content inside directory. |
|
| 75 | + * |
|
| 76 | + * @return bool true on success; false on failure |
|
| 77 | + */ |
|
| 78 | + public static function rrmdir(string $source, bool $removeOnlyChildren = false): bool |
|
| 79 | + { |
|
| 80 | + if (empty($source) || file_exists($source) === false) { |
|
| 81 | + return false; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + if (is_file($source) || is_link($source)) { |
|
| 85 | + clearstatcache(true, $source); |
|
| 86 | + return unlink($source); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $files = new RecursiveIteratorIterator( |
|
| 90 | + new RecursiveDirectoryIterator($source, FilesystemIterator::SKIP_DOTS), |
|
| 91 | + RecursiveIteratorIterator::CHILD_FIRST |
|
| 92 | + ); |
|
| 93 | + |
|
| 94 | + foreach ($files as $fileInfo) { |
|
| 95 | + /** |
|
| 96 | + * @var SplFileInfo $fileInfo |
|
| 97 | + */ |
|
| 98 | + $realpath = $fileInfo->getRealPath(); |
|
| 99 | + if ($realpath) { |
|
| 100 | + if ($fileInfo->isDir()) { |
|
| 101 | + if (self::rrmdir($fileInfo->getRealPath()) === false) { |
|
| 102 | + return false; |
|
| 103 | + } |
|
| 104 | + } elseif (unlink($realpath) === false) { |
|
| 105 | + return false; |
|
| 106 | + } |
|
| 107 | + } else { |
|
| 108 | + return false; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + if ($removeOnlyChildren === false) { |
|
| 113 | + return rmdir($source); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + return true; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Alias of realpath() but work |
|
| 121 | + * on non-existing files |
|
| 122 | + * |
|
| 123 | + * @param string $path |
|
| 124 | + * @return string |
|
| 125 | + */ |
|
| 126 | + public static function getAbsolutePath(string $path): string |
|
| 127 | + { |
|
| 128 | + $parts = preg_split('~[/\\\\]+~', $path, 0, PREG_SPLIT_NO_EMPTY); |
|
| 129 | + $absolutes = []; |
|
| 130 | + foreach ($parts as $part) { |
|
| 131 | + if ('.' === $part) { |
|
| 132 | + continue; |
|
| 133 | + } |
|
| 134 | + if ('..' === $part) { |
|
| 135 | + array_pop($absolutes); |
|
| 136 | + } else { |
|
| 137 | + $absolutes[] = $part; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Allows dereferencing char |
|
| 143 | + */ |
|
| 144 | + $file = preg_replace('~^(([a-z0-9\-]+)://)~', '', __FILE__);// remove file protocols such as "phar://" etc. |
|
| 145 | + $prefix = $file[0] === DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : ''; |
|
| 146 | + return $prefix . implode(DIRECTORY_SEPARATOR, $absolutes); |
|
| 147 | + } |
|
| 148 | 148 | } |
@@ -141,7 +141,7 @@ |
||
| 141 | 141 | /** |
| 142 | 142 | * Allows dereferencing char |
| 143 | 143 | */ |
| 144 | - $file = preg_replace('~^(([a-z0-9\-]+)://)~', '', __FILE__);// remove file protocols such as "phar://" etc. |
|
| 144 | + $file = preg_replace('~^(([a-z0-9\-]+)://)~', '', __FILE__); // remove file protocols such as "phar://" etc. |
|
| 145 | 145 | $prefix = $file[0] === DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : ''; |
| 146 | 146 | return $prefix . implode(DIRECTORY_SEPARATOR, $absolutes); |
| 147 | 147 | } |
@@ -38,7 +38,8 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | if ($file->isFile()) { |
| 40 | 40 | $size += filesize($file->getRealPath()); |
| 41 | - } elseif ($includeDirAllocSize) { |
|
| 41 | + } |
|
| 42 | + elseif ($includeDirAllocSize) { |
|
| 42 | 43 | $size += $file->getSize(); |
| 43 | 44 | } |
| 44 | 45 | } |
@@ -101,10 +102,12 @@ discard block |
||
| 101 | 102 | if (self::rrmdir($fileInfo->getRealPath()) === false) { |
| 102 | 103 | return false; |
| 103 | 104 | } |
| 104 | - } elseif (unlink($realpath) === false) { |
|
| 105 | + } |
|
| 106 | + elseif (unlink($realpath) === false) { |
|
| 105 | 107 | return false; |
| 106 | 108 | } |
| 107 | - } else { |
|
| 109 | + } |
|
| 110 | + else { |
|
| 108 | 111 | return false; |
| 109 | 112 | } |
| 110 | 113 | } |
@@ -133,7 +136,8 @@ discard block |
||
| 133 | 136 | } |
| 134 | 137 | if ('..' === $part) { |
| 135 | 138 | array_pop($absolutes); |
| 136 | - } else { |
|
| 139 | + } |
|
| 140 | + else { |
|
| 137 | 141 | $absolutes[] = $part; |
| 138 | 142 | } |
| 139 | 143 | } |
@@ -18,16 +18,16 @@ |
||
| 18 | 18 | |
| 19 | 19 | class SapiDetector |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @SuppressWarnings(PHPMD.Superglobals) |
|
| 23 | - */ |
|
| 24 | - public static function isWebScript(): bool |
|
| 25 | - { |
|
| 26 | - return \PHP_SAPI === 'apache2handler' || str_contains(\PHP_SAPI, 'handler') || isset($_SERVER['REQUEST_METHOD']); |
|
| 27 | - } |
|
| 21 | + /** |
|
| 22 | + * @SuppressWarnings(PHPMD.Superglobals) |
|
| 23 | + */ |
|
| 24 | + public static function isWebScript(): bool |
|
| 25 | + { |
|
| 26 | + return \PHP_SAPI === 'apache2handler' || str_contains(\PHP_SAPI, 'handler') || isset($_SERVER['REQUEST_METHOD']); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public static function isCliScript(): bool |
|
| 30 | - { |
|
| 31 | - return (\PHP_SAPI === 'cli') || \defined('STDIN'); |
|
| 32 | - } |
|
| 29 | + public static function isCliScript(): bool |
|
| 30 | + { |
|
| 31 | + return (\PHP_SAPI === 'cli') || \defined('STDIN'); |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -18,31 +18,31 @@ |
||
| 18 | 18 | |
| 19 | 19 | trait MemcacheDriverCollisionDetectorTrait |
| 20 | 20 | { |
| 21 | - protected static string $driverUsed; |
|
| 21 | + protected static string $driverUsed; |
|
| 22 | 22 | |
| 23 | - public static function checkCollision(string $driverName): bool |
|
| 24 | - { |
|
| 25 | - $constantName = __NAMESPACE__ . '\MEMCACHE_DRIVER_USED'; |
|
| 23 | + public static function checkCollision(string $driverName): bool |
|
| 24 | + { |
|
| 25 | + $constantName = __NAMESPACE__ . '\MEMCACHE_DRIVER_USED'; |
|
| 26 | 26 | |
| 27 | - if ($driverName) { |
|
| 28 | - if (!defined($constantName)) { |
|
| 29 | - define($constantName, $driverName); |
|
| 27 | + if ($driverName) { |
|
| 28 | + if (!defined($constantName)) { |
|
| 29 | + define($constantName, $driverName); |
|
| 30 | 30 | |
| 31 | - return true; |
|
| 32 | - } |
|
| 31 | + return true; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - if (constant($constantName) !== $driverName) { |
|
| 35 | - trigger_error( |
|
| 36 | - 'Memcache collision detected, you used both Memcache and Memcached driver in your script, this may leads to unexpected behaviours', |
|
| 37 | - E_USER_WARNING |
|
| 38 | - ); |
|
| 34 | + if (constant($constantName) !== $driverName) { |
|
| 35 | + trigger_error( |
|
| 36 | + 'Memcache collision detected, you used both Memcache and Memcached driver in your script, this may leads to unexpected behaviours', |
|
| 37 | + E_USER_WARNING |
|
| 38 | + ); |
|
| 39 | 39 | |
| 40 | - return false; |
|
| 41 | - } |
|
| 40 | + return false; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - return true; |
|
| 44 | - } |
|
| 43 | + return true; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - return false; |
|
| 47 | - } |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 48 | 48 | } |