2017-11-23 8 views
0

私はDEVモードで正常に動作アプリを持っているが、私は生産にそれを実行すると、これがポップアップ表示:のSymfony 3小枝拡張 AbstractExtension見つからないエラー

Fatal error: Class 'Twig\Extension\AbstractExtension' not found in C:\Users\wackm\PhpstormProjects\poem\vendor\symfony\symfony\src\Symfony\Bridge\Twig\Extension\LogoutUrlExtension.php on line 23 

私はこれを推測しています私のカスタム小枝拡張に関する:

<?php 
// src/AppBundle/Twig/VersionExtension.php 
namespace AppBundle\Twig; 

use AppBundle\Entity\Version; 
use PhpOffice\PhpSpreadsheet\Calculation\DateTime; 

/** 
* Class VersionExtension - converts versions to readable HTML. 
* @package AppBundle\Twig 
*/ 
class VersionExtension extends \Twig_Extension 
{ 
    /** 
    * Defines the function name for use in twig templates. 
    * @return array 
    */ 
    public function getFunctions() 
    { 
     return array(
      new \Twig_SimpleFunction('version', array($this, 'versionFunction')), 
     ); 
    } 

    /** 
    * Actual function that converts a Version object into a HTML string. 
    * 
    * Indent indents the associated entities within each other, but NOT 
    * the individual items, it does this by incrementing in 0.5 and truncating 
    * $indent with intval() 
    * @param array $hydrated_entity 
    * @param string $title 
    * @param indent 
    * @return string 
    */ 
    public function versionFunction($hydrated_entity, $title = null, $indent = 0) 
    { 
     $result_html = ''; 
     if (!empty($hydrated_entity) and $title != null) { 
      $result_html .= '<div style="text-indent:' . (intval($indent) * 20) . 'px"><strong>' . $title . '</strong></div>'; 
     } 
     foreach ($hydrated_entity as $key => $value) { 
      // Ignore meta attributes. 
      if (in_array($key, array("ID", "Updated At", "Created At"))) { 
       continue; 
      } 

      if (is_array($value)) { 
       $result_html .= $this->versionFunction($value, $key, ($indent + 0.5)); 
      } else { 
       $value = $this->tidyValue($value); 
       if ($this->startsWith($key, "added_")) { 
        $result_html .= '<div class="bg-success" style="text-indent:' . (intval($indent) * 20) . 'px">' . explode("_", $key)[1] . ': ' . '<p>' . $value . '</p>' . '</div>'; 
       } else if ($this->startsWith($key, "removed_")) { 
        $result_html .= '<div class="bg-danger" style="text-indent:' . (intval($indent) * 20) . 'px">' . explode("_", $key)[1] . ': ' . '<p>' . $value . '</p>' . '</div>'; 
       } else { 
        $result_html .= '<div class="bg-info" style="text-indent:' . (intval($indent) * 20) . 'px">' . $key . ': ' . '<p>' . $value . '</p>' . '</div>'; 
       } 
      } 
     } 
     return $result_html; 
    } 

    /** 
    * Tidies up value for display. 
    * @param $value 
    * @return string 
    */ 
    private function tidyValue($value) 
    { 
     // Convert DateTime to String. 
     if ($value instanceof \DateTime) { 
      $value = $value->format('Y-m-d'); 
     } else if (is_bool($value)) { 
      $value = ($value) ? 'true' : 'false'; 
     } else if (is_string($value)) { 
      //Remove extra <p> tags if present. 
      $value = preg_replace('!^<p>(.*?)</p>$!i', '$1', $value); 
     } 
     return $value; 
    } 

    /** 
    * Checks whether a string begins with a another string. 
    * @param $haystack 
    * @param $needle 
    * @return bool 
    */ 
    private function startsWith($haystack, $needle) 
    { 
     $length = strlen($needle); 
     return (substr($haystack, 0, $length) === $needle); 
    } 
} 

拡張子がLogoutUrlExtension.php以外の何かを拡張すべきか?それはそれを拡張しようとするための奇妙なファイルのように思えます。 PHPStormは私に、\Twig_Extensionには複数の定義があると警告しているので、これは関連していると思っています。

私はTwig 1.8を使用しています。

誰でも洞察力を提供できますか?

編集:

Composer.json:

