コード例 #1
0
 private function scanBundle(Bundle $bundle, BundleService $bundleService)
 {
     $bundleService->addBundle($bundle);
     if ($bundle->hasBundles()) {
         $rootNamespace = $bundle->getNamespace();
         $rootDir = $bundle->getBundlesDir();
         $bundles = Chain::create(scandir($bundle->getBundlesDir()))->filter(function (string $dir) use($rootDir) {
             return $dir != '.' && $dir != '..' && is_dir($rootDir . '/' . $dir);
         })->map(function (string $dir) use($rootNamespace) {
             $bundleClassName = "{$rootNamespace}\\{$dir}\\{$dir}Bundle";
             if (!class_exists($bundleClassName)) {
                 $bundleClassName = "{$rootNamespace}\\Bundles\\{$dir}\\{$dir}Bundle";
                 if (!class_exists($bundleClassName)) {
                     throw new \Exception(sprintf('No Bundle available for bundle `%s`', $bundleClassName));
                 }
             }
             if (!is_subclass_of($bundleClassName, Bundle::class)) {
                 throw new \Exception(sprintf('Bundle `%s` should implements interface %s', $bundleClassName, Bundle::class));
             }
             return new $bundleClassName();
         })->array;
         foreach ($bundles as $bundle) {
             $this->scanBundle($bundle, $bundleService);
         }
     }
 }
コード例 #2
0
ファイル: DiffTest.php プロジェクト: cocur/chain
 /**
  * @test
  * @covers Cocur\Chain\Link\Diff::diff()
  */
 public function diffDiffsChainWithChain()
 {
     /** @var \Cocur\Chain\Link\Diff $mock */
     $mock = $this->getMockForTrait('Cocur\\Chain\\Link\\Diff');
     $mock->array = [0, 1, 2];
     $mock->diff(Chain::create([1, 2, 3]));
     $this->assertEquals([0], $mock->array);
 }
コード例 #3
0
ファイル: CombineTest.php プロジェクト: cocur/chain
 /**
  * @test
  * @covers Cocur\Chain\Link\Combine::combine()
  */
 public function combineValuesAndKeysWithChainTest()
 {
     /** @var \Cocur\Chain\Link\Combine $mock */
     $mock = $this->getMockForTrait('Cocur\\Chain\\Link\\Combine');
     $keys = Chain::create(['foo', 'bar']);
     $values = Chain::create([42, 43]);
     $this->assertEquals(['foo' => 42, 'bar' => 43], $mock->combine($keys, $values)->array);
 }
コード例 #4
0
ファイル: MergeTest.php プロジェクト: cocur/chain
 /**
  * @test
  * @covers Cocur\Chain\Link\Merge::merge()
  */
 public function mergeMergesRecursiveChain()
 {
     /** @var \Cocur\Chain\Link\Merge $mock */
     $mock = $this->getMockForTrait('Cocur\\Chain\\Link\\Merge');
     $mock->array = ['foo' => [0, 1], 'bar' => ['a', 'b']];
     $mock->merge(Chain::create(['foo' => [2, 3], 'bar' => ['c', 'd']]), ['recursive' => true]);
     $this->assertEquals(['foo' => [0, 1, 2, 3], 'bar' => ['a', 'b', 'c', 'd']], $mock->array);
 }
コード例 #5
0
ファイル: IntersectKeyTest.php プロジェクト: cocur/chain
 /**
  * @test
  * @covers Cocur\Chain\Link\IntersectKey::intersectKey()
  */
 public function intersectKeyIntersectsWithChain()
 {
     /** @var \Cocur\Chain\Link\IntersectKey $mock */
     $mock = $this->getMockForTrait('Cocur\\Chain\\Link\\IntersectKey');
     $mock->array = ['a' => 1, 'b' => 2, 'c' => 3];
     $mock->intersectKey(Chain::create(['a' => 3, 'b' => 4, 'd' => 5]));
     $this->assertEquals(['a' => 1, 'b' => 2], $mock->array);
 }
コード例 #6
0
ファイル: IntersectAssocTest.php プロジェクト: cocur/chain
 /**
  * @test
  * @covers Cocur\Chain\Link\IntersectAssoc::intersectAssoc()
  */
 public function intersectAssocIntersectsWithChain()
 {
     /** @var \Cocur\Chain\Link\IntersectAssoc $mock */
     $mock = $this->getMockForTrait('Cocur\\Chain\\Link\\IntersectAssoc');
     $mock->array = [1, 2, 3];
     $mock->intersectAssoc(Chain::create([3, 2, 1]));
     $this->assertContains(2, $mock->array);
     $this->assertNotContains(1, $mock->array);
     $this->assertNotContains(3, $mock->array);
 }
