web/Zend/Amf/Adobe/DbInspector.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Amf
       
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    19  * @version    $Id: DbInspector.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    20  */
       
    21 
       
    22 /**
       
    23  * This class implements authentication against XML file with roles for Flex Builder.
       
    24  *
       
    25  * @package    Zend_Amf
       
    26  * @subpackage Adobe
       
    27  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    28  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    29  */
       
    30 class Zend_Amf_Adobe_DbInspector
       
    31 {
       
    32 
       
    33     /**
       
    34      * Connect to the database
       
    35      *
       
    36      * @param string $dbType Database adapter type for Zend_Db
       
    37      * @param array|object $dbDescription Adapter-specific connection settings
       
    38      * @return Zend_Db_Adapter_Abstract
       
    39      * @see Zend_Db::factory()
       
    40      */
       
    41     protected function _connect($dbType, $dbDescription)
       
    42     {
       
    43         if(is_object($dbDescription)) {
       
    44             $dbDescription = get_object_vars($dbDescription);
       
    45         }
       
    46         return Zend_Db::factory($dbType, $dbDescription);
       
    47     }
       
    48 
       
    49     /**
       
    50      * Describe database object.
       
    51      *
       
    52      * Usage example:
       
    53      * $inspector->describeTable('Pdo_Mysql',
       
    54      *     array(
       
    55      *         'host'     => '127.0.0.1',
       
    56      *         'username' => 'webuser',
       
    57      *         'password' => 'xxxxxxxx',
       
    58      *         'dbname'   => 'test'
       
    59      *     ),
       
    60      *     'mytable'
       
    61      * );
       
    62      *
       
    63      * @param string $dbType Database adapter type for Zend_Db
       
    64      * @param array|object $dbDescription Adapter-specific connection settings
       
    65      * @param string $tableName Table name
       
    66      * @return array Table description
       
    67      * @see Zend_Db::describeTable()
       
    68      * @see Zend_Db::factory()
       
    69      */
       
    70     public function describeTable($dbType, $dbDescription, $tableName)
       
    71     {
       
    72         $db = $this->_connect($dbType, $dbDescription);
       
    73         return $db->describeTable($tableName);
       
    74     }
       
    75 
       
    76     /**
       
    77      * Test database connection
       
    78      *
       
    79      * @param string $dbType Database adapter type for Zend_Db
       
    80      * @param array|object $dbDescription Adapter-specific connection settings
       
    81      * @return bool
       
    82      * @see Zend_Db::factory()
       
    83      */
       
    84     public function connect($dbType, $dbDescription)
       
    85     {
       
    86         $db = $this->_connect($dbType, $dbDescription);
       
    87         $db->listTables();
       
    88         return true;
       
    89     }
       
    90 
       
    91     /**
       
    92      * Get the list of database tables
       
    93      *
       
    94      * @param string $dbType Database adapter type for Zend_Db
       
    95      * @param array|object $dbDescription Adapter-specific connection settings
       
    96      * @return array List of the tables
       
    97      */
       
    98     public function getTables($dbType, $dbDescription)
       
    99     {
       
   100         $db = $this->_connect($dbType, $dbDescription);
       
   101         return $db->listTables();
       
   102     }
       
   103 }