Beispiel #1
0
 /**
  * Defined by IfwPsn_Vendor_Zend_Validate_Interface
  *
  * Returns true if the mimetype of the file does not matche the given ones. Also parts
  * of mimetypes can be checked. If you give for example "image" all image
  * mime types will not be accepted like "image/gif", "image/jpeg" and so on.
  *
  * @param  string $value Real file to check for mimetype
  * @param  array  $file  File data from IfwPsn_Vendor_Zend_File_Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     if ($file === null) {
         $file = array('type' => null, 'name' => $value);
     }
     // Is file readable ?
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
     if (!IfwPsn_Zend_Loader::isReadable($value)) {
         return $this->_throw($file, self::NOT_READABLE);
     }
     $this->_type = $this->_detectMimeType($value);
     if (empty($this->_type) && $this->_headerCheck) {
         $this->_type = $file['type'];
     }
     if (empty($this->_type)) {
         return $this->_throw($file, self::NOT_DETECTED);
     }
     $mimetype = $this->getMimeType(true);
     if (in_array($this->_type, $mimetype)) {
         return $this->_throw($file, self::FALSE_TYPE);
     }
     $types = explode('/', $this->_type);
     $types = array_merge($types, explode('-', $this->_type));
     foreach ($mimetype as $mime) {
         if (in_array($mime, $types)) {
             return $this->_throw($file, self::FALSE_TYPE);
         }
     }
     return true;
 }
Beispiel #2
0
 /**
  * Defined by IfwPsn_Vendor_Zend_Validate_Interface
  *
  * Returns true if and only if the fileextension of $value is not included in the
  * set extension list
  *
  * @param  string  $value Real file to check for extension
  * @param  array   $file  File data from IfwPsn_Vendor_Zend_File_Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     // Is file readable ?
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
     if (!IfwPsn_Zend_Loader::isReadable($value)) {
         return $this->_throw($file, self::NOT_FOUND);
     }
     if ($file !== null) {
         $info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1);
     } else {
         $info = pathinfo($value);
     }
     $extensions = $this->getExtension();
     if ($this->_case and !in_array($info['extension'], $extensions)) {
         return true;
     } else {
         if (!$this->_case) {
             $found = false;
             foreach ($extensions as $extension) {
                 if (strtolower($extension) == strtolower($info['extension'])) {
                     $found = true;
                 }
             }
             if (!$found) {
                 return true;
             }
         }
     }
     return $this->_throw($file, self::FALSE_EXTENSION);
 }
Beispiel #3
0
 /**
  * Class constructor
  *
  * @param array $options (Optional) Options to set
  */
 public function __construct($options = null)
 {
     if (!class_exists('Archive_Tar')) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
         try {
             IfwPsn_Zend_Loader::loadClass('Archive_Tar');
         } catch (IfwPsn_Vendor_Zend_Exception $e) {
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Filter/Exception.php';
             throw new IfwPsn_Vendor_Zend_Filter_Exception('This filter needs PEARs Archive_Tar', 0, $e);
         }
     }
     parent::__construct($options);
 }
