public function instantiateAnnotation(Customweb_Annotation_Cache_Annotation $cacheInstance, $targetReflection = false)
 {
     $class = Customweb_Annotation_Util::resolveClassName($cacheInstance->getName());
     $parameters = $this->instanciateNestedAnnotations($cacheInstance->getParameters());
     if (Customweb_Core_Util_Class::isClassLoaded($class) && !Customweb_Annotation_Util::ignores($class)) {
         $annotationReflection = new ReflectionClass($class);
         $instance = $annotationReflection->newInstance();
         if (method_exists($instance, 'setData')) {
             $instance->setData($parameters);
         } else {
             set_error_handler(array($this, 'handleInstanciationErrors'));
             try {
                 foreach ($parameters as $propertyName => $propertyValue) {
                     $methodName = 'set' . $propertyName;
                     if (method_exists($instance, $methodName)) {
                         $instance->{$methodName}($propertyValue);
                     } elseif (property_exists($instance, $propertyName)) {
                         $instance->{$propertyName} = $propertyValue;
                     } else {
                         throw new Exception(Customweb_Core_String::_("Property @property could not be set on annotation class @class")->format(array('@class' => $class, '@property' => $propertyName)));
                     }
                 }
             } catch (Exception $e) {
                 restore_error_handler();
                 throw $e;
             }
             restore_error_handler();
         }
         if (method_exists($instance, 'checkConstraints')) {
             $instance->checkConstraints($targetReflection);
         }
         return $instance;
     }
     return false;
 }
 /**
  * Creates a key based on both addresses found in the orderContext
  *
  * @param Customweb_Payment_Authorization_IOrderContext $orderContext
  * @param array $additionalData Other identifiers to be added to the generated key (e.g. amount, payment type etc)
  * @return string
  */
 public static function generateAddressKey(Customweb_Payment_Authorization_IOrderContext $orderContext, $additionalData = array())
 {
     $billing = $orderContext->getBillingAddress();
     $shipping = $orderContext->getShippingAddress();
     $addressParts = array_merge(self::addressPartsToArray($billing), self::addressPartsToArray($shipping), $additionalData);
     $addressString = Customweb_Core_String::_(implode($addressParts))->toLowerCase()->toString();
     return substr(hash('SHA512', $addressString), 0, 160);
 }
Exemple #3
0
 protected function getFormat($iban)
 {
     $countryCode = self::extractCountryCode($iban);
     if (isset($this->data[$countryCode])) {
         return $this->data[$countryCode];
     } else {
         throw new Exception(Customweb_Core_String::_("No valid country code in the given IBAN. Country Code: '!code'")->format(array('!code' => $countryCode)));
     }
 }
 public static function getFileExtensions($mimeType)
 {
     $key = strtolower($mimeType);
     $inversion = self::getInversionMap();
     if (isset($inversion[$key])) {
         return $inversion[$key];
     } else {
         throw new Exception(Customweb_Core_String::_("No file extension found for mime type '@mime'.")->format(array('@mime' => $mimeType)));
     }
 }
 public function __call($name, $arguments)
 {
     if (isset($this->plugins[$name])) {
         $plugin = $this->plugins[$name];
         if ($plugin instanceof Customweb_Mvc_Template_IFilter) {
             return $this->plugins[$name]->filter(current($arguments));
         }
     }
     throw new Exception(Customweb_Core_String::_("The plugin '!plugin' has not been found.")->format(array('!plugin' => $name)));
 }
Exemple #6
0
 /**
  * Checks if the given BIC is valid.
  * 
  * @param unknown $iban
  * @throws Exception
  * @return boolean
  */
 public function validate($bic)
 {
     if (strlen($bic) < 8) {
         throw new Exception(Customweb_Core_String::_("The BIC is too short."));
     }
     if (!preg_match('/^[a-z0-9]{4}[a-z]{2}[a-z0-9]{2}([a-z0-9]{3})?$/i', $bic)) {
         throw new Exception(Customweb_Core_String::_("The BIC has a invalid format."));
     }
     return true;
 }
