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; }
/** * 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; }
/** * 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($object) { if (!is_object($object)) { throw new InvalidArgumentException("No provided object is not of type 'object'."); } $this->object = $object; $this->beanId = get_class($this->object); $this->classes = Customweb_Core_Util_Class::getAllTypes($this->beanId); }
/** * Get the javascript to send the shipping method form via ajax. * * $shippingPaneSelector and $confirmationPaneSelector are jquery selectors pointing to the pane element surrounding the shipping method and * confirmation forms. * * Customweb.ExternalCheckout.submit() can be used to submit the shipping method form manually. * * @param string $shippingPaneSelector * @param string $confirmationPaneSelector * @return string */ protected final function getAjaxJavascript($shippingPaneSelector, $confirmationPaneSelector) { $jqueryVariableName = 'j' . Customweb_Util_Rand::getRandomString(30); $javascript = Customweb_Core_Util_Class::readResource('Customweb_Payment_ExternalCheckout', 'ExternalCheckout.js') . "\n\n"; $variables = array('jQueryNameSpace' => $jqueryVariableName); foreach ($variables as $variableName => $value) { $javascript = str_replace('____' . $variableName . '____', $value, $javascript); } $javascript .= Customweb_Util_JavaScript::getLoadJQueryCode('1.10.2', $jqueryVariableName, 'function() { Customweb.ExternalCheckout.init("' . $shippingPaneSelector . '", "' . $confirmationPaneSelector . '"); }') . "\n\n"; return $javascript; }
public function __construct() { $this->setControlCssClass('input-box'); $this->setControlCssClassResolver(Mage::getModel('saferpaycw/controlCssClassResolver')); if (!function_exists('cw_resource_loader')) { function cw_resource_loader($relativeClassName, $resourceFile) { $path = Mage::getBaseDir('lib') . '/' . str_replace('_', '/', $relativeClassName) . '/' . $resourceFile; if (file_exists($path)) { return file_get_contents($path); } } Customweb_Core_Util_Class::registerResourceResolver('cw_resource_loader'); } }
/** * @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; } } } } } }
/** * @return Customweb_DependencyInjection_Container_Default */ public function createContainer() { if (self::$container === null) { if (!function_exists('cw_class_loader')) { function cw_class_loader($className) { return Varien_Autoload::instance()->autoload($className); } Customweb_Core_Util_Class::registerClassLoader('cw_class_loader'); } $packages = array(0 => 'Customweb_Saferpay', 1 => 'Customweb_Payment_Authorization'); $packages[] = 'Customweb_SaferpayCw_Model_'; $packages[] = 'Customweb_Mvc_Template_Php_Renderer'; $packages[] = 'Customweb_Payment_SettingHandler'; $provider = new Customweb_DependencyInjection_Bean_Provider_Editable(new Customweb_DependencyInjection_Bean_Provider_Annotation($packages)); $provider->addObject(Customweb_Core_Http_ContextRequest::getInstance())->addObject($this->getAssetResolver()); self::$container = new Customweb_DependencyInjection_Container_Default($provider); } return self::$container; }
/** * This method generates all the JavaScript required to * handle the user input as configured. * * Subclasses may override this method, but should call this method in first place. * The additional JS can be added by invoking the method self::appendJavaScript(). * * @return string */ protected function generateJavaScript() { $js = Customweb_Core_Util_Class::readResource('Customweb_Payment_Authorization_Method_CreditCard', 'CardHandler.js'); $filteredData = array(); foreach ($this->getCardHandler()->getCardInformationObjects() as $object) { $key = strtolower($object->getBrandKey()); $filteredData[$key] = array(); $filteredData[$key]['validators'] = $object->getValidators(); $filteredData[$key]['lengths'] = $object->getCardNumberLengths(); if ($object->isCvvPresentOnCard()) { $filteredData[$key]['cvv_length'] = $object->getCvvLength(); $filteredData[$key]['cvv_required'] = $object->isCvvRequired(); } } $selectedBrand = $this->getSelectedBrand(); if ($selectedBrand === null) { $selectedBrand = 'null'; } $brandMapping = $this->getCardHandler()->getExternalBrandMap(); if ($brandMapping === null) { $brandMapping = array(); } $variables = array('jQueryNameSpace' => $this->getJQueryVariableName(), 'imageBrandControlId' => self::getControlId($this->brandImageControl), 'brandDropDownControlId' => self::getControlId($this->brandDropDownControl), 'creditCardControlId' => self::getControlId($this->cardNumberControl), 'cvcControlId' => self::getControlId($this->cvcControl), 'expiryMonthControlId' => self::getControlId($this->expiryMonthControl), 'expiryYearControlId' => self::getControlId($this->expiryYearControl), 'cardHandlerNameSpace' => $this->getCardHandlerJavaScriptNameSpace(), 'brandMapping' => Customweb_Util_JavaScript::toJavaScript($brandMapping), 'cardInformation' => Customweb_Util_JavaScript::toJavaScript($filteredData), 'cardNumberPrefixMap' => Customweb_Util_JavaScript::toJavaScript($this->getCardHandler()->getCardNumberPrefixMap()), 'imageBrandSelectionActive' => self::handleBoolean($this->isImageBrandSelectionActive()), 'autoBrandSelectionActive' => self::handleBoolean($this->isAutoBrandSelectionActive()), 'brandSelectionActive' => self::handleBoolean($this->isBrandSelectionActive()), 'enhancedWithJavaScript' => $this->isEnhancedWithJavaScript(), 'selectedBrand' => $selectedBrand, 'forceCvcOptional' => self::handleBoolean($this->isForceCvcOptional()), 'expiryFieldFormat' => $this->getExpiryFieldFormat(), 'expiryControlId' => self::getControlId($this->expiryControl)); foreach ($variables as $variableName => $value) { $js = str_replace('____' . $variableName . '____', $value, $js); } $this->appendJavaScript($js . "\n"); // Add jQuery $this->appendJavaScript(Customweb_Util_JavaScript::getLoadJQueryCode('1.10.2', $this->getJQueryVariableName(), 'function() { ' . $this->getCardHandlerJavaScriptNameSpace() . '.init(); }')); return $this->getJavaScript(); }
/** * This function checks if a given file exists in the include path or not. * * @param string $fileName * @return boolean True if the file exists. False if the file does not exists. * @deprecated Use Instead Customweb_Core_Util_Class */ function library_load_check_if_file_exists_on_include_path($fileName) { return Customweb_Core_Util_Class::isLibraryClassFileExisting($fileName); }
/** * 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]; }
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; } } } } } }
/** * This method adds the container to the internal bean list. Hence beans * can access the bean container. * * @return void */ protected function addSelfToContainer() { $className = get_class($this); $classes = Customweb_Core_Util_Class::getAllTypes($className); $this->addBean($classes, $this); // We need to add the bean container to the range query index. foreach ($classes as $class) { $class = strtolower($class); if (!isset($this->beansByClasses[$class])) { $this->beansByClasses[$class] = array(); } $this->beansByClasses[$class][] = $this; } }
protected function isActionMethodContainParameterTransaction(ReflectionMethod $method) { foreach ($method->getParameters() as $parameter) { $type = self::getParameterType($parameter); $tpyes = Customweb_Core_Util_Class::getAllTypes($type); if (in_array('Customweb_Payment_Authorization_ITransaction', $tpyes)) { return true; } } return false; }
public function getClasses() { $classes = Customweb_Core_Util_Class::getAllTypes($this->getBeanClassName()); return $classes; }
public static function loadLibraryCss($libraryName) { return Customweb_Core_Util_Class::readResource('Customweb_Util_JavaScript', $libraryName . '.css'); }
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; }