Beispiel #4
0
 /**
  * Defined by IfwPsn_Vendor_Zend_Validate_Interface
  *
  * Returns true if and only if the counted words are at least min and
  * not bigger than max (when max is not null).
  *
  * @param  string $value Filename to check for word count
  * @param  array  $file  File data from IfwPsn_Vendor_Zend_File_Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     // Is file readable ?
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
     if (!IfwPsn_Zend_Loader::isReadable($value)) {
         return $this->_throw($file, self::NOT_FOUND);
     }
     $content = file_get_contents($value);
     $this->_count = str_word_count($content);
     if ($this->_max !== null && $this->_count > $this->_max) {
         return $this->_throw($file, self::TOO_MUCH);
     }
     if ($this->_min !== null && $this->_count < $this->_min) {
         return $this->_throw($file, self::TOO_LESS);
     }
     return true;
 }
Beispiel #5
0
 /**
  * Defined by IfwPsn_Vendor_Zend_Validate_Interface
  *
  * Returns true if and only if the filesize of $value is at least min and
  * not bigger than max (when max is not null).
  *
  * @param  string $value Real file to check for size
  * @param  array  $file  File data from IfwPsn_Vendor_Zend_File_Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     // Is file readable ?
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
     if (!IfwPsn_Zend_Loader::isReadable($value)) {
         return $this->_throw($file, self::NOT_FOUND);
     }
     // limited to 4GB files
     $size = sprintf("%u", @filesize($value));
     $this->_size = $size;
     // Check to see if it's smaller than min size
     $min = $this->getMin(true);
     $max = $this->getMax(true);
     if ($min !== null && $size < $min) {
         if ($this->useByteString()) {
             $this->_min = $this->_toByteString($min);
             $this->_size = $this->_toByteString($size);
             $this->_throw($file, self::TOO_SMALL);
             $this->_min = $min;
             $this->_size = $size;
         } else {
             $this->_throw($file, self::TOO_SMALL);
         }
     }
     // Check to see if it's larger than max size
     if ($max !== null && $max < $size) {
         if ($this->useByteString()) {
             $this->_max = $this->_toByteString($max);
             $this->_size = $this->_toByteString($size);
             $this->_throw($file, self::TOO_BIG);
             $this->_max = $max;
             $this->_size = $size;
         } else {
             $this->_throw($file, self::TOO_BIG);
         }
     }
     if (count($this->_messages) > 0) {
         return false;
     }
     return true;
 }
Beispiel #6
0
 /**
  * Defined by IfwPsn_Vendor_Zend_Validate_Interface
  *
  * Returns true if and only if the disk usage of all files is at least min and
  * not bigger than max (when max is not null).
  *
  * @param  string|array $value Real file to check for size
  * @param  array        $file  File data from IfwPsn_Vendor_Zend_File_Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
     if (is_string($value)) {
         $value = array($value);
     }
     $min = $this->getMin(true);
     $max = $this->getMax(true);
     $size = $this->_getSize();
     foreach ($value as $files) {
         // Is file readable ?
         if (!IfwPsn_Zend_Loader::isReadable($files)) {
             $this->_throw($file, self::NOT_READABLE);
             continue;
         }
         if (!isset($this->_files[$files])) {
             $this->_files[$files] = $files;
         } else {
             // file already counted... do not count twice
             continue;
         }
         // limited to 2GB files
         $size += @filesize($files);
         $this->_size = $size;
         if ($max !== null && $max < $size) {
             if ($this->useByteString()) {
                 $this->_max = $this->_toByteString($max);
                 $this->_size = $this->_toByteString($size);
                 $this->_throw($file, self::TOO_BIG);
                 $this->_max = $max;
                 $this->_size = $size;
             } else {
                 $this->_throw($file, self::TOO_BIG);
             }
         }
     }
     // Check that aggregate files are >= minimum size
     if ($min !== null && $size < $min) {
         if ($this->useByteString()) {
             $this->_min = $this->_toByteString($min);
             $this->_size = $this->_toByteString($size);
             $this->_throw($file, self::TOO_SMALL);
             $this->_min = $min;
             $this->_size = $size;
         } else {
             $this->_throw($file, self::TOO_SMALL);
         }
     }
     if (count($this->_messages) > 0) {
         return false;
     }
     return true;
 }
Beispiel #7
0
 /**
  * Defined by IfwPsn_Vendor_Zend_Validate_Interface
  *
  * Returns true if and only if the given file confirms the set hash
  *
  * @param  string $value Filename to check for hash
  * @param  array  $file  File data from IfwPsn_Vendor_Zend_File_Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     // Is file readable ?
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
     if (!IfwPsn_Zend_Loader::isReadable($value)) {
         return $this->_throw($file, self::NOT_FOUND);
     }
     $hashes = array_unique(array_keys($this->_hash));
     $filehash = hash_file('sha1', $value);
     if ($filehash === false) {
         return $this->_throw($file, self::NOT_DETECTED);
     }
     foreach ($hashes as $hash) {
         if ($filehash === $hash) {
             return true;
         }
     }
     return $this->_throw($file, self::DOES_NOT_MATCH);
 }
Beispiel #8
0
 /**
  * Sets a new barcode adapter
  *
  * @param  string|IfwPsn_Vendor_Zend_Validate_Barcode $adapter Barcode adapter to use
  * @param  array  $options Options for this adapter
  * @return void
  * @throws IfwPsn_Vendor_Zend_Validate_Exception
  */
 public function setAdapter($adapter, $options = null)
 {
     $adapter = ucfirst(strtolower($adapter));
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
     if (IfwPsn_Zend_Loader::isReadable('IfwPsn/Vendor/Zend/Validate/Barcode/' . $adapter . '.php')) {
         $adapter = 'IfwPsn_Vendor_Zend_Validate_Barcode_' . $adapter;
     }
     if (!class_exists($adapter)) {
         IfwPsn_Zend_Loader::loadClass($adapter);
     }
     $this->_adapter = new $adapter($options);
     if (!$this->_adapter instanceof IfwPsn_Vendor_Zend_Validate_Barcode_AdapterInterface) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Validate/Exception.php';
         throw new IfwPsn_Vendor_Zend_Validate_Exception("Adapter " . $adapter . " does not implement IfwPsn_Vendor_Zend_Validate_Barcode_AdapterInterface");
     }
     return $this;
 }
