Initial commit with Symfony 2.1+Vendors

Signed-off-by: Gergely POLONKAI (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
Polonkai Gergely
2012-07-01 09:52:20 +02:00
commit 082a0130c2
5381 changed files with 416709 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\Platforms;
/**
* A Doctrine DBAL driver for the Oracle OCI8 PHP extensions.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
class Driver implements \Doctrine\DBAL\Driver
{
public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{
return new OCI8Connection(
$username,
$password,
$this->_constructDsn($params),
isset($params['charset']) ? $params['charset'] : null,
isset($params['sessionMode']) ? $params['sessionMode'] : OCI_DEFAULT
);
}
/**
* Constructs the Oracle DSN.
*
* @return string The DSN.
*/
protected function _constructDsn(array $params)
{
$dsn = '';
if (isset($params['host']) && $params['host'] != '') {
$dsn .= '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' .
'(HOST=' . $params['host'] . ')';
if (isset($params['port'])) {
$dsn .= '(PORT=' . $params['port'] . ')';
} else {
$dsn .= '(PORT=1521)';
}
if (isset($params['service']) && $params['service'] == true) {
$dsn .= '))(CONNECT_DATA=(SERVICE_NAME=' . $params['dbname'] . ')))';
} else {
$dsn .= '))(CONNECT_DATA=(SID=' . $params['dbname'] . ')))';
}
} else {
$dsn .= $params['dbname'];
}
return $dsn;
}
public function getDatabasePlatform()
{
return new \Doctrine\DBAL\Platforms\OraclePlatform();
}
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{
return new \Doctrine\DBAL\Schema\OracleSchemaManager($conn);
}
public function getName()
{
return 'oci8';
}
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return $params['user'];
}
}

View File

