Example #1
0
 public function _getServerTypeForClientClass($clientClass)
 {
     if (array_key_exists($clientClass, $this->m_clientMappings)) {
         return $this->m_clientMappings[$clientClass];
     }
     return TypeLoader::loadType($clientClass);
 }
 private function Validate(ClassMappingItem $newClassMappingItem)
 {
     if ($newClassMappingItem->ServerClass == "") {
         throw new Exception("Server class not defined");
     }
     if ($newClassMappingItem->ClientClass == "") {
         throw new Exception("Client class not defined");
     }
     try {
         if (TypeLoader::loadType($newClassMappingItem->ServerClass) == null) {
             throw new Exception("Unable to load server type " . $newClassMappingItem->ServerClass);
         }
     } catch (Exception $e) {
         throw new Exception("Server type " . $newClassMappingItem->ServerClass . " not found");
     }
 }
 private function ValidateAlias(ServiceAlias $serviceAlias)
 {
     if ($serviceAlias->Alias == "") {
         throw new Exception("Alias not defined");
     }
     if ($serviceAlias->Service == "") {
         throw new Exception("Service name not defined");
     }
     try {
         if (TypeLoader::LoadType($serviceAlias->Service) == null) {
             throw new Exception("Unable to load service " . $serviceAlias->Service);
         }
     } catch (Exception $e) {
         throw new Exception("Service '" . $serviceAlias->Service . "' not found", $e);
     }
 }
 public function inspect($targetObject)
 {
     if (LOGGING) {
         Log::log(LoggingConstants::INFO, "Processing service inspection in " . $this->getName());
     }
     $clazz = TypeLoader::loadType($targetObject);
     // class cannot be found
     if ($clazz == null) {
         if (LOGGING) {
             Log::log(LoggingConstants::INFO, "Unable to find a class coresponding to " . $targetObject);
         }
         return null;
     }
     /*ServiceDescriptor*/
     $serviceDescriptor = ClassInspector::inspectClass($clazz);
     if (LOGGING) {
         Log::log(LoggingConstants::INFO, "PHP object handler has successfully inspected target service");
     }
     return $serviceDescriptor;
 }
 public function configure($parent, $configContext, DOMNode $documentElement)
 {
     $this->setORBConfig($configContext);
     $section = $documentElement->getElementsByTagName("classMappings")->item(0);
     // check required !
     $this->m_configNode = $section;
     foreach ($section->childNodes as $element) {
         if (!$element instanceof DOMElement) {
             continue;
         }
         $elements = $element->getElementsByTagName("clientClass");
         $clientClass = trim($elements->item(0)->nodeValue);
         $elements = $element->getElementsByTagName("serverClass");
         $serverClass = trim($elements->item(0)->nodeValue);
         $type = TypeLoader::loadType($serverClass);
         if (LOGGING) {
             Log::log(LoggingConstants::DEBUG, $clientClass . " : " . $serverClass);
         }
         ORBConfig::getInstance()->getTypeMapper()->_addClientClassMapping($clientClass, $type);
     }
 }
Example #6
0
 protected function getMethodResult($method)
 {
     /*String*/
     $methodString = substr($method, strlen(self::$METHOD_CODE));
     /*String*/
     $serviceString = substr($methodString, 0, strrpos($methodString, "."));
     /*String*/
     $methodName = substr($methodString, strlen($serviceString) + 1, strpos($methodString, "(") - strlen($serviceString) - 1);
     /*String*/
     $parametrsString = substr($methodString, strpos($methodString, "(") + 1, strpos($methodString, ")") - strpos($methodString, "(") - 1);
     /*Array*/
     $args = $this->parseOperands($parametrsString);
     /*ReflectionClass*/
     $class = TypeLoader::loadType($serviceString);
     $object = $class->newInstance();
     /*ReflectionMethod*/
     $method = $class->getMethod($methodName);
     $result = $method->invokeArgs($object, $args);
     return $result;
 }
Example #7
0
 public function canAccessObject($obj)
 {
     $serviceId = "";
     if (is_string($obj)) {
         $serviceId = ServiceRegistry::getMapping($obj);
     } else {
         $serviceId = TypeLoader::getFullClassName(new ReflectionClass(get_class($obj)));
     }
     return $this->canAccess($serviceId);
 }
 public function write(&$obj, IProtocolFormatter $writer)
 {
     if ($obj instanceof IRemote) {
         $this->m_remoteReferenceWriter->write($obj, $writer);
         return;
     }
     if (!$this->m_configured) {
         $this->m_serializePrivate = false;
         //ThreadContext.getORBConfig().serializePrivateFields; - skipped
         $this->m_configured = true;
     }
     $className = get_class($obj);
     $objectFields = array();
     $objectClass = null;
     //Log::log(LoggingConstants::INFO, "****************************************************************");
     //Log::log(LoggingConstants::INFO, "serializingclass - ".$className);
     if (!isset($this->m_cache[$className])) {
         $objectCache = new ObjectWriterCache();
         $objectClass = new ReflectionClass($className);
         $fullClassName = TypeLoader::getFullClassName($objectClass);
         $clientSideMapping = $this->getClientClass($className);
         if (!is_null($clientSideMapping)) {
             $objectCache->className = $clientSideMapping;
         } else {
             $objectCache->className = $fullClassName;
         }
         $objectCache->classMeta = $objectClass;
         $this->m_cache[$className] = $objectCache;
         $className = $objectCache->className;
     } else {
         $objectCache = $this->m_cache[$className];
         $className = $objectCache->className;
         $objectClass = $objectCache->classMeta;
     }
     // IAutoUpdate check - skipped
     while ($objectClass) {
         $properties = $objectClass->getProperties();
         $propCount = count($properties);
         for ($i = 0; $i < $propCount; $i++) {
             $prop = $properties[$i];
             if (!$prop->isPublic()) {
                 continue;
             }
             $propName = $prop->getName();
             if (!array_key_exists($propName, $objectFields)) {
                 $val = $prop->getValue($obj);
                 //Log::log(LoggingConstants::INFO, "serializing property - ".$propName."     value ".print_r($val, true));
                 $objectFields[$propName] = $val;
             }
         }
         /* $properties = $objectClass->getStaticProperties();
         
                  for ($i = 0; $i < count($properties); $i++)
                  {
                     if(!array_key_exists($properties[$i]->getName(),$objectFields))
                     {
                       $objectFields[$properties[$i]->getName()] = $properties[$i]->getValue($obj);
                     }
                  }                                           
         	   */
         $objectClass = $objectClass->getParentClass();
     }
     if (LOGGING) {
         Log::log(LoggingConstants::INFO, "going to serializer");
     }
     $writer->getObjectSerializer()->writeObject($className, $objectFields, $writer);
     if (LOGGING) {
         Log::log(LoggingConstants::INFO, "done with serializer");
     }
 }
 private static function getClass($name)
 {
     for ($i = 0; $i <= count(self::$basePath); $i++) {
         try {
             if ($i == count(self::$basePath)) {
                 $result = TypeLoader::loadType($name);
                 return $result;
             } else {
                 $result = TypeLoader::loadType(self::$basePath[$i] . $name);
                 return $result;
             }
         } catch (ReflectionException $e) {
             if ($i == count(self::$basePath)) {
                 return null;
                 throw new Exception("No class found for element [" . $name . "]");
             }
         } catch (Exception $e) {
             if ($i == count(self::$basePath)) {
                 return null;
                 throw new Exception("No class found for element [" . $name . "]");
             }
         }
     }
     return null;
 }
 public static function createServiceObject($objectName)
 {
     return TypeLoader::loadType($objectName)->newInstance();
 }