Beispiel #9
0
 /**
  * Factory for IfwPsn_Vendor_Zend_Navigation_Page classes
  *
  * A specific type to construct can be specified by specifying the key
  * 'type' in $options. If type is 'uri' or 'mvc', the type will be resolved
  * to IfwPsn_Vendor_Zend_Navigation_Page_Uri or IfwPsn_Vendor_Zend_Navigation_Page_Mvc. Any other value
  * for 'type' will be considered the full name of the class to construct.
  * A valid custom page class must extend IfwPsn_Vendor_Zend_Navigation_Page.
  *
  * If 'type' is not given, the type of page to construct will be determined
  * by the following rules:
  * - If $options contains either of the keys 'action', 'controller',
  *   'module', or 'route', a IfwPsn_Vendor_Zend_Navigation_Page_Mvc page will be created.
  * - If $options contains the key 'uri', a IfwPsn_Vendor_Zend_Navigation_Page_Uri page
  *   will be created.
  *
  * @param  array|IfwPsn_Vendor_Zend_Config $options  options used for creating page
  * @return IfwPsn_Vendor_Zend_Navigation_Page        a page instance
  * @throws IfwPsn_Vendor_Zend_Navigation_Exception   if $options is not array/IfwPsn_Vendor_Zend_Config
  * @throws IfwPsn_Vendor_Zend_Exception              if 'type' is specified and
  *                                     IfwPsn_Vendor_Zend_Loader is unable to load the
  *                                     class
  * @throws IfwPsn_Vendor_Zend_Navigation_Exception   if something goes wrong during
  *                                     instantiation of the page
  * @throws IfwPsn_Vendor_Zend_Navigation_Exception   if 'type' is given, and the specified
  *                                     type does not extend this class
  * @throws IfwPsn_Vendor_Zend_Navigation_Exception   if unable to determine which class
  *                                     to instantiate
  */
 public static function factory($options)
 {
     if ($options instanceof IfwPsn_Vendor_Zend_Config) {
         $options = $options->toArray();
     }
     if (!is_array($options)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Navigation/Exception.php';
         throw new IfwPsn_Vendor_Zend_Navigation_Exception('Invalid argument: $options must be an array or IfwPsn_Vendor_Zend_Config');
     }
     if (isset($options['type'])) {
         $type = $options['type'];
     } elseif (self::getDefaultPageType() != null) {
         $type = self::getDefaultPageType();
     }
     if (isset($type)) {
         if (is_string($type) && !empty($type)) {
             switch (strtolower($type)) {
                 case 'mvc':
                     $type = 'IfwPsn_Vendor_Zend_Navigation_Page_Mvc';
                     break;
                 case 'uri':
                     $type = 'IfwPsn_Vendor_Zend_Navigation_Page_Uri';
                     break;
             }
             if (!class_exists($type)) {
                 require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
                 @IfwPsn_Zend_Loader::loadClass($type);
             }
             $page = new $type($options);
             if (!$page instanceof IfwPsn_Vendor_Zend_Navigation_Page) {
                 require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Navigation/Exception.php';
                 throw new IfwPsn_Vendor_Zend_Navigation_Exception(sprintf('Invalid argument: Detected type "%s", which ' . 'is not an instance of IfwPsn_Vendor_Zend_Navigation_Page', $type));
             }
             return $page;
         }
     }
     $hasUri = isset($options['uri']);
     $hasMvc = isset($options['action']) || isset($options['controller']) || isset($options['module']) || isset($options['route']) || isset($options['params']);
     if ($hasMvc) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Navigation/Page/Mvc.php';
         return new IfwPsn_Vendor_Zend_Navigation_Page_Mvc($options);
     } elseif ($hasUri) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Navigation/Page/Uri.php';
         return new IfwPsn_Vendor_Zend_Navigation_Page_Uri($options);
     } else {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Navigation/Exception.php';
         $message = 'Invalid argument: Unable to determine class to instantiate';
         if (isset($options['label'])) {
             $message .= ' (Page label: ' . $options['label'] . ')';
         }
         throw new IfwPsn_Vendor_Zend_Navigation_Exception($message);
     }
 }
Beispiel #10
0
 /**
  * Set the class name to use for the default registry instance.
  * Does not affect the currently initialized instance, it only applies
  * for the next time you instantiate.
  *
  * @param string $registryClassName
  * @return void
  * @throws IfwPsn_Vendor_Zend_Exception if the registry is initialized or if the
  *   class name is not valid.
  */
 public static function setClassName($registryClassName = 'IfwPsn_Vendor_Zend_Registry')
 {
     if (self::$_registry !== null) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Exception.php';
         throw new IfwPsn_Vendor_Zend_Exception('Registry is already initialized');
     }
     if (!is_string($registryClassName)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Exception.php';
         throw new IfwPsn_Vendor_Zend_Exception("Argument is not a class name");
     }
     /**
      * @see IfwPsn_Vendor_Zend_Loader
      */
     if (!class_exists($registryClassName)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
         IfwPsn_Zend_Loader::loadClass($registryClassName);
     }
     self::$_registryClassName = $registryClassName;
 }
Beispiel #11
0
 /**
  * Create a new IfwPsn_Vendor_Zend_Uri object for a URI.  If building a new URI, then $uri should contain
  * only the scheme (http, ftp, etc).  Otherwise, supply $uri with the complete URI.
  *
  * @param  string $uri       The URI form which a IfwPsn_Vendor_Zend_Uri instance is created
  * @param  string $className The name of the class to use in order to manipulate URI
  * @throws IfwPsn_Vendor_Zend_Uri_Exception When an empty string was supplied for the scheme
  * @throws IfwPsn_Vendor_Zend_Uri_Exception When an illegal scheme is supplied
  * @throws IfwPsn_Vendor_Zend_Uri_Exception When the scheme is not supported
  * @throws IfwPsn_Vendor_Zend_Uri_Exception When $className doesn't exist or doesn't implements IfwPsn_Vendor_Zend_Uri
  * @return IfwPsn_Vendor_Zend_Uri
  * @link   http://www.faqs.org/rfcs/rfc2396.html
  */
 public static function factory($uri = 'http', $className = null)
 {
     // Separate the scheme from the scheme-specific parts
     $uri = explode(':', $uri, 2);
     $scheme = strtolower($uri[0]);
     $schemeSpecific = isset($uri[1]) === true ? $uri[1] : '';
     if (strlen($scheme) === 0) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Uri/Exception.php';
         throw new IfwPsn_Vendor_Zend_Uri_Exception('An empty string was supplied for the scheme');
     }
     // Security check: $scheme is used to load a class file, so only alphanumerics are allowed.
     if (ctype_alnum($scheme) === false) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Uri/Exception.php';
         throw new IfwPsn_Vendor_Zend_Uri_Exception('Illegal scheme supplied, only alphanumeric characters are permitted');
     }
     if ($className === null) {
         /**
          * Create a new IfwPsn_Vendor_Zend_Uri object for the $uri. If a subclass of IfwPsn_Vendor_Zend_Uri exists for the
          * scheme, return an instance of that class. Otherwise, a IfwPsn_Vendor_Zend_Uri_Exception is thrown.
          */
         switch ($scheme) {
             case 'http':
                 // Break intentionally omitted
             // Break intentionally omitted
             case 'https':
                 $className = 'IfwPsn_Vendor_Zend_Uri_Http';
                 break;
             case 'mailto':
                 // TODO
             // TODO
             default:
                 require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Uri/Exception.php';
                 throw new IfwPsn_Vendor_Zend_Uri_Exception("Scheme \"{$scheme}\" is not supported");
                 break;
         }
     }
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
     try {
         IfwPsn_Zend_Loader::loadClass($className);
     } catch (Exception $e) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Uri/Exception.php';
         throw new IfwPsn_Vendor_Zend_Uri_Exception("\"{$className}\" not found");
     }
     $schemeHandler = new $className($scheme, $schemeSpecific);
     if (!$schemeHandler instanceof IfwPsn_Vendor_Zend_Uri) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Uri/Exception.php';
         throw new IfwPsn_Vendor_Zend_Uri_Exception("\"{$className}\" is not an instance of IfwPsn_Vendor_Zend_Uri");
     }
     return $schemeHandler;
 }
