/**
  * Constructor
  *
  * @param   string endpoint default 'http://api.google.com/search/beta2'
  */
 public function __construct($endpoint = 'http://api.google.com/search/beta2')
 {
     $this->client = SoapDriver::getInstance()->forEndpoint($endpoint, 'urn:GoogleSearch');
     $this->client->registerMapping(new QName('urn:GoogleSearch', 'GoogleSearchResult'), XPClass::forName('com.google.soap.search.GoogleSearchResult'));
     $this->client->registerMapping(new QName('urn:GoogleSearch', 'ResultElement'), XPClass::forName('com.google.soap.search.ResultElement'));
     $this->client->registerMapping(new QName('urn:GoogleSearch', 'DirectoryCategory'), XPClass::forName('com.google.soap.search.DirectoryCategory'));
 }
 /**
  * Matches implementation
  * 
  * @param   var value
  * @return  bool
  */
 public function matches($value)
 {
     if (NULL === $value && $this->matchNull) {
         return TRUE;
     }
     return xp::typeof($value) == XPClass::forName($this->type)->getName();
 }
 /**
  * Constructor
  *
  * @param   rdbms.DSN dsn
  */
 public function __construct($dsn)
 {
     $this->dsn = $dsn;
     $this->flags = $dsn->getFlags();
     $this->setTimeout($dsn->getProperty('timeout', 0));
     // 0 means no timeout
     // Keep this for BC reasons
     $observers = $dsn->getProperty('observer', array());
     if (NULL !== ($cat = $dsn->getProperty('log'))) {
         $observers['util.log.LogObserver'] = $cat;
     }
     // Add observers
     foreach ($observers as $observer => $param) {
         $class = XPClass::forName($observer);
         // Check if class implements BoundLogObserver: in that case use factory method to acquire instance
         if (XPClass::forName('util.log.BoundLogObserver')->isAssignableFrom($class)) {
             $this->addObserver($class->getMethod('instanceFor')->invoke(NULL, array($param)));
             // Otherwise, just use the constructor
         } else {
             $this->addObserver($class->newInstance($param));
         }
     }
     // Time zone handling
     if ($tz = $dsn->getProperty('timezone', FALSE)) {
         $this->tz = new TimeZone($tz);
     }
 }
예제 #4
0
 /**
  * Main
  *
  * Exitcodes used:
  * <ul>
  *   <li>127: Archive referenced in -xar [...] does not exist</li>
  *   <li>126: No manifest or manifest does not have a main-class</li>
  * </ul>
  *
  * @see     http://tldp.org/LDP/abs/html/exitcodes.html
  * @param   string[] args
  * @return  int
  */
 public static function main(array $args)
 {
     // Open archive
     $f = new File(array_shift($args));
     if (!$f->exists()) {
         Console::$err->writeLine('*** Cannot find archive ' . $f->getURI());
         return 127;
     }
     // Register class loader
     $cl = ClassLoader::registerLoader(new ArchiveClassLoader(new Archive($f)));
     if (!$cl->providesResource(self::MANIFEST)) {
         Console::$err->writeLine('*** Archive ' . $f->getURI() . ' does not have a manifest');
         return 126;
     }
     // Load manifest
     $pr = Properties::fromString($cl->getResource(self::MANIFEST));
     if (NULL === ($class = $pr->readString('archive', 'main-class', NULL))) {
         Console::$err->writeLine('*** Archive ' . $f->getURI() . '\'s manifest does not have a main class');
         return 126;
     }
     // Run main()
     try {
         return XPClass::forName($class, $cl)->getMethod('main')->invoke(NULL, array($args));
     } catch (TargetInvocationException $e) {
         throw $e->getCause();
     }
 }
