Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
0
 protected function createActionInvocationContainer(Customweb_Core_Http_IRequest $request, ReflectionMethod $method, $controllerObject)
 {
     $container = parent::createActionInvocationContainer($request, $method, $controllerObject);
     if ($this->isActionMethodContainParameterTransaction($method)) {
         $controllerReflection = new Customweb_Annotation_ReflectionAnnotatedClass($controllerObject);
         $ids = null;
         foreach ($controllerReflection->getMethods(ReflectionMethod::IS_PUBLIC) as $controllerMethod) {
             if ($controllerMethod->hasAnnotation('Customweb_Payment_Endpoint_Annotation_ExtractionMethod')) {
                 $ids = $controllerMethod->invoke($controllerObject, $request);
                 break;
             }
         }
         if (is_array($ids)) {
             if (!isset($ids['id'])) {
                 throw new Exception("The extraction method does not return an array with an index 'id'.");
             }
             if (!isset($ids['key'])) {
                 throw new Exception("The extraction method does not return an array with an index 'key'.");
             }
             $transaction = null;
             if ($ids['key'] == Customweb_Payment_Endpoint_Annotation_ExtractionMethod::PAYMENT_ID_KEY) {
                 $this->getTransactionHandler()->beginTransaction();
                 $this->databaseTransactionActive = true;
                 $transaction = $this->getTransactionHandler()->findTransactionByPaymentId($ids['id']);
             } else {
                 if ($ids['key'] == Customweb_Payment_Endpoint_Annotation_ExtractionMethod::TRANSACTION_ID_KEY) {
                     $this->getTransactionHandler()->beginTransaction();
                     $this->databaseTransactionActive = true;
                     $transaction = $this->getTransactionHandler()->findTransactionByTransactionId($ids['id']);
                 } else {
                     if ($ids['key'] == Customweb_Payment_Endpoint_Annotation_ExtractionMethod::EXTERNAL_TRANSACTION_ID_KEY) {
                         $this->getTransactionHandler()->beginTransaction();
                         $this->databaseTransactionActive = true;
                         $transaction = $this->getTransactionHandler()->findTransactionByTransactionExternalId($ids['id']);
                     } else {
                         throw new Exception("Invalid value for 'key' provided.");
                     }
                 }
             }
             $container->addBean(new Customweb_DependencyInjection_Bean_Object($transaction));
         } else {
             throw new Exception(Customweb_I18n_Translation::__("The controller class '@controller' does not provide any method with annotation 'Customweb_Payment_Endpoint_Annotation_ExtractionMethod' and valid output.", array('@controller' => get_class($controllerObject))));
         }
     }
     return $container;
 }
Ejemplo n.º 3
0
 /**
  * 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];
 }