【发布时间】:2017-04-19 21:57:15
【问题描述】:
我想为一个项目安装 twig,但没有对服务器的命令行访问权限。我只能通过 ftp 上传文件。这意味着我必须手动设置 twig lib,即自己创建 Autoload.php 文件。我已经彻底搜索过,但关于这个主题的信息很少。我已尝试从另一个项目“借用”以下自动加载,但这不会产生有效的设置。
<?php
/*
* This file is part of Twig.
*
* (c) 2009 Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Autoloads Twig classes.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Twig_Autoloader
{
/**
* Registers Twig_Autoloader as an SPL autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not.
*/
public static function register($prepend = false)
{
if (version_compare(phpversion(), '5.3.0', '>=')) {
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
} else {
spl_autoload_register(array(__CLASS__, 'autoload'));
}
}
/**
* Handles autoloading of classes.
*
* @param string $class A class name.
*/
public static function autoload($class)
{
if (0 !== strpos($class, 'Twig')) {
return;
}
if (is_file($file = dirname(__FILE__).'/../'.str_replace(array('_', "\0"), array('/', ''), $class).'.php')) {
require $file;
}
}
}
任何帮助将不胜感激。
【问题讨论】:
-
你有本地开发副本吗?您可以使用 Composer 在本地安装,然后使用您的部署过程部署新版本。
-
您能找到其他托管服务提供商吗?
标签: php installation twig