Beispiel #12
0
 /**
  * Sets a new adapter
  *
  * @param  array|IfwPsn_Vendor_Zend_Config $options Options to use
  * @throws IfwPsn_Vendor_Zend_Translate_Exception
  */
 public function setAdapter($options = array())
 {
     if ($options instanceof IfwPsn_Vendor_Zend_Config) {
         $options = $options->toArray();
     } else {
         if (func_num_args() > 1) {
             $args = func_get_args();
             $options = array();
             $options['adapter'] = array_shift($args);
             if (!empty($args)) {
                 $options['content'] = array_shift($args);
             }
             if (!empty($args)) {
                 $options['locale'] = array_shift($args);
             }
             if (!empty($args)) {
                 $opt = array_shift($args);
                 $options = array_merge($opt, $options);
             }
         } else {
             if (!is_array($options)) {
                 $options = array('adapter' => $options);
             }
         }
     }
     if (IfwPsn_Zend_Loader::isReadable('IfwPsn/Vendor/Zend/Translate/Adapter/' . ucfirst($options['adapter']) . '.php')) {
         $options['adapter'] = 'IfwPsn_Vendor_Zend_Translate_Adapter_' . ucfirst($options['adapter']);
     }
     if (!class_exists($options['adapter'])) {
         IfwPsn_Zend_Loader::loadClass($options['adapter']);
     }
     if (array_key_exists('cache', $options)) {
         IfwPsn_Vendor_Zend_Translate_Adapter::setCache($options['cache']);
     }
     $adapter = $options['adapter'];
     unset($options['adapter']);
     $this->_adapter = new $adapter($options);
     if (!$this->_adapter instanceof IfwPsn_Vendor_Zend_Translate_Adapter) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Translate/Exception.php';
         throw new IfwPsn_Vendor_Zend_Translate_Exception("Adapter " . $adapter . " does not extend IfwPsn_Vendor_Zend_Translate_Adapter");
     }
 }
Beispiel #13
0
 /**
  * Defined by IfwPsn_Vendor_Zend_Validate_Interface
  *
  * Returns true if and only if the fileextension of $value is included in the
  * set extension list
  *
  * @param  string  $value Real file to check for extension
  * @param  array   $file  File data from IfwPsn_Vendor_Zend_File_Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     // Is file readable ?
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
     if (!IfwPsn_Zend_Loader::isReadable($value)) {
         return $this->_throw($file, self::NOT_FOUND);
     }
     if ($file !== null) {
         $info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1);
     } else {
         $info = pathinfo($value);
         if (!array_key_exists('extension', $info)) {
             // From the manual at http://php.net/pathinfo:
             // "If the path does not have an extension, no extension element
             // will be returned (see second example below)."
             return false;
         }
     }
     $extensions = $this->getExtension();
     if ($this->_case && in_array($info['extension'], $extensions)) {
         return true;
     } else {
         if (!$this->getCase()) {
             foreach ($extensions as $extension) {
                 if (strtolower($extension) == strtolower($info['extension'])) {
                     return true;
                 }
             }
         }
     }
     return $this->_throw($file, self::FALSE_EXTENSION);
 }
Beispiel #14
0
 /**
  * Returns the current adapter, instantiating it if necessary
  *
  * @return string
  */
 public function getAdapter()
 {
     if ($this->_adapter instanceof IfwPsn_Vendor_Zend_Filter_Compress_CompressInterface) {
         return $this->_adapter;
     }
     $adapter = $this->_adapter;
     $options = $this->getAdapterOptions();
     if (!class_exists($adapter)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
         if (IfwPsn_Zend_Loader::isReadable('IfwPsn/Vendor/Zend/Filter/Compress/' . ucfirst($adapter) . '.php')) {
             $adapter = 'IfwPsn_Vendor_Zend_Filter_Compress_' . ucfirst($adapter);
         }
         IfwPsn_Zend_Loader::loadClass($adapter);
     }
     $this->_adapter = new $adapter($options);
     if (!$this->_adapter instanceof IfwPsn_Vendor_Zend_Filter_Compress_CompressInterface) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Filter/Exception.php';
         throw new IfwPsn_Vendor_Zend_Filter_Exception("Compression adapter '" . $adapter . "' does not implement IfwPsn_Vendor_Zend_Filter_Compress_CompressInterface");
     }
     return $this->_adapter;
 }
