/**
  * Gets the name of the method.
  *
  * @return string The method name
  */
 public function getName()
 {
     if (ckString::isNullOrEmpty($this->name)) {
         $this->name = $this->invokeCreateMethodNameCallback($this->target);
     }
     return $this->name;
 }
 /**
  * Removes the header suffix from a given string, if it is present.
  *
  * @param string $name A name
  *
  * @return string The name without the header suffix
  *
  * @see HEADER_SUFFIX
  */
 protected function getSoapHeaderName($name)
 {
     $result = $name;
     if (ckString::endsWith($result, self::HEADER_SUFFIX)) {
         $result = substr($result, 0, -strlen(self::HEADER_SUFFIX));
     }
     return $result;
 }
 /**
  * Gets a soap:body element for a given wsdl message.
  *
  * @param DOMDocument   $document A xml document used to create node objects
  * @param ckWsdlMessage $message  A wsdl message
  *
  * @return DOMElement A soap:body element
  */
 private function getSoapBodyNode(DOMDocument $document, ckWsdlMessage $message)
 {
     $soap = ckXsdNamespace::get('soap');
     $soapenc = ckXsdNamespace::get('soapenc');
     $tns = ckXsdNamespace::get('tns');
     $body_node = $document->createElementNS($soap->getUrl(), $soap->qualify('body'));
     $parts = $message->getBodyParts();
     if (!empty($parts)) {
         $body_node->setAttribute('parts', ckString::implode(' ', $parts));
     }
     $body_node->setAttribute('use', 'literal');
     $body_node->setAttribute('namespace', $tns->getUrl());
     $body_node->setAttribute('encodingStyle', $soapenc->getUrl());
     return $body_node;
 }
 /**
  * Checks wether the given type is an array type.
  *
  * @param string $name A type name
  *
  * @return boolean True, if the given type is an array type, false otherwise
  */
 public static function isArrayType($name)
 {
     return ckString::endsWith($name, self::ARRAY_SUFFIX);
 }
 /**
  * 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;
 }
 /**
  * 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());
     }
 }
 /**
  * @see ckDOMSerializable::serialize()
  */
 public function serialize(DOMDocument $document)
 {
     $wsdl = ckXsdNamespace::get('wsdl');
     $tns = ckXsdNamespace::get('tns');
     $node = $document->createElementNS($wsdl->getUrl(), $wsdl->qualify($this->getNodeName()));
     $node->setAttribute('name', $this->getName());
     if (!is_null($this->getInput())) {
         $input_node = $document->createElementNS($wsdl->getUrl(), $wsdl->qualify('input'));
         $input_node->setAttribute('message', $tns->qualify($this->getInput()->getName()));
         $parts = $this->getInput()->getParts();
         if (!empty($parts)) {
             $node->setAttribute('parameterOrder', ckString::implode(' ', $parts));
         }
         $node->appendChild($input_node);
     }
     if (!is_null($this->getOutput())) {
         $output_node = $document->createElementNS($wsdl->getUrl(), $wsdl->qualify('output'));
         $output_node->setAttribute('message', $tns->qualify($this->getOutput()->getName()));
         $node->appendChild($output_node);
     }
     return $node;
 }
 /**
  * @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 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;
 }
 /**
  * Normalizes a given namespace uri, this means adding a slash at end if none is present.
  *
  * @param string $namespace A namespace uri
  *
  * @return string The normalized namespace uri
  */
 private function normalizeNamespaceUri($namespace)
 {
     return !ckString::endsWith($namespace, '/') ? $namespace . '/' : $namespace;
 }
 /**
  * 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 . '_');
 }
 /**
  * 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));
 }
 /**
  * (non-PHPdoc)
  * @see vendor/addendum/Annotation#checkConstraints()
  */
 protected function checkConstraints($target)
 {
     if (ckString::isNullOrEmpty($this->name) || ckString::isNullOrEmpty($this->type)) {
         throw new InvalidArgumentException();
     }
 }
 protected function isPluginActive($plugin)
 {
     foreach ($this->configuration->getPluginPaths() as $plugin_path) {
         if (ckString::endsWith($plugin_path, $plugin)) {
             return true;
         }
     }
     return false;
 }