Exemple #7
0
 protected function getFopenHandler()
 {
     if ($this->fopenHandler === null) {
         if (!file_exists($this->filePath)) {
             throw new Exception(Customweb_Core_String::_("File on path '@path' does not exists.")->format(array('@path' => $this->filePath)));
         }
         Customweb_Core_Util_Error::startErrorHandling();
         $this->fopenHandler = fopen($this->filePath, 'r');
         Customweb_Core_Util_Error::endErrorHandling();
         $this->open = true;
     }
     return $this->fopenHandler;
 }
 /**
  * Returns the protocol to use in case of an SSL connection.
  *
  * @return string
  */
 protected function getSslProtocol()
 {
     $version = $this->getForcedSslVersion();
     $rs = null;
     switch ($version) {
         case self::SSL_VERSION_SSLV2:
             $rs = 'sslv2';
             break;
         case self::SSL_VERSION_SSLV3:
             $rs = 'sslv3';
             break;
         case self::SSL_VERSION_TLSV1:
             $rs = 'tls';
             break;
         case self::SSL_VERSION_TLSV11:
             $rs = 'tlsv1.1';
             break;
         case self::SSL_VERSION_TLSV12:
             $rs = 'tlsv1.2';
             break;
         default:
             $rs = 'ssl';
     }
     if ($rs === null) {
         throw new Exception("Invalid state.");
     }
     $possibleTransportProtocols = stream_get_transports();
     if (!in_array($rs, $possibleTransportProtocols)) {
         throw new Exception(Customweb_Core_String::_("The enforced SSL protocol is '@actual'. But this protocol is not supported by the web server. Supported stream protocols by the web server are @supported.")->format(array('@actual' => $rs, '@supported' => implode(',', $possibleTransportProtocols))));
     }
     return $rs;
 }
 private function getCurrentForm()
 {
     $machineName = $this->getRequest()->getParam('tab');
     foreach ($this->getFormAdapter()->getForms() as $form) {
         if ($form->getMachineName() == $machineName) {
             return $form;
         }
     }
     throw new Exception(Customweb_Core_String::_("Could not find form with form name '@name'.")->format(array('@name' => $machineName)));
 }
 /**
  * Search the given package list for controllers. The method returns a map
  * with the controller names as key and the class name as the value.
  *
  * @return array
  */
 protected function getControllers()
 {
     if ($this->controllers === null) {
         $scanner = new Customweb_Annotation_Scanner();
         $annotations = $scanner->find('Customweb_Mvc_Controller_Annotation_Controller', $this->getControllerPackages());
         foreach ($annotations as $className => $annotation) {
             if ($annotation instanceof Customweb_Mvc_Controller_Annotation_Controller) {
                 $controllerName = $annotation->getName();
                 if (empty($controllerName)) {
                     throw new Exception(Customweb_Core_String::_("The class '@className' is annotated with Customweb_Mvc_Controller_Annotation_Controller. However it does not provide a controller name.")->format(array('@className' => $className)));
                 }
                 $this->controllers[strtolower($controllerName)] = $className;
             }
         }
     }
     return $this->controllers;
 }
 /**
  * This method tries to find based on the given input the IETF 
  * language tag.
  * 
  * The input can be either ISO-639-3, ISO-639-1, IETF tag or the 
  * language name.
  * 
  * @param string $lang
  * @return string
  */
 private static function convertToIETFCode($lang)
 {
     // Check if the language is a IETF tag
     if (preg_match('/([a-z]{2})[-_]{1}([a-z]{2})/i', $lang, $matches)) {
         $language = $matches[1];
         $region = $matches[2];
         return strtolower($language) . '_' . strtoupper($region);
     }
     // It seems to be a ISO-639-3
     $lang = strtolower($lang);
     if (strlen($lang) == 3) {
         foreach (self::$languages as $langCode => $l) {
             if ($l['ISO-639-3'] == $lang) {
                 return self::getIETFTagFromLanguageArray($langCode, $l);
             }
         }
     } else {
         if (strlen($lang) == 2) {
             if (isset(self::$languages[$lang])) {
                 return self::getIETFTagFromLanguageArray($lang, self::$languages[$lang]);
             }
         } else {
             foreach (self::$languages as $langCode => $l) {
                 if (strtolower($l['name']) == $lang) {
                     return self::getIETFTagFromLanguageArray($langCode, $l);
                 }
             }
         }
     }
     throw new Exception(Customweb_Core_String::_("No valid language found for '@lang'.")->format(array('@lang' => $lang)));
 }
 /**
  * Returns the value of the given cookie. The cookie key is case
  * sensitive.
  * 
  * @param string $cookieKey
  * @throws Exception In case the given cookie key is not defined.
  * @return string
  */
 public function getCookieValue($cookieKey)
 {
     $cookies = $this->getCookies();
     if (isset($cookies[$cookieKey])) {
         return $cookies[$cookieKey]->getValue();
     } else {
         throw new Exception(Customweb_Core_String::_("No cookie for key '@key'.")->format(array('@key' => $cookieKey)));
     }
 }
