/** * Checks if a given method name identifies a getter method. * * @param string $name A method name * * @return bool True, if the method name identifies a getter method, false otherwise */ protected function isGetterName($name) { return ckString::startsWith($name, 'get') && strlen($name) > 3; }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $app = $arguments['application']; $env = $options['environment']; $dbg = $options['debug']; $file = $arguments['name']; $url = $arguments['url']; $url = ckString::endsWith($url, '/') ? $url : $url . '/'; $controller_name = $file . '.php'; $controller_path = sprintf('%s/%s', sfConfig::get('sf_web_dir'), $controller_name); $this->getFilesystem()->remove($controller_path); $this->getFilesystem()->copy(sfConfig::get('sf_symfony_lib_dir') . self::CONTROLLER_TEMPLATE_PATH, $controller_path); $this->getFilesystem()->replaceTokens($controller_path, '##', '##', array('APP_NAME' => $app, 'ENVIRONMENT' => $env, 'IS_DEBUG' => $dbg ? 'true' : 'false')); $finder = sfFinder::type('directory')->name('*')->relative()->maxdepth(0); $gen = new ckWsdlGenerator($file, $url, $url . $controller_name); $gen->setCheckEnablement(true); foreach ($finder->in(sfConfig::get('sf_app_module_dir')) as $module_dir) { // proposed by Nicolas Martin to avoid problems with 'inited' modules if (!preg_match('/class(.*)Actions(.*)extends(.*)auto/', file_get_contents(sfConfig::get('sf_app_module_dir') . '/' . $module_dir . '/actions/actions.class.php')) && file_exists(sfConfig::get('sf_app_module_dir') . '/' . $module_dir . '/actions/actions.class.php')) { require_once sfConfig::get('sf_app_module_dir') . '/' . $module_dir . '/actions/actions.class.php'; $class = new ReflectionClass($module_dir . 'Actions'); $module_config = sfConfig::get('sf_app_module_dir') . '/' . $module_dir . '/config/module.yml'; $this->getFilesystem()->mkdirs(dirname($module_config)); if (!file_exists($module_config)) { $this->getFilesystem()->touch($module_config); } $yml = sfYaml::load($module_config); if (!isset($yml[$env]) || !is_array($yml[$env])) { $yml[$env] = array(); } foreach ($class->getMethods() as $method) { $name = $method->getName(); if (ckString::startsWith($name, 'execute') && strlen($name) > 7) { $action = ckString::lcfirst(substr($name, 7)); $name = $module_dir . '_' . $action; if (!$gen->addMethod($name, $method)) { $yml[$env][$action] = array('enable' => false); continue; } $yml[$env][$action] = array('enable' => true, 'parameter' => array(), 'result' => null, 'render' => false); foreach (ckDocBlockParser::parseParameters($method->getDocComment()) as $param) { $yml[$env][$action]['parameter'][] = $param['name']; } } } // only save if we added something to the configuration if (!empty($yml[$env])) { file_put_contents($module_config, sfYaml::dump($yml)); } } } $file = sprintf('%s/%s.wsdl', sfConfig::get('sf_web_dir'), $file); $gen->save($file); $this->logSection('file+', $file); }
/** * Checks if the given class name identifies a ckGenericObjectAdapter implementation. * * @param string $class The class name to check * * @return bool True, if the given class name identifies a ckGenericObjectAdapter implementation, false otherwise */ protected function isGenericObjectAdapter($class) { return ckString::startsWith($class, self::$CLASS . '_'); }
/** * Gets an array with property definitions for all ends of *-to-many relations. * * @return array An array with property definitions */ protected function getToManyProperties() { $properties = array(); foreach ($this->getClass()->getMethods() as $method) { if (ckString::startsWith($method->getName(), 'init')) { $refClass = substr($method->getName(), 4, -1); if ($this->isToManyProperty($refClass)) { $properties[] = array('name' => $refClass . 's', 'type' => $refClass . '[]'); } } } return $properties; }
protected function getModuleAndAction(ReflectionMethod $method) { $class = $method->getDeclaringClass()->getName(); $method = $method->getName(); if (!ckString::endsWith($class, 'Actions') || !ckString::startsWith($method, 'execute') || strlen($method) <= 7) { throw new InvalidArgumentException(); } return array('module' => substr($class, 0, -7), 'action' => ckString::lcfirst(substr($method, 7))); }