Beispiel #15
0
 /**
  * _processValidator() - internal function that is called in the existence of VALID metadata
  *
  * @throws IfwPsn_Vendor_Zend_Session_Exception
  * @return void
  */
 private static function _processValidators()
 {
     foreach ($_SESSION['__ZF']['VALID'] as $validator_name => $valid_data) {
         if (!class_exists($validator_name)) {
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
             IfwPsn_Zend_Loader::loadClass($validator_name);
         }
         $validator = new $validator_name();
         if ($validator->validate() === false) {
             /** @see IfwPsn_Vendor_Zend_Session_Exception */
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Session/Exception.php';
             throw new IfwPsn_Vendor_Zend_Session_Exception("This session is not valid according to {$validator_name}.");
         }
     }
 }
Beispiel #16
0
 /**
  * Sets new encryption options
  *
  * @param  string|array $options (Optional) Encryption options
  * @return IfwPsn_Vendor_Zend_Filter_Encrypt
  */
 public function setAdapter($options = null)
 {
     if (is_string($options)) {
         $adapter = $options;
     } else {
         if (isset($options['adapter'])) {
             $adapter = $options['adapter'];
             unset($options['adapter']);
         } else {
             $adapter = 'Mcrypt';
         }
     }
     if (!is_array($options)) {
         $options = array();
     }
     if (IfwPsn_Zend_Loader::isReadable('IfwPsn/Vendor/Zend/Filter/Encrypt/' . ucfirst($adapter) . '.php')) {
         $adapter = 'IfwPsn_Vendor_Zend_Filter_Encrypt_' . ucfirst($adapter);
     }
     if (!class_exists($adapter)) {
         IfwPsn_Zend_Loader::loadClass($adapter);
     }
     $this->_adapter = new $adapter($options);
     if (!$this->_adapter instanceof IfwPsn_Vendor_Zend_Filter_Encrypt_Interface) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Filter/Exception.php';
         throw new IfwPsn_Vendor_Zend_Filter_Exception("Encoding adapter '" . $adapter . "' does not implement IfwPsn_Vendor_Zend_Filter_Encrypt_Interface");
     }
     return $this;
 }
Beispiel #17
0
 /**
  * Defined by IfwPsn_Vendor_Zend_Validate_Interface
  *
  * Returns true if and only if the imagesize of $value is at least min and
  * not bigger than max
  *
  * @param  string $value Real file to check for image size
  * @param  array  $file  File data from IfwPsn_Vendor_Zend_File_Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     // Is file readable ?
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
     if (!IfwPsn_Zend_Loader::isReadable($value)) {
         return $this->_throw($file, self::NOT_READABLE);
     }
     $size = @getimagesize($value);
     $this->_setValue($file);
     if (empty($size) or $size[0] === 0 or $size[1] === 0) {
         return $this->_throw($file, self::NOT_DETECTED);
     }
     $this->_width = $size[0];
     $this->_height = $size[1];
     if ($this->_width < $this->_minwidth) {
         $this->_throw($file, self::WIDTH_TOO_SMALL);
     }
     if ($this->_maxwidth !== null and $this->_maxwidth < $this->_width) {
         $this->_throw($file, self::WIDTH_TOO_BIG);
     }
     if ($this->_height < $this->_minheight) {
         $this->_throw($file, self::HEIGHT_TOO_SMALL);
     }
     if ($this->_maxheight !== null and $this->_maxheight < $this->_height) {
         $this->_throw($file, self::HEIGHT_TOO_BIG);
     }
     if (count($this->_messages) > 0) {
         return false;
     }
     return true;
 }
Beispiel #18
0
 /**
  * Load a plugin via the name provided
  *
  * @param  string $name
  * @param  bool $throwExceptions Whether or not to throw exceptions if the
  * class is not resolved
  * @return string|false Class name of loaded class; false if $throwExceptions
  * if false and no class found
  * @throws IfwPsn_Vendor_Zend_Loader_Exception if class not found
  */
 public function load($name, $throwExceptions = true)
 {
     $name = $this->_formatName($name);
     if ($this->isLoaded($name)) {
         return $this->getClassName($name);
     }
     if ($this->_useStaticRegistry) {
         $registry = self::$_staticPrefixToPaths[$this->_useStaticRegistry];
     } else {
         $registry = $this->_prefixToPaths;
     }
     $registry = array_reverse($registry, true);
     $found = false;
     if (false !== strpos($name, '\\')) {
         $classFile = str_replace('\\', DIRECTORY_SEPARATOR, $name) . '.php';
     } else {
         $classFile = str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php';
     }
     $incFile = self::getIncludeFileCache();
     foreach ($registry as $prefix => $paths) {
         $className = $prefix . $name;
         if (class_exists($className, false)) {
             $found = true;
             break;
         }
         $paths = array_reverse($paths, true);
         foreach ($paths as $path) {
             $loadFile = $path . $classFile;
             if (IfwPsn_Zend_Loader::isReadable($loadFile)) {
                 include_once $loadFile;
                 if (class_exists($className, false)) {
                     if (null !== $incFile) {
                         self::_appendIncFile($loadFile);
                     }
                     $found = true;
                     break 2;
                 }
             }
         }
     }
     if (!$found) {
         if (!$throwExceptions) {
             return false;
         }
         $message = "Plugin by name '{$name}' was not found in the registry; used paths:";
         foreach ($registry as $prefix => $paths) {
             $message .= "\n{$prefix}: " . implode(PATH_SEPARATOR, $paths);
         }
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Loader/PluginLoader/Exception.php';
         throw new IfwPsn_Vendor_Zend_Loader_PluginLoader_Exception($message);
     }
     if ($this->_useStaticRegistry) {
         self::$_staticLoadedPlugins[$this->_useStaticRegistry][$name] = $className;
     } else {
         $this->_loadedPlugins[$name] = $className;
     }
     return $className;
 }
