-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
123 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\Component\Resource\Reflection; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Resource\Reflection\ClassReflection as NewClassReflection; | ||
|
||
final class ClassReflectionSpec extends ObjectBehavior | ||
{ | ||
function it_is_an_alias_of_the_class_reflection(): void | ||
{ | ||
$this->shouldBeAnInstanceOf(NewClassReflection::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Resource\Reflection; | ||
|
||
use Symfony\Component\Finder\Finder; | ||
|
||
final class ClassReflection | ||
{ | ||
public static function getResourcesByPaths(array $paths): iterable | ||
{ | ||
foreach ($paths as $resourceDirectory) { | ||
$resources = self::getResourcesByPath($resourceDirectory); | ||
|
||
foreach ($resources as $className) { | ||
yield $className; | ||
} | ||
} | ||
} | ||
|
||
public static function getResourcesByPath(string $path): iterable | ||
{ | ||
$finder = new Finder(); | ||
$finder->files()->in($path)->name('*.php')->sortByName(true); | ||
|
||
foreach ($finder as $file) { | ||
$fileContent = (string) file_get_contents((string) $file->getRealPath()); | ||
|
||
preg_match('/namespace (.+);/', $fileContent, $matches); | ||
|
||
$namespace = $matches[1] ?? null; | ||
|
||
if (!preg_match('/class +([^{ ]+)/', $fileContent, $matches)) { | ||
// no class found | ||
continue; | ||
} | ||
|
||
$className = trim($matches[1]); | ||
|
||
if (null !== $namespace) { | ||
yield $namespace . '\\' . $className; | ||
} else { | ||
yield $className; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @psalm-param class-string $className | ||
* | ||
* @return \ReflectionAttribute[] | ||
*/ | ||
public static function getClassAttributes(string $className, ?string $attributeName = null): array | ||
{ | ||
$reflectionClass = new \ReflectionClass($className); | ||
|
||
/** @psalm-suppress ArgumentTypeCoercion */ | ||
return $reflectionClass->getAttributes($attributeName); | ||
} | ||
} | ||
|
||
class_alias(ClassReflection::class, \Sylius\Component\Resource\Reflection\ClassReflection::class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters