2017-04-19 27 views
0

我想爲項目安裝小枝,但對服務器沒有命令行訪問權限。我只能通過ftp上傳文件。這意味着我必須手動設置twig庫,即自己創建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 <[email protected]> 
*/ 
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; 
     } 
    } 
} 

任何幫助,將不勝感激。

+1

你有本地開發副本嗎?您可以使用Composer在本地安裝,然後使用您的部署過程來部署新版本。 – Chris

+0

你能找到不同的託管服務提供商嗎? – user2182349

回答

0

如果你真的需要加載的樹枝沒有作曲,你可以使用這個:https://gist.github.com/sarciszewski/b6cd3776fbd20acaf26b

我建議設置作曲家在您的本地開發環境。 (可以從https://getcomposer.org/下載) 安裝枝條與作曲家。

composer require twig/twig:~2.0 

然後包括自動加載到您的項目:

require_once 'vendor/autoload.php'; 

您可以在本地工作,並在項目準備部署到與供應商目錄,其中包含已安裝的軟件包您的服務器。你不需要你的服務器上的作曲家。

+1

你爲什麼不提供[官方](https://github.com/twigphp/Twig/releases)來源來下載'Twig'? – DarkBee

0

在研究了András提供的鏈接之後,我意識到關鍵不是加載機制,但「autoload.php」似乎缺少。我發現,我使用的Twig版本實際上是一個2.X版本,至少需要PHP 7.因爲我使用5.4,所以這顯然不起作用。幸運的是最新的1.X版本的lib提供了一個autoload.php,所以從那裏一切工作正常。

相關問題