Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Static Public Member Functions | Static Protected Member Functions
Zend_Loader Class Reference

Static Public Member Functions

static loadClass ($class, $dirs=null)
 
static loadFile ($filename, $dirs=null, $once=false)
 
static isReadable ($filename)
 
static explodeIncludePath ($path=null)
 
static autoload ($class)
 
static registerAutoload ($class='Zend_Loader', $enabled=true)
 
static standardiseFile ($file)
 

Static Protected Member Functions

static _securityCheck ($filename)
 
static _includeFile ($filespec, $once=false)
 

Detailed Description

Definition at line 30 of file Loader.php.

Member Function Documentation

◆ _includeFile()

static _includeFile (   $filespec,
  $once = false 
)
staticprotected

Attempt to include() the file.

include() is not prefixed with the @ operator because if the file is loaded and contains a parse error, execution will halt silently and this is difficult to debug.

Always set display_errors = Off on production servers!

Parameters
string$filespec
boolean$once
Returns
boolean
Deprecated:
Since 1.5.0; use loadFile() instead

Definition at line 309 of file Loader.php.

310  {
311  if ($once) {
312  return include_once $filespec;
313  } else {
314  return include $filespec ;
315  }
316  }

◆ _securityCheck()

static _securityCheck (   $filename)
staticprotected

Ensure that filename does not contain exploits

Parameters
string$filename
Returns
void
Exceptions
Zend_Exception

Security check

Definition at line 284 of file Loader.php.

285  {
289  if (preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename)) {
290  #require_once 'Zend/Exception.php';
291  throw new Zend_Exception('Security check: Illegal character in filename');
292  }
293  }

◆ autoload()

static autoload (   $class)
static

spl_autoload() suitable implementation for supporting class autoloading.

Attach to spl_autoload() using the following: spl_autoload_register(array('Zend_Loader', 'autoload'));

Deprecated:
Since 1.8.0
Parameters
string$class
Returns
string|false Class name on success; false on failure

Definition at line 231 of file Loader.php.

232  {
233  trigger_error(__CLASS__ . '::' . __METHOD__ . ' is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead', E_USER_NOTICE);
234  try {
236  return $class;
237  } catch (Exception $e) {
238  return false;
239  }
240  }
static loadClass($class, $dirs=null)
Definition: Loader.php:52
$_option $_optionId $class
Definition: date.phtml:13

◆ explodeIncludePath()

static explodeIncludePath (   $path = null)
static

Explode an include path into an array

If no path provided, uses current include_path. Works around issues that occur when the path includes stream schemas.

Parameters
string | null$path
Returns
array

Definition at line 202 of file Loader.php.

203  {
204  if (null === $path) {
205  $path = get_include_path();
206  }
207 
208  if (PATH_SEPARATOR == ':') {
209  // On *nix systems, include_paths which include paths with a stream
210  // schema cannot be safely explode'd, so we have to be a bit more
211  // intelligent in the approach.
212  $paths = preg_split('#:(?!//)#', $path);
213  } else {
214  $paths = explode(PATH_SEPARATOR, $path);
215  }
216  return $paths;
217  }
$paths
Definition: _bootstrap.php:83

◆ isReadable()

static isReadable (   $filename)
static

Returns TRUE if the $filename is readable, or FALSE otherwise. This function uses the PHP include_path, where PHP's is_readable() does not.

Note from ZF-2900: If you use custom error handler, please check whether return value from error_reporting() is zero or not. At mark of fopen() can not suppress warning if the handler is used.

Parameters
string$filename
Returns
boolean

Definition at line 162 of file Loader.php.

163  {
164  if (is_readable($filename)) {
165  // Return early if the filename is readable without needing the
166  // include_path
167  return true;
168  }
169 
170  if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN'
171  && preg_match('/^[a-z]:/i', $filename)
172  ) {
173  // If on windows, and path provided is clearly an absolute path,
174  // return false immediately
175  return false;
176  }
177 
178  foreach (self::explodeIncludePath() as $path) {
179  if ($path == '.') {
180  if (is_readable($filename)) {
181  return true;
182  }
183  continue;
184  }
185  $file = $path . '/' . $filename;
186  if (is_readable($file)) {
187  return true;
188  }
189  }
190  return false;
191  }

◆ loadClass()

static loadClass (   $class,
  $dirs = null 
)
static

Loads a class from a PHP file. The filename must be formatted as "$class.php".

If $dirs is a string or an array, it will search the directories in the order supplied, and attempt to load the first matching file.

If $dirs is null, it will split the class name at underscores to generate a path hierarchy (e.g., "Zend_Example_Class" will map to "Zend/Example/Class.php").

If the file was not found in the $dirs, or if no $dirs were specified, it will attempt to load it from PHP's include_path.

Parameters
string$class- The full class name of a Zend component.
string | array$dirs- OPTIONAL Either a path or an array of paths to search.
Returns
void
Exceptions
Zend_Exception

Definition at line 52 of file Loader.php.

