Pārlūkot izejas kodu

Merge remote branch 'symfony/master' into experimental

Bernhard Schussek 14 gadi atpakaļ
vecāks
revīzija
55c14680d3

+ 71 - 0
UPDATE.ja.md

@@ -0,0 +1,71 @@
+プロジェクトをアップデートする方法
+==================================
+
+このドキュメントでは、Symfony2 PRの特定のバージョンから1つ次のバージョンへアップデートする方法を説明します。
+このドキュメントでは、フレームワークの "パブリックな" APIを使っている場合に必要な変更点についてのみ説明しています。
+フレームワークのコアコードを "ハック" している場合は、変更履歴を注意深く追跡する必要があるでしょう。
+
+PR8 から PR9
+------------
+
+* `Symfony\Bundle\FrameworkBundle\Util\Filesystem` は、`Symfony\Component\HttpKernel\Util\Filesystem` へ移動されました
+
+* `Execute` 制約は、`Callback` 制約に名前が変更されました
+
+* HTTPの例外クラスのシグニチャが変更されました:
+
+    変更前:
+
+        throw new NotFoundHttpException('Not Found', $message, 0, $e);
+
+    変更後:
+
+        throw new NotFoundHttpException($message, $e);
+
+* RequestMatcher クラスでは、正規表現に `^` と `$` が自動的には追加されなくなりました
+
+    この変更によって、セキュリティの設定をたとえば次のように変更する必要があります:
+
+    変更前:
+
+        profiler:
+            pattern:  /_profiler/.*
+
+    変更後:
+
+        profiler:
+            pattern:  ^/_profiler
+
+* `app/` ディレクトリ以下のグローバルテンプレートの位置が変更されました(古いディレクトリでは動作しなくなります):
+
+    変更前:
+
+        app/views/base.html.twig
+        app/views/AcmeDemoBundle/base.html.twig
+
+    変更後:
+
+        app/Resources/views/base.html.twig
+        app/Resources/AcmeDemo/views/base.html.twig
+
+* バリデータの名前空間が `validation` から `assert` へ変更されました:
+
+    変更前:
+
+        @validation:NotNull
+
+    変更後:
+
+        @assert:NotNull
+
+    さらに、いくつかの制約で使われていた `Assert` プレフィックスは削除されました(`AssertTrue` から `True` へ変更)
+
+* バンドルの論理名に、`Bundle` サフィックスをつける必要がなくなりました:
+
+    *コントローラ*: `BlogBundle:Post:show` -> `Blog:Post:show`
+
+    *テンプレート*: `BlogBundle:Post:show.html.twig` -> `Blog:Post:show.html.twig`
+
+    *リソース*:     `@BlogBundle/Resources/config/blog.xml` -> `@Blog/Resources/config/blog.xml`
+
+    *Doctrine*:    `$em->find('BlogBundle:Post', $id)` -> `$em->find('Blog:Post', $id)`

+ 16 - 4
UPDATE.md

@@ -16,8 +16,13 @@ PR8 to PR9
 
 * The HTTP exceptions classes signatures have changed:
 
-    Before: throw new NotFoundHttpException('Not Found', $message, 0, $e);
-    After:  throw new NotFoundHttpException($message, $e);
+    Before:
+
+        throw new NotFoundHttpException('Not Found', $message, 0, $e);
+
+    After:
+
+        throw new NotFoundHttpException($message, $e);
 
 * The RequestMatcher class does not add `^` and `$` anymore to regexp.
 
@@ -37,17 +42,24 @@ PR8 to PR9
   work anyway):
 
     Before:
+
         app/views/base.html.twig
         app/views/AcmeDemoBundle/base.html.twig
 
     After:
+
         app/Resources/views/base.html.twig
         app/Resources/AcmeDemo/views/base.html.twig
 
 * Namespace for validators has changed from `validation` to `assert`:
 
-    Before: @validation:NotNull
-    After:  @assert:NotNull
+    Before:
+
+        @validation:NotNull
+
+    After:
+
+        @assert:NotNull
 
     Moreover, the `Assert` prefix used for some constraints has been removed
     (`AssertTrue` to `True`).

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php