Beispiel #19
0
 /**
  * Returns a value filtered through a specified filter class, without requiring separate
  * instantiation of the filter object.
  *
  * The first argument of this method is a data input value, that you would have filtered.
  * The second argument is a string, which corresponds to the basename of the filter class,
  * relative to the IfwPsn_Vendor_Zend_Filter namespace. This method automatically loads the class,
  * creates an instance, and applies the filter() method to the data input. You can also pass
  * an array of constructor arguments, if they are needed for the filter class.
  *
  * @param  mixed        $value
  * @param  string       $classBaseName
  * @param  array        $args          OPTIONAL
  * @param  array|string $namespaces    OPTIONAL
  * @return mixed
  * @throws IfwPsn_Vendor_Zend_Filter_Exception
  */
 public static function filterStatic($value, $classBaseName, array $args = array(), $namespaces = array())
 {
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
     $namespaces = array_merge((array) $namespaces, self::$_defaultNamespaces, array('IfwPsn_Vendor_Zend_Filter'));
     foreach ($namespaces as $namespace) {
         $className = $namespace . '_' . ucfirst($classBaseName);
         if (!class_exists($className, false)) {
             try {
                 $file = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
                 if (IfwPsn_Zend_Loader::isReadable($file)) {
                     IfwPsn_Zend_Loader::loadClass($className);
                 } else {
                     continue;
                 }
             } catch (IfwPsn_Vendor_Zend_Exception $ze) {
                 continue;
             }
         }
         $class = new ReflectionClass($className);
         if ($class->implementsInterface('IfwPsn_Vendor_Zend_Filter_Interface')) {
             if ($class->hasMethod('__construct')) {
                 $object = $class->newInstanceArgs($args);
             } else {
                 $object = $class->newInstance();
             }
             return $object->filter($value);
         }
     }
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Filter/Exception.php';
     throw new IfwPsn_Vendor_Zend_Filter_Exception("Filter class not found from basename '{$classBaseName}'");
 }
Beispiel #20
0
 /**
  * @param  mixed    $value
  * @param  string   $classBaseName
  * @param  array    $args          OPTIONAL
  * @param  mixed    $namespaces    OPTIONAL
  * @return boolean
  * @throws IfwPsn_Vendor_Zend_Validate_Exception
  */
 public static function is($value, $classBaseName, array $args = array(), $namespaces = array())
 {
     $namespaces = array_merge((array) $namespaces, self::$_defaultNamespaces, array('IfwPsn_Vendor_Zend_Validate'));
     $className = ucfirst($classBaseName);
     try {
         if (!class_exists($className, false)) {
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
             foreach ($namespaces as $namespace) {
                 $class = $namespace . '_' . $className;
                 $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
                 if (IfwPsn_Zend_Loader::isReadable($file)) {
                     IfwPsn_Zend_Loader::loadClass($class);
                     $className = $class;
                     break;
                 }
             }
         }
         $class = new ReflectionClass($className);
         if ($class->implementsInterface('IfwPsn_Vendor_Zend_Validate_Interface')) {
             if ($class->hasMethod('__construct')) {
                 $keys = array_keys($args);
                 $numeric = false;
                 foreach ($keys as $key) {
                     if (is_numeric($key)) {
                         $numeric = true;
                         break;
                     }
                 }
                 if ($numeric) {
                     $object = $class->newInstanceArgs($args);
                 } else {
                     $object = $class->newInstance($args);
                 }
             } else {
                 $object = $class->newInstance();
             }
             return $object->isValid($value);
         }
     } catch (IfwPsn_Vendor_Zend_Validate_Exception $ze) {
         // if there is an exception while validating throw it
         throw $ze;
     } catch (Exception $e) {
         // fallthrough and continue for missing validation classes
     }
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Validate/Exception.php';
     throw new IfwPsn_Vendor_Zend_Validate_Exception("Validate class not found from basename '{$classBaseName}'");
 }
Beispiel #21
0
 /**
  * Get a route frm a config instance
  *
  * @param  IfwPsn_Vendor_Zend_Config $info
  * @return IfwPsn_Vendor_Zend_Controller_Router_Route_Interface
  */
 protected function _getRouteFromConfig(IfwPsn_Vendor_Zend_Config $info)
 {
     $class = isset($info->type) ? $info->type : 'IfwPsn_Vendor_Zend_Controller_Router_Route';
     if (!class_exists($class)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
         IfwPsn_Zend_Loader::loadClass($class);
     }
     $route = call_user_func(array($class, 'getInstance'), $info);
     if (isset($info->abstract) && $info->abstract && method_exists($route, 'isAbstract')) {
         $route->isAbstract(true);
     }
     return $route;
 }
