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 }
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); })]; }
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)); }