Exemplo n.º 1
0
 public function testWriteCacheFile()
 {
     $expected = 'This is a config cache test.';
     $config = AgaviConfig::get('core.config_dir') . DIRECTORY_SEPARATOR . 'foo.xml';
     $cacheName = AgaviConfigCache::getCacheName($config);
     if (file_exists($cacheName)) {
         unlink($cacheName);
     }
     AgaviConfigCache::writeCacheFile($config, $cacheName, $expected);
     $this->assertFileExists($cacheName);
     $content = file_get_contents($cacheName);
     $this->assertEquals($expected, $content);
     $append = "\nAnd a second line appended.";
     AgaviConfigCache::writeCacheFile($config, $cacheName, $append, true);
     $content = file_get_contents($cacheName);
     $this->assertEquals($expected . $append, $content);
 }
Exemplo n.º 2
0
 /**
  * Do any necessary startup work after initialization.
  *
  * This method is not called directly after initialize().
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function startup()
 {
     parent::startup();
     // user-supplied "wsdl" and "options" parameters
     $wsdl = $this->getParameter('wsdl');
     if (!$wsdl) {
         // no wsdl was specified, that means we generate one from the annotations in routing.xml
         $wsdl = $this->context->getRouting()->getWsdlPath();
     }
     $this->setParameter('wsdl', $wsdl);
     // get the name of the class to use for the client, defaults to PHP's own "SoapClient"
     $soapClientClass = $this->getParameter('soap_client_class', 'SoapClient');
     $soapClientOptions = $this->getParameter('soap_client_options', array());
     // get the name of the class to use for the server, defaults to PHP's own "SoapServer"
     $soapServerClass = $this->getParameter('soap_server_class', 'SoapServer');
     $soapServerOptions = $this->getParameter('soap_server_options', array());
     // get the name of the class to use for handling soap calls, defaults to Agavi's "AgaviSoapControllerCallHandler"
     $soapHandlerClass = $this->getParameter('soap_handler_class', 'AgaviSoapControllerCallHandler');
     // force client's soap version to be the same as the server's
     if (isset($soapServerOptions['soap_version'])) {
         $soapClientOptions['soap_version'] = $soapServerOptions['soap_version'];
     }
     // force client's cache_wsdl setting to be the same as the server's
     if (isset($soapServerOptions['cache_wsdl'])) {
         // and cast it to an int
         $soapServerOptions['cache_wsdl'] = (int) $soapServerOptions['cache_wsdl'];
         $soapClientOptions['cache_wsdl'] = $soapServerOptions['cache_wsdl'];
     }
     if (isset($soapServerOptions['features'])) {
         // cast this to an int
         $soapServerOptions['features'] = (int) $soapServerOptions['features'];
     }
     // create a client, so we can grab the functions and types defined in the wsdl (not possible from the server, duh)
     $this->soapClient = new $soapClientClass($wsdl, $soapClientOptions);
     if ($this->getParameter('auto_classmap')) {
         // we have to create a classmap automatically.
         // to do that, we read the defined types, and set identical values for type and class name.
         $classmap = array();
         // with an optional prefix, of course.
         $prefix = $this->getParameter('auto_classmap_prefix', '');
         foreach ($this->soapClient->__getTypes() as $definition) {
             if (preg_match('/^struct (\\S+) \\{$/m', $definition, $matches)) {
                 $classmap[$matches[1]] = $prefix . $matches[1];
             }
         }
         if (isset($soapServerOptions['classmap'])) {
             $classmap = array_merge((array) $classmap, $soapServerOptions['classmap']);
         }
         $soapServerOptions['classmap'] = $classmap;
     }
     // create a server
     $this->soapServer = new $soapServerClass($wsdl, $soapServerOptions);
     $newSoapHandlerClass = $soapHandlerClass . 'WithAutoHeaders';
     // build the special extension class to the handler that contains methods for each of the headers
     if ($this->getParameter('auto_headers', true)) {
         // the cache filename we'll be using
         $cache = AgaviConfigCache::getCacheName($soapHandlerClass, $this->context->getName());
         if (AgaviConfigCache::isModified($wsdl, $cache)) {
             $doc = new DOMDocument();
             $doc->load($wsdl);
             $xpath = new DOMXPath($doc);
             $xpath->registerNamespace('soap', 'http://schemas.xmlsoap.org/wsdl/soap/');
             $code = array();
             $code[] = '<?php';
             $code[] = sprintf('class %s extends %s {', $newSoapHandlerClass, $soapHandlerClass);
             $code[] = '  protected $rd;';
             $code[] = '  public function __construct(AgaviContext $context) {';
             $code[] = '    parent::__construct($context);';
             $code[] = '    $this->rd = $this->context->getRequest()->getRequestData();';
             $code[] = '  }';
             $headers = array();
             foreach ($xpath->query('//soap:header') as $header) {
                 $name = $header->getAttribute('part');
                 if (in_array($name, $headers)) {
                     continue;
                 }
                 $headers[] = $name;
                 $code[] = sprintf('  public function %s($value) {', $name);
                 $code[] = sprintf('    $this->rd->setHeader(%s, $value);', var_export($name, true));
                 $code[] = '  }';
             }
             $code[] = '}';
             $code[] = '?>';
             $code = implode("\n", $code);
             AgaviConfigCache::writeCacheFile($soapHandlerClass, $cache, $code);
         }
         include $cache;
     }
     // give it a class that handles method calls
     // that class uses __call
     // the class ctor gets the context as the first argument
     $this->soapServer->setClass($newSoapHandlerClass, $this->context);
 }
Exemplo n.º 3
0
 /**
  * Runs AgaviToolkit::expandDirectives() on all attributes and text nodes of
  * the given file and writes a it to a new file in the Agavi cache directory.
  *
  * @param      string The path to the xml file
  * 
  * @return     string The path to the expanded file
  *
  * @author     Dominik del Bondio <*****@*****.**>
  * @since      1.1.0
  */
 private static function expandConfiguration($file)
 {
     // file does not exist, let PHPUnit handle that case
     if (!is_readable($file) || !is_file($file)) {
         return $file;
     }
     $doc = new DOMDocument();
     $doc->substituteEntities = true;
     $doc->load($file);
     $xpath = new DOMXPath($doc);
     $attributeNodes = $xpath->query('//@*');
     foreach ($attributeNodes as $attributeNode) {
         $attributeNode->value = AgaviToolkit::expandDirectives($attributeNode->value);
     }
     $textNodes = $xpath->query('//text()');
     foreach ($textNodes as $textNode) {
         $textNode->nodeValue = AgaviToolkit::expandDirectives($textNode->nodeValue);
     }
     $translatedFile = AgaviConfigCache::getCacheName($file);
     AgaviConfigCache::writeCacheFile($file, $translatedFile, $doc->saveXML());
     return $translatedFile;
 }