Beispiel #22
0
 /**
  * Add a display group
  *
  * Groups named elements for display purposes.
  *
  * If a referenced element does not yet exist in the form, it is omitted.
  *
  * @param  array $elements
  * @param  string $name
  * @param  array|IfwPsn_Vendor_Zend_Config $options
  * @return IfwPsn_Vendor_Zend_Form
  * @throws IfwPsn_Vendor_Zend_Form_Exception if no valid elements provided
  */
 public function addDisplayGroup(array $elements, $name, $options = null)
 {
     $group = array();
     foreach ($elements as $element) {
         if ($element instanceof IfwPsn_Vendor_Zend_Form_Element) {
             $elementName = $element->getName();
             if (!isset($this->_elements[$elementName])) {
                 $this->addElement($element);
             }
             $element = $elementName;
         }
         if (isset($this->_elements[$element])) {
             $add = $this->getElement($element);
             if (null !== $add) {
                 $group[] = $add;
             }
         }
     }
     if (empty($group)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Form/Exception.php';
         throw new IfwPsn_Vendor_Zend_Form_Exception('No valid elements specified for display group');
     }
     $name = (string) $name;
     if (is_array($options)) {
         $options['form'] = $this;
         $options['elements'] = $group;
     } elseif ($options instanceof IfwPsn_Vendor_Zend_Config) {
         $options = $options->toArray();
         $options['form'] = $this;
         $options['elements'] = $group;
     } else {
         $options = array('form' => $this, 'elements' => $group);
     }
     if (isset($options['displayGroupClass'])) {
         $class = $options['displayGroupClass'];
         unset($options['displayGroupClass']);
     } else {
         $class = $this->getDefaultDisplayGroupClass();
     }
     if (!class_exists($class)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
         IfwPsn_Zend_Loader::loadClass($class);
     }
     $this->_displayGroups[$name] = new $class($name, $this->getPluginLoader(self::DECORATOR), $options);
     if (!empty($this->_displayGroupPrefixPaths)) {
         $this->_displayGroups[$name]->addPrefixPaths($this->_displayGroupPrefixPaths);
     }
     $this->_order[$name] = $this->_displayGroups[$name]->getOrder();
     $this->_orderUpdated = true;
     return $this;
 }
Beispiel #23
0
 /**
  * Helper method to calculate the correct class path
  *
  * @param string $class
  * @return False if not matched other wise the correct path
  */
 public function getClassPath($class)
 {
     $segments = explode('_', $class);
     $namespaceTopLevel = $this->getNamespace();
     $namespace = '';
     if (!empty($namespaceTopLevel)) {
         $namespace = array();
         $topLevelSegments = count(explode('_', $namespaceTopLevel));
         for ($i = 0; $i < $topLevelSegments; $i++) {
             $namespace[] = array_shift($segments);
         }
         $namespace = implode('_', $namespace);
         if ($namespace != $namespaceTopLevel) {
             // wrong prefix? we're done
             return false;
         }
     }
     if (count($segments) < 2) {
         // assumes all resources have a component and class name, minimum
         return false;
     }
     $final = array_pop($segments);
     $component = $namespace;
     $lastMatch = false;
     do {
         $segment = array_shift($segments);
         $component .= empty($component) ? $segment : '_' . $segment;
         if (isset($this->_components[$component])) {
             $lastMatch = $component;
         }
     } while (count($segments));
     if (!$lastMatch) {
         return false;
     }
     $final = substr($class, strlen($lastMatch) + 1);
     $path = $this->_components[$lastMatch];
     $classPath = $path . '/' . str_replace('_', '/', $final) . '.php';
     if (IfwPsn_Zend_Loader::isReadable($classPath)) {
         return $classPath;
     }
     return false;
 }
Beispiel #24
0
 /**
  * Set the container class to use
  *
  * @param  string $name
  * @return IfwPsn_Vendor_Zend_View_Helper_Placeholder_Registry
  */
 public function setContainerClass($name)
 {
     if (!class_exists($name)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
         IfwPsn_Zend_Loader::loadClass($name);
     }
     $reflection = new ReflectionClass($name);
     if (!$reflection->isSubclassOf(new ReflectionClass('IfwPsn_Vendor_Zend_View_Helper_Placeholder_Container_Abstract'))) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/View/Helper/Placeholder/Registry/Exception.php';
         $e = new IfwPsn_Vendor_Zend_View_Helper_Placeholder_Registry_Exception('Invalid Container class specified');
         $e->setView($this->view);
         throw $e;
     }
     $this->_containerClass = $name;
     return $this;
 }
