-
-
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.
refactor #806 Move some namespaces on reflection (loic425)
This PR was merged into the 1.11 branch. Discussion ---------- | Q | A | --------------- | ----- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | | License | MIT Based on #805 Only ClassReflection needs a bc-layer cause the other classes have been introduced in 1.11. Commits ------- ffeaa37 Move some namespaces on reflection b98ab44 Apply suggestions from code review cea38d6 Remove an unnecessary empty line
- Loading branch information
Showing
21 changed files
with
125 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,75 @@ | ||
<?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 = file_get_contents((string) $file->getRealPath()); | ||
if (false === $fileContent) { | ||
throw new \RuntimeException(sprintf('Unable to read "%s" file', $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