@@ -0,0 +1,172 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver\OCI8;
/**
* OCI8 implementation of the Connection interface.
*
* @since 2.0
*/
class OCI8Connection implements \Doctrine\DBAL\Driver\Connection
{
protected $_dbh;
protected $_executeMode = OCI_COMMIT_ON_SUCCESS;
/**
* Create a Connection to an Oracle Database using oci8 extension.
*
* @param string $username
* @param string $password
* @param string $db
*/
public function __construct($username, $password, $db, $charset = null, $sessionMode = OCI_DEFAULT)
{
if (!defined('OCI_NO_AUTO_COMMIT')) {
define('OCI_NO_AUTO_COMMIT', 0);
}
$this->_dbh = @oci_connect($username, $password, $db, $charset, $sessionMode);
if (!$this->_dbh) {
throw OCI8Exception::fromErrorInfo(oci_error());
}
}
/**
* Create a non-executed prepared statement.
*
* @param string $prepareString
* @return OCI8Statement
*/
public function prepare($prepareString)
{
return new OCI8Statement($this->_dbh, $prepareString, $this);
}
/**
* @param string $sql
* @return OCI8Statement
*/
public function query()
{
$args = func_get_args();
$sql = $args[0];
//$fetchMode = $args[1];
$stmt = $this->prepare($sql);
$stmt->execute();
return $stmt;
}
/**
* Quote input value.
*
* @param mixed $input
* @param int $type PDO::PARAM*
* @return mixed
*/
public function quote($value, $type=\PDO::PARAM_STR)
{
if (is_int($value) || is_float($value)) {
return $value;
}
$value = str_replace("'", "''", $value);
return "'" . addcslashes($value, "\000\n\r\\\032") . "'";
}
/**
*
* @param string $statement
* @return int
*/
public function exec($statement)
{
$stmt = $this->prepare($statement);
$stmt->execute();
return $stmt->rowCount();
}
public function lastInsertId($name = null)
{
//TODO: throw exception or support sequences?
}
/**
* Return the current execution mode.
*/
public function getExecuteMode()
{
return $this->_executeMode;
}
/**
* Start a transactiom
*
* Oracle has to explicitly set the autocommit mode off. That means
* after connection, a commit or rollback there is always automatically
* opened a new transaction.
*
* @return bool
*/
public function beginTransaction()
{
$this->_executeMode = OCI_NO_AUTO_COMMIT;
return true;
}
/**
* @throws OCI8Exception
* @return bool
*/
public function commit()
{
if (!oci_commit($this->_dbh)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
$this->_executeMode = OCI_COMMIT_ON_SUCCESS;
return true;
}
/**
* @throws OCI8Exception
* @return bool
*/
public function rollBack()
{
if (!oci_rollback($this->_dbh)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
$this->_executeMode = OCI_COMMIT_ON_SUCCESS;
return true;
}
public function errorCode()
{
$error = oci_error($this->_dbh);
if ($error !== false) {
$error = $error['code'];
}
return $error;
}
public function errorInfo()
{
return oci_error($this->_dbh);
}
}

View File

@@ -0,0 +1,30 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver\OCI8;
class OCI8Exception extends \Exception
{
static public function fromErrorInfo($error)
{
return new self($error['message'], $error['code']);
}
}

View File

@@ -0,0 +1,258 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver\OCI8;
use PDO;
use IteratorAggregate;
use Doctrine\DBAL\Driver\Statement;
/**
* The OCI8 implementation of the Statement interface.
*
* @since 2.0
* @author Roman Borschel <roman@code-factory.org>
*/
class OCI8Statement implements \IteratorAggregate, Statement
{
/** Statement handle. */
protected $_dbh;
protected $_sth;
protected $_conn;
protected static $_PARAM = ':param';
protected static $fetchStyleMap = array(
PDO::FETCH_BOTH => OCI_BOTH,
PDO::FETCH_ASSOC => OCI_ASSOC,
PDO::FETCH_NUM => OCI_NUM,
PDO::PARAM_LOB => OCI_B_BLOB,
);
protected $_defaultFetchStyle = PDO::FETCH_BOTH;
protected $_paramMap = array();
/**
* Creates a new OCI8Statement that uses the given connection handle and SQL statement.
*
* @param resource $dbh The connection handle.
* @param string $statement The SQL statement.
*/
public function __construct($dbh, $statement, OCI8Connection $conn)
{
list($statement, $paramMap) = self::convertPositionalToNamedPlaceholders($statement);
$this->_sth = oci_parse($dbh, $statement);
$this->_dbh = $dbh;
$this->_paramMap = $paramMap;
$this->_conn = $conn;
}
/**
* Convert positional (?) into named placeholders (:param<num>)
*
* Oracle does not support positional parameters, hence this method converts all
* positional parameters into artificially named parameters. Note that this conversion
* is not perfect. All question marks (?) in the original statement are treated as
* placeholders and converted to a named parameter.
*
* The algorithm uses a state machine with two possible states: InLiteral and NotInLiteral.
* Question marks inside literal strings are therefore handled correctly by this method.
* This comes at a cost, the whole sql statement has to be looped over.
*
* @todo extract into utility class in Doctrine\DBAL\Util namespace
* @todo review and test for lost spaces. we experienced missing spaces with oci8 in some sql statements.
* @param string $statement The SQL statement to convert.
* @return string
*/
static public function convertPositionalToNamedPlaceholders($statement)
{
$count = 1;
$inLiteral = false; // a valid query never starts with quotes
$stmtLen = strlen($statement);
$paramMap = array();
for ($i = 0; $i < $stmtLen; $i++) {
if ($statement[$i] == '?' && !$inLiteral) {
// real positional parameter detected
$paramMap[$count] = ":param$count";
$len = strlen($paramMap[$count]);
$statement = substr_replace($statement, ":param$count", $i, 1);
$i += $len-1; // jump ahead
$stmtLen = strlen($statement); // adjust statement length
++$count;
} else if ($statement[$i] == "'" || $statement[$i] == '"') {
$inLiteral = ! $inLiteral; // switch state!
}
}
return array($statement, $paramMap);
}
/**
* {@inheritdoc}
*/
public function bindValue($param, $value, $type = null)
{
return $this->bindParam($param, $value, $type);
}
/**
* {@inheritdoc}
*/
public function bindParam($column, &$variable, $type = null)
{
$column = isset($this->_paramMap[$column]) ? $this->_paramMap[$column] : $column;
if ($type == \PDO::PARAM_LOB) {
$lob = oci_new_descriptor($this->_dbh, OCI_D_LOB);
$lob->writeTemporary($variable, OCI_TEMP_BLOB);
return oci_bind_by_name($this->_sth, $column, $lob, -1, OCI_B_BLOB);
} else {
return oci_bind_by_name($this->_sth, $column, $variable);
}
}
/**
* Closes the cursor, enabling the statement to be executed again.
*
* @return boolean Returns TRUE on success or FALSE on failure.
*/
public function closeCursor()
{
return oci_free_statement($this->_sth);
}
/**
* {@inheritdoc}
*/
public function columnCount()
{
return oci_num_fields($this->_sth);
}
/**
* {@inheritdoc}
*/
public function errorCode()
{
$error = oci_error($this->_sth);
if ($error !== false) {
$error = $error['code'];
}
return $error;
}
/**
* {@inheritdoc}
*/
public function errorInfo()
{
return oci_error($this->_sth);
}
/**
* {@inheritdoc}
*/
public function execute($params = null)
{
if ($params) {
$hasZeroIndex = array_key_exists(0, $params);
foreach ($params as $key => $val) {
if ($hasZeroIndex && is_numeric($key)) {
$this->bindValue($key + 1, $val);
} else {
$this->bindValue($key, $val);
}
}
}
$ret = @oci_execute($this->_sth, $this->_conn->getExecuteMode());
if ( ! $ret) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
return $ret;
}
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchStyle = PDO::FETCH_BOTH, $arg2 = null, $arg3 = null)
{
$this->_defaultFetchStyle = $fetchStyle;
}
/**
* {@inheritdoc}
*/
public function getIterator()
{
$data = $this->fetchAll($this->_defaultFetchStyle);
return new \ArrayIterator($data);
}
/**
* {@inheritdoc}
*/
public function fetch($fetchStyle = null)
{
$fetchStyle = $fetchStyle ?: $this->_defaultFetchStyle;
if ( ! isset(self::$fetchStyleMap[$fetchStyle])) {
throw new \InvalidArgumentException("Invalid fetch style: " . $fetchStyle);
}
return oci_fetch_array($this->_sth, self::$fetchStyleMap[$fetchStyle] | OCI_RETURN_NULLS | OCI_RETURN_LOBS);
}
/**
* {@inheritdoc}
*/
public function fetchAll($fetchStyle = null)
{
$fetchStyle = $fetchStyle ?: $this->_defaultFetchStyle;
if ( ! isset(self::$fetchStyleMap[$fetchStyle])) {
throw new \InvalidArgumentException("Invalid fetch style: " . $fetchStyle);
}
$result = array();
if (self::$fetchStyleMap[$fetchStyle] === OCI_BOTH) {
while ($row = $this->fetch($fetchStyle)) {
$result[] = $row;
}
} else {
oci_fetch_all($this->_sth, $result, 0, -1,
self::$fetchStyleMap[$fetchStyle] | OCI_RETURN_NULLS | OCI_FETCHSTATEMENT_BY_ROW | OCI_RETURN_LOBS);
}
return $result;
}
/**
* {@inheritdoc}
*/
public function fetchColumn($columnIndex = 0)
{
$row = oci_fetch_array($this->_sth, OCI_NUM | OCI_RETURN_NULLS | OCI_RETURN_LOBS);
return isset($row[$columnIndex]) ? $row[$columnIndex] : false;
}
/**
* {@inheritdoc}
*/
public function rowCount()
{
return oci_num_rows($this->_sth);
}
}