Beispiel #25
0
 /**
  * Construct a filter or writer from config
  *
  * @param string $type 'writer' of 'filter'
  * @param mixed $config IfwPsn_Vendor_Zend_Config or Array
  * @param string $namespace
  * @return object
  * @throws IfwPsn_Vendor_Zend_Log_Exception
  */
 protected function _constructFromConfig($type, $config, $namespace)
 {
     if ($config instanceof IfwPsn_Vendor_Zend_Config) {
         $config = $config->toArray();
     }
     if (!is_array($config) || empty($config)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Log/Exception.php';
         throw new IfwPsn_Vendor_Zend_Log_Exception('Configuration must be an array or instance of IfwPsn_Vendor_Zend_Config');
     }
     $params = isset($config[$type . 'Params']) ? $config[$type . 'Params'] : array();
     $className = $this->getClassName($config, $type, $namespace);
     if (!class_exists($className)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
         IfwPsn_Zend_Loader::loadClass($className);
     }
     $reflection = new ReflectionClass($className);
     if (!$reflection->implementsInterface('IfwPsn_Vendor_Zend_Log_FactoryInterface')) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Log/Exception.php';
         throw new IfwPsn_Vendor_Zend_Log_Exception($className . ' does not implement IfwPsn_Vendor_Zend_Log_FactoryInterface and can not be constructed from config.');
     }
     return call_user_func(array($className, 'factory'), $params);
 }
Beispiel #26
0
 /**
  * Set plugin loader
  *
  * @param  string $type Type of plugin loader; one of 'storage', (?)
  * @param  string|IfwPsn_Vendor_Zend_Loader_PluginLoader $loader
  * @return IfwPsn_Vendor_Zend_Http_UserAgent
  */
 public function setPluginLoader($type, $loader)
 {
     $type = $this->_validateLoaderType($type);
     if (is_string($loader)) {
         if (!class_exists($loader)) {
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
             IfwPsn_Zend_Loader::loadClass($loader);
         }
         $loader = new $loader();
     } elseif (!is_object($loader)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Http/UserAgent/Exception.php';
         throw new IfwPsn_Vendor_Zend_Http_UserAgent_Exception(sprintf('Expected a plugin loader class or object; received %s', gettype($loader)));
     }
     if (!$loader instanceof IfwPsn_Vendor_Zend_Loader_PluginLoader) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Http/UserAgent/Exception.php';
         throw new IfwPsn_Vendor_Zend_Http_UserAgent_Exception(sprintf('Expected an object extending IfwPsn_Vendor_Zend_Loader_PluginLoader; received %s', get_class($loader)));
     }
     $basePrefix = 'IfwPsn_Vendor_Zend_Http_UserAgent_';
     $basePath = IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Http/UserAgent/';
     switch ($type) {
         case 'storage':
             $prefix = $basePrefix . 'Storage';
             $path = $basePath . 'Storage';
             break;
         case 'device':
             $prefix = $basePrefix;
             $path = $basePath;
             break;
     }
     $loader->addPrefixPath($prefix, $path);
     $this->_loaders[$type] = $loader;
     return $this;
 }
Beispiel #27
0
 /**
  * Load the connection adapter
  *
  * While this method is not called more than one for a client, it is
  * seperated from ->request() to preserve logic and readability
  *
  * @param IfwPsn_Vendor_Zend_Http_Client_Adapter_Interface|string $adapter
  * @return null
  * @throws IfwPsn_Vendor_Zend_Http_Client_Exception
  */
 public function setAdapter($adapter)
 {
     if (is_string($adapter)) {
         try {
             IfwPsn_Zend_Loader::loadClass($adapter);
         } catch (IfwPsn_Vendor_Zend_Exception $e) {
             /** @see IfwPsn_Vendor_Zend_Http_Client_Exception */
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Http/Client/Exception.php';
             throw new IfwPsn_Vendor_Zend_Http_Client_Exception("Unable to load adapter '{$adapter}': {$e->getMessage()}", 0, $e);
         }
         $adapter = new $adapter();
     }
     if (!$adapter instanceof IfwPsn_Vendor_Zend_Http_Client_Adapter_Interface) {
         /** @see IfwPsn_Vendor_Zend_Http_Client_Exception */
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Http/Client/Exception.php';
         throw new IfwPsn_Vendor_Zend_Http_Client_Exception('Passed adapter is not a HTTP connection adapter');
     }
     $this->adapter = $adapter;
     $config = $this->config;
     unset($config['adapter']);
     $this->adapter->setConfig($config);
 }
Beispiel #28
0
 /**
  * Set response class/object
  *
  * Set the response object.  The response is a container for action
  * responses and headers. Usage is optional.
  *
  * If a class name is provided, instantiates a response object.
  *
  * @param string|IfwPsn_Vendor_Zend_Controller_Response_Abstract $response
  * @throws IfwPsn_Vendor_Zend_Controller_Exception if invalid response class
  * @return IfwPsn_Vendor_Zend_Controller_Front
  */
 public function setResponse($response)
 {
     if (is_string($response)) {
         if (!class_exists($response)) {
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
             IfwPsn_Zend_Loader::loadClass($response);
         }
         $response = new $response();
     }
     if (!$response instanceof IfwPsn_Vendor_Zend_Controller_Response_Abstract) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Exception.php';
         throw new IfwPsn_Vendor_Zend_Controller_Exception('Invalid response class');
     }
     $this->_response = $response;
     return $this;
 }
Beispiel #29
0
 /**
  * Initialize action helper
  *
  * @return void
  */
 protected function _initHelper()
 {
     $helperClass = $this->getHelperClass();
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Action/HelperBroker.php';
     if (!IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::hasHelper('layout')) {
         if (!class_exists($helperClass)) {
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Zend/Loader.php';
             IfwPsn_Zend_Loader::loadClass($helperClass);
         }
         IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStack()->offsetSet(-90, new $helperClass($this));
     }
 }