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


PHP Wire::getAllFuel方法代码示例

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


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

示例1: fuel

/**
 * Return all Fuel, or specified ProcessWire API variable, or NULL if it doesn't exist.
 *
 * Same as Wire::getFuel($name) and Wire::getAllFuel();
 * When a $name is specified, this function is identical to the wire() function.
 * Both functions exist more for consistent naming depending on usage. 
 *
 * @param string $name If ommitted, returns a Fuel object with references to all the fuel.
 * @return mixed Fuel value if available, NULL if not. 
 *
 */
function fuel($name = '')
{
    if (!$name) {
        return Wire::getAllFuel();
    }
    return Wire::getFuel($name);
}
开发者ID:ryancramerdesign,项目名称:ProcessWire-2.0,代码行数:18,代码来源:Functions.php

示例2: wireIncludeFile

/**
 * Include a PHP file passing it all API variables and optionally your own specified variables
 * 
 * This is the same as PHP's include() function except for the following: 
 * - It receives all API variables and optionally your custom variables
 * - If your filename is not absolute, it doesn't look in PHP's include path, only in the current dir.
 * - It only allows including files that are part of the PW installation: templates, core modules or site modules
 * - It will assume a ".php" extension if filename has no extension.
 * 
 * Note this function produced direct output. To retrieve output as a return value, use the 
 * wireTemplateFile function instead. 
 * 
 * @param $filename
 * @param array $vars Optional variables you want to hand to the include (associative array)
 * @param array $options Array of options to modify behavior: 
 * 	- func: Function to use: include, include_once, require or require_once (default=include)
 *  - autoExtension: Extension to assume when no ext in filename, make blank for no auto assumption (default=php) 
 * 	- allowedPaths: Array of paths include files are allowed from. Note current dir is always allowed.
 * @return bool Returns true 
 * @throws WireException if file doesn't exist or is not allowed
 * 
 */
function wireIncludeFile($filename, array $vars = array(), array $options = array())
{
    $paths = wire('config')->paths;
    $defaults = array('func' => 'include', 'autoExtension' => 'php', 'allowedPaths' => array($paths->templates, $paths->adminTemplates, $paths->modules, $paths->siteModules));
    $options = array_merge($defaults, $options);
    $filename = trim($filename);
    if (DIRECTORY_SEPARATOR != '/') {
        $filename = str_replace(DIRECTORY_SEPARATOR, '/', $filename);
    }
    // add .php extension if filename doesn't already have an extension
    if ($options['autoExtension'] && !strrpos(basename($filename), '.')) {
        $filename .= "." . $options['autoExtension'];
    }
    if (strpos($filename, '..') !== false) {
        // if backtrack/relative components, convert to real path
        $_filename = $filename;
        $filename = realpath($filename);
        if ($filename === false) {
            throw new WireException("File does not exist: {$_filename}");
        }
    }
    if (strpos($filename, '//') !== false) {
        throw new WireException("File is not allowed (double-slash): {$filename}");
    }
    if (strpos($filename, './') !== 0) {
        // file does not specify "current directory"
        $slashPos = strpos($filename, '/');
        // If no absolute path specified, ensure it only looks in current directory
        if ($slashPos !== 0 && strpos($filename, ':/') === false) {
            $filename = "./{$filename}";
        }
    }
    if (strpos($filename, '/') === 0 || strpos($filename, ':/') !== false) {
        // absolute path, make sure it's part of PW's installation
        $allowed = false;
        foreach ($options['allowedPaths'] as $path) {
            if (strpos($filename, $path) === 0) {
                $allowed = true;
            }
        }
        if (!$allowed) {
            throw new WireException("File is not in an allowed path: {$filename}");
        }
    }
    if (!file_exists($filename)) {
        throw new WireException("File does not exist: {$filename}");
    }
    // extract all API vars
    $fuel = array_merge(Wire::getAllFuel()->getArray(), $vars);
    extract($fuel);
    // include the file
    $func = $options['func'];
    if ($func == 'require') {
        require $filename;
    } else {
        if ($func == 'require_once') {
            require_once $filename;
        } else {
            if ($func == 'include_once') {
                include_once $filename;
            } else {
                include $filename;
            }
        }
    }
    return true;
}
开发者ID:posixpascal,项目名称:TrooperCMS,代码行数:89,代码来源:Functions.php


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