/**
  * @param string $type
  * @param Config $config
  * @param Client $client
  *
  * @return AbstractConnectorCommand
  * @throws ConfigurationException
  */
 public function create($type, Config $config, Client $client)
 {
     $class = sprintf('NMR\\Connector\\%sConnector', ucfirst($type));
     if (!class_exists($class)) {
         throw new ConfigurationException(sprintf('Invalid Connector "%s".', $type));
     }
     $reflectionClass = new ReflectionClass($class);
     $constructorParameters = $reflectionClass->getConstructor()->getParameters();
     $parameters = [];
     /** @var ReflectionParameter $constructorParameter */
     foreach ($constructorParameters as $constructorParameter) {
         $name = $constructorParameter->getName();
         $configName = sprintf('twgit.connectors.%s.%s', $type, TextUtil::convertCamelCaseToSeparator($name));
         $parameters[] = $config->get($configName, '');
     }
     $instance = $reflectionClass->newInstanceArgs($parameters);
     $instance->setClient($client);
     return $instance;
 }
Example #2
0
 /**
  * @param Config $config
  * @param Git    $git
  * @param Shell  $shell
  * @param Logger $logger
  *
  * @throws ConfigurationException
  */
 protected function initWorkflow()
 {
     $classname = sprintf('NMR\\Workflow\\%sWorkflow', str_replace('Command', '', TextUtil::getNamespaceShortName($this)));
     $this->workflow = (new $classname($this->config))->setGit($this->git)->setShell($this->shell)->setLogger($this->logger);
     $type = $this->config->get('twgit.connectors.enabled');
     if (!empty($type)) {
         $connectorFactory = new ConnectorFactory();
         $connector = $connectorFactory->create($type, $this->getConfig(), $this->getClient());
         $this->workflow->setConnector($connector);
     }
 }
 /**
  * @param string $branch
  *
  * @return string
  */
 protected function getFeatureSubject($branch)
 {
     $subject = "";
     $branch = str_replace(sprintf('%s/', $this->origin), '', $branch);
     $issue = $this->cleanPrefix($branch, self::FEATURE);
     if (file_exists($this->getFeaturesSubjectPath())) {
         $content = explode("\n", file_get_contents($this->getFeaturesSubjectPath()));
         foreach ($content as $info) {
             $logIssue = substr($info, 0, strpos($info, ';'));
             $logTitle = TextUtil::sanitize(substr($info, strpos($info, ';') + 1));
             if ($logIssue === $issue) {
                 return $logTitle;
             }
         }
     }
     if (empty($subject) && $this->getConnector()) {
         $subject = TextUtil::sanitize($this->getConnector()->getIssueTitle($issue));
         file_put_contents($this->getFeaturesSubjectPath(), sprintf('%s;%s', $issue, $subject) . "\n", FILE_APPEND);
     }
     return $subject;
 }