1<?php 2/* 3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14 * 15 * This software consists of voluntary contributions made by many individuals 16 * and is licensed under the MIT license. For more information, see 17 * <http://www.doctrine-project.org>. 18 */ 19 20namespace Doctrine\DBAL; 21 22use Doctrine\DBAL\Logging\SQLLogger; 23use Doctrine\Common\Cache\Cache; 24 25/** 26 * Configuration container for the Doctrine DBAL. 27 * 28 * @since 2.0 29 * @author Guilherme Blanco <guilhermeblanco@hotmail.com> 30 * @author Jonathan Wage <jonwage@gmail.com> 31 * @author Roman Borschel <roman@code-factory.org> 32 * @internal When adding a new configuration option just write a getter/setter 33 * pair and add the option to the _attributes array with a proper default value. 34 */ 35class Configuration 36{ 37 /** 38 * The attributes that are contained in the configuration. 39 * Values are default values. 40 * 41 * @var array 42 */ 43 protected $_attributes = array(); 44 45 /** 46 * Sets the SQL logger to use. Defaults to NULL which means SQL logging is disabled. 47 * 48 * @param \Doctrine\DBAL\Logging\SQLLogger|null $logger 49 * 50 * @return void 51 */ 52 public function setSQLLogger(SQLLogger $logger = null) 53 { 54 $this->_attributes['sqlLogger'] = $logger; 55 } 56 57 /** 58 * Gets the SQL logger that is used. 59 * 60 * @return \Doctrine\DBAL\Logging\SQLLogger|null 61 */ 62 public function getSQLLogger() 63 { 64 return isset($this->_attributes['sqlLogger']) ? 65 $this->_attributes['sqlLogger'] : null; 66 } 67 68 /** 69 * Gets the cache driver implementation that is used for query result caching. 70 * 71 * @return \Doctrine\Common\Cache\Cache|null 72 */ 73 public function getResultCacheImpl() 74 { 75 return isset($this->_attributes['resultCacheImpl']) ? 76 $this->_attributes['resultCacheImpl'] : null; 77 } 78 79 /** 80 * Sets the cache driver implementation that is used for query result caching. 81 * 82 * @param \Doctrine\Common\Cache\Cache $cacheImpl 83 * 84 * @return void 85 */ 86 public function setResultCacheImpl(Cache $cacheImpl) 87 { 88 $this->_attributes['resultCacheImpl'] = $cacheImpl; 89 } 90 91 /** 92 * Sets the filter schema assets expression. 93 * 94 * Only include tables/sequences matching the filter expression regexp in 95 * schema instances generated for the active connection when calling 96 * {AbstractSchemaManager#createSchema()}. 97 * 98 * @param string $filterExpression 99 * 100 * @return void 101 */ 102 public function setFilterSchemaAssetsExpression($filterExpression) 103 { 104 $this->_attributes['filterSchemaAssetsExpression'] = $filterExpression; 105 } 106 107 /** 108 * Returns filter schema assets expression. 109 * 110 * @return string|null 111 */ 112 public function getFilterSchemaAssetsExpression() 113 { 114 if (isset($this->_attributes['filterSchemaAssetsExpression'])) { 115 return $this->_attributes['filterSchemaAssetsExpression']; 116 } 117 118 return null; 119 } 120 121 /** 122 * Sets the default auto-commit mode for connections. 123 * 124 * If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual 125 * transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either 126 * the method commit or the method rollback. By default, new connections are in auto-commit mode. 127 * 128 * @param boolean $autoCommit True to enable auto-commit mode; false to disable it. 129 * 130 * @see getAutoCommit 131 */ 132 public function setAutoCommit($autoCommit) 133 { 134 $this->_attributes['autoCommit'] = (boolean) $autoCommit; 135 } 136 137 /** 138 * Returns the default auto-commit mode for connections. 139 * 140 * @return boolean True if auto-commit mode is enabled by default for connections, false otherwise. 141 * 142 * @see setAutoCommit 143 */ 144 public function getAutoCommit() 145 { 146 if (isset($this->_attributes['autoCommit'])) { 147 return $this->_attributes['autoCommit']; 148 } 149 150 return true; 151 } 152} 153