Exemple #13
0
 protected static function valueOfInner($className, $key)
 {
     $values = self::valuesInner($className);
     if (isset($values[$key])) {
         return $values[$key];
     } else {
         throw new Exception(Customweb_Core_String::_("The key '@key' does not exists on the Enum '@enum'.")->format(array('@key' => $key, '@enum' => $className)));
     }
 }
 /**
  * This method parses the given header. In case the header is a key / value 
  * pair the header is written to the list of parsed headers.
  * 
  * @param string $header
  * @throws Exception
  */
 protected final function parseHeader($header)
 {
     if (!is_string($header)) {
         throw new Exception("The given header is not a string.");
     }
     if (preg_match('/([^:]+):(.*)/', $header, $rs)) {
         $key = strtolower($rs[1]);
         $value = trim($rs[2]);
         $key = strtolower($key);
         if (!isset($this->parsedHeaders[$key])) {
             $this->parsedHeaders[$key] = array();
         }
         $this->parsedHeaders[$key][] = $value;
         $this->processKeyedHeader($key, $value);
     } else {
         throw new Exception(Customweb_Core_String::_("Invalid format of the header '@header'. It must contain a ':' char.")->format(array('@header' => $header)));
     }
 }
 public function __construct($identifier)
 {
     $message = Customweb_Core_String::_("The asset with identifier '@identifier' is not public reachable.")->format(array('@identifier' => $identifier));
     parent::__construct($message);
 }
 public function __construct($paymentMethodName, $authorizationMethod)
 {
     parent::__construct(Customweb_Core_String::_("The payment method name '!name' with the authorization method '!authorizationMethod' could not be mapped to a payment method class.")->format(array('!name' => $paymentMethodName, '!authorizationMethod' => $authorizationMethod)));
 }
 public function setValue($object, $value)
 {
     if ($this->propertyReflector !== null && $this->propertyReflector->isPublic()) {
         $object->{$this->getName()} = $value;
     } else {
         if ($this->setMethodReflector !== null && $this->setMethodReflector->isPublic()) {
             $this->setMethodReflector->invoke($object, $value);
         } else {
             throw new Exception(Customweb_Core_String::_("Unable to set the property '@property' on '@class'.")->format(array('@property' => $this->getName(), '@class' => $this->getClassName())));
         }
     }
 }
Exemple #18
0
 public function setRawValue($value)
 {
     if (preg_match('/[;,[:space:]]+/i', $value)) {
         throw new Exception(Customweb_Core_String::_("Unallowed chars in the cookie value. Not allowed are ',', ';' and any space. Use instead setValue. Value: @value")->format(array('@value' => $value)));
     }
     $this->value = $value;
     return $this;
 }
 public function __construct($controllerName)
 {
     $this->controllerName = $controllerName;
     parent::__construct(Customweb_Core_String::_("No controller found for controller name '@controllerName'.")->format(array('@controllerName' => $controllerName)));
 }
 public function __construct($actionName)
 {
     $this->actionName = $actionName;
     parent::__construct(Customweb_Core_String::_("No action found for action name '@actionName'.")->format(array('@actionName' => $actionName)));
 }
 public function __construct($expectedClassName)
 {
     parent::__construct((string) Customweb_Core_String::_("Failed to cast to type '@name'.")->format(array('@name' => $expectedClassName)));
     $this->expectedClassName = $expectedClassName;
 }
 protected function resolveInvocationArguements(ReflectionMethod $method)
 {
     $args = array();
     foreach ($method->getParameters() as $parameter) {
         $type = Customweb_Core_Util_Reflection::getParameterType($parameter);
         if ($type === null) {
             throw new Exception(Customweb_Core_String::_("Unable to invoke method @method because it contain a primitive type.")->format(array('@method' => $method->getName())));
         }
         $args[] = $this->getContainer()->getBean($type);
     }
     return $args;
 }
 public function __construct($name)
 {
     parent::__construct((string) Customweb_Core_String::_("The charset with the name '@name' is not defined.")->format(array('@name' => $name)));
     $this->charsetName = $name;
 }
 public function __construct($methodName)
 {
     $this->methodName = $methodName;
     parent::__construct(Customweb_Core_String::_("The method '@method' has a sclar parameter value. This is not supported on action methods.")->format(array('@method' => $methodName)));
 }
 public function __construct($codeNumber, $utf8Representation)
 {
     $this->codeNumber = $codeNumber;
     $this->charAsUtf8 = $utf8Representation;
     parent::__construct(Customweb_Core_String::_("The char '@char' (code: '@codeNumber') was not found in conversion table.")->format(array('@codeNumber' => (string) $this->codeNumber, '@char' => (string) $utf8Representation)));
 }
 public function __construct($methodName, $type)
 {
     $this->methodName = $methodName;
     $this->type = $type;
     parent::__construct(Customweb_Core_String::_("The parameter '@parameter' on method '@method' could not be resolved.")->format(array('@method' => $methodName, '@parameter' => $type)));
 }
Exemple #27
0
 /**
  * Returns the first of direct child elements with the given tagName. Optionally also the
  * namespace can be enforced. If no such child exists this method throws an exception.
  *
  * @param DOMElement $node
  * @param string $tagName
  * @param string $namespaceUri
  * @return DOMElement
  */
 public static function getChildElement(DOMElement $node, $tagName, $namespaceUri = null)
 {
     $list = self::getChildElements($node, $tagName, $namespaceUri);
     if (count($list) > 0) {
         return current($list);
     } else {
         throw new Exception(Customweb_Core_String::_("No element with tag name '@tag' does exists.")->format(array('@tag' => $tagName)));
     }
 }