Procházet zdrojové kódy

ZF-7924
- Fixed adapter name to work as case-insensitive naming

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18372 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph před 16 roky
rodič
revize
ed670c2b3c

+ 5 - 2
library/Zend/Db.php

@@ -171,7 +171,10 @@ class Zend_Db
      *
      * First argument may be a string containing the base of the adapter class
      * name, e.g. 'Mysqli' corresponds to class Zend_Db_Adapter_Mysqli.  This
-     * is case-insensitive.
+     * name is currently case-insensitive, but is not ideal to rely on this behavior.
+     * If your class is named 'My_Company_Pdo_Mysql', where 'My_Company' is the namespace
+     * and 'Pdo_Mysql' is the adapter name, it is best to use the name exactly as it
+     * is defined in the class.  This will ensure proper use of the factory API.
      *
      * First argument may alternatively be an object of type Zend_Config.
      * The adapter class base name is read from the 'adapter' property.
@@ -244,7 +247,7 @@ class Zend_Db
 
         // Adapter no longer normalized- see http://framework.zend.com/issues/browse/ZF-5606
         $adapterName = $adapterNamespace . '_';
-        $adapterName .= str_replace(' ', '_', ucwords(str_replace('_', ' ', $adapter)));
+        $adapterName .= str_replace(' ', '_', ucwords(str_replace('_', ' ', strtolower($adapter))));
 
         /*
          * Load the adapter class.  This throws an exception

+ 34 - 3
tests/Zend/Db/Adapter/StaticTest.php

@@ -56,6 +56,8 @@ require_once 'Zend/Db/Adapter/Static.php';
 class Zend_Db_Adapter_StaticTest extends PHPUnit_Framework_TestCase
 {
 
+    protected static $_isCaseSensitiveFileSystem = null;
+    
     public function testDbConstructor()
     {
         $db = new Zend_Db_Adapter_Static( array('dbname' => 'dummy') );
@@ -335,9 +337,7 @@ class Zend_Db_Adapter_StaticTest extends PHPUnit_Framework_TestCase
         $newIncludePath = realpath(dirname(__FILE__) . '/_files/') . PATH_SEPARATOR . get_include_path();
         $oldIncludePath = set_include_path($newIncludePath);
         
-        $loadedCaseInspecificFile = @include 'Test/MyCompany1/iscasespecific.php';
-        
-        if ($loadedCaseInspecificFile === true) {
+        if (!$this->_isCaseSensitiveFileSystem()) {
             set_include_path($oldIncludePath);
             $this->markTestSkipped('This test is irrelevant on case-inspecific file systems.');
             return;
@@ -358,6 +358,37 @@ class Zend_Db_Adapter_StaticTest extends PHPUnit_Framework_TestCase
         set_include_path($oldIncludePath);
     }
     
+    /**
+     * @group ZF-7924
+     */
+    public function testDbFactoryWillLoadCaseInsensitiveAdapterName()
+    {
+        $newIncludePath = realpath(dirname(__FILE__) . '/_files/') . PATH_SEPARATOR . get_include_path();
+        $oldIncludePath = set_include_path($newIncludePath);
+        
+        try {
+            $adapter = Zend_Db::factory(
+                'DB_ADAPTER',
+                array('dbname' => 'dummy', 'adapterNamespace' => 'Test_MyCompany1')
+                );
+        } catch (Exception $e) {
+            set_include_path($oldIncludePath);
+            $this->fail('Could not load file for reason: ' . $e->getMessage());
+        }
+        $this->assertEquals('Test_MyCompany1_Db_Adapter', get_class($adapter));
+        set_include_path($oldIncludePath);
+        
+    }
+    
+    protected function _isCaseSensitiveFileSystem()
+    {
+        if (self::$_isCaseSensitiveFileSystem === null) {
+            self::$_isCaseSensitiveFileSystem = !(@include 'Test/MyCompany1/iscasespecific.php');
+        }
+        
+        return self::$_isCaseSensitiveFileSystem;
+    }
+    
     public function getDriver()
     {
         return 'Static';

+ 50 - 0
tests/Zend/Db/Adapter/_files/Test/MyCompany1/Db/Adapter.php

@@ -0,0 +1,50 @@
+<?php 
+
+class Test_MyCompany1_Db_Adapter extends Zend_Db_Adapter_Abstract
+{
+    protected function _connect()
+    {}
+
+    function _checkRequiredOptions(array $config)
+    {}
+    
+    public function isConnected()
+    {}
+
+    public function closeConnection()
+    {}
+
+    public function prepare($sql)
+    {}
+
+    public function lastInsertId($tableName = null, $primaryKey = null)
+    {}
+
+    protected function _beginTransaction()
+    {}
+
+    protected function _commit()
+    {}
+
+    protected function _rollBack()
+    {}
+    
+    public function listTables()
+    {}
+    
+    public function describeTable($tableName, $schemaName = null)
+    {}
+
+    public function setFetchMode($mode)
+    {}
+    
+    public function limit($sql, $count, $offset = 0)
+    {}
+    
+    public function supportsParameters($type)
+    {}
+    
+    public function getServerVersion()
+    {}
+    
+}