Esempio n. 1
0
 public function getInstance(Customweb_DependencyInjection_IContainer $container)
 {
     Customweb_Core_Util_Class::loadLibraryClassByName($this->getBeanClassName());
     $reflection = new ReflectionClass($this->getBeanClassName());
     /* @var $constructor ReflectionMethod */
     $constructor = $reflection->getConstructor();
     $args = array();
     if ($constructor !== null && count($constructor->getParameters()) > 0) {
         foreach ($this->getDependencies() as $dependency) {
             if ($dependency->getAccessMethodName() == $constructor->getName()) {
                 $args = $this->getMethodInvocationArguments($constructor, $dependency, $container);
                 break;
             }
         }
         if (count($args) != count($constructor->getParameters())) {
             throw new Exception("Could not resolve all parameters for the contructor of " . $this->getBeanClassName() . "::" . $constructor->getName() . "().");
         }
     }
     if (count($args) === 0) {
         $instance = $reflection->newInstance();
     } else {
         $instance = $reflection->newInstanceArgs($args);
     }
     foreach ($this->getDependencies() as $dependency) {
         $this->injectDependency($instance, $dependency, $container);
     }
     return $instance;
 }
Esempio n. 2
0
 /**
  * Returns a map with all annotation found for the given annotation name. The
  * key of the map is the class name and the value is an instance of the annotation 
  * class.
  * 
  * @param string $annotationName
  * @param array $targetPackageNames
  * @return Customweb_IAnnotation[]
  */
 public function find($annotationName, $targetPackageNames = null)
 {
     try {
         Customweb_Core_Util_Class::loadLibraryClassByName($annotationName);
     } catch (Customweb_Core_Exception_ClassNotFoundException $e) {
     }
     $rs = array();
     $candiates = $this->findTargetClassCandidates($annotationName, $targetPackageNames);
     if (strstr($annotationName, '_') !== false) {
         $alternativeAnnotationName = substr($annotationName, strrpos($annotationName, '_') + 1);
         $candiates = array_merge($candiates, $this->findTargetClassCandidates($alternativeAnnotationName, $targetPackageNames));
     }
     foreach ($candiates as $candidate) {
         if (strpos($candidate, '::') === false) {
             Customweb_Core_Util_Class::loadLibraryClassByName($candidate);
             $reflection = new Customweb_Annotation_ReflectionAnnotatedClass($candidate);
             if ($reflection->hasAnnotation($annotationName)) {
                 $rs[$reflection->getName()] = $reflection->getAnnotation($annotationName);
             }
         } else {
             $candiateClass = substr($candidate, 0, strpos($candidate, '::'));
             $candidateMethod = substr($candidate, strlen($candiateClass) + 2);
             Customweb_Core_Util_Class::loadLibraryClassByName($candiateClass);
             $reflectionClass = new Customweb_Annotation_ReflectionAnnotatedClass($candiateClass);
             $reflectionMethod = $reflectionClass->getMethod($candidateMethod);
             if ($reflectionMethod->hasAnnotation($annotationName)) {
                 $rs[$candidate] = $reflectionMethod->getAnnotation($annotationName);
             }
         }
     }
     return $rs;
 }