@@ -65,6 +65,6 @@ EOF
 
         $dumper = new ApacheMatcherDumper($router->getRouteCollection());
 
-        $output->writeln($dumper->dump($dumpOptions), Output::OUTPUT_RAW);
+        $output->writeln($dumper->dump($dumpOptions), OutputInterface::OUTPUT_RAW);
     }
 }

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php

@@ -134,7 +134,7 @@ EOF
         }
         $output->writeln(sprintf('<comment>Options</comment>      %s', $options));
         $output->write('<comment>Regex</comment>        ');
-        $output->writeln(preg_replace('/^             /', '', preg_replace('/^/m', '             ', $route->getRegex())), Output::OUTPUT_RAW);
+        $output->writeln(preg_replace('/^             /', '', preg_replace('/^/m', '             ', $route->getRegex())), OutputInterface::OUTPUT_RAW);
 
         $tokens = '';
         foreach ($route->getTokens() as $token) {

+ 2 - 1
src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php

@@ -11,6 +11,7 @@
 
 namespace Symfony\Component\ClassLoader;
 
+require_once __DIR__.'/ClassLoaderInterface.php';
 require_once __DIR__.'/UniversalClassLoader.php';
 
 /**
@@ -36,7 +37,7 @@ class ApcUniversalClassLoader extends UniversalClassLoader
         $this->prefix = $prefix;
     }
 
-    protected function findFile($class)
+    public function findFile($class)
     {
         if (false === $file = apc_fetch($this->prefix.$class)) {
             apc_store($this->prefix.$class, $file = parent::findFile($class));

+ 42 - 0
src/Symfony/Component/ClassLoader/ClassLoaderInterface.php

@@ -0,0 +1,42 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\ClassLoader;
+
+/**
+ * ClassLoaderInterface.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @api
+ */
+interface ClassLoaderInterface
+{
+    /**
+     * Loads the given class or interface.
+     *
+     * @param string $class The name of the class
+     *
+     * @api
+     */
+    function loadClass($class);
+
+    /**
+     * Finds the path to the file where the class is defined.
+     *
+     * @param string $class The name of the class
+     *
+     * @return string|null The path, if found
+     *
+     * @api
+     */
+    function findFile($class);
+}

+ 21 - 1
src/Symfony/Component/ClassLoader/MapFileClassLoader.php

@@ -11,6 +11,8 @@
 
 namespace Symfony\Component\ClassLoader;
 
+require_once __DIR__.'/ClassLoaderInterface.php';
+
 /**
  * A class loader that uses a mapping file to look up paths.
  *
@@ -18,7 +20,7 @@ namespace Symfony\Component\ClassLoader;
  *
  * @api
  */
-class MapFileClassLoader
+class MapFileClassLoader implements ClassLoaderInterface
 {
     private $map = array();
 
@@ -61,4 +63,22 @@ class MapFileClassLoader
             require $this->map[$class];
         }
     }
+
+    /**
+     * Finds the path to the file where the class is defined.
+     *
+     * @param string $class The name of the class
+     *
+     * @return string|null The path, if found
+     */
+    public function findFile($class)
+    {
+        if ('\\' === $class[0]) {
+            $class = substr($class, 1);
+        }
+
+        if (isset($this->map[$class])) {
+            return $this->map[$class];
+        }
+    }
 }

+ 4 - 2
src/Symfony/Component/ClassLoader/UniversalClassLoader.php

@@ -11,6 +11,8 @@
 
 namespace Symfony\Component\ClassLoader;
 
+require_once __DIR__.'/ClassLoaderInterface.php';
+
 /**
  * UniversalClassLoader implements a "universal" autoloader for PHP 5.3.
  *
@@ -54,7 +56,7 @@ namespace Symfony\Component\ClassLoader;
  *
  * @api
  */