{ 
    "name": "symfony/framework-standard-edition", 
    "license": "MIT", 
    "type": "project", 
    "description": "The \"Symfony Standard Edition\" distribution", 
    "minimum-stability": "dev", 
    "prefer-stable": true, 
    "autoload": { 
    "psr-4": { 
     "": "src/" 
    }, 
    "classmap": [ 
     "app/AppKernel.php", 
     "app/AppCache.php" 
    ] 
    }, 
    "autoload-dev": { 
    "psr-4": { 
     "Tests\\": "tests/" 
    } 
    }, 
    "require": { 
    "php": "7.0.0", 
    "symfony/symfony": "3.2.*", 
    "doctrine/orm": "^2.5", 
    "doctrine/doctrine-bundle": "^1.6", 
    "doctrine/doctrine-cache-bundle": "^1.2", 
    "symfony/swiftmailer-bundle": "^2.3", 
    "symfony/monolog-bundle": "^2.8", 
    "symfony/polyfill-apcu": "^1.0", 
    "sensio/distribution-bundle": "^5.0", 
    "sensio/framework-extra-bundle": "^3.0.2", 
    "incenteev/composer-parameter-handler": "^2.0", 
    "doctrine/doctrine-fixtures-bundle": "2.3.0", 
    "symfony/assetic-bundle": "v2.8.0", 
    "twig/twig": "1.*", 
    "components/jquery": "3.1.1", 
    "friendsofsymfony/user-bundle": "~2.0.0-beta2", 
    "fr3d/ldap-bundle": "3.0.*@dev", 
    "doctrine/doctrine-migrations-bundle": "^1.0", 
    "symfony/console": "^3.2", 
    "phpoffice/phpexcel": "^1.8", 
    "waldo/datatable-bundle": "^4.0" 
    }, 
    "require-dev": { 
    "sensio/generator-bundle": "^3.0", 
    "symfony/phpunit-bridge": "^3.0", 
    "liip/functional-test-bundle": "^1.6", 
    "phpunit/phpunit": "5.7" 
    }, 
    "scripts": { 
    "symfony-scripts": [ 
     "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", 
     "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", 
     "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", 
     "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", 
     "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", 
     "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget" 
    ], 
    "post-install-cmd": [ 
     "@symfony-scripts" 
    ], 
    "post-update-cmd": [ 
     "@symfony-scripts" 
    ] 
    }, 
    "config": { 
    "platform": { 
     "php": "7.0.0" 
    } 
    }, 
    "extra": { 
    "symfony-app-dir": "app", 
    "symfony-bin-dir": "bin", 
    "symfony-var-dir": "var", 
    "symfony-web-dir": "web", 
    "symfony-tests-dir": "tests", 
    "symfony-assets-install": "relative", 
    "incenteev-parameters": { 
     "file": "app/config/parameters.yml" 
    }, 
    "branch-alias": { 
     "dev-master": "3.1-dev" 
    } 
    } 
} 
+1

あなたの 'composer.json'を表示してください。 'LogoutUrlExtension'はSymfony Twig Bridgeの一部です。 (例えば 'ベンダー/ symfony/symfony/src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php')、それは' Twig \ Extension \ AbstractExtension'を拡張しています。 – ccKep

+0

'composer.json'が追加されました。 – Darkstarone

+1

'composer require twig/extensions'を追加してみてください(' twig/extensions 'には 'twig/twig'が必要なので' twig/twig'を削除できます)。 – ccKep

答えて

2

Symfony\Bridge\Twig\Extension\LogoutUrlExtensionは(あなたのために不足しているように見えた)Twig\Extension\AbstractExtension\AbstractExtensionを拡張します。

このファイルはtwig/extensionsパッケージに含まれているため、composer require twig/extensionsというのはすべきことです。

なぜtwig/extensionsがSymfony Twig Bridgeに必要でないのか分かりません。 (requiresセクションのpackagist.orgにのみtwig/twigと記載されています)

+0

こんにちは、symfonyを2.7.4にアップデートした後も同じエラーが発生しています。 私はすでにtwig/extensionsが1.5.1で必要と更新されていますが、私はどこでもAbstractExentionsファイルを見つけることができません。さらに、枝拡張の名前空間は、Twig \ Extensionではなく、Twig \ Extensionです。これは私をもっと混乱させます。 助けていただければ幸いです。 – Stev

関連する問題