예제 #5
0
 /**
  * Get a type instance for a given name
  *
  * @param   string name
  * @return  lang.ArrayType
  * @throws  lang.IllegalArgumentException if the given name does not correspond to a wildcard type
  */
 public static function forName($name)
 {
     if (false === strpos($name, '?') || false === ($p = strpos($name, '<'))) {
         throw new IllegalArgumentException('Not a wildcard type: ' . $name);
     }
     $base = substr($name, 0, $p);
     $components = [];
     for ($args = substr($name, $p + 1, -1) . ',', $o = 0, $brackets = 0, $i = 0, $s = strlen($args); $i < $s; $i++) {
         if (',' === $args[$i] && 0 === $brackets) {
             $component = ltrim(substr($args, $o, $i - $o));
             if ('?' === $component) {
                 $components[] = Wildcard::$ANY;
             } else {
                 if (false === strpos($component, '?')) {
                     $components[] = parent::forName($component);
                 } else {
                     $components[] = self::forName($component);
                 }
             }
             $o = $i + 1;
         } else {
             if ('<' === $args[$i]) {
                 $brackets++;
             } else {
                 if ('>' === $args[$i]) {
                     $brackets--;
                 }
             }
         }
     }
     return new self(XPClass::forName($base), $components);
 }
 /**
  * Compile and then run sourcecode
  *
  * @param   string source
  * @return  lang.Runnable
  */
 protected function compile($source)
 {
     $decl = '
 import integrationtests.ArrayExtensions;
 
 class FixturePrimitiveExtensionMethodsIntegrationTest·%d implements Runnable {
   public var run() {
     %s
   }
 }';
     $emitter = new V54Emitter();
     $task = new CompilationTask(new StringSource(sprintf($decl, $this->counter++, $source), self::$syntax, $this->name), new NullDiagnosticListener(), newinstance(FileManager::class, [$this->getClass()->getClassLoader()], '{
     protected $cl;
     
     public function __construct($cl) {
       $this->cl= $cl;
     }
     
     public function findClass($qualified) {
       return new FileSource($this->cl->getResourceAsStream("net/xp_lang/tests/integration/src/".strtr($qualified, ".", "/").".xp"));
     }
     
     public function write($r, File $target) {
       // DEBUG $r->writeTo(Console::$out->getStream());
       $r->executeWith(array());   // Defines the class
     }
   }'), $emitter);
     $type = $task->run();
     return XPClass::forName($type->name())->newInstance();
 }
 /**
  * Add Portlets
  *
  * @param   string classname
  * @param   string layout
  * @return  xml.portlet.Portlet
  */
 public function addPortlet($classname, $layout = NULL)
 {
     with($portlet = XPClass::forName($classname)->newInstance());
     $portlet->setLayout($layout);
     $this->portlets[] = $portlet;
     return $portlet;
 }
예제 #8
0
 public function genericInterface()
 {
     $interfaces = XPClass::forName('lang.Object')->getInterfaces();
     $this->assertEquals(1, sizeof($interfaces));
     $this->assertInstanceOf('lang.XPClass', $interfaces[0]);
     $this->assertEquals('lang.Generic', $interfaces[0]->getName());
 }
 /**
  * Returns the implementation for the given operating system.
  *
  * @param   string os operating system name, e.g. PHP_OS
  * @param   string socket default NULL
  * @return  rdbms.mysqlx.LocalSocket
  */
 public static function forName($os, $socket = NULL)
 {
     if (0 === strncasecmp($os, 'Win', 3)) {
         return XPClass::forName('rdbms.mysqlx.NamedPipe')->newInstance($socket);
     } else {
         return XPClass::forName('rdbms.mysqlx.UnixSocket')->newInstance($socket);
     }
 }
 /**
  * Creates a segment instance
  *
  * @param  string $marker
  * @param  string $bytes
  * @return self
  */
 public static function read($marker, $bytes)
 {
     if (is_array($iptc = iptcparse($bytes))) {
         return XPClass::forName('img.io.IptcSegment')->newInstance($marker, $iptc);
     } else {
         return new self($marker, $bytes);
     }
 }
 static function __static()
 {
     self::$handlers[REMOTE_MSG_INIT] = XPClass::forName('remote.server.message.EascInitMessage');
     self::$handlers[REMOTE_MSG_LOOKUP] = XPClass::forName('remote.server.message.EascLookupMessage');
     self::$handlers[REMOTE_MSG_CALL] = XPClass::forName('remote.server.message.EascCallMessage');
     self::$handlers[REMOTE_MSG_VALUE] = XPClass::forName('remote.server.message.EascValueMessage');
     self::$handlers[REMOTE_MSG_EXCEPTION] = XPClass::forName('remote.server.message.EascExceptionMessage');
 }
 public static function initializeClasses()
 {
     if (version_compare(PHP_VERSION, '5.3.2', 'lt')) {
         throw new PrerequisitesNotMetError('Private not supported', NULL, array('PHP 5.3.2'));
     }
     self::$fixture = XPClass::forName('net.xp_framework.unittest.reflection.PrivateAccessibilityFixture');
     self::$fixtureChild = XPClass::forName('net.xp_framework.unittest.reflection.PrivateAccessibilityFixtureChild');
     self::$fixtureCtorChild = XPClass::forName('net.xp_framework.unittest.reflection.PrivateAccessibilityFixtureCtorChild');
 }
예제 #13
0
 /**
  * Add a connection listener. Provided for BC reasons.
  *
  * @deprecated Use setProtocol() instead!
  * @param   peer.server.ConnectionListener listener
  * @return  peer.server.ConnectionListener the added listener
  */
 public function addListener($listener)
 {
     if (!$this->protocol) {
         $c = XPClass::forName('peer.server.protocol.ListenerWrapperProtocol');
         $this->protocol = $c->newInstance();
     }
     $listener->server = $this;
     $this->protocol->addListener($listener);
     return $listener;
 }
 /**
  * Create client by inspecting the URL
  * 
  * @param string url The API url
  * @return com.atlassian.jira.api.JiraClientProtocol
  */
 public static function forURL($url)
 {
     $u = new URL($url);
     // Check for REST API client v2
     if (create(new String($u->getPath()))->contains('/rest/api/2')) {
         return XPClass::forName('com.atlassian.jira.api.protocol.JiraClientRest2Protocol')->newInstance($u);
         // No suitable protocol found
     } else {
         throw new IllegalArgumentException('No suitable client found for ' . $url);
     }
 }
 /**
  * Factory method
  *
  * @param   string name
  * @return  lang.XPClass
  * @throws  lang.IllegalArgumentException
  */
 public static function forName($name)
 {
     switch ($name) {
         case 'dialog':
             return XPClass::forName('net.xp_framework.unittest.xml.DialogType');
         case 'button':
             return XPClass::forName('net.xp_framework.unittest.xml.ButtonType');
         default:
             throw new IllegalArgumentException('Unknown tag "' . $name . '"');
     }
 }
 /**
  * Initialize this request object - overridden from base class.
  *
  * @see     xp://scriptlet.xml.XMLScriptletRequest#initialize
  */
 public function initialize()
 {
     parent::initialize();
     if ($this->stateName) {
         $name = implode('', array_map('ucfirst', array_reverse(explode('/', $this->stateName))));
         try {
             $this->state = XPClass::forName($this->package . '.' . ('state.' . $name . 'State'))->newInstance();
         } catch (ClassNotFoundException $e) {
             throw new ScriptletException('Cannot find ' . $this->stateName, HttpConstants::STATUS_NOT_FOUND, $e);
         }
     }
 }
예제 #17
0
 /**
  * Creates a segment instance
  *
  * @param  string $marker
  * @param  string $bytes
  * @return self
  */
 public static function read($marker, $bytes)
 {
     if (0 === strncmp('Exif', $bytes, 4)) {
         return XPClass::forName('img.io.ExifSegment')->getMethod('read')->invoke(NULL, array($marker, $bytes));
     } else {
         if (0 === strncmp('http://ns.adobe.com/xap/1.0/', $bytes, 28)) {
             return XPClass::forName('img.io.XMPSegment')->getMethod('read')->invoke(NULL, array($marker, $bytes));
         } else {
             return new self($marker, $bytes);
         }
     }
 }
 static function __static()
 {
     if (strncasecmp(PHP_OS, 'Win', 3) === 0) {
         self::$lookup = XPClass::forName('rdbms.tds.SqlIniLookup')->newInstance();
     } else {
         if (getenv('SYBASE')) {
             self::$lookup = XPClass::forName('rdbms.tds.InterfacesLookup')->newInstance();
         } else {
             self::$lookup = XPClass::forName('rdbms.tds.FreeTdsLookup')->newInstance();
         }
     }
     DriverManager::register('sybase+x', new XPClass(__CLASS__));
 }
예제 #19
0
 /**
  * Get all test cases
  *
  * @param   var[] arguments
  * @return  unittest.TestCase[]
  */
 public function testCasesWith($arguments)
 {
     $r = array();
     $section = $this->prop->getFirstSection();
     do {
         if ('this' == $section) {
             continue;
         }
         // Ignore special section
         $r = array_merge($r, $this->testCasesInClass(XPClass::forName($this->prop->readString($section, 'class')), $arguments ? $arguments : $this->prop->readArray($section, 'args')));
     } while ($section = $this->prop->getNextSection());
     return $r;
 }
예제 #20
0
 /**
  * Returns the wrapper class for this primitive
  *
  * @deprecated Wrapper types will move to their own library
  * @see     http://en.wikipedia.org/wiki/Wrapper_class
  * @return  lang.XPClass
  */
 public function wrapperClass()
 {
     switch ($this) {
         case self::$STRING:
             return XPClass::forName('lang.types.String');
         case self::$INT:
             return XPClass::forName('lang.types.Integer');
         case self::$DOUBLE:
             return XPClass::forName('lang.types.Double');
         case self::$BOOL:
             return XPClass::forName('lang.types.Boolean');
     }
 }
 static function __static()
 {
     self::$transports['http'] = XPClass::forName('peer.http.SocketHttpTransport');
     // Depending on what extension is available, choose a different implementation
     // for SSL transport. CURL is the slower one, so favor SSLSockets.
     if (extension_loaded('openssl')) {
         self::$transports['https'] = XPClass::forName('peer.http.SSLSocketHttpTransport');
     } else {
         if (extension_loaded('curl')) {
             self::$transports['https'] = XPClass::forName('peer.http.CurlHttpTransport');
         }
     }
 }
예제 #22
0
 /**
  * Start server
  *
  * @param   string[] args
  */
 public static function main(array $args)
 {
     $s = new Server('127.0.0.1', 0);
     try {
         $s->setProtocol(XPClass::forName($args[0])->newInstance());
         $s->init();
         Console::writeLinef('+ Service %s:%d', $s->socket->host, $s->socket->port);
         $s->service();
         Console::writeLine('+ Done');
     } catch (Throwable $e) {
         Console::writeLine('- ', $e->getMessage());
     }
 }
예제 #23
0
 /**
  *
  * @param   array classnames List of fully qualified class names
  * @param   int recurse default 0
  * @param   bool depend default FALSE
  * @return  &org.dia.DiaDiagram
  */
 public function marshal($classnames, $recurse = 0, $depend = FALSE)
 {
     // create new DiaDiagram
     $Dia = new DiaDiagram();
     // check classnames?
     foreach ($classnames as $classname) {
         try {
             $Class = XPClass::forName($Classname);
         } catch (Exception $e) {
             Console::writeLine("CLASS NOT FOUND: {$classname}!");
         }
     }
     return TestMarshaller::recurse($Dia, $classnames, $recurse, $depend);
 }
예제 #24
0
 static function __static()
 {
     self::$instance = new self();
     // Workaround for bugs in older PHP versions, see MD5HexHashImplementation's
     // class apidoc for an explanation. Earlier versions returned LONG_MAX for
     // hex numbers larger than LONG_MAX. Use 2^64 + 1 as hex literal and see if
     // it's "truncated", using the slower hexdec(md5()) implementation then.
     if (LONG_MAX === @0.0) {
         $impl = XPClass::forName('util.collections.MD5HexHashImplementation')->newInstance();
     } else {
         $impl = new MD5HashImplementation();
     }
     self::$instance->setImplementation($impl);
 }
예제 #25
0
 /**
  * Get all test cases
  *
  * @param   var[] arguments
  * @return  unittest.TestCase[]
  */
 public function testCasesWith($arguments)
 {
     $uri = $this->file->getURI();
     $path = dirname($uri);
     $paths = array_flip(array_filter(array_map('realpath', xp::$classpath)));
     // Search class path
     while (FALSE !== ($pos = strrpos($path, DIRECTORY_SEPARATOR))) {
         if (isset($paths[$path])) {
             return $this->testCasesInClass(XPClass::forName(strtr(substr($uri, strlen($path) + 1, -10), DIRECTORY_SEPARATOR, '.')), $arguments);
         }
         $path = substr($path, 0, $pos);
     }
     throw new IllegalArgumentException('Cannot load class from ' . $this->file->toString());
 }
 public function lookupOfLookupOfStringsReflection()
 {
     $l = create('new net.xp_framework.unittest.core.generics.Lookup<string, net.xp_framework.unittest.core.generics.Lookup<string, lang.Generic>>');
     with($class = $l->getClass());
     $this->assertTrue($class->isGeneric());
     $arguments = $class->genericArguments();
     $this->assertEquals(2, sizeof($arguments));
     $this->assertEquals(Primitive::$STRING, $arguments[0]);
     with($vclass = $arguments[1]);
     $this->assertTrue($vclass->isGeneric());
     $arguments = $vclass->genericArguments();
     $this->assertEquals(2, sizeof($arguments));
     $this->assertEquals(Primitive::$STRING, $arguments[0]);
     $this->assertEquals(XPClass::forName('lang.Generic'), $arguments[1]);
 }
예제 #27
0
 /**
  * Accessor method for a type matcher.
  * 
  * @param   typeName string
  */
 public static function anyOfType($typeName)
 {
     $builder = new MockProxyBuilder();
     $builder->setOverwriteExisting(FALSE);
     $interfaces = array(XPClass::forName('unittest.mock.arguments.IArgumentMatcher'));
     $parentClass = NULL;
     $type = XPClass::forName($typeName);
     if ($type->isInterface()) {
         $interfaces[] = $type;
     } else {
         $parentClass = $type;
     }
     $proxyClass = $builder->createProxyClass(ClassLoader::getDefault(), $interfaces, $parentClass);
     return $proxyClass->newInstance(new TypeMatcher($typeName));
 }
 /**
  * Processes a method invocation on a proxy instance and returns
  * the result.
  *
  * @param   lang.reflect.Proxy proxy
  * @param   string method the method name
  * @param   var* args an array of arguments
  * @return  var
  * @throws  util.DeferredInitializationException
  */
 public function invoke($proxy, $method, $args)
 {
     if (NULL === $this->_instance) {
         try {
             $this->_instance = $this->initialize();
         } catch (Throwable $e) {
             $this->_instance = NULL;
             throw new DeferredInitializationException($method, $e);
         }
         if (!$this->_instance instanceof Generic) {
             throw new DeferredInitializationException($method, XPClass::forName('lang.ClassCastException')->newInstance('Initializer returned ' . xp::typeOf($this->_instance)));
         }
     }
     return call_user_func_array(array($this->_instance, $method), $args);
 }
예제 #29
0
 /**
  * Runner method
  *
  */
 public static function main(array $args)
 {
     // Show command usage if invoked without arguments
     if (!$args) {
         exit(self::usage(XPClass::forName(xp::nameOf(__CLASS__))));
     }
     $root = new RootDoc();
     for ($i = 0, $s = sizeof($args); $i < $s; $i++) {
         if ('-sp' === $args[$i]) {
             $root->setSourcePath(explode(PATH_SEPARATOR, $args[++$i]));
         } else {
             if ('-cp' === $args[$i]) {
                 foreach (explode(PATH_SEPARATOR, $args[++$i]) as $element) {
                     $root->addSourcePath(ClassLoader::registerPath($element, NULL)->path);
                 }
             } else {
                 try {
                     $class = XPClass::forName($args[$i]);
                 } catch (ClassNotFoundException $e) {
                     Console::$err->writeLine('*** ', $e->getMessage());
                     exit(2);
                 }
                 if (!$class->isSubclassOf('text.doclet.Doclet')) {
                     Console::$err->writeLine('*** ', $class, ' is not a doclet');
                     exit(2);
                 }
                 $doclet = $class->newInstance();
                 $params = new ParamString(array_slice($args, $i));
                 // Show doclet usage if the command line contains "-?" (at any point).
                 if ($params->exists('help', '?')) {
                     self::usage($class);
                     if ($valid = $doclet->validOptions()) {
                         Console::$err->writeLine();
                         Console::$err->writeLine('Options:');
                         foreach ($valid as $name => $value) {
                             Console::$err->writeLine('  * --', $name, OPTION_ONLY == $value ? '' : '=<value>');
                         }
                     }
                     exit(3);
                 }
                 $root->start($doclet, $params);
                 exit(0);
             }
         }
     }
     Console::$err->writeLine('*** No doclet classname given');
     exit(1);
 }
예제 #30
0
 /**
  * Receive next frame, nonblocking
  *
  * @param   double timeout default 0.2
  * @return  org.codehaus.stomp.frame.Frame or NULL
  */
 public function recvFrame($timeout = 0.2)
 {
     // Check whether we can read, before we actually read...
     if ($this->socket instanceof Socket && !$this->socket->canRead($timeout)) {
         $this->cat && $this->cat->debug($this->getClassName(), '<<<', '0 bytes - reading no frame.');
         return NULL;
     }
     $line = $this->in->readLine();
     $this->cat && $this->cat->debug($this->getClassName(), '<<<', 'Have "' . trim($line) . '" command.');
     if (0 == strlen($line)) {
         throw new ProtocolException('Expected frame token, got "' . xp::stringOf($line) . '"');
     }
     $frame = XPClass::forName(sprintf('org.codehaus.stomp.frame.%sFrame', ucfirst(strtolower(trim($line)))))->newInstance();
     $frame->fromWire($this->in);
     return $frame;
 }