コード例 #7
0
ファイル: APIDocsBuilder.php プロジェクト: cass-project/cass
 public function build()
 {
     $request = $this->apiDocsBuildRequest;
     $result = Chain::create($request->getDirectories())->filter(function ($directory) {
         return is_dir($directory);
     })->map(function ($directory) {
         $definitions = Chain::create(scandir($directory))->filter(function ($input) use($directory) {
             return $input !== '.' && $input !== '..' && is_dir("{$directory}/{$input}");
         })->map(function ($prefix) use($directory) {
             $subDirectory = "{$directory}/{$prefix}";
             return ['prefix' => $prefix, 'files' => $this->recursiveListYAMLFiles($subDirectory)];
         })->array;
         if (file_exists($globalFile = "{$directory}/global.yml")) {
             $definitions[] = ['prefix' => null, 'files' => [$globalFile]];
         }
         return $definitions;
     })->map(function ($definitions) {
         $config = [];
         foreach ($definitions as $definition) {
             $prefix = $definition['prefix'];
             $files = $definition['files'];
             $ymlParsedFiles = Chain::create($files)->map(function ($file) {
                 return Yaml::parse(file_get_contents($file));
             })->reduce(function ($carry, $item) {
                 return array_merge_recursive($carry, $item);
             }, []);
             if ($prefix === null) {
                 $config = $config + $ymlParsedFiles;
             } else {
                 if (!isset($config[$prefix])) {
                     $config[$prefix] = [];
                 }
                 $config = array_merge_recursive($config, [$prefix => $ymlParsedFiles]);
             }
         }
         return $config;
     })->reduce(function ($config, $yml) {
         return array_merge_recursive($config, $yml);
     }, ['paths' => [], 'definitions' => [], 'responses' => []]);
     if (!count($result['paths'])) {
         unset($result['paths']);
     }
     if (!count($result['definitions'])) {
         unset($result['definitions']);
     }
     if (!count($result['responses'])) {
         unset($result['responses']);
     }
     return $result;
 }
コード例 #8
0
 private function mergeBundleConfigs(ConfigService $configService, array $bundles)
 {
     array_walk($bundles, function (Bundle $bundle) use($configService) {
         $dir = $bundle->getConfigDir();
         if (is_dir($dir)) {
             Chain::create(scandir($dir))->filter(function ($input) use($dir) {
                 return is_file($dir . '/' . $input) && preg_match('/\\.config.php$/', $input);
             })->map(function ($input) use($dir) {
                 return require $dir . '/' . $input;
             })->map(function (array $config) use($configService) {
                 $configService->merge($config);
                 return null;
             });
         }
     });
 }
コード例 #9
0
 private function setupEvents(Application $app, EventEmitter $emitter, $eventConfigFile)
 {
     if (file_exists($eventConfigFile)) {
         $callback = (require $eventConfigFile);
         if (!is_callable($callback)) {
             throw new \Exception(sprintf('Event config `%s` should returns a Callable with EventEmitter and Container argument', $eventConfigFile));
         }
         $result = $callback($emitter, $app->getContainer());
         if (is_array($result) && count($result)) {
             Chain::create($result)->map(function (string $script) use($app) {
                 return $app->getContainer()->get($script);
             })->map(function (EventsBootstrapInterface $script) use($emitter) {
                 $script->up($emitter);
             });
         }
     }
 }
コード例 #10
0
 public function fetch(Filter $filter) : array
 {
     $result = [];
     $scripts = Chain::create($this->bundlesService->getBundles())->filter(function (Bundle $bundle) {
         return $bundle instanceof FrontlineBundleInjectable;
     })->map(function (FrontlineBundleInjectable $bundle) {
         return $bundle->getFrontlineScripts();
     })->reduce(function (array $carry, array $scripts) {
         return array_merge($carry, $scripts);
     }, []);
     $scripts = array_map(function (string $script) {
         return $this->container->get($script);
     }, $scripts);
     foreach ($filter->filter($scripts) as $script) {
         if ($script instanceof FrontlineScript) {
             $result = array_merge_recursive($result, $script());
         } else {
             throw new \Exception();
         }
     }
     return $result;
 }
コード例 #11
0
ファイル: ChainTest.php プロジェクト: cocur/chain
 /**
  * @test
  * @covers Cocur\Chain\Chain::count()
  */
 public function chainIsCountable()
 {
     $c = Chain::create([0, 1, 2]);
     $this->assertInstanceOf('\\Countable', $c);
     $this->assertEquals(3, count($c));
 }
コード例 #12
0
 public function removeDirectory($directory)
 {
     $this->directories = Chain::create($this->directories)->filter(function ($input) use($directory) {
         return $input !== $directory;
     });
 }