本文整理汇总了PHP中Zend\Loader类的典型用法代码示例。如果您正苦于以下问题:PHP Loader类的具体用法?PHP Loader怎么用?PHP Loader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Loader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: setUp
public function setUp()
{
if (!class_exists('Archive_Tar')) {
try {
\Zend\Loader::loadClass('Archive_Tar');
} catch (\Zend\Loader\Exception $e) {
$this->markTestSkipped('This filter needs PEARs Archive_Tar');
}
}
$files = array(dirname(__DIR__) . '/_files/zipextracted.txt', dirname(__DIR__) . '/_files/_compress/Compress/First/Second/zipextracted.txt', dirname(__DIR__) . '/_files/_compress/Compress/First/Second', dirname(__DIR__) . '/_files/_compress/Compress/First/zipextracted.txt', dirname(__DIR__) . '/_files/_compress/Compress/First', dirname(__DIR__) . '/_files/_compress/Compress/zipextracted.txt', dirname(__DIR__) . '/_files/_compress/Compress', dirname(__DIR__) . '/_files/_compress/zipextracted.txt', dirname(__DIR__) . '/_files/_compress', dirname(__DIR__) . '/_files/compressed.tar');
foreach ($files as $file) {
if (file_exists($file)) {
if (is_dir($file)) {
rmdir($file);
} else {
unlink($file);
}
}
}
if (!file_exists(dirname(__DIR__) . '/_files/Compress/First/Second')) {
mkdir(dirname(__DIR__) . '/_files/Compress/First/Second', 0777, true);
file_put_contents(dirname(__DIR__) . '/_files/Compress/First/Second/zipextracted.txt', 'compress me');
file_put_contents(dirname(__DIR__) . '/_files/Compress/First/zipextracted.txt', 'compress me');
file_put_contents(dirname(__DIR__) . '/_files/Compress/zipextracted.txt', 'compress me');
}
}
示例3: 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);
}
示例4: setAdapter
public function setAdapter($adapter)
{
if (is_string($adapter)) {
$storageAdapterClass = 'Zend\\Tool\\Framework\\Client\\Storage\\' . ucfirst($adapter);
\Zend\Loader::loadClass($storageAdapterClass);
$adapter = new $storageAdapterClass();
}
$this->_adapter = $adapter;
}
示例5: testSelectQueryWithBinds
/**
* ZF-2017: Test bind use of the Zend_Db_Select class.
*/
public function testSelectQueryWithBinds()
{
$select = $this->_select()->where('product_id = :product_id')->bind(array(':product_id' => 1));
$sql = preg_replace('/\\s+/', ' ', $select->__toString());
$this->assertEquals('SELECT "zfproducts".* FROM "zfproducts" WHERE (product_id = :product_id)', $sql);
$stmt = $select->query();
\Zend\Loader::loadClass('Zend_Db_Statement_Static');
$this->assertInstanceOf('Zend_Db_Statement_Static', $stmt);
}
示例6: 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;
}
示例7: __construct
/**
* Class constructor
*
* @param array $options (Optional) Options to set
*/
public function __construct($options = null)
{
if (!class_exists('Archive_Tar')) {
try {
\Zend\Loader::loadClass('Archive_Tar');
} catch (\Exception $e) {
throw new Exception\ExtensionNotLoadedException('This filter needs PEARs Archive_Tar', 0, $e);
}
}
parent::__construct($options);
}
示例8: addContextClass
public function addContextClass($contextClass)
{
if (!class_exists($contextClass)) {
\Zend\Loader::loadClass($contextClass);
}
$reflectionContextClass = new \ReflectionClass($contextClass);
if ($reflectionContextClass->isInstantiable()) {
$context = new $contextClass();
return $this->addContext($context);
}
return $this;
}
示例9: _getFiles
/**
* _getFiles()
*
* @return array Array of files to load
*/
protected function _getFiles()
{
$paths = \Zend\Loader::explodeIncludePath();
// used for checking similarly named files
$relativeItems = array();
$files = array();
$isZendTraversed = false;
foreach ($paths as $path) {
// default patterns to use
$filterDenyDirectoryPattern = '.*(/|\\\\).svn';
$filterAcceptFilePattern = '.*(?:Manifest|Provider)\\.php$';
if (!file_exists($path) || $path[0] == '.') {
continue;
}
$realIncludePath = realpath($path);
// ensure that we only traverse a single version of Zend Framework on all include paths
if (file_exists($realIncludePath . '/Zend/Tool/Framework/Loader/IncludePathLoader.php')) {
if ($isZendTraversed === false) {
$isZendTraversed = true;
} else {
// use the deny directory pattern that includes the path to 'Zend', it will not be accepted
$filterDenyDirectoryPattern = '.*((/|\\\\).svn|' . preg_quote($realIncludePath . DIRECTORY_SEPARATOR) . 'Zend)';
}
}
// create recursive directory iterator
$rdi = new \RecursiveDirectoryIterator($path);
// pass in the RecursiveDirectoryIterator & the patterns
$filter = new RecursiveFilterIterator($rdi, $filterDenyDirectoryPattern, $filterAcceptFilePattern);
// build the rii with the filter
$iterator = new \RecursiveIteratorIterator($filter);
// iterate over the accepted items
foreach ($iterator as $item) {
$file = (string) $item;
if ($this->_fileIsBlacklisted($file)) {
continue;
}
// ensure that the same named file from separate include_paths is not loaded
$relativeItem = preg_replace('#^' . preg_quote($realIncludePath . DIRECTORY_SEPARATOR, '#') . '#', '', $item->getRealPath());
// no links allowed here for now
if ($item->isLink()) {
continue;
}
// no items that are relavitely the same are allowed
if (in_array($relativeItem, $relativeItems)) {
continue;
}
$relativeItems[] = $relativeItem;
$files[] = $item->getRealPath();
}
}
return $files;
}
示例10: _getTable
protected function _getTable($tableClass, $options = array())
{
if (is_array($options) && !isset($options['db'])) {
$options['db'] = $this->_db;
}
if (!class_exists($tableClass)) {
$this->_useMyIncludePath();
\Zend\Loader::loadClass($tableClass);
$this->_restoreIncludePath();
}
$table = new $tableClass($options);
return $table;
}
示例11: 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;
}
示例12: 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;
}
示例13: convertToObject
/**
* Converts a DOMElement object into the specific class
*
* @throws \Zend\InfoCard\XML\Exception
* @param DOMElement $e The DOMElement object to convert
* @param string $classname The name of the class to convert it to (must inhert from \Zend\InfoCard\XML\Element)
* @return \Zend\InfoCard\XML\Element a Xml Element object from the DOM element
*/
public static function convertToObject(\DOMElement $e, $classname)
{
if (!class_exists($classname)) {
\Zend\Loader::loadClass($classname);
}
if (!is_subclass_of($classname, 'Zend\\InfoCard\\XML\\Element')) {
throw new Exception\InvalidArgumentException("DOM element must be converted to an instance of Zend_InfoCard_Xml_Element");
}
$sxe = simplexml_import_dom($e, $classname);
if (!$sxe instanceof Element) {
// Since we just checked to see if this was a subclass of Zend_infoCard_Xml_Element this shoudl never fail
// @codeCoverageIgnoreStart
throw new Exception\RuntimeException("Failed to convert between DOM and SimpleXML");
// @codeCoverageIgnoreEnd
}
return $sxe;
}
示例14: 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;
}
示例15: 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;
}