-class UniversalClassLoader
+class UniversalClassLoader implements ClassLoaderInterface
 {
     private $namespaces = array();
     private $prefixes = array();
@@ -210,7 +212,7 @@ class UniversalClassLoader
      *
      * @return string|null The path, if found
      */
-    protected function findFile($class)
+    public function findFile($class)
     {
         if ('\\' == $class[0]) {
             $class = substr($class, 1);

+ 3 - 3
src/Symfony/Component/Console/Application.php

@@ -170,9 +170,9 @@ class Application
         }
 
         if (true === $input->hasParameterOption(array('--quiet', '-q'))) {
-            $output->setVerbosity(Output::VERBOSITY_QUIET);
+            $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
         } elseif (true === $input->hasParameterOption(array('--verbose', '-v'))) {
-            $output->setVerbosity(Output::VERBOSITY_VERBOSE);
+            $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
         }
 
         if (true === $input->hasParameterOption(array('--version', '-V'))) {
@@ -723,7 +723,7 @@ class Application
             }
             $output->writeln("\n");
 
-            if (Output::VERBOSITY_VERBOSE === $output->getVerbosity()) {
+            if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) {
                 $output->writeln('</comment>Exception trace:</comment>');
 
                 // exception related properties

+ 1 - 1
src/Symfony/Component/Console/Command/HelpCommand.php

@@ -74,7 +74,7 @@ EOF
         }
 
         if ($input->getOption('xml')) {
-            $output->writeln($this->command->asXml(), Output::OUTPUT_RAW);
+            $output->writeln($this->command->asXml(), OutputInterface::OUTPUT_RAW);
         } else {
             $output->writeln($this->command->asText());
         }

+ 1 - 1
src/Symfony/Component/Console/Command/ListCommand.php

@@ -59,7 +59,7 @@ EOF
     protected function execute(InputInterface $input, OutputInterface $output)
     {
         if ($input->getOption('xml')) {
-            $output->writeln($this->getApplication()->asXml($input->getArgument('namespace')), Output::OUTPUT_RAW);
+            $output->writeln($this->getApplication()->asXml($input->getArgument('namespace')), OutputInterface::OUTPUT_RAW);
         } else {
             $output->writeln($this->getApplication()->asText($input->getArgument('namespace')));
         }

+ 3 - 11
src/Symfony/Component/Console/Output/Output.php

@@ -29,14 +29,6 @@ use Symfony\Component\Console\Formatter\OutputFormatter;
  */
 abstract class Output implements OutputInterface
 {
-    const VERBOSITY_QUIET   = 0;
-    const VERBOSITY_NORMAL  = 1;
-    const VERBOSITY_VERBOSE = 2;
-
-    const OUTPUT_NORMAL = 0;
-    const OUTPUT_RAW = 1;
-    const OUTPUT_PLAIN = 2;
-
     private $verbosity;
     private $formatter;
 
@@ -168,12 +160,12 @@ abstract class Output implements OutputInterface
 
         foreach ($messages as $message) {
             switch ($type) {
-                case Output::OUTPUT_NORMAL:
+                case OutputInterface::OUTPUT_NORMAL:
                     $message = $this->formatter->format($message);
                     break;
-                case Output::OUTPUT_RAW:
+                case OutputInterface::OUTPUT_RAW:
                     break;
-                case Output::OUTPUT_PLAIN:
+                case OutputInterface::OUTPUT_PLAIN:
                     $message = strip_tags($this->formatter->format($message));
                     break;
                 default:

+ 8 - 0
src/Symfony/Component/Console/Output/OutputInterface.php

@@ -22,6 +22,14 @@ use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  */
 interface OutputInterface
 {
+    const VERBOSITY_QUIET   = 0;
+    const VERBOSITY_NORMAL  = 1;
+    const VERBOSITY_VERBOSE = 2;
+
+    const OUTPUT_NORMAL = 0;
+    const OUTPUT_RAW = 1;
+    const OUTPUT_PLAIN = 2;
+
     /**
      * Writes a message to the output.
      *

+ 9 - 0
src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php

@@ -21,6 +21,15 @@ use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
  */
 class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
 {
+    /**
+     * Returns whether this guesser is supported on the current OS
+     *
+     * @return Boolean
+     */
+    static public function isSupported()
+    {
+        return !strstr(PHP_OS, 'WIN');
+    }
     /**
      * Guesses the mime type of the file with the given path
      *

+ 3 - 1
src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php

@@ -63,7 +63,9 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface
      */
     private function __construct()
     {
-        $this->register(new FileBinaryMimeTypeGuesser());
+        if (FileBinaryMimeTypeGuesser::isSupported()) {
+            $this->register(new FileBinaryMimeTypeGuesser());
+        }
 
         if (ContentTypeMimeTypeGuesser::isSupported()) {
             $this->register(new ContentTypeMimeTypeGuesser());

+ 2 - 2
tests/Symfony/Tests/Component/Finder/FinderTest.php

@@ -265,7 +265,7 @@ class FinderTest extends Iterator\RealIteratorTestCase
     public function testAppendWithAFinder()
     {
         $finder = new Finder();
-        $finder->files()->in(self::$tmpDir.'/foo');
+        $finder->files()->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo');
 
         $finder1 = new Finder();
         $finder1->directories()->in(self::$tmpDir);
@@ -278,7 +278,7 @@ class FinderTest extends Iterator\RealIteratorTestCase
     public function testAppendWithAnArray()
     {
         $finder = new Finder();
-        $finder->files()->in(self::$tmpDir.'/foo');
+        $finder->files()->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo');
 
         $finder->append($this->toAbsolute(array('foo', 'toto')));
 

+ 25 - 5
tests/Symfony/Tests/Component/HttpFoundation/File/MimeType/MimeTypeTest.php

@@ -24,31 +24,51 @@ class MimeTypeTest extends \PHPUnit_Framework_TestCase
 
     public function testGuessImageWithoutExtension()
     {
-        $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
+        if (extension_loaded('fileinfo')) {
+            $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
+        } else {
+            $this->assertNull(MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
+        }
     }
 
     public function testGuessImageWithContentTypeMimeTypeGuesser()
     {
         $guesser = MimeTypeGuesser::getInstance();
         $guesser->register(new ContentTypeMimeTypeGuesser());
-        $this->assertEquals('image/gif', $guesser->guess(__DIR__.'/../Fixtures/test'));
+        if (extension_loaded('fileinfo')) {
+            $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
+        } else {
+            $this->assertNull(MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
+        }
     }
 
     public function testGuessImageWithFileBinaryMimeTypeGuesser()
     {
         $guesser = MimeTypeGuesser::getInstance();
         $guesser->register(new FileBinaryMimeTypeGuesser());
-        $this->assertEquals('image/gif', $guesser->guess(__DIR__.'/../Fixtures/test'));
+        if (extension_loaded('fileinfo')) {
+            $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
+        } else {
+            $this->assertNull(MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
+        }
     }
 
     public function testGuessImageWithKnownExtension()
     {
-        $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.gif'));
+        if (extension_loaded('fileinfo')) {
+            $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.gif'));
+        } else {
+            $this->assertNull(MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.gif'));
+        }
     }
 
     public function testGuessFileWithUnknownExtension()
     {
-        $this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
+        if (extension_loaded('fileinfo')) {
+            $this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
+        } else {
+            $this->assertNull(MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
+        }
     }
 
     public function testGuessWithIncorrectPath()

+ 5 - 1
tests/Symfony/Tests/Component/HttpFoundation/File/UploadedFileTest.php

@@ -33,7 +33,11 @@ class UploadedFileTest extends \PHPUnit_Framework_TestCase
         );
 
         $this->assertAttributeEquals('application/octet-stream', 'mimeType', $file);
-        $this->assertEquals('image/gif', $file->getMimeType());
+        if (extension_loaded('fileinfo')) {
+            $this->assertEquals('image/gif', $file->getMimeType());
+        } else {
+            $this->assertEquals('application/octet-stream', $file->getMimeType());
+        }
     }
 
     public function testFileUploadsWithUnknownMimeType()