├── application ├── repose-models │ └── index.html ├── config │ └── sample-repose.php └── libraries │ └── Repose.php ├── README └── LICENSE /application/repose-models/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |Directory access is forbidden.
8 | 9 | 10 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | CodeIgniter Library for Repose ORM for PHP 2 | http://code.google.com/p/repose-ci-php/ 3 | http://repose-php.org/ 4 | 5 | 6 | Repose is an ORM tool for PHP. Similar to Hibernate and SQLAlchemy and inspired 7 | by Outlet, another ORM tool for PHP. 8 | 9 | CodeIgniter is a PHP Framework. 10 | 11 | This Library allows CodeIgniter developers to integrate Repose into their apps. 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009, 2010, Dragonfly Development Inc 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Dragonfly Development Inc nor the names of its 13 | contributors may be used to endorse or promote products derived from 14 | this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /application/config/sample-repose.php: -------------------------------------------------------------------------------- 1 | '', 24 | // 'username' => '', 25 | // 'password' => '', 26 | //); 27 | 28 | /** 29 | * Repose mapping 30 | * 31 | * Refer to the Repose manual for configuration based mapping. 32 | * http://code.google.com/p/repose-php/wiki/ManualMapping 33 | * 34 | * The classes referenced here should be accessible in the repose_model_libs 35 | * path. For instance, if a class named 'sample_Project' is mapped, it should 36 | * live at application/repose-models/sample_Project.php 37 | */ 38 | $config['repose_mapping'] = array( 39 | 40 | // 41 | // Example mapping: 42 | // 43 | //'sample_Project' => array( 44 | // 'tableName' => 'project', 45 | // 'properties' => array( 46 | // 'projectId' => array( 'primaryKey' => 'true', ), 47 | // 'name' => null, 48 | // 'manager' => array( 49 | // 'relationship' => 'many-to-one', 50 | // 'className' => 'sample_User', 51 | // 'columnName' => 'managerUserId', 52 | // ), 53 | // 'bugs' => array( 54 | // 'relationship' => 'one-to-many', 55 | // 'className' => 'sample_Bug', 56 | // 'backref' => 'project', 57 | // 'cascade' => 'delete-orphan', 58 | // ), 59 | // ), 60 | //), 61 | // 62 | //'sample_ProjectInfo' => array( 63 | // 'tableName' => 'projectInfo', 64 | // 'properties' => array( 65 | // 'projectInfoId' => array( 'primaryKey' => 'true', ), 66 | // 'description' => null, 67 | // 'project' => array( 68 | // 'relationship' => 'one-to-one', 69 | // 'className' => 'sample_Project', 70 | // ), 71 | // ), 72 | //), 73 | // 74 | //'sample_Bug' => array( 75 | // 'tableName' => 'bug', 76 | // 'properties' => array( 77 | // 'bugId' => array( 'primaryKey' => 'true', ), 78 | // 'title' => null, 79 | // 'body' => null, 80 | // 'project' => array( 81 | // 'relationship' => 'many-to-one', 82 | // 'className' => 'sample_Project', 83 | // ), 84 | // 'reporter' => array( 85 | // 'relationship' => 'many-to-one', 86 | // 'className' => 'sample_User', 87 | // 'columnName' => 'reporterUserId', 88 | // ), 89 | // 'owner' => array( 90 | // 'relationship' => 'many-to-one', 91 | // 'className' => 'sample_User', 92 | // 'columnName' => 'ownerUserId', 93 | // ), 94 | // ), 95 | //), 96 | // 97 | //'sample_User' => array( 98 | // 'tableName' => 'user', 99 | // 'properties' => array( 100 | // 'userId' => array( 'primaryKey' => 'true', ), 101 | // 'name' => null, 102 | // ), 103 | //) 104 | // 105 | 106 | ); 107 | 108 | ?> -------------------------------------------------------------------------------- /application/libraries/Repose.php: -------------------------------------------------------------------------------- 1 | config; 60 | 61 | $config->load('repose'); 62 | 63 | if ( ! $config->item('repose_model_libs') ) { 64 | // If the location for the model libs has not been specified 65 | // we will use the default location. 66 | $config->set_item('repose_model_libs', APPPATH . 'repose-models'); 67 | } 68 | 69 | if ( $config->item('repose_pdo_connection') ) { 70 | $dataSourceConfig = $config->item('repose_pdo_connection'); 71 | require_once('repose_PdoEngine.php'); 72 | $pdo = new PDO( 73 | $dataSourceConfig['dsn'], 74 | $dataSourceConfig['username'], 75 | $dataSourceConfig['password'] 76 | ); 77 | $pdo->setAttribute( 78 | PDO::ATTR_ERRMODE, 79 | PDO::ERRMODE_EXCEPTION 80 | ); 81 | $this->engine = new repose_PdoEngine($pdo); 82 | } else { 83 | $CI->load->database(); 84 | $this->engine = new repose_ci_DbEngine($CI->db); 85 | } 86 | $this->mapping = new repose_Mapping(); 87 | $this->autoloader = new repose_PathAutoloader($config->item('repose_model_libs')); 88 | 89 | foreach ( $config->item('repose_mapping') as $clazz => $clazzConfig ) { 90 | // TODO Replace this with an autoloader. 91 | $this->mapping->mapClass( 92 | $clazz, 93 | $clazzConfig['tableName'], 94 | $clazzConfig['properties'] 95 | ); 96 | } 97 | 98 | } 99 | 100 | 101 | /** 102 | * Session 103 | * @return repose_Session 104 | */ 105 | public function session() { 106 | return $this->currentSession(); 107 | } 108 | 109 | /** 110 | * Opens a new session 111 | * @return repose_Session 112 | */ 113 | public function openSession() { 114 | return new repose_Session( 115 | $this->engine, 116 | $this->mapping, 117 | $this->autoloader 118 | ); 119 | } 120 | 121 | /** 122 | * Load a model class 123 | * @param string $clazz Model class to load 124 | */ 125 | public function loadClass($clazz) { 126 | $this->autoloader->loadClass($clazz); 127 | } 128 | 129 | } 130 | 131 | /** 132 | * Db Engine. 133 | * @package repose 134 | */ 135 | class repose_ci_DbEngine extends repose_AbstractSqlEngine { 136 | 137 | /** 138 | * Simplify the SQL 139 | * @var bool 140 | */ 141 | protected $simplify = true; 142 | 143 | /** 144 | * CodeIgniter DB Instance 145 | * @var Db 146 | */ 147 | protected $ciDb; 148 | 149 | /** 150 | * Constructor 151 | * @param Db $ciDb Db Data Source 152 | */ 153 | public function __construct($ciDb) { 154 | $this->ciDb = $ciDb; 155 | } 156 | 157 | /** 158 | * Insert data into a table 159 | * @param string $sql SQL 160 | * @param array $data Associative array 161 | */ 162 | protected function doInsert($sql, array $params) { 163 | $this->ciDb->query($sql, $params); 164 | return $this->ciDb->insert_id(); 165 | } 166 | 167 | /** 168 | * Update data in a table 169 | * @param string $sql SQL 170 | * @param array $data Associative array 171 | */ 172 | protected function doUpdate($sql, array $params) { 173 | $this->ciDb->query($sql, $params); 174 | } 175 | 176 | /** 177 | * Delete data from a table 178 | * @param string $sql SQL 179 | * @param array $data Associative array 180 | */ 181 | protected function doDelete($sql, array $params) { 182 | $this->ciDb->query($sql, $params); 183 | } 184 | 185 | /** 186 | * Select data 187 | * @param string $sql SQL 188 | * @param array $data Associative array 189 | * @return array 190 | */ 191 | protected function doSelect($sql, array $params) { 192 | return $this->ciDb->query($sql, $params)->result_array(); 193 | } 194 | 195 | } 196 | 197 | ?> 198 | --------------------------------------------------------------------------------