public function __construct(ConfigInterface $config, $xsdUrl)
 {
     $this->url = $xsdUrl;
     // Generate a stream context used by libxml to access external resources.
     // This will allow DOMDocument to load XSDs through a proxy.
     $streamContextFactory = new StreamContextFactory();
     libxml_set_streams_context($streamContextFactory->create($config));
     $document = new DOMDocument();
     $loaded = $document->load($xsdUrl);
     if (!$loaded) {
         throw new Exception('Unable to load XML from ' . $xsdUrl);
     }
     parent::__construct($document, $document->documentElement);
     // Register the schema to avoid cyclic imports.
     self::$loadedUrls[] = $xsdUrl;
     // Locate and instantiate schemas which are referenced by the current schema.
     // A reference in this context can either be
     // - an import from another namespace: http://www.w3.org/TR/xmlschema-1/#composition-schemaImport
     // - an include within the same namespace: http://www.w3.org/TR/xmlschema-1/#compound-schema
     $this->referereces = array();
     foreach ($this->xpath('//wsdl:import/@location|' . '//s:import/@schemaLocation|' . '//s:include/@schemaLocation') as $reference) {
         $referenceUrl = $reference->value;
         if (strpos($referenceUrl, '//') === false) {
             $referenceUrl = dirname($xsdUrl) . '/' . $referenceUrl;
         }
         if (!in_array($referenceUrl, self::$loadedUrls)) {
             $this->referereces[] = new SchemaDocument($config, $referenceUrl);
         }
     }
 }
 /**
  * Test that authentication and proxy configuration are both reflected in stream context.
  */
 public function testAuthorizationHeaderAndProxyShouldBeDefined()
 {
     $soapOptions = array('login' => 'user', 'password' => 'secret');
     $proxy = array('host' => '192.168.0.1', 'port' => 8080, 'login' => 'proxy-user', 'password' => 'proxy-secret');
     $config = new Config(array('inputFile' => null, 'outputDir' => null, 'soapClientOptions' => $soapOptions, 'proxy' => $proxy));
     $factory = new StreamContextFactory();
     $resource = $factory->create($config);
     $options = stream_context_get_options($resource);
     $this->assertArrayHasKey('http', $options);
     $this->assertArrayHasKey('proxy', $options['http']);
     $this->assertArrayHasKey('header', $options['http']);
     $header = 'Authorization: Basic ' . base64_encode($soapOptions['login'] . ':' . $soapOptions['password']);
     $this->assertContains($header, $options['http']['header']);
     $header = 'Proxy-Authorization: Basic ' . base64_encode($proxy['login'] . ':' . $proxy['password']);
     $this->assertContains($header, $options['http']['header']);
 }
 /**
  * Test that proxy configuration is reflected in stream context.
  */
 public function testProxyStreamContext()
 {
     $proxy = array('host' => '192.168.0.1', 'port' => 8080, 'login' => 'user', 'password' => 'secret');
     $config = new Config(array('inputFile' => null, 'outputDir' => null, 'proxy' => $proxy));
     $streamContextFactory = new StreamContextFactory();
     $resource = $streamContextFactory->create($config);
     $options = stream_context_get_options($resource);
     $this->assertArrayHasKey('http', $options);
     // The proxy configuration should be reflected in the HTTP proxy option.
     $this->assertArrayHasKey('proxy', $options['http']);
     $this->assertEquals($proxy['host'] . ':' . $proxy['port'], $options['http']['proxy']);
     // Proxy authentication information should be reflected in a HTTP header.
     $this->assertArrayHasKey('header', $options['http']);
     $proxyAuthHeader = 'Proxy-Authorization: Basic ' . base64_encode($proxy['login'] . ':' . $proxy['password']);
     $this->assertContains($proxyAuthHeader, $options['http']['header']);
 }
 /**
  * Test that the stream context options are merged if a proxy configuration is applicable
  */
 public function testStreamContextOptionsAreMerged()
 {
     $soapOptions = array('login' => 'user', 'password' => 'secret');
     $proxy = array('host' => '192.168.0.1', 'port' => 8080, 'login' => 'proxy-user', 'password' => 'proxy-secret');
     $config = new Config(array('inputFile' => null, 'outputDir' => null, 'soapClientOptions' => $soapOptions, 'proxy' => $proxy, 'streamContextOptions' => array('ssl' => array('ciphers' => 'foo'))));
     $factory = new StreamContextFactory();
     $resource = $factory->create($config);
     $options = stream_context_get_options($resource);
     $this->assertArrayHasKey('http', $options);
     $this->assertArrayHasKey('proxy', $options['http']);
     $this->assertArrayHasKey('ssl', $options);
     $this->assertArrayHasKey('ciphers', $options['ssl']);
 }