Esempio n. 3
0
 /**
  * Creates a bean object. This object can be used to create an instance of the 
  * class defined with this bean. 
  * 
  * @param string $beanId
  * @param string $className
  * @throws Exception
  * @return Customweb_DependencyInjection_Bean_Generic
  */
 public static function createBeanInstance($beanId, $className)
 {
     if (empty($beanId)) {
         $beanId = $className;
     }
     Customweb_Core_Util_Class::loadLibraryClassByName('Customweb_DependencyInjection_Bean_Provider_Annotation_Inject');
     $dependencies = array();
     Customweb_Core_Util_Class::loadLibraryClassByName($className);
     $reflector = new Customweb_Annotation_ReflectionAnnotatedClass($className);
     foreach ($reflector->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
         $annotations = $method->getAllAnnotations();
         if ($method->isConstructor() || $method->hasAnnotation('Customweb_DependencyInjection_Bean_Provider_Annotation_Inject')) {
             if ($method->isConstructor() && !$method->hasAnnotation('Customweb_DependencyInjection_Bean_Provider_Annotation_Inject')) {
                 $injects = self::getInjectsFromMethod($method);
             } else {
                 $annotation = $method->getAnnotation('Customweb_DependencyInjection_Bean_Provider_Annotation_Inject');
                 /* @var $annotation Customweb_DependencyInjection_Bean_Provider_Annotation_Inject */
                 $injects = $annotation->getInjects();
                 if (!is_array($injects) || count($injects) <= 0) {
                     $injects = self::getInjectsFromMethod($method);
                 } elseif (count($injects) !== $method->getNumberOfParameters()) {
                     throw new Exception("Invalid annotation 'Inject' on method '" . $method->getName() . "' on class '" . $className . "'. The number of inject arguments do not match the number of arguments.");
                 }
             }
             $dependencies[] = new Customweb_DependencyInjection_Bean_Generic_DefaultDependency($method->getName(), $injects);
         }
     }
     return new Customweb_DependencyInjection_Bean_Generic($beanId, $className, $dependencies);
 }
 public function __construct(Customweb_Payment_Endpoint_IAdapter $adapter, Customweb_DependencyInjection_IContainer $container, array $controllerScanPackages)
 {
     parent::__construct($adapter, $container, $controllerScanPackages);
     Customweb_Core_Util_Class::loadLibraryClassByName('Customweb_Payment_Endpoint_Annotation_ExtractionMethod');
     if (!$container->hasBean('Customweb_Payment_ITransactionHandler')) {
         throw new Exception("The dependency container does not contain a bean with type 'Customweb_Payment_ITransactionHandler'.");
     }
     $this->transactionHandler = $container->getBean('Customweb_Payment_ITransactionHandler');
 }
 /**
  * @param string $serializedString
  * @throws Customweb_Core_Exception_ClassNotFoundException
  */
 private static function preloadClasses($serializedString)
 {
     $matches = array();
     preg_match_all('/O:[0-9]+:\\"(.+?)\\":/', $serializedString, $matches);
     if (isset($matches[1])) {
         foreach ($matches[1] as $match) {
             $className = $match;
             if (!Customweb_Core_Util_Class::isClassLoaded($className)) {
                 try {
                     Customweb_Core_Util_Class::loadLibraryClassByName($className);
                 } catch (Customweb_Core_Exception_ClassNotFoundException $e) {
                     if (!class_exists($className)) {
                         throw $e;
                     }
                 }
             }
         }
     }
 }
 /**
  * This method returns a map of actions on the given class. The key is the action name and
  * the value is the method.
  * 
  * @param string $controllerClassName Controller class name
  * @return array
  */
 protected function getActions($controllerClassName)
 {
     Customweb_Core_Util_Class::loadLibraryClassByName('Customweb_Mvc_Controller_Annotation_Action');
     $key = strtolower($controllerClassName);
     if (!isset($this->actions[$key])) {
         $this->actions[$key] = array();
         $reflector = new Customweb_Annotation_ReflectionAnnotatedClass($controllerClassName);
         foreach ($reflector->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
             if ($method->hasAnnotation('Customweb_Mvc_Controller_Annotation_Action')) {
                 $annotation = $method->getAnnotation('Customweb_Mvc_Controller_Annotation_Action');
                 if ($annotation instanceof Customweb_Mvc_Controller_Annotation_Action) {
                     $actionName = $annotation->getName();
                     if (empty($actionName)) {
                         $actionName = $method->getName();
                     }
                     $this->actions[$key][$actionName] = $method->getName();
                 }
             }
         }
     }
     return $this->actions[$key];
 }
Esempio n. 7
0
 protected function processKeyedHeader($headerKey, $headerValue)
 {
     parent::processKeyedHeader($headerKey, $headerValue);
     if ($headerKey == self::HEADER_KEY_COOKIE) {
         $this->processCookieHeader($headerValue);
     } else {
         if ($headerKey == self::HEADER_KEY_HOST) {
             $this->url->setHost($headerValue);
         } else {
             if ($headerKey == self::HEADER_KEY_USER_AGENT) {
                 $this->userAgent = $headerValue;
             } else {
                 if ($headerKey == self::HEADER_KEY_AUTHORIZATION) {
                     $authorizationName = strtolower(trim(substr($headerValue, 0, strpos($headerValue, ' '))));
                     if (isset(self::$authorizations[$authorizationName])) {
                         $className = self::$authorizations[$authorizationName];
                         Customweb_Core_Util_Class::loadLibraryClassByName($className);
                         $object = new $className();
                         if (!$object instanceof Customweb_Core_Http_IAuthorization) {
                             throw new Exception("The given authorization class does not implement the authorization interface.");
                         }
                         $object->parseHeaderFieldValue($headerValue);
                         $this->authorization = $object;
                     }
                 }
             }
         }
     }
 }
Esempio n. 8
0
 private static function searchAllAliasForName($name)
 {
     foreach (self::$classMap as $charSetName => $className) {
         if (!isset(self::$charsets[$charSetName])) {
             Customweb_Core_Util_Class::loadLibraryClassByName($className);
             self::$charsets[$charSetName] = new $className($name);
         }
         foreach (self::$charsets[$charSetName]->getAliases() as $alias) {
             $alias = self::normalizeCharsetName($alias);
             self::$charsets[$alias] = self::$charsets[$charSetName];
             if ($alias == $name) {
                 return $charSetName;
             }
         }
     }
     return null;
 }
Esempio n. 9
0
 /**
  * This function loads a class from the library. It resolves the path and
  * checks if the given class does not already exists in the program
  * space.
  *
  * @param string $className The name of the class
  * @throws Exception When the given class could not be resolved to a file.
  * @return boolean True if the class was loaded newly. False if the class
  * already exists.
  * @deprecated Use Instead Customweb_Core_Util_Class
  */
 function library_load_class_by_name($className)
 {
     return Customweb_Core_Util_Class::loadLibraryClassByName($className);
 }