Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #27 from localheinz/feature/classy
Browse files Browse the repository at this point in the history
Enhancement: Use localheinz/classy
  • Loading branch information
localheinz authored Oct 11, 2017
2 parents 551e41e + e44f381 commit 055aee1
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 108 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"require": {
"php": "^7.0",
"zendframework/zend-file": "^2.7.1"
"localheinz/classy": "0.2.0"
},
"require-dev": {
"breerly/factory-girl-php": "^1.0.0",
Expand Down
203 changes: 123 additions & 80 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 24 additions & 27 deletions src/Definitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Localheinz\FactoryGirl\Definition;

use FactoryGirl\Provider\Doctrine\FixtureFactory;
use Zend\File;
use Localheinz\Classy;

final class Definitions
{
Expand Down Expand Up @@ -43,36 +43,33 @@ public static function in(string $directory)
throw Exception\InvalidDirectory::notDirectory($directory);
}

$locator = new File\ClassFileLocator($directory);
$instance = new self();

/** @var File\PhpClassFile[] $files */
$files = \iterator_to_array($locator);
$constructs = Classy\Constructs::fromDirectory($directory);

$instance = new self();
foreach ($constructs as $construct) {
$className = $construct->name();

try {
$reflection = new \ReflectionClass($className);
} catch (\ReflectionException $exception) {
continue;
}

foreach ($files as $file) {
foreach ($file->getClasses() as $className) {
try {
$reflection = new \ReflectionClass($className);
} catch (\ReflectionException $exception) {
continue;
}

if (!$reflection->isSubclassOf(Definition::class) || !$reflection->isInstantiable()) {
continue;
}

try {
$definition = $reflection->newInstance();
} catch (\Exception $exception) {
throw Exception\InvalidDefinition::fromClassNameAndException(
$className,
$exception
);
}

$instance->definitions[] = $definition;
if (!$reflection->isSubclassOf(Definition::class) || !$reflection->isInstantiable()) {
continue;
}

try {
$definition = $reflection->newInstance();
} catch (\Exception $exception) {
throw Exception\InvalidDefinition::fromClassNameAndException(
$className,
$exception
);
}

$instance->definitions[] = $definition;
}

return $instance;
Expand Down

0 comments on commit 055aee1

Please sign in to comment.