function it_renders_a_configuration(Configuration $configuration, Section $section)
 {
     $configuration->getSections()->willReturn([$section]);
     $section->getName()->willReturn('section');
     $section->getProperties()->willReturn(['key1' => 'value', 'key2' => true, 'key3' => ['val1', 'val2', 'val3']]);
     $this->render($configuration)->shouldReturn("[section]\nkey1 = value\nkey2 = true\nkey3 = val1,val2,val3\n\n");
 }
 /**
  * Renders a configuration
  *
  * @param Configuration $configuration
  *
  * @return string
  */
 public function render(Configuration $configuration)
 {
     $output = '';
     foreach ($configuration->getSections() as $name => $section) {
         $output .= $this->renderSection($section);
     }
     return $output;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function parse(Configuration $configuration = null)
 {
     if (is_null($configuration)) {
         $configuration = new Configuration();
     }
     // Suppress error to handle it
     if (!($ini = @parse_ini_string($this->text, true, INI_SCANNER_RAW))) {
         throw new ParsingFailed('Given data cannot be parsed as INI string');
     }
     $sections = $this->parseArray($ini);
     $configuration->addSections($sections);
     return $configuration;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function parse(Configuration $configuration = null)
 {
     if (!is_file($this->file)) {
         throw new ParsingFailed(sprintf('File "%s" not found', $this->file));
     }
     if (is_null($configuration)) {
         $configuration = new Configuration();
     }
     // Suppress error to handle it
     if (!($ini = @parse_ini_file($this->file, true, INI_SCANNER_RAW))) {
         throw new ParsingFailed(sprintf('File "%s" cannot be parsed as INI', $this->file));
     }
     $sections = $this->parseArray($ini);
     $configuration->addSections($sections);
     return $configuration;
 }
 public function indexAction()
 {
     $request = $this->getRequest();
     /* @var $request \Zend\Console\Request */
     $path = $request->getParam('path', getcwd() . '/supervisord.conf');
     if (substr($path, 0, 1) != '/') {
         $path = getcwd() . '/' . $path;
     }
     // @todo: do not parse config, but use the plugin managers instead, see: getRegisteredServices()
     $config = $this->getServiceLocator()->get('Config');
     $moduleConfig = $config['humus_amqp_module'];
     $supervisordConfig = $config['humus_supervisor_module']['humus-amqp-supervisor']['supervisord'];
     $consumerTypes = array('consumers', 'rpc_servers');
     $config = new Configuration();
     $section = new SupervisordSection($supervisordConfig['config']);
     $config->addSection($section);
     $section = new RpcInterfaceSection('supervisor', $supervisordConfig['rpcinterface']);
     $config->addSection($section);
     $section = new SupervisorctlSection($supervisordConfig['supervisorctl']);
     $config->addSection($section);
     $section = new UnixHttpServerSection($supervisordConfig['unix_http_server']);
     $config->addSection($section);
     $section = new InetHttpServerSection($supervisordConfig['inet_http_server']);
     $config->addSection($section);
     foreach ($consumerTypes as $consumerType) {
         $partConfig = $moduleConfig[$consumerType];
         // no config found, check next one
         if (empty($partConfig)) {
             continue;
         }
         foreach ($partConfig as $name => $part) {
             $section = new ProgramSection($name, array('process_name' => '%(program_name)s_%(host_node_name)s_%(process_num)02d', 'directory' => getcwd(), 'autostart' => true, 'autorestart' => true, 'numprocs' => 1, 'command' => 'php public/index.php humus amqp ' . str_replace('_', '-', strtolower(substr($consumerType, 0, -1))) . ' ' . $name));
             if (isset($part['supervisord']) && is_array($part['supervisord'])) {
                 $options = array_merge($section->getOptions(), $part['supervisord']);
                 $section->setOptions($options);
             }
             $config->addSection($section);
         }
     }
     ErrorHandler::start();
     $rs = file_put_contents($path, $config->render());
     $error = ErrorHandler::stop();
     if (false === $rs || $error) {
         $this->getConsole()->writeLine('ERROR: Cannot write configuration to ' . $path, ColorInterface::RED);
         return null;
     }
     $this->getConsole()->writeLine('OK: configuration written to ' . $path, ColorInterface::GREEN);
     return null;
 }
 function it_parses_configuration(Flysystem $filesystem, Configuration $configuration)
 {
     $configuration->addSections(Argument::type('array'))->shouldBeCalled();
     $filesystem->read(Argument::type('string'))->willReturn("[supervisord]\nidentifier = supervisor");
     $this->parse($configuration);
 }
 function it_parses_configuration(Configuration $configuration)
 {
     $configuration->addSections(Argument::type('array'))->shouldBeCalled();
     $this->parse($configuration);
 }