Exemple #1
0
 /**
  * Merge two arrays recursively manually
  * because PHP is bad at it.
  *
  * @param array $configuration
  *
  * @return array
  */
 protected function recursiveMerge(array $configuration)
 {
     foreach ($this->configuration->toArray() as $key => $value) {
         $current = array_get($configuration, $key);
         if (is_array($value)) {
             $current = $current ?: [];
             $configuration[$key] = array_merge($value, $current);
         } else {
             $configuration[$key] = $current !== null ? $current : $value;
         }
     }
     return $configuration;
 }
 /**
  * Print the current definitions.
  */
 protected function printDefinitions()
 {
     $this->title('Definitions');
     $rows = [];
     foreach ($this->configuration->getDefinitionProviders() as $definition) {
         if ($definition instanceof ImmutableContainerAwareInterface) {
             $definition->setContainer(new Container());
         }
         $parameters = [];
         $reflection = new ReflectionClass($definition);
         if ($reflection->getProperties()) {
             foreach ($reflection->getProperties() as $parameter) {
                 if ($parameter->getName() === 'container') {
                     continue;
                 }
                 // Extract parameter type
                 $doc = $parameter->getDocComment();
                 preg_match('/.*@(type|var) (.+)\\n.*/', $doc, $type);
                 $type = $type[2];
                 $parameters[] = '<info>' . $parameter->getName() . '</info>: ' . $type;
             }
         }
         $definitions = array_keys($definition->getDefinitions());
         foreach ($definitions as $key => $binding) {
             $definitions[$key] = is_string($binding) ? $key + 1 . '. <comment>' . $binding . '</comment>' : null;
         }
         $rows[] = ['definition' => '<comment>' . get_class($definition) . '</comment>', 'options' => implode(PHP_EOL, $parameters), 'bindings' => implode(PHP_EOL, $definitions)];
         $rows[] = new TableSeparator();
     }
     $this->output->table(['Definition', 'Options', 'Bindings'], array_slice($rows, 0, -1));
 }
Exemple #3
0
 /**
  * Modify something in the configuration.
  *
  * @param string|array $configuration
  * @param null         $value
  */
 public function configure($configuration, $value = null)
 {
     if ($value && is_string($configuration)) {
         $configuration = [$configuration => $value];
     }
     // Merge stuff manually cause PHP is bad at it
     foreach ($this->configuration->toArray() as $key => $value) {
         $current = array_get($configuration, $key);
         if (is_array($value)) {
             $current = $current ?: [];
             $configuration[$key] = array_merge($value, $current);
         } else {
             $configuration[$key] = $current !== null ? $current : $value;
         }
     }
     $this->configuration = new Configuration($configuration);
 }
 /**
  * @param string $path
  *
  * @return string
  */
 protected function formatPath($path)
 {
     $rootPath = $this->configuration->getRootPath();
     $path = str_replace($rootPath, null, $path);
     return $path;
 }