/**
  * Invokes an action requested by a webservice call and returns the action result.
  *
  * @param string $moduleName A module name
  * @param string $actionName An action name
  * @param array  $parameters The paramters to pass to the action
  *
  * @throws SoapFault thrown if any exception is thrown during the action call.
  *
  * @return mixed The result of the called action
  */
 public function invokeSoapEnabledAction($moduleName, $actionName, $parameters)
 {
     $moduleName = ckString::lcfirst($moduleName);
     $actionName = ckString::lcfirst($actionName);
     $request = $this->context->getRequest();
     $request->setParameter('param', $parameters, 'ckWebServicePlugin');
     try {
         if (sfConfig::get('sf_logging_enabled')) {
             $this->context->getLogger()->info(sprintf('{%s} Forwarding to \'%s/%s\'.', __CLASS__, $moduleName, $actionName));
         }
         // use forward to invoke the action, so we have to pass the filter chain
         $this->forward($moduleName, $actionName);
         // get the function which retrieves the action result
         $soapResultCallback = sfConfig::get('app_ck_web_service_plugin_result_callback', 'getSoapResult');
         // get the last executed action
         $actionInstance = $this->getActionStack()->getLastEntry()->getActionInstance();
         // if we have been redirected to the 404 module, we raise an exception
         if ($actionInstance->getModuleName() == sfConfig::get('sf_error_404_module') && $actionInstance->getActionName() == sfConfig::get('sf_error_404_action')) {
             throw new sfError404Exception(sprintf('{%s} SoapFunction \'%s_%s\' not found.', __CLASS__, $moduleName, $actionName));
         }
         // check if we are able to call a custom result getter
         if (!method_exists($actionInstance, $soapResultCallback)) {
             $soapResultCallback = self::DEFAULT_RESULT_CALLBACK;
             if (sfConfig::get('sf_logging_enabled')) {
                 $this->context->getLogger()->info(sprintf('{%s} Start listening to \'component.method_not_found event\'.', __CLASS__, $soapResultCallback));
             }
             // listen to the component.method_not_found event
             $this->dispatcher->connect('component.method_not_found', array($this, 'listenToComponentMethodNotFoundEvent'));
         }
         if (sfConfig::get('sf_logging_enabled')) {
             $this->context->getLogger()->info(sprintf('{%s} Calling soapResultCallback \'%s\'.', __CLASS__, $soapResultCallback));
         }
         // return the result of our action
         return $actionInstance->{$soapResultCallback}();
     } catch (Exception $e) {
         // we return all exceptions as soap faults to the remote caller
         if ($e instanceof SoapFault) {
             throw $e;
         }
         throw new SoapFault('Server', $e->getMessage(), '', $e->getTraceAsString());
     }
 }
 /**
  * Gets the property name for a given getter or setter method name.
  *
  * @param string $name A getter or setter method name
  *
  * @return string The property name
  */
 protected function getPropertyName($name)
 {
     if (ckString::startsWith($name, 'get') || ckString::startsWith($name, 'set')) {
         return ckString::lcfirst(substr($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);
 }
 /**
  * Gets an array with property definitions for all simple properties, this means they are stored in a column.
  *
  * @return array An array with property definitions
  */
 protected function getSimpleProperties()
 {
     $properties = array();
     foreach ($this->getTableMap()->getColumns() as $column) {
         if (!$column->isForeignKey()) {
             $properties[] = array('name' => ckString::lcfirst($column->getPhpName()), 'type' => $this->getPhpTypeForPropelType($column->getType()));
         }
     }
     return $properties;
 }
 /**
  * Invokes an action requested by a webservice call and returns the action result.
  *
  * @param string $moduleName A module name
  * @param string $actionName An action name
  * @param array  $parameters The paramters to pass to the action
  *
  * @throws SoapFault thrown if any exception is thrown during the action call.
  *
  * @return mixed The result of the called action
  */
 public function invokeSoapEnabledAction($moduleName, $actionName, $parameters)
 {
     $moduleName = ckString::lcfirst($moduleName);
     $actionName = ckString::lcfirst($actionName);
     $request = $this->context->getRequest();
     $request->setRequestFormat('soap');
     $request->setParameter(ckSoapParameterFilter::PARAMETER_KEY, $parameters);
     try {
         if (sfConfig::get('sf_logging_enabled')) {
             $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Forwarding to "%s/%s".', $moduleName, $actionName))));
         }
         try {
             // use forward to invoke the action, so we have to pass the filter chain
             $this->forward($moduleName, $actionName);
         } catch (sfStopException $e) {
         }
         // get the last executed action
         $actionInstance = $this->getActionStack()->getLastEntry()->getActionInstance();
         // if we have been redirected to the 404 module, we raise an exception
         if ($actionInstance->getModuleName() == sfConfig::get('sf_error_404_module') && $actionInstance->getActionName() == sfConfig::get('sf_error_404_action')) {
             throw new sfError404Exception(sprintf('{%s} SoapFunction "%s_%s" not found.', __CLASS__, $moduleName, $actionName));
         }
         return $this->getResultAdapter()->getResult($actionInstance);
     } catch (SoapFault $e) {
         // soap fault with custom fault codes thrown in the actions will be left untouched
         throw $e;
     } catch (Exception $e) {
         // we return all other exceptions as soap faults to the remote caller
         throw $this->getSoapFaultFromException($e);
     }
 }
 protected function getPropertyName($fieldname)
 {
     return ckString::lcfirst(Doctrine_Inflector::classify($fieldname));
 }
 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)));
 }