53  {
54  if (class_exists($class, false) || interface_exists($class, false)) {
55  return;
56  }
57 
58  if ((null !== $dirs) && !is_string($dirs) && !is_array($dirs)) {
59  #require_once 'Zend/Exception.php';
60  throw new Zend_Exception('Directory argument must be a string or an array');
61  }
62 
64 
65  if (!empty($dirs)) {
66  // use the autodiscovered path
67  $dirPath = dirname($file);
68  if (is_string($dirs)) {
69  $dirs = explode(PATH_SEPARATOR, $dirs);
70  }
71  foreach ($dirs as $key => $dir) {
72  if ($dir == '.') {
73  $dirs[$key] = $dirPath;
74  } else {
75  $dir = rtrim($dir, '\\/');
76  $dirs[$key] = $dir . DIRECTORY_SEPARATOR . $dirPath;
77  }
78  }
79  $file = basename($file);
80  self::loadFile($file, $dirs, true);
81  } else {
82  self::loadFile($file, null, true);
83  }
84 
85  if (!class_exists($class, false) && !interface_exists($class, false)) {
86  #require_once 'Zend/Exception.php';
87  throw new Zend_Exception("File \"$file\" does not exist or class \"$class\" was not found in the file");
88  }
89  }
$_option $_optionId $class
Definition: date.phtml:13
static loadFile($filename, $dirs=null, $once=false)
Definition: Loader.php:114
static standardiseFile($file)
Definition: Loader.php:330

◆ loadFile()

static loadFile (   $filename,
  $dirs = null,
  $once = false 
)
static

Loads a PHP file. This is a wrapper for PHP's include() function.

$filename must be the complete filename, including any extension such as ".php". Note that a security check is performed that does not permit extended characters in the filename. This method is intended for loading Zend Framework files.

If $dirs is a string or an array, it will search the directories in the order supplied, and attempt to load the first matching file.

If the file was not found in the $dirs, or if no $dirs were specified, it will attempt to load it from PHP's include_path.

If $once is TRUE, it will use include_once() instead of include().

Parameters
string$filename
string | array$dirs- OPTIONAL either a path or array of paths to search.
boolean$once
Returns
boolean
Exceptions
Zend_Exception

Search in provided directories, as well as include_path

Try finding for the plain filename in the include_path.

If searching in directories, reset include_path

Definition at line 114 of file Loader.php.

115  {
116  self::_securityCheck($filename);
117 
121  $incPath = false;
122  if (!empty($dirs) && (is_array($dirs) || is_string($dirs))) {
123  if (is_array($dirs)) {
124  $dirs = implode(PATH_SEPARATOR, $dirs);
125  }
126  $incPath = get_include_path();
127  set_include_path($dirs . PATH_SEPARATOR . $incPath);
128  }
129 
133  if ($once) {
134  include_once $filename;
135  } else {
136  include $filename;
137  }
138 
142  if ($incPath) {
143  set_include_path($incPath);
144  }
145 
146  return true;
147  }
static _securityCheck($filename)
Definition: Loader.php:284

◆ registerAutoload()

static registerAutoload (   $class = 'Zend_Loader',
  $enabled = true 
)
static

Register autoload() with spl_autoload()

Deprecated:
Since 1.8.0
Parameters
string$class(optional)
boolean$enabled(optional)
Returns
void
Exceptions
Zend_Exceptionif spl_autoload() is not found or if the specified class does not have an autoload() method.

Definition at line 252 of file Loader.php.

253  {
254  trigger_error(__CLASS__ . '::' . __METHOD__ . ' is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead', E_USER_NOTICE);
255  #require_once 'Zend/Loader/Autoloader.php';
256  $autoloader = Zend_Loader_Autoloader::getInstance();
257  $autoloader->setFallbackAutoloader(true);
258 
259  if ('Zend_Loader' != $class) {
261  $methods = get_class_methods($class);
262  if (!in_array('autoload', (array) $methods)) {
263  #require_once 'Zend/Exception.php';
264  throw new Zend_Exception("The class \"$class\" does not have an autoload() method");
265  }
266 
267  $callback = array($class, 'autoload');
268 
269  if ($enabled) {
270  $autoloader->pushAutoloader($callback);
271  } else {
272  $autoloader->removeAutoloader($callback);
273  }
274  }
275  }
static loadClass($class, $dirs=null)
Definition: Loader.php:52
$methods
Definition: billing.phtml:71
$_option $_optionId $class
Definition: date.phtml:13

◆ standardiseFile()

static standardiseFile (   $file)
static

Standardise the filename.

Convert the supplied filename into the namespace-aware standard, based on the Framework Interop Group reference implementation: http://groups.google.com/group/php-standards/web/psr-0-final-proposal

The filename must be formatted as "$file.php".

Parameters
string$file- The file name to be loaded.
Returns
string

Definition at line 330 of file Loader.php.

331  {
332  $fileName = ltrim($file, '\\');
333  $file = '';
334  $namespace = '';
335  if ($lastNsPos = strripos($fileName, '\\')) {
336  $namespace = substr($fileName, 0, $lastNsPos);
337  $fileName = substr($fileName, $lastNsPos + 1);
338  $file = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
339  }
340  $file .= str_replace('_', DIRECTORY_SEPARATOR, $fileName) . '.php';
341  return $file;
342  }
$fileName
Definition: translate.phtml:15

The documentation for this class was generated from the following file: