コード例 #1
0
 public function interact(QuestionsSet $questions)
 {
     $questions->communicate('sf_bundle_name', Question::ask('Bundle name', function (array $configuration) {
         $bundleName = strtr($configuration['namespace'], ['\\Bundle\\' => '', '\\' => '']);
         $bundleName .= substr($bundleName, -6) === 'Bundle' ? '' : 'Bundle';
         return $bundleName;
     }, function ($bundle) {
         if (!preg_match('/^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$/', $bundle)) {
             throw new \InvalidArgumentException(sprintf('The bundle name %s contains invalid characters.', $bundle));
         }
         if (!preg_match('/Bundle$/', $bundle)) {
             throw new \InvalidArgumentException('The bundle name must end with Bundle.');
         }
         return $bundle;
     }));
     $questions->communicate('sf_extension_name', Question::ask('Bundle Extension name', function (array $configuration) {
         return substr($configuration['sf_bundle_name'], 0, -6);
     })->markOptional());
     $questions->communicate('sf_extension_alias', Question::ask('Bundle Extension alias', function (array $configuration) {
         return StringUtil::underscore(substr($configuration['sf_bundle_name'], 0, -6));
     })->markOptional());
     $questions->communicate('sf_bundle_config_format', Question::choice('Configuration format', ['yml', 'xml'], 1));
     // XXX Add confirm for: routing (format), Configuration class, service file location (allow null)
     // type of the bundle (http-kernel of framework), full structure (form, controller)
     // separate generator
 }
コード例 #2
0
 public function getFunctions()
 {
     return [new ExpressionFunction('substr', function ($str, $start, $length = null) {
         return sprintf('substr(%s, %d, %d)', $str, $start, $length);
     }, function (array $values, $str, $start, $length = null) {
         return is_int($length) ? substr($str, $start, $length) : substr($str, $start);
     }), new ExpressionFunction('strpos', function ($haystack, $needle, $offset = 0) {
         return sprintf('strpos(%s, %s, %d)', $haystack, $needle, $offset);
     }, function (array $values, $haystack, $needle, $offset = 0) {
         return strpos($haystack, $needle, $offset);
     }), new ExpressionFunction('strrpos', function ($haystack, $needle, $offset = 0) {
         return sprintf('strrpos(%s, %s, %d)', $haystack, $needle, $offset);
     }, function (array $values, $haystack, $needle, $offset = 0) {
         return strrpos($haystack, $needle, $offset);
     }), new ExpressionFunction('ucfirst', function ($str) {
         return sprintf('ucfirst(%s)', $str);
     }, function (array $values, $str) {
         return ucfirst($str);
     }), new ExpressionFunction('lowercase', function ($str) {
         return sprintf('strtolower(%s)', $str);
     }, function (array $values, $str) {
         return strtolower($str);
     }), new ExpressionFunction('uppercase', function ($str) {
         return sprintf('strtoupper(%s)', $str);
     }, function (array $values, $str) {
         return strtoupper($str);
     }), new ExpressionFunction('replace', function ($search, $replace, $subject) {
         return sprintf('str_replace(%s, %s, %s)', $search, $replace, $subject);
     }, function (array $values, $search, $replace, $subject) {
         return str_replace($search, $replace, $subject);
     }), new ExpressionFunction('preg_replace', function ($search, $replace, $subject) {
         return sprintf('preg_replace(%s, %s, %s)', $search, $replace, $subject);
     }, function (array $values, $search, $replace, $subject) {
         return preg_replace($search, $replace, $subject);
     }), new ExpressionFunction('underscore', function ($input) {
         return sprintf('\\Rollerworks\\Tools\\SkeletonDancer\\StringUtil::underscore(%s)', $input);
     }, function (array $values, $input) {
         return StringUtil::underscore($input);
     }), new ExpressionFunction('camelize', function ($input) {
         return sprintf('\\Rollerworks\\Tools\\SkeletonDancer\\StringUtil::camelize(%s)', $input);
     }, function (array $values, $input) {
         return StringUtil::camelize($input);
     }), new ExpressionFunction('humanize', function ($input) {
         return sprintf('\\Rollerworks\\Tools\\SkeletonDancer\\StringUtil::humanize(%s)', $input);
     }, function (array $values, $input) {
         return StringUtil::humanize($input);
     }), new ExpressionFunction('vendor_namespace', function ($input) {
         return sprintf('\\Rollerworks\\Tools\\SkeletonDancer\\StringUtil::vendorNamespace(%s)', $input);
     }, function (array $values, $input) {
         return StringUtil::vendorNamespace($input);
     }), new ExpressionFunction('nth_dirname', function ($path, $index = 0, $default = '') {
         return sprintf('\\Rollerworks\\Tools\\SkeletonDancer\\StringUtil::getNthDirname(%s, $d, $s)', $path, $index, $default);
     }, function (array $values, $path, $index = 0, $default = '') {
         return StringUtil::getNthDirname($path, $index, $default);
     }), new ExpressionFunction('getenv', function ($key) {
         return sprintf('getenv(%s)', $key);
     }, function (array $values, $path) {
         return getenv($path);
     })];
 }
コード例 #3
0
 public function interact(QuestionsSet $questions)
 {
     $format = $questions->communicate('doc_format', Question::choice('Documentation format', ['rst', 'markdown', 'none']));
     if ('rst' === $format) {
         $questions->communicate('rst_short_name', Question::ask('Short product name', function (array $config) {
             return StringUtil::shortProductName($config['name']);
         }));
     }
 }
コード例 #4
0
 private function resolveArgument(\ReflectionParameter $parameter)
 {
     $name = StringUtil::underscore($parameter->name);
     if ('container' === $name) {
         return $this->container;
     }
     if (isset($this->container[$name])) {
         return $this->container[$name];
     }
     if ($parameter->isOptional()) {
         return $parameter->getDefaultValue();
     }
     throw new \RuntimeException(sprintf('Unable to resolve parameter "%s" of class "%s" no service/parameter found with name "%s". ' . 'Consider adding a default value.', $name, $parameter->getDeclaringClass()->name, $name));
 }
コード例 #5
0
 public function interact(QuestionsSet $questions)
 {
     $questions->communicate('enable_phpunit', Question::confirm('Enable PHPUnit?', true));
     if ($questions->communicate('enable_phpspec', Question::confirm('Enable PHPSpec?', false))) {
         $questions->communicate('phpspec_suite_name', Question::confirm('PHPSpec suite-name', function (array $values) {
             return isset($values['name']) ? StringUtil::shortProductName($values['name']) : null;
         }));
     } else {
         $questions->set('phpspec_shortname', null);
     }
     if ($questions->communicate('enable_behat', Question::confirm('Enable Behat?', false))) {
         $questions->communicate('behat_suite_name', Question::ask('Behat suite-name', function (array $values) {
             return isset($values['name']) ? StringUtil::shortProductName($values['name']) : null;
         }));
     } else {
         $questions->set('behat_shortname', null);
     }
     $questions->communicate('enable_mink', Question::confirm('Enable Mink?', false));
 }
コード例 #6
0
 public function interact(QuestionsSet $questions)
 {
     $questions->communicate('name', Question::ask('Name'));
     $questions->communicate('package_name', Question::ask('Package name (<vendor>/<name>)', function (array $config) {
         if ('' !== (string) $config['name'] && preg_match('/^(?P<vendor>[a-z0-9_.-]+)\\s+(?P<name>[a-z0-9_.-]+)$/i', $config['name'], $regs)) {
             return strtolower(StringUtil::humanize($regs[1]) . '/' . StringUtil::humanize($regs[2]));
         }
     }, function ($name) {
         if (!preg_match('{^[a-z0-9_.-]+/[a-z0-9_.-]+$}', $name)) {
             throw new \InvalidArgumentException('The package name ' . $name . ' is invalid, it should be lowercase and have a vendor name, a forward slash, and a package name, matching: [a-z0-9_.-]+/[a-z0-9_.-]+');
         }
         return $name;
     }));
     $questions->communicate('namespace', Question::ask('PHP Namespace', null, function ($namespace) {
         $namespace = trim(str_replace('/', '\\', $namespace), '\\');
         if (!preg_match('/^(?:[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*\\\\?)+$/', $namespace)) {
             throw new \InvalidArgumentException('The namespace contains invalid characters.');
         }
         // validate reserved keywords
         $reserved = self::getReservedWords();
         foreach (explode('\\', $namespace) as $word) {
             if (in_array(strtolower($word), $reserved, true)) {
                 throw new \InvalidArgumentException(sprintf('The namespace cannot contain PHP reserved words ("%s").', $word));
             }
         }
         return $namespace;
     }));
     $questions->communicate('author_name', Question::ask('Author name', function () {
         return $this->git->getGitConfig('user.name', 'global');
     }));
     $questions->communicate('author_email', Question::ask('Author e-mail', function () {
         return $this->git->getGitConfig('user.email', 'global');
     }));
     $questions->communicate('php_min', Question::ask('Php-min', substr(PHP_VERSION, 0, 3)));
     $questions->communicate('src_dir', Question::ask('PHP source directory', 'src', function ($value) {
         return trim($value, '/');
     })->markOptional('.'));
 }