当前位置: 首页>>代码示例>>PHP>>正文


PHP Loader::isReadable方法代码示例

本文整理汇总了PHP中Zend\Loader::isReadable方法的典型用法代码示例。如果您正苦于以下问题:PHP Loader::isReadable方法的具体用法?PHP Loader::isReadable怎么用?PHP Loader::isReadable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Loader的用法示例。


在下文中一共展示了Loader::isReadable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: isValid

 /**
  * 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 \Zend\File\Transfer\Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     if ($file === null) {
         $file = array('name' => basename($value));
     }
     // Is file readable ?
     if (!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->getCase() and !in_array($info['extension'], $extensions)) {
         return true;
     } else {
         if (!$this->getCase()) {
             $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);
 }
开发者ID:rikaix,项目名称:zf2,代码行数:40,代码来源:ExcludeExtension.php

示例2: setAdapter

 /**
  * Sets new encryption options
  *
  * @param  string|array $options (Optional) Encryption options
  * @return \Zend\Filter\Encrypt\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 (\Zend\Loader::isReadable('Zend/Filter/Encrypt/' . ucfirst($adapter) . '.php')) {
         $adapter = 'Zend\\Filter\\Encrypt\\' . ucfirst($adapter);
     }
     if (!class_exists($adapter)) {
         \Zend\Loader::loadClass($adapter);
     }
     $this->_adapter = new $adapter($options);
     if (!$this->_adapter instanceof Encrypt\EncryptionAlgorithm) {
         throw new Exception\InvalidArgumentException("Encoding adapter '" . $adapter . "' does not implement Zend\\Filter\\Encrypt\\EncryptionAlgorithm");
     }
     return $this;
 }
开发者ID:alab1001101,项目名称:zf2,代码行数:33,代码来源:Encrypt.php

示例3: setAdapter

 /**
  * Sets new encryption options
  *
  * @param  string|array $options (Optional) Encryption options
  * @return 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 (Loader::isReadable('Zend/Filter/Encrypt/' . ucfirst($adapter) . '.php')) {
         $adapter = 'Zend\\Filter\\Encrypt\\' . ucfirst($adapter);
     }
     if (!class_exists($adapter)) {
         throw new Exception\DomainException(sprintf('%s expects a valid registry class name; received "%s", which did not resolve', __METHOD__, $adapter));
     }
     $this->_adapter = new $adapter($options);
     if (!$this->_adapter instanceof Encrypt\EncryptionAlgorithmInterface) {
         throw new Exception\InvalidArgumentException("Encoding adapter '" . $adapter . "' does not implement Zend\\Filter\\Encrypt\\EncryptionAlgorithmInterface");
     }
     return $this;
 }
开发者ID:rikaix,项目名称:zf2,代码行数:33,代码来源:Encrypt.php

示例4: isValid

    /**
     * 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 \Zend\File\Transfer\Transfer
     * @return boolean
     */
    public function isValid($value, $file = null)
    {
        if ($file === null) {
            $file = array(
                'type' => null,
                'name' => $value
            );
        }

        // Is file readable ?
        if (!\Zend\Loader::isReadable($value)) {
            return $this->_throw($file, self::NOT_READABLE);
        }

        $mimefile = $this->getMagicFile();
        if (class_exists('finfo', false)) {
            $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
            if (!empty($mimefile)) {
                $mime = new \finfo($const, $mimefile);
            } else {
                $mime = new \finfo($const);
            }

            if (!empty($mime)) {
                $this->_type = $mime->file($value);
            }
            unset($mime);
        }

        if (empty($this->_type)) {
            if (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) {
                $this->_type = mime_content_type($value);
            } elseif ($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;
    }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:65,代码来源:ExcludeMimeType.php

示例5: setAdapter

 /**
  * Sets a new adapter
  *
  * @param  string  $adapter   Adapter to use
  * @param  boolean $direction OPTIONAL False means Download, true means upload
  * @param  array   $options   OPTIONAL Options to set for this adapter
  * @throws \Zend\File\Transfer\Exception
  */
 public function setAdapter($adapter, $direction = false, $options = array())
 {
     if (\Zend\Loader::isReadable('Zend/File/Transfer/Adapter/' . ucfirst($adapter) . '.php')) {
         $adapter = 'Zend\\File\\Transfer\\Adapter\\' . ucfirst($adapter);
     }
     if (!class_exists($adapter)) {
         \Zend\Loader::loadClass($adapter);
     }
     $direction = (int) $direction;
     $this->_adapter[$direction] = new $adapter($options);
     if (!$this->_adapter[$direction] instanceof Adapter\AbstractAdapter) {
         throw new Transfer\Exception("Adapter " . $adapter . " does not extend Zend_File_Transfer_Adapter_Abstract");
     }
     return $this;
 }
开发者ID:heiglandreas,项目名称:zf2,代码行数:23,代码来源:Transfer.php

示例6: isValid

 /**
  * Defined by 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 \Zend\File\Transfer\Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     // Is file readable ?
     if (!\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;
 }
开发者ID:heiglandreas,项目名称:zf2,代码行数:26,代码来源:WordCount.php

示例7: isValid

 /**
  * 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 \Zend\File\Transfer\Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     if ($file === null) {
         $file = array('type' => null, 'name' => $value);
     }
     // Is file readable ?
     if (!Loader::isReadable($value)) {
         return $this->createError($file, self::NOT_READABLE);
     }
     $mimefile = $this->getMagicFile();
     if (class_exists('finfo', false)) {
         $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
         if (!$this->isMagicFileDisabled() && (!empty($mimefile) && empty($this->finfo))) {
             $this->finfo = finfo_open($const, $mimefile);
         }
         if (empty($this->finfo)) {
             $this->finfo = finfo_open($const);
         }
         $this->type = null;
         if (!empty($this->finfo)) {
             $this->type = finfo_file($this->finfo, $value);
         }
     }
     if (empty($this->type) && (function_exists('mime_content_type') && ini_get('mime_magic.magicfile'))) {
         $this->type = mime_content_type($value);
     }
     if (empty($this->type) && $this->getHeaderCheck()) {
         $this->type = $file['type'];
     }
     if (empty($this->type)) {
         return $this->createError($file, self::NOT_DETECTED);
     }
     $mimetype = $this->getMimeType(true);
     if (in_array($this->type, $mimetype)) {
         return $this->createError($file, self::FALSE_TYPE);
     }
     $types = explode('/', $this->type);
     $types = array_merge($types, explode('-', $this->type));
     $types = array_merge($types, explode(';', $this->type));
     foreach ($mimetype as $mime) {
         if (in_array($mime, $types)) {
             return $this->createError($file, self::FALSE_TYPE);
         }
     }
     return true;
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:55,代码来源:ExcludeMimeType.php

示例8: setAdapter

 /**
  * Sets a new barcode adapter
  *
  * @param  string|\Zend\Validator\Barcode\Adapter $adapter Barcode adapter to use
  * @param  array  $options Options for this adapter
  * @return Zend\Validator\Barcode
  * @throws \Zend\Validator\Exception
  */
 public function setAdapter($adapter, $options = null)
 {
     if (is_string($adapter)) {
         $adapter = ucfirst(strtolower($adapter));
         $adapter = 'Zend\\Validator\\Barcode\\' . $adapter;
         if (\Zend\Loader::isReadable('Zend/Validator/Barcode/' . $adapter . '.php')) {
             $adapter = 'Zend\\Validator\\Barcode\\' . $adapter;
         }
         if (!class_exists($adapter)) {
             throw new Exception\InvalidArgumentException('Barcode adapter matching "' . $adapter . '" not found');
         }
         $this->options['adapter'] = new $adapter($options);
     }
     if (!$this->options['adapter'] instanceof Barcode\AdapterInterface) {
         throw new Exception\InvalidArgumentException("Adapter " . $adapter . " does not implement Zend\\Validate\\Barcode\\AdapterInterface");
     }
     return $this;
 }
开发者ID:rikaix,项目名称:zf2,代码行数:26,代码来源:Barcode.php

示例9: isValid

 /**
  * 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 \Zend\File\Transfer\Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     if ($file === null) {
         $file = array('name' => basename($value));
     }
     // Is file readable ?
     if (!Loader::isReadable($value)) {
         return $this->_throw($file, self::NOT_FOUND);
     }
     $content = file_get_contents($value);
     $this->_count = str_word_count($content);
     if ($this->getMax() !== null && $this->_count > $this->getMax()) {
         return $this->_throw($file, self::TOO_MUCH);
     }
     if ($this->getMin() !== null && $this->_count < $this->getMin()) {
         return $this->_throw($file, self::TOO_LESS);
     }
     return true;
 }
开发者ID:kingsj,项目名称:core,代码行数:27,代码来源:WordCount.php

示例10: testIsReadableShouldFailEarlyWhenProvidedInvalidWindowsAbsolutePath

 /**
  * @group ZF-9263
  * @group ZF-9166
  * @group ZF-9306
  */
 public function testIsReadableShouldFailEarlyWhenProvidedInvalidWindowsAbsolutePath()
 {
     if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
         $this->markTestSkipped('Windows-only test');
     }
     $path = 'C:/this/file/should/not/exist.php';
     $this->assertFalse(Loader::isReadable($path));
 }
开发者ID:rexmac,项目名称:zf2,代码行数:13,代码来源:LoaderTest.php

示例11: isValid

 /**
  * 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 \Zend\File\Transfer\Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     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 (!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->getByteString()) {
                 $this->options['max'] = $this->_toByteString($max);
                 $this->_size = $this->_toByteString($size);
                 $this->_throw($file, self::TOO_BIG);
                 $this->options['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->getByteString()) {
             $this->options['min'] = $this->_toByteString($min);
             $this->_size = $this->_toByteString($size);
             $this->_throw($file, self::TOO_SMALL);
             $this->options['min'] = $min;
             $this->_size = $size;
         } else {
             $this->_throw($file, self::TOO_SMALL);
         }
     }
     if (count($this->getMessages()) > 0) {
         return false;
     }
     return true;
 }
开发者ID:kingsj,项目名称:core,代码行数:60,代码来源:FilesSize.php

示例12: bootstrap

 /**
  * Bootstrap the front controller
  *
  * Resets the front controller, and then bootstraps it.
  *
  * If {@link $bootstrap} is a callback, executes it; if it is a file, it include's
  * it. When done, sets the test case request and response objects into the
  * front controller.
  *
  * @return void
  */
 public final function bootstrap()
 {
     $this->reset();
     if (null !== $this->bootstrap) {
         if ($this->bootstrap instanceof Application\Application) {
             $this->bootstrap->bootstrap();
             $this->_frontController = $this->bootstrap->getBootstrap()->getResource('frontcontroller');
         } elseif (is_callable($this->bootstrap)) {
             call_user_func($this->bootstrap);
         } elseif (is_string($this->bootstrap)) {
             if (\Zend\Loader::isReadable($this->bootstrap)) {
                 include $this->bootstrap;
             }
         }
     }
     $this->frontController->setRequest($this->getRequest())->setResponse($this->getResponse());
 }
开发者ID:heiglandreas,项目名称:zf2,代码行数:28,代码来源:ControllerTestCase.php

示例13: execute

 /**
  * @param  mixed    $value
  * @param  string   $classBaseName
  * @param  array    $args          OPTIONAL
  * @param  mixed    $namespaces    OPTIONAL
  * @return boolean
  * @throws \Zend\Validator\Exception
  */
 public static function execute($value, $classBaseName, array $args = array(), $namespaces = array())
 {
     $namespaces = array_merge((array) $namespaces, self::$_defaultNamespaces, array('Zend_Validate'));
     $className = ucfirst($classBaseName);
     try {
         if (!class_exists($className, false)) {
             foreach ($namespaces as $namespace) {
                 $class = $namespace . '_' . $className;
                 $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
                 if (\Zend\Loader::isReadable($file)) {
                     \Zend\Loader::loadClass($class);
                     $className = $class;
                     break;
                 }
             }
         }
         $class = new \ReflectionClass($className);
         if ($class->implementsInterface('Zend\\Validator\\Validator')) {
             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 (Exception $ze) {
         // if there is an exception while validating throw it
         throw $ze;
     } catch (\Exception $e) {
         // fallthrough and continue for missing validation classes
     }
     throw new Exception("Validate class not found from basename '{$classBaseName}'");
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:53,代码来源:StaticValidator.php

示例14: testIsReadableShouldReturnTrueForAbsolutePaths

 /**
  * @group ZF-9100
  */
 public function testIsReadableShouldReturnTrueForAbsolutePaths()
 {
     set_include_path(__DIR__ . '../../../');
     $path = __DIR__;
     $this->assertTrue(Loader::isReadable($path));
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:9,代码来源:LoaderTest.php

示例15: loadClass

 /**
  * Load a controller class
  *
  * Attempts to load the controller class file from
  * {@link getControllerDirectory()}.  If the controller belongs to a
  * module, looks for the module prefix to the controller class.
  *
  * @param string $className
  * @return string Class name loaded
  * @throws \Zend\Controller\Dispatcher\Exception if class not loaded
  */
 public function loadClass($className)
 {
     $finalClass = $className;
     if ($this->_defaultModule != $this->_curModule || $this->getParam('prefixDefaultModule')) {
         $finalClass = $this->formatClassName($this->_curModule, $className);
     }
     if (class_exists($finalClass, false)) {
         return $finalClass;
     }
     $dispatchDir = $this->getDispatchDirectory();
     $loadFile = $dispatchDir . DIRECTORY_SEPARATOR . $this->classToFilename($className);
     if (\Zend\Loader::isReadable($loadFile)) {
         include_once $loadFile;
     } else {
         throw new Exception('Cannot load controller class "' . $className . '" from file "' . $loadFile . "'");
     }
     if (!class_exists($finalClass, false)) {
         throw new Exception('Invalid controller class ("' . $finalClass . '")');
     }
     return $finalClass;
 }
开发者ID:narixx,项目名称:zf2,代码行数:32,代码来源:Standard.php


注:本文中的Zend\Loader::isReadable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。