diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000000000000000000000000000000000000..bac608b2dac762464a5504a9fc6b0275ffe6cc5e --- /dev/null +++ b/composer.lock @@ -0,0 +1,105 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" + ], + "hash": "6b81f90fd68b712c49f5610cbcb93810", + "packages": [ + { + "name": "saltybeagle/savvy", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/saltybeagle/Savvy.git", + "reference": "d8b58c71b5184dfb6615048748c118147706dab4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/saltybeagle/Savvy/zipball/d8b58c71b5184dfb6615048748c118147706dab4", + "reference": "d8b58c71b5184dfb6615048748c118147706dab4", + "shasum": "" + }, + "type": "library", + "autoload": { + "psr-0": { + "Savvy": "src/" + } + }, + "description": "Savvy is a powerful but lightweight object-oriented template system for PHP.", + "support": { + "source": "https://github.com/saltybeagle/Savvy/tree/master", + "issues": "https://github.com/saltybeagle/Savvy/issues" + }, + "time": "2014-03-11 16:58:11" + }, + { + "name": "zendframework/zend-db", + "version": "2.3.1", + "target-dir": "Zend/Db", + "source": { + "type": "git", + "url": "https://github.com/zendframework/Component_ZendDb.git", + "reference": "29bb7f1ceacb32fa3e1c122bc3d14da6490aba2c" + }, + "dist": { + "type": "zip", + "url": "https://packages.zendframework.com/composer/zendframework-zend-db-29bb7f1ceacb32fa3e1c122bc3d14da6490aba2c-zip-4340f1.zip", + "reference": "2.3.1", + "shasum": "4993066700cc03e2cf18fe69192e35302f8c3d27" + }, + "require": { + "php": ">=5.3.23" + }, + "require-dev": { + "zendframework/zend-eventmanager": "self.version", + "zendframework/zend-servicemanager": "self.version", + "zendframework/zend-stdlib": "self.version" + }, + "suggest": { + "zendframework/zend-eventmanager": "Zend\\EventManager component", + "zendframework/zend-servicemanager": "Zend\\ServiceManager component", + "zendframework/zend-stdlib": "Zend\\Stdlib component" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3-dev", + "dev-develop": "2.4-dev" + } + }, + "autoload": { + "psr-0": { + "Zend\\Db\\": "" + } + }, + "license": [ + "BSD-3-Clause" + ], + "description": " ", + "keywords": [ + "db", + "zf2" + ], + "support": { + "source": "https://github.com/zendframework/Component_ZendDb/tree/release-2.3.1" + }, + "time": "2014-04-15 15:29:07" + } + ], + "packages-dev": [ + + ], + "aliases": [ + + ], + "minimum-stability": "stable", + "stability-flags": { + "saltybeagle/savvy": 20 + }, + "platform": [ + + ], + "platform-dev": [ + + ] +} diff --git a/vendor/autoload.php b/vendor/autoload.php new file mode 100644 index 0000000000000000000000000000000000000000..5faaa58744ca50f472b0562c99ca833d7dad2fce --- /dev/null +++ b/vendor/autoload.php @@ -0,0 +1,7 @@ +<?php + +// autoload.php @generated by Composer + +require_once __DIR__ . '/composer' . '/autoload_real.php'; + +return ComposerAutoloaderInit7b2a97b8e090b6f85dc49f15ce5e9162::getLoader(); diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php new file mode 100644 index 0000000000000000000000000000000000000000..a7105553143a422546083f2bb49dd6a79a280a6a --- /dev/null +++ b/vendor/composer/ClassLoader.php @@ -0,0 +1,378 @@ +<?php + +/* + * This file is part of Composer. + * + * (c) Nils Adermann <naderman@naderman.de> + * Jordi Boggiano <j.boggiano@seld.be> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0 class loader + * + * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier <fabien@symfony.com> + * @author Jordi Boggiano <j.boggiano@seld.be> + */ +class ClassLoader +{ + // PSR-4 + private $prefixLengthsPsr4 = array(); + private $prefixDirsPsr4 = array(); + private $fallbackDirsPsr4 = array(); + + // PSR-0 + private $prefixesPsr0 = array(); + private $fallbackDirsPsr0 = array(); + + private $useIncludePath = false; + private $classMap = array(); + + public function getPrefixes() + { + return call_user_func_array('array_merge', $this->prefixesPsr0); + } + + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-0 base directories + * @param bool $prepend Whether to prepend the directories + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 base directories + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + */ + public function setPsr4($prefix, $paths) { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + /** + * Unregisters this instance as an autoloader. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return bool|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + includeFile($file); + + return true; + } + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 + if ('\\' == $class[0]) { + $class = substr($class, 1); + } + + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if ($file === null && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if ($file === null) { + // Remember that this class does not exist. + return $this->classMap[$class] = false; + } + + return $file; + } + + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { + if (0 === strpos($class, $prefix)) { + foreach ($this->prefixDirsPsr4[$prefix] as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + */ +function includeFile($file) +{ + include $file; +} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php new file mode 100644 index 0000000000000000000000000000000000000000..7a91153b0d8ea10bc693176a81d8a9eb96883a76 --- /dev/null +++ b/vendor/composer/autoload_classmap.php @@ -0,0 +1,9 @@ +<?php + +// autoload_classmap.php @generated by Composer + +$vendorDir = dirname(dirname(__FILE__)); +$baseDir = dirname($vendorDir); + +return array( +); diff --git a/vendor/composer/autoload_namespaces.php b/vendor/composer/autoload_namespaces.php new file mode 100644 index 0000000000000000000000000000000000000000..983d7b6ebf9ba78a400f78e6173a3651398b037e --- /dev/null +++ b/vendor/composer/autoload_namespaces.php @@ -0,0 +1,12 @@ +<?php + +// autoload_namespaces.php @generated by Composer + +$vendorDir = dirname(dirname(__FILE__)); +$baseDir = dirname($vendorDir); + +return array( + 'Zend\\Db\\' => array($vendorDir . '/zendframework/zend-db'), + 'UNL' => array($baseDir . '/src'), + 'Savvy' => array($vendorDir . '/saltybeagle/savvy/src'), +); diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php new file mode 100644 index 0000000000000000000000000000000000000000..b265c64a22f6691ca4a508347bd3dee43b9b19e7 --- /dev/null +++ b/vendor/composer/autoload_psr4.php @@ -0,0 +1,9 @@ +<?php + +// autoload_psr4.php @generated by Composer + +$vendorDir = dirname(dirname(__FILE__)); +$baseDir = dirname($vendorDir); + +return array( +); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php new file mode 100644 index 0000000000000000000000000000000000000000..a83573ab27a1887bbf8b0d589939e42ae81c3de1 --- /dev/null +++ b/vendor/composer/autoload_real.php @@ -0,0 +1,53 @@ +<?php + +// autoload_real.php @generated by Composer + +class ComposerAutoloaderInit7b2a97b8e090b6f85dc49f15ce5e9162 +{ + private static $loader; + + public static function loadClassLoader($class) + { + if ('Composer\Autoload\ClassLoader' === $class) { + require __DIR__ . '/ClassLoader.php'; + } + } + + public static function getLoader() + { + if (null !== self::$loader) { + return self::$loader; + } + + spl_autoload_register(array('ComposerAutoloaderInit7b2a97b8e090b6f85dc49f15ce5e9162', 'loadClassLoader'), true, true); + self::$loader = $loader = new \Composer\Autoload\ClassLoader(); + spl_autoload_unregister(array('ComposerAutoloaderInit7b2a97b8e090b6f85dc49f15ce5e9162', 'loadClassLoader')); + + $vendorDir = dirname(__DIR__); + $baseDir = dirname($vendorDir); + + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + + $loader->register(true); + + return $loader; + } +} + +function composerRequire7b2a97b8e090b6f85dc49f15ce5e9162($file) +{ + require $file; +} diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json new file mode 100644 index 0000000000000000000000000000000000000000..5116f0b82e3ced8035674435d2411187dc4d4d02 --- /dev/null +++ b/vendor/composer/installed.json @@ -0,0 +1,86 @@ +[ + { + "name": "zendframework/zend-db", + "version": "2.3.1", + "version_normalized": "2.3.1.0", + "target-dir": "Zend/Db", + "source": { + "type": "git", + "url": "https://github.com/zendframework/Component_ZendDb.git", + "reference": "29bb7f1ceacb32fa3e1c122bc3d14da6490aba2c" + }, + "dist": { + "type": "zip", + "url": "https://packages.zendframework.com/composer/zendframework-zend-db-29bb7f1ceacb32fa3e1c122bc3d14da6490aba2c-zip-4340f1.zip", + "reference": "2.3.1", + "shasum": "4993066700cc03e2cf18fe69192e35302f8c3d27" + }, + "require": { + "php": ">=5.3.23" + }, + "require-dev": { + "zendframework/zend-eventmanager": "self.version", + "zendframework/zend-servicemanager": "self.version", + "zendframework/zend-stdlib": "self.version" + }, + "suggest": { + "zendframework/zend-eventmanager": "Zend\\EventManager component", + "zendframework/zend-servicemanager": "Zend\\ServiceManager component", + "zendframework/zend-stdlib": "Zend\\Stdlib component" + }, + "time": "2014-04-15 15:29:07", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3-dev", + "dev-develop": "2.4-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Zend\\Db\\": "" + } + }, + "license": [ + "BSD-3-Clause" + ], + "description": " ", + "keywords": [ + "db", + "zf2" + ], + "support": { + "source": "https://github.com/zendframework/Component_ZendDb/tree/release-2.3.1" + } + }, + { + "name": "saltybeagle/savvy", + "version": "dev-master", + "version_normalized": "9999999-dev", + "source": { + "type": "git", + "url": "https://github.com/saltybeagle/Savvy.git", + "reference": "d8b58c71b5184dfb6615048748c118147706dab4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/saltybeagle/Savvy/zipball/d8b58c71b5184dfb6615048748c118147706dab4", + "reference": "d8b58c71b5184dfb6615048748c118147706dab4", + "shasum": "" + }, + "time": "2014-03-11 16:58:11", + "type": "library", + "installation-source": "source", + "autoload": { + "psr-0": { + "Savvy": "src/" + } + }, + "description": "Savvy is a powerful but lightweight object-oriented template system for PHP.", + "support": { + "source": "https://github.com/saltybeagle/Savvy/tree/master", + "issues": "https://github.com/saltybeagle/Savvy/issues" + } + } +] diff --git a/vendor/saltybeagle/savvy b/vendor/saltybeagle/savvy new file mode 160000 index 0000000000000000000000000000000000000000..d8b58c71b5184dfb6615048748c118147706dab4 --- /dev/null +++ b/vendor/saltybeagle/savvy @@ -0,0 +1 @@ +Subproject commit d8b58c71b5184dfb6615048748c118147706dab4 diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Adapter.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Adapter.php new file mode 100644 index 0000000000000000000000000000000000000000..a64f937a954828e5349abb9d7233c2bfaf0415a5 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Adapter.php @@ -0,0 +1,388 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter; + +use Zend\Db\ResultSet; + +/** + * @property Driver\DriverInterface $driver + * @property Platform\PlatformInterface $platform + */ +class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface +{ + /** + * Query Mode Constants + */ + const QUERY_MODE_EXECUTE = 'execute'; + const QUERY_MODE_PREPARE = 'prepare'; + + /** + * Prepare Type Constants + */ + const PREPARE_TYPE_POSITIONAL = 'positional'; + const PREPARE_TYPE_NAMED = 'named'; + + const FUNCTION_FORMAT_PARAMETER_NAME = 'formatParameterName'; + const FUNCTION_QUOTE_IDENTIFIER = 'quoteIdentifier'; + const FUNCTION_QUOTE_VALUE = 'quoteValue'; + + const VALUE_QUOTE_SEPARATOR = 'quoteSeparator'; + + /** + * @var Driver\DriverInterface + */ + protected $driver = null; + + /** + * @var Platform\PlatformInterface + */ + protected $platform = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * @var ResultSet\ResultSetInterface + */ + protected $queryResultSetPrototype = null; + + /** + * @var Driver\StatementInterface + */ + protected $lastPreparedStatement = null; + + /** + * @param Driver\DriverInterface|array $driver + * @param Platform\PlatformInterface $platform + * @param ResultSet\ResultSetInterface $queryResultPrototype + * @param Profiler\ProfilerInterface $profiler + * @throws Exception\InvalidArgumentException + */ + public function __construct($driver, Platform\PlatformInterface $platform = null, ResultSet\ResultSetInterface $queryResultPrototype = null, Profiler\ProfilerInterface $profiler = null) + { + // first argument can be an array of parameters + $parameters = array(); + + if (is_array($driver)) { + $parameters = $driver; + if ($profiler === null && isset($parameters['profiler'])) { + $profiler = $this->createProfiler($parameters); + } + $driver = $this->createDriver($parameters); + } elseif (!$driver instanceof Driver\DriverInterface) { + throw new Exception\InvalidArgumentException( + 'The supplied or instantiated driver object does not implement Zend\Db\Adapter\Driver\DriverInterface' + ); + } + + $driver->checkEnvironment(); + $this->driver = $driver; + + if ($platform == null) { + $platform = $this->createPlatform($parameters); + } + + $this->platform = $platform; + $this->queryResultSetPrototype = ($queryResultPrototype) ?: new ResultSet\ResultSet(); + + if ($profiler) { + $this->setProfiler($profiler); + } + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Adapter + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + if ($this->driver instanceof Profiler\ProfilerAwareInterface) { + $this->driver->setProfiler($profiler); + } + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * getDriver() + * + * @throws Exception\RuntimeException + * @return Driver\DriverInterface + */ + public function getDriver() + { + if ($this->driver == null) { + throw new Exception\RuntimeException('Driver has not been set or configured for this adapter.'); + } + return $this->driver; + } + + /** + * @return Platform\PlatformInterface + */ + public function getPlatform() + { + return $this->platform; + } + + /** + * @return ResultSet\ResultSetInterface + */ + public function getQueryResultSetPrototype() + { + return $this->queryResultSetPrototype; + } + + public function getCurrentSchema() + { + return $this->driver->getConnection()->getCurrentSchema(); + } + + /** + * query() is a convenience function + * + * @param string $sql + * @param string|array|ParameterContainer $parametersOrQueryMode + * @throws Exception\InvalidArgumentException + * @return Driver\StatementInterface|ResultSet\ResultSet + */ + public function query($sql, $parametersOrQueryMode = self::QUERY_MODE_PREPARE, ResultSet\ResultSetInterface $resultPrototype = null) + { + if (is_string($parametersOrQueryMode) && in_array($parametersOrQueryMode, array(self::QUERY_MODE_PREPARE, self::QUERY_MODE_EXECUTE))) { + $mode = $parametersOrQueryMode; + $parameters = null; + } elseif (is_array($parametersOrQueryMode) || $parametersOrQueryMode instanceof ParameterContainer) { + $mode = self::QUERY_MODE_PREPARE; + $parameters = $parametersOrQueryMode; + } else { + throw new Exception\InvalidArgumentException('Parameter 2 to this method must be a flag, an array, or ParameterContainer'); + } + + if ($mode == self::QUERY_MODE_PREPARE) { + $this->lastPreparedStatement = null; + $this->lastPreparedStatement = $this->driver->createStatement($sql); + $this->lastPreparedStatement->prepare(); + if (is_array($parameters) || $parameters instanceof ParameterContainer) { + $this->lastPreparedStatement->setParameterContainer((is_array($parameters)) ? new ParameterContainer($parameters) : $parameters); + $result = $this->lastPreparedStatement->execute(); + } else { + return $this->lastPreparedStatement; + } + } else { + $result = $this->driver->getConnection()->execute($sql); + } + + if ($result instanceof Driver\ResultInterface && $result->isQueryResult()) { + $resultSet = clone ($resultPrototype ?: $this->queryResultSetPrototype); + $resultSet->initialize($result); + return $resultSet; + } + + return $result; + } + + /** + * Create statement + * + * @param string $initialSql + * @param ParameterContainer $initialParameters + * @return Driver\StatementInterface + */ + public function createStatement($initialSql = null, $initialParameters = null) + { + $statement = $this->driver->createStatement($initialSql); + if ($initialParameters == null || !$initialParameters instanceof ParameterContainer && is_array($initialParameters)) { + $initialParameters = new ParameterContainer((is_array($initialParameters) ? $initialParameters : array())); + } + $statement->setParameterContainer($initialParameters); + return $statement; + } + + public function getHelpers(/* $functions */) + { + $functions = array(); + $platform = $this->platform; + foreach (func_get_args() as $arg) { + switch ($arg) { + case self::FUNCTION_QUOTE_IDENTIFIER: + $functions[] = function ($value) use ($platform) { return $platform->quoteIdentifier($value); }; + break; + case self::FUNCTION_QUOTE_VALUE: + $functions[] = function ($value) use ($platform) { return $platform->quoteValue($value); }; + break; + + } + } + } + + /** + * @param $name + * @throws Exception\InvalidArgumentException + * @return Driver\DriverInterface|Platform\PlatformInterface + */ + public function __get($name) + { + switch (strtolower($name)) { + case 'driver': + return $this->driver; + case 'platform': + return $this->platform; + default: + throw new Exception\InvalidArgumentException('Invalid magic property on adapter'); + } + + } + + /** + * @param array $parameters + * @return Driver\DriverInterface + * @throws \InvalidArgumentException + * @throws Exception\InvalidArgumentException + */ + protected function createDriver($parameters) + { + if (!isset($parameters['driver'])) { + throw new Exception\InvalidArgumentException(__FUNCTION__ . ' expects a "driver" key to be present inside the parameters'); + } + + if ($parameters['driver'] instanceof Driver\DriverInterface) { + return $parameters['driver']; + } + + if (!is_string($parameters['driver'])) { + throw new Exception\InvalidArgumentException(__FUNCTION__ . ' expects a "driver" to be a string or instance of DriverInterface'); + } + + $options = array(); + if (isset($parameters['options'])) { + $options = (array) $parameters['options']; + unset($parameters['options']); + } + + $driverName = strtolower($parameters['driver']); + switch ($driverName) { + case 'mysqli': + $driver = new Driver\Mysqli\Mysqli($parameters, null, null, $options); + break; + case 'sqlsrv': + $driver = new Driver\Sqlsrv\Sqlsrv($parameters); + break; + case 'oci8': + $driver = new Driver\Oci8\Oci8($parameters); + break; + case 'pgsql': + $driver = new Driver\Pgsql\Pgsql($parameters); + break; + case 'ibmdb2': + $driver = new Driver\IbmDb2\IbmDb2($parameters); + break; + case 'pdo': + default: + if ($driverName == 'pdo' || strpos($driverName, 'pdo') === 0) { + $driver = new Driver\Pdo\Pdo($parameters); + } + } + + if (!isset($driver) || !$driver instanceof Driver\DriverInterface) { + throw new Exception\InvalidArgumentException('DriverInterface expected', null, null); + } + + return $driver; + } + + /** + * @param Driver\DriverInterface $driver + * @return Platform\PlatformInterface + */ + protected function createPlatform($parameters) + { + if (isset($parameters['platform'])) { + $platformName = $parameters['platform']; + } elseif ($this->driver instanceof Driver\DriverInterface) { + $platformName = $this->driver->getDatabasePlatformName(Driver\DriverInterface::NAME_FORMAT_CAMELCASE); + } else { + throw new Exception\InvalidArgumentException('A platform could not be determined from the provided configuration'); + } + + // currently only supported by the IbmDb2 & Oracle concrete implementations + $options = (isset($parameters['platform_options'])) ? $parameters['platform_options'] : array(); + + switch ($platformName) { + case 'Mysql': + // mysqli or pdo_mysql driver + $driver = ($this->driver instanceof Driver\Mysqli\Mysqli || $this->driver instanceof Driver\Pdo\Pdo) ? $this->driver : null; + return new Platform\Mysql($driver); + case 'SqlServer': + // PDO is only supported driver for quoting values in this platform + return new Platform\SqlServer(($this->driver instanceof Driver\Pdo\Pdo) ? $this->driver : null); + case 'Oracle': + // oracle does not accept a driver as an option, no driver specific quoting available + return new Platform\Oracle($options); + case 'Sqlite': + // PDO is only supported driver for quoting values in this platform + return new Platform\Sqlite(($this->driver instanceof Driver\Pdo\Pdo) ? $this->driver : null); + case 'Postgresql': + // pgsql or pdo postgres driver + $driver = ($this->driver instanceof Driver\Pgsql\Pgsql || $this->driver instanceof Driver\Pdo\Pdo) ? $this->driver : null; + return new Platform\Postgresql($driver); + case 'IbmDb2': + // ibm_db2 driver escaping does not need an action connection + return new Platform\IbmDb2($options); + default: + return new Platform\Sql92(); + } + } + + protected function createProfiler($parameters) + { + if ($parameters['profiler'] instanceof Profiler\ProfilerInterface) { + $profiler = $parameters['profiler']; + } elseif (is_bool($parameters['profiler'])) { + $profiler = ($parameters['profiler'] == true) ? new Profiler\Profiler : null; + } else { + throw new Exception\InvalidArgumentException( + '"profiler" parameter must be an instance of ProfilerInterface or a boolean' + ); + } + return $profiler; + } + + /** + * @param array $parameters + * @return Driver\DriverInterface + * @throws \InvalidArgumentException + * @throws Exception\InvalidArgumentException + * @deprecated + */ + protected function createDriverFromParameters(array $parameters) + { + return $this->createDriver($parameters); + } + + /** + * @param Driver\DriverInterface $driver + * @return Platform\PlatformInterface + * @deprecated + */ + protected function createPlatformFromDriver(Driver\DriverInterface $driver) + { + return $this->createPlatform($driver); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterAbstractServiceFactory.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterAbstractServiceFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..42800a2ce929a731cb244895cfb030b0e37c6a26 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterAbstractServiceFactory.php @@ -0,0 +1,99 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter; + +use Zend\ServiceManager\AbstractFactoryInterface; +use Zend\ServiceManager\ServiceLocatorInterface; + +/** + * Database adapter abstract service factory. + * + * Allows configuring several database instances (such as writer and reader). + */ +class AdapterAbstractServiceFactory implements AbstractFactoryInterface +{ + /** + * @var array + */ + protected $config; + + /** + * Can we create an adapter by the requested name? + * + * @param ServiceLocatorInterface $services + * @param string $name + * @param string $requestedName + * @return bool + */ + public function canCreateServiceWithName(ServiceLocatorInterface $services, $name, $requestedName) + { + $config = $this->getConfig($services); + if (empty($config)) { + return false; + } + + return ( + isset($config[$requestedName]) + && is_array($config[$requestedName]) + && !empty($config[$requestedName]) + ); + } + + /** + * Create a DB adapter + * + * @param ServiceLocatorInterface $services + * @param string $name + * @param string $requestedName + * @return Adapter + */ + public function createServiceWithName(ServiceLocatorInterface $services, $name, $requestedName) + { + $config = $this->getConfig($services); + return new Adapter($config[$requestedName]); + } + + /** + * Get db configuration, if any + * + * @param ServiceLocatorInterface $services + * @return array + */ + protected function getConfig(ServiceLocatorInterface $services) + { + if ($this->config !== null) { + return $this->config; + } + + if (!$services->has('Config')) { + $this->config = array(); + return $this->config; + } + + $config = $services->get('Config'); + if (!isset($config['db']) + || !is_array($config['db']) + ) { + $this->config = array(); + return $this->config; + } + + $config = $config['db']; + if (!isset($config['adapters']) + || !is_array($config['adapters']) + ) { + $this->config = array(); + return $this->config; + } + + $this->config = $config['adapters']; + return $this->config; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterAwareInterface.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterAwareInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..95443a9a0df192d4e8a06c723e0fe3590b61d54d --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterAwareInterface.php @@ -0,0 +1,21 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter; + +interface AdapterAwareInterface +{ + /** + * Set db adapter + * + * @param Adapter $adapter + * @return AdapterAwareInterface + */ + public function setDbAdapter(Adapter $adapter); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterAwareTrait.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterAwareTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..3df7b36b110f2fb71950850d25841e513328fd53 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterAwareTrait.php @@ -0,0 +1,32 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter; + + +trait AdapterAwareTrait +{ + /** + * @var Adapter + */ + protected $adapter = null; + + /** + * Set db adapter + * + * @param Adapter $adapter + * @return mixed + */ + public function setDbAdapter(Adapter $adapter) + { + $this->adapter = $adapter; + + return $this; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterInterface.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..0f51e8dd5f703579a5b699b88b0f0eaaa3838771 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterInterface.php @@ -0,0 +1,29 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter; + +/** + * + * @property Driver\DriverInterface $driver + * @property Platform\PlatformInterface $platform + */ +interface AdapterInterface +{ + /** + * @return Driver\DriverInterface + */ + public function getDriver(); + + /** + * @return Platform\PlatformInterface + */ + public function getPlatform(); + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterServiceFactory.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterServiceFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..f0619ad8e77245fb38920e46a0de7b1449199e58 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/AdapterServiceFactory.php @@ -0,0 +1,28 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter; + +use Zend\ServiceManager\FactoryInterface; +use Zend\ServiceManager\ServiceLocatorInterface; + +class AdapterServiceFactory implements FactoryInterface +{ + /** + * Create db adapter service + * + * @param ServiceLocatorInterface $serviceLocator + * @return Adapter + */ + public function createService(ServiceLocatorInterface $serviceLocator) + { + $config = $serviceLocator->get('Config'); + return new Adapter($config['db']); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/ConnectionInterface.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/ConnectionInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..2e27fd68893752e7bc5b5f51beba5e40438c7895 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/ConnectionInterface.php @@ -0,0 +1,85 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver; + +interface ConnectionInterface +{ + /** + * Get current schema + * + * @return string + */ + public function getCurrentSchema(); + + /** + * Get resource + * + * @return mixed + */ + public function getResource(); + + /** + * Connect + * + * @return ConnectionInterface + */ + public function connect(); + + /** + * Is connected + * + * @return bool + */ + public function isConnected(); + + /** + * Disconnect + * + * @return ConnectionInterface + */ + public function disconnect(); + + /** + * Begin transaction + * + * @return ConnectionInterface + */ + public function beginTransaction(); + + /** + * Commit + * + * @return ConnectionInterface + */ + public function commit(); + + /** + * Rollback + * + * @return ConnectionInterface + */ + public function rollback(); + + /** + * Execute + * + * @param string $sql + * @return ResultInterface + */ + public function execute($sql); + + /** + * Get last generated id + * + * @param null $name Ignored + * @return int + */ + public function getLastGeneratedValue($name = null); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/DriverInterface.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/DriverInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..98bbc835df7a60d9e9d2c9a542d7ca07bb5327b8 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/DriverInterface.php @@ -0,0 +1,79 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver; + +interface DriverInterface +{ + const PARAMETERIZATION_POSITIONAL = 'positional'; + const PARAMETERIZATION_NAMED = 'named'; + const NAME_FORMAT_CAMELCASE = 'camelCase'; + const NAME_FORMAT_NATURAL = 'natural'; + + /** + * Get database platform name + * + * @param string $nameFormat + * @return string + */ + public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE); + + /** + * Check environment + * + * @return bool + */ + public function checkEnvironment(); + + /** + * Get connection + * + * @return ConnectionInterface + */ + public function getConnection(); + + /** + * Create statement + * + * @param string|resource $sqlOrResource + * @return StatementInterface + */ + public function createStatement($sqlOrResource = null); + + /** + * Create result + * + * @param resource $resource + * @return ResultInterface + */ + public function createResult($resource); + + /** + * Get prepare type + * + * @return array + */ + public function getPrepareType(); + + /** + * Format parameter name + * + * @param string $name + * @param mixed $type + * @return string + */ + public function formatParameterName($name, $type = null); + + /** + * Get last generated value + * + * @return mixed + */ + public function getLastGeneratedValue(); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Feature/AbstractFeature.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Feature/AbstractFeature.php new file mode 100644 index 0000000000000000000000000000000000000000..699ba2af20172a3d0f7338cf7d12b174c97c97e4 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Feature/AbstractFeature.php @@ -0,0 +1,40 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Feature; + +use Zend\Db\Adapter\Driver\DriverInterface; + +abstract class AbstractFeature +{ + + /** + * @var DriverInterface + */ + protected $driver = null; + + /** + * Set driver + * + * @param DriverInterface $driver + * @return void + */ + public function setDriver(DriverInterface $driver) + { + $this->driver = $driver; + } + + /** + * Get name + * + * @return string + */ + abstract public function getName(); + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Feature/DriverFeatureInterface.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Feature/DriverFeatureInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..10c96f7731d6988bd3a2765ec5281899f90d9787 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Feature/DriverFeatureInterface.php @@ -0,0 +1,37 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Feature; + +interface DriverFeatureInterface +{ + /** + * Setup the default features for Pdo + * + * @return DriverFeatureInterface + */ + public function setupDefaultFeatures(); + + /** + * Add feature + * + * @param string $name + * @param mixed $feature + * @return DriverFeatureInterface + */ + public function addFeature($name, $feature); + + /** + * Get feature + * + * @param $name + * @return mixed|false + */ + public function getFeature($name); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Connection.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Connection.php new file mode 100644 index 0000000000000000000000000000000000000000..50c161537d30ae2967e414f007909305dc659912 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Connection.php @@ -0,0 +1,283 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\IbmDb2; + +use Zend\Db\Adapter\Driver\ConnectionInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\Profiler; + +class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface +{ + /** @var IbmDb2 */ + protected $driver = null; + + /** + * @var array + */ + protected $connectionParameters = null; + + /** + * @var resource + */ + protected $resource = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * Constructor + * + * @param array|resource|null $connectionParameters (ibm_db2 connection resource) + * @throws Exception\InvalidArgumentException + */ + public function __construct($connectionParameters = null) + { + if (is_array($connectionParameters)) { + $this->setConnectionParameters($connectionParameters); + } elseif (is_resource($connectionParameters)) { + $this->setResource($connectionParameters); + } elseif (null !== $connectionParameters) { + throw new Exception\InvalidArgumentException( + '$connection must be an array of parameters, a db2 connection resource or null' + ); + } + } + + /** + * Set driver + * + * @param IbmDb2 $driver + * @return Connection + */ + public function setDriver(IbmDb2 $driver) + { + $this->driver = $driver; + return $this; + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Connection + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * @param array $connectionParameters + * @return Connection + */ + public function setConnectionParameters(array $connectionParameters) + { + $this->connectionParameters = $connectionParameters; + return $this; + } + + /** + * @return array + */ + public function getConnectionParameters() + { + return $this->connectionParameters; + } + + /** + * @param resource $resource DB2 resource + * @return Connection + */ + public function setResource($resource) + { + if (!is_resource($resource) || get_resource_type($resource) !== 'DB2 Connection') { + throw new Exception\InvalidArgumentException('The resource provided must be of type "DB2 Connection"'); + } + $this->resource = $resource; + return $this; + } + + /** + * Get current schema + * + * @return string + */ + public function getCurrentSchema() + { + if (!$this->isConnected()) { + $this->connect(); + } + + $info = db2_server_info($this->resource); + return (isset($info->DB_NAME) ? $info->DB_NAME : ''); + } + + /** + * Get resource + * + * @return mixed + */ + public function getResource() + { + return $this->resource; + } + + /** + * Connect + * + * @return ConnectionInterface + */ + public function connect() + { + if (is_resource($this->resource)) { + return $this; + } + + // localize + $p = $this->connectionParameters; + + // given a list of key names, test for existence in $p + $findParameterValue = function (array $names) use ($p) { + foreach ($names as $name) { + if (isset($p[$name])) { + return $p[$name]; + } + } + return null; + }; + + $database = $findParameterValue(array('database', 'db')); + $username = $findParameterValue(array('username', 'uid', 'UID')); + $password = $findParameterValue(array('password', 'pwd', 'PWD')); + $isPersistent = $findParameterValue(array('persistent', 'PERSISTENT', 'Persistent')); + $options = (isset($p['driver_options']) ? $p['driver_options'] : array()); + + if ($isPersistent) { + $this->resource = db2_pconnect($database, $username, $password, $options); + } else { + $this->resource = db2_connect($database, $username, $password, $options); + } + + if ($this->resource === false) { + throw new Exception\RuntimeException(sprintf( + '%s: Unable to connect to database', + __METHOD__ + )); + } + return $this; + } + + /** + * Is connected + * + * @return bool + */ + public function isConnected() + { + return ($this->resource !== null); + } + + /** + * Disconnect + * + * @return ConnectionInterface + */ + public function disconnect() + { + if ($this->resource) { + db2_close($this->resource); + $this->resource = null; + } + return $this; + } + + /** + * Begin transaction + * + * @return ConnectionInterface + */ + public function beginTransaction() + { + // TODO: Implement beginTransaction() method. + } + + /** + * Commit + * + * @return ConnectionInterface + */ + public function commit() + { + // TODO: Implement commit() method. + } + + /** + * Rollback + * + * @return ConnectionInterface + */ + public function rollback() + { + // TODO: Implement rollback() method. + } + + /** + * Execute + * + * @param string $sql + * @return Result + */ + public function execute($sql) + { + if (!$this->isConnected()) { + $this->connect(); + } + + if ($this->profiler) { + $this->profiler->profilerStart($sql); + } + + set_error_handler(function () {}, E_WARNING); // suppress warnings + $resultResource = db2_exec($this->resource, $sql); + restore_error_handler(); + + if ($this->profiler) { + $this->profiler->profilerFinish($sql); + } + + // if the returnValue is something other than a pg result resource, bypass wrapping it + if ($resultResource === false) { + throw new Exception\InvalidQueryException(db2_stmt_errormsg()); + } + + $resultPrototype = $this->driver->createResult(($resultResource === true) ? $this->resource : $resultResource); + return $resultPrototype; + } + + /** + * Get last generated id + * + * @param null $name Ignored + * @return int + */ + public function getLastGeneratedValue($name = null) + { + return db2_last_insert_id($this->resource); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/IbmDb2.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/IbmDb2.php new file mode 100644 index 0000000000000000000000000000000000000000..d129b49b38cfe35844e2ec99fbad696b29b6ff61 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/IbmDb2.php @@ -0,0 +1,214 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\IbmDb2; + +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\Profiler; + +class IbmDb2 implements DriverInterface, Profiler\ProfilerAwareInterface +{ + /** + * @var Connection + */ + protected $connection; + + /** @var Statement */ + protected $statementPrototype; + + /** @var Result */ + protected $resultPrototype; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler; + + /** + * @param array|Connection|resource $connection + * @param null|Statement $statementPrototype + * @param null|Result $resultPrototype + */ + public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null) + { + if (!$connection instanceof Connection) { + $connection = new Connection($connection); + } + + $this->registerConnection($connection); + $this->registerStatementPrototype(($statementPrototype) ?: new Statement()); + $this->registerResultPrototype(($resultPrototype) ?: new Result()); + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return IbmDb2 + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + if ($this->connection instanceof Profiler\ProfilerAwareInterface) { + $this->connection->setProfiler($profiler); + } + if ($this->statementPrototype instanceof Profiler\ProfilerAwareInterface) { + $this->statementPrototype->setProfiler($profiler); + } + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * @param Connection $connection + * @return IbmDb2 + */ + public function registerConnection(Connection $connection) + { + $this->connection = $connection; + $this->connection->setDriver($this); + return $this; + } + + /** + * @param Statement $statementPrototype + * @return IbmDb2 + */ + public function registerStatementPrototype(Statement $statementPrototype) + { + $this->statementPrototype = $statementPrototype; + $this->statementPrototype->setDriver($this); + return $this; + } + + /** + * @param Result $resultPrototype + * @return IbmDb2 + */ + public function registerResultPrototype(Result $resultPrototype) + { + $this->resultPrototype = $resultPrototype; + return $this; + } + + /** + * Get database platform name + * + * @param string $nameFormat + * @return string + */ + public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE) + { + if ($nameFormat == self::NAME_FORMAT_CAMELCASE) { + return 'IbmDb2'; + } else { + return 'IBM DB2'; + } + } + + /** + * Check environment + * + * @return bool + */ + public function checkEnvironment() + { + if (!extension_loaded('ibm_db2')) { + throw new Exception\RuntimeException('The ibm_db2 extension is required by this driver.'); + } + } + + /** + * Get connection + * + * @return Connection + */ + public function getConnection() + { + return $this->connection; + } + + /** + * Create statement + * + * @param string|resource $sqlOrResource + * @return Statement + */ + public function createStatement($sqlOrResource = null) + { + $statement = clone $this->statementPrototype; + if (is_resource($sqlOrResource) && get_resource_type($sqlOrResource) == 'DB2 Statement') { + $statement->setResource($sqlOrResource); + } else { + if (is_string($sqlOrResource)) { + $statement->setSql($sqlOrResource); + } elseif ($sqlOrResource !== null) { + throw new Exception\InvalidArgumentException( + __FUNCTION__ . ' only accepts an SQL string or an ibm_db2 resource' + ); + } + if (!$this->connection->isConnected()) { + $this->connection->connect(); + } + $statement->initialize($this->connection->getResource()); + } + return $statement; + } + + /** + * Create result + * + * @param resource $resource + * @return Result + */ + public function createResult($resource) + { + $result = clone $this->resultPrototype; + $result->initialize($resource, $this->connection->getLastGeneratedValue()); + return $result; + } + + /** + * Get prepare type + * + * @return array + */ + public function getPrepareType() + { + return self::PARAMETERIZATION_POSITIONAL; + } + + /** + * Format parameter name + * + * @param string $name + * @param mixed $type + * @return string + */ + public function formatParameterName($name, $type = null) + { + return '?'; + } + + /** + * Get last generated value + * + * @return mixed + */ + public function getLastGeneratedValue() + { + return $this->connection->getLastGeneratedValue(); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Result.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Result.php new file mode 100644 index 0000000000000000000000000000000000000000..add4e1e3f163102e5362c2f0a9a64a5a80e54484 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Result.php @@ -0,0 +1,192 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\IbmDb2; + +use Zend\Db\Adapter\Driver\ResultInterface; +use Zend\Db\Adapter\Exception; + +class Result implements ResultInterface +{ + /** + * @var resource + */ + protected $resource; + + /** + * @var int + */ + protected $position = 0; + + /** + * @var bool + */ + protected $currentComplete = false; + + /** + * @var mixed + */ + protected $currentData = null; + + /** + * @var mixed + */ + protected $generatedValue = null; + + /** + * @param resource $resource + * @param mixed $generatedValue + * @return Result + */ + public function initialize($resource, $generatedValue = null) + { + $this->resource = $resource; + $this->generatedValue = $generatedValue; + return $this; + } + + /** + * (PHP 5 >= 5.0.0)<br/> + * Return the current element + * @link http://php.net/manual/en/iterator.current.php + * @return mixed Can return any type. + */ + public function current() + { + if ($this->currentComplete) { + return $this->currentData; + } + + $this->currentData = db2_fetch_assoc($this->resource); + return $this->currentData; + } + + /** + * @return mixed + */ + public function next() + { + $this->currentData = db2_fetch_assoc($this->resource); + $this->currentComplete = true; + $this->position++; + return $this->currentData; + } + + /** + * @return int|string + */ + public function key() + { + return $this->position; + } + + /** + * @return bool + */ + public function valid() + { + return ($this->currentData !== false); + } + + /** + * (PHP 5 >= 5.0.0)<br/> + * Rewind the Iterator to the first element + * @link http://php.net/manual/en/iterator.rewind.php + * @return void Any returned value is ignored. + */ + public function rewind() + { + if ($this->position > 0) { + throw new Exception\RuntimeException( + 'This result is a forward only result set, calling rewind() after moving forward is not supported' + ); + } + $this->currentData = db2_fetch_assoc($this->resource); + $this->currentComplete = true; + $this->position = 1; + } + + /** + * Force buffering + * + * @return void + */ + public function buffer() + { + return null; + } + + /** + * Check if is buffered + * + * @return bool|null + */ + public function isBuffered() + { + return false; + } + + /** + * Is query result? + * + * @return bool + */ + public function isQueryResult() + { + return (db2_num_fields($this->resource) > 0); + } + + /** + * Get affected rows + * + * @return int + */ + public function getAffectedRows() + { + return db2_num_rows($this->resource); + } + + /** + * Get generated value + * + * @return mixed|null + */ + public function getGeneratedValue() + { + return $this->generatedValue; + } + + /** + * Get the resource + * + * @return mixed + */ + public function getResource() + { + return $this->resource; + } + + /** + * Get field count + * + * @return int + */ + public function getFieldCount() + { + return db2_num_fields($this->resource); + } + + /** + * @return null|int + */ + public function count() + { + return null; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Statement.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Statement.php new file mode 100644 index 0000000000000000000000000000000000000000..029a9ed276fcdf8ac5111366bd1c31132d0fd907 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/IbmDb2/Statement.php @@ -0,0 +1,240 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\IbmDb2; + +use Zend\Db\Adapter\Driver\StatementInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Profiler; + +class Statement implements StatementInterface, Profiler\ProfilerAwareInterface +{ + /** + * @var resource + */ + protected $db2 = null; + + /** + * @var IbmDb2 + */ + protected $driver = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * @var string + */ + protected $sql = ''; + + /** + * @var ParameterContainer + */ + protected $parameterContainer = null; + + /** + * @var bool + */ + protected $isPrepared = false; + + /** + * @var resource + */ + protected $resource = null; + + /** + * @param $resource + * @return Statement + */ + public function initialize($resource) + { + $this->db2 = $resource; + return $this; + } + + /** + * @param IbmDb2 $driver + * @return Statement + */ + public function setDriver(IbmDb2 $driver) + { + $this->driver = $driver; + return $this; + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Statement + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Set sql + * + * @param $sql + * @return mixed + */ + public function setSql($sql) + { + $this->sql = $sql; + return $this; + } + + /** + * Get sql + * + * @return mixed + */ + public function getSql() + { + return $this->sql; + } + + /** + * Set parameter container + * + * @param ParameterContainer $parameterContainer + * @return mixed + */ + public function setParameterContainer(ParameterContainer $parameterContainer) + { + $this->parameterContainer = $parameterContainer; + return $this; + } + + /** + * Get parameter container + * + * @return mixed + */ + public function getParameterContainer() + { + return $this->parameterContainer; + } + + /** + * @param $resource + * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException + */ + public function setResource($resource) + { + if (get_resource_type($resource) !== 'DB2 Statement') { + throw new Exception\InvalidArgumentException('Resource must be of type DB2 Statement'); + } + $this->resource = $resource; + } + + /** + * Get resource + * + * @return resource + */ + public function getResource() + { + return $this->resource; + } + + /** + * Prepare sql + * + * @param string|null $sql + * @return Statement + */ + public function prepare($sql = null) + { + if ($this->isPrepared) { + throw new Exception\RuntimeException('This statement has been prepared already'); + } + + if ($sql == null) { + $sql = $this->sql; + } + + $this->resource = db2_prepare($this->db2, $sql); + + if ($this->resource === false) { + throw new Exception\RuntimeException(db2_stmt_errormsg(), db2_stmt_error()); + } + + $this->isPrepared = true; + return $this; + } + + /** + * Check if is prepared + * + * @return bool + */ + public function isPrepared() + { + return $this->isPrepared; + } + + /** + * Execute + * + * @param null $parameters + * @return Result + */ + public function execute($parameters = null) + { + if (!$this->isPrepared) { + $this->prepare(); + } + + /** START Standard ParameterContainer Merging Block */ + if (!$this->parameterContainer instanceof ParameterContainer) { + if ($parameters instanceof ParameterContainer) { + $this->parameterContainer = $parameters; + $parameters = null; + } else { + $this->parameterContainer = new ParameterContainer(); + } + } + + if (is_array($parameters)) { + $this->parameterContainer->setFromArray($parameters); + } + /** END Standard ParameterContainer Merging Block */ + + if ($this->profiler) { + $this->profiler->profilerStart($this); + } + + set_error_handler(function () {}, E_WARNING); // suppress warnings + $response = db2_execute($this->resource, $this->parameterContainer->getPositionalArray()); + restore_error_handler(); + + if ($this->profiler) { + $this->profiler->profilerFinish(); + } + + if ($response === false) { + throw new Exception\RuntimeException(db2_stmt_errormsg($this->resource)); + } + + $result = $this->driver->createResult($this->resource); + return $result; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Connection.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Connection.php new file mode 100644 index 0000000000000000000000000000000000000000..a7c1dea2186a0865536df7b7651ec79a8de84df1 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Connection.php @@ -0,0 +1,347 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Mysqli; + +use Zend\Db\Adapter\Driver\ConnectionInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\Profiler; + +class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface +{ + + /** + * @var Mysqli + */ + protected $driver = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * Connection parameters + * + * @var array + */ + protected $connectionParameters = array(); + + /** + * @var \mysqli + */ + protected $resource = null; + + /** + * In transaction + * + * @var bool + */ + protected $inTransaction = false; + + /** + * Constructor + * + * @param array|mysqli|null $connectionInfo + * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException + */ + public function __construct($connectionInfo = null) + { + if (is_array($connectionInfo)) { + $this->setConnectionParameters($connectionInfo); + } elseif ($connectionInfo instanceof \mysqli) { + $this->setResource($connectionInfo); + } elseif (null !== $connectionInfo) { + throw new Exception\InvalidArgumentException('$connection must be an array of parameters, a mysqli object or null'); + } + } + + /** + * @param Mysqli $driver + * @return Connection + */ + public function setDriver(Mysqli $driver) + { + $this->driver = $driver; + return $this; + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Connection + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Set connection parameters + * + * @param array $connectionParameters + * @return Connection + */ + public function setConnectionParameters(array $connectionParameters) + { + $this->connectionParameters = $connectionParameters; + return $this; + } + + /** + * Get connection parameters + * + * @return array + */ + public function getConnectionParameters() + { + return $this->connectionParameters; + } + + /** + * Get current schema + * + * @return string + */ + public function getCurrentSchema() + { + if (!$this->isConnected()) { + $this->connect(); + } + + /** @var $result \mysqli_result */ + $result = $this->resource->query('SELECT DATABASE()'); + $r = $result->fetch_row(); + return $r[0]; + } + + /** + * Set resource + * + * @param \mysqli $resource + * @return Connection + */ + public function setResource(\mysqli $resource) + { + $this->resource = $resource; + return $this; + } + + /** + * Get resource + * + * @return \mysqli + */ + public function getResource() + { + $this->connect(); + return $this->resource; + } + + /** + * Connect + * + * @throws Exception\RuntimeException + * @return Connection + */ + public function connect() + { + if ($this->resource instanceof \mysqli) { + return $this; + } + + // localize + $p = $this->connectionParameters; + + // given a list of key names, test for existence in $p + $findParameterValue = function (array $names) use ($p) { + foreach ($names as $name) { + if (isset($p[$name])) { + return $p[$name]; + } + } + return; + }; + + $hostname = $findParameterValue(array('hostname', 'host')); + $username = $findParameterValue(array('username', 'user')); + $password = $findParameterValue(array('password', 'passwd', 'pw')); + $database = $findParameterValue(array('database', 'dbname', 'db', 'schema')); + $port = (isset($p['port'])) ? (int) $p['port'] : null; + $socket = (isset($p['socket'])) ? $p['socket'] : null; + + $this->resource = new \mysqli(); + $this->resource->init(); + + if (!empty($p['driver_options'])) { + foreach ($p['driver_options'] as $option => $value) { + if (is_string($option)) { + $option = strtoupper($option); + if (!defined($option)) { + continue; + } + $option = constant($option); + } + $this->resource->options($option, $value); + } + } + + $this->resource->real_connect($hostname, $username, $password, $database, $port, $socket); + + if ($this->resource->connect_error) { + throw new Exception\RuntimeException( + 'Connection error', + null, + new Exception\ErrorException($this->resource->connect_error, $this->resource->connect_errno) + ); + } + + if (!empty($p['charset'])) { + $this->resource->set_charset($p['charset']); + } + + return $this; + } + + /** + * Is connected + * + * @return bool + */ + public function isConnected() + { + return ($this->resource instanceof \mysqli); + } + + /** + * Disconnect + * + * @return void + */ + public function disconnect() + { + if ($this->resource instanceof \mysqli) { + $this->resource->close(); + } + $this->resource = null; + } + + /** + * Begin transaction + * + * @return void + */ + public function beginTransaction() + { + if (!$this->isConnected()) { + $this->connect(); + } + + $this->resource->autocommit(false); + $this->inTransaction = true; + } + + /** + * In transaction + * + * @return bool + */ + public function inTransaction() + { + return $this->inTransaction; + } + + /** + * Commit + * + * @return void + */ + public function commit() + { + if (!$this->resource) { + $this->connect(); + } + + $this->resource->commit(); + $this->inTransaction = false; + $this->resource->autocommit(true); + } + + /** + * Rollback + * + * @throws Exception\RuntimeException + * @return Connection + */ + public function rollback() + { + if (!$this->resource) { + throw new Exception\RuntimeException('Must be connected before you can rollback.'); + } + + if (!$this->inTransaction) { + throw new Exception\RuntimeException('Must call beginTransaction() before you can rollback.'); + } + + $this->resource->rollback(); + $this->resource->autocommit(true); + return $this; + } + + /** + * Execute + * + * @param string $sql + * @throws Exception\InvalidQueryException + * @return Result + */ + public function execute($sql) + { + if (!$this->isConnected()) { + $this->connect(); + } + + if ($this->profiler) { + $this->profiler->profilerStart($sql); + } + + $resultResource = $this->resource->query($sql); + + if ($this->profiler) { + $this->profiler->profilerFinish($sql); + } + + // if the returnValue is something other than a mysqli_result, bypass wrapping it + if ($resultResource === false) { + throw new Exception\InvalidQueryException($this->resource->error); + } + + $resultPrototype = $this->driver->createResult(($resultResource === true) ? $this->resource : $resultResource); + return $resultPrototype; + } + + /** + * Get last generated id + * + * @param null $name Ignored + * @return int + */ + public function getLastGeneratedValue($name = null) + { + return $this->resource->insert_id; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Mysqli.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Mysqli.php new file mode 100644 index 0000000000000000000000000000000000000000..8c1be74b1e05d2e7fab30bab0cc924c0bfcfb4db --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Mysqli.php @@ -0,0 +1,257 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Mysqli; + +use mysqli_stmt; +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\Profiler; + +class Mysqli implements DriverInterface, Profiler\ProfilerAwareInterface +{ + + /** + * @var Connection + */ + protected $connection = null; + + /** + * @var Statement + */ + protected $statementPrototype = null; + + /** + * @var Result + */ + protected $resultPrototype = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * @var array + */ + protected $options = array( + 'buffer_results' => false + ); + + /** + * Constructor + * + * @param array|Connection|\mysqli $connection + * @param null|Statement $statementPrototype + * @param null|Result $resultPrototype + * @param array $options + */ + public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null, array $options = array()) + { + if (!$connection instanceof Connection) { + $connection = new Connection($connection); + } + + $options = array_intersect_key(array_merge($this->options, $options), $this->options); + + $this->registerConnection($connection); + $this->registerStatementPrototype(($statementPrototype) ?: new Statement($options['buffer_results'])); + $this->registerResultPrototype(($resultPrototype) ?: new Result()); + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Mysqli + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + if ($this->connection instanceof Profiler\ProfilerAwareInterface) { + $this->connection->setProfiler($profiler); + } + if ($this->statementPrototype instanceof Profiler\ProfilerAwareInterface) { + $this->statementPrototype->setProfiler($profiler); + } + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Register connection + * + * @param Connection $connection + * @return Mysqli + */ + public function registerConnection(Connection $connection) + { + $this->connection = $connection; + $this->connection->setDriver($this); // needs access to driver to createStatement() + return $this; + } + + /** + * Register statement prototype + * + * @param Statement $statementPrototype + */ + public function registerStatementPrototype(Statement $statementPrototype) + { + $this->statementPrototype = $statementPrototype; + $this->statementPrototype->setDriver($this); // needs access to driver to createResult() + } + + /** + * Get statement prototype + * + * @return null|Statement + */ + public function getStatementPrototype() + { + return $this->statementPrototype; + } + + /** + * Register result prototype + * + * @param Result $resultPrototype + */ + public function registerResultPrototype(Result $resultPrototype) + { + $this->resultPrototype = $resultPrototype; + } + + /** + * @return null|Result + */ + public function getResultPrototype() + { + return $this->resultPrototype; + } + + /** + * Get database platform name + * + * @param string $nameFormat + * @return string + */ + public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE) + { + if ($nameFormat == self::NAME_FORMAT_CAMELCASE) { + return 'Mysql'; + } + + return 'MySQL'; + } + + /** + * Check environment + * + * @throws Exception\RuntimeException + * @return void + */ + public function checkEnvironment() + { + if (!extension_loaded('mysqli')) { + throw new Exception\RuntimeException('The Mysqli extension is required for this adapter but the extension is not loaded'); + } + } + + /** + * Get connection + * + * @return Connection + */ + public function getConnection() + { + return $this->connection; + } + + /** + * Create statement + * + * @param string $sqlOrResource + * @return Statement + */ + public function createStatement($sqlOrResource = null) + { + /** + * @todo Resource tracking + if (is_resource($sqlOrResource) && !in_array($sqlOrResource, $this->resources, true)) { + $this->resources[] = $sqlOrResource; + } + */ + + $statement = clone $this->statementPrototype; + if ($sqlOrResource instanceof mysqli_stmt) { + $statement->setResource($sqlOrResource); + } else { + if (is_string($sqlOrResource)) { + $statement->setSql($sqlOrResource); + } + if (!$this->connection->isConnected()) { + $this->connection->connect(); + } + $statement->initialize($this->connection->getResource()); + } + return $statement; + } + + /** + * Create result + * + * @param resource $resource + * @param null|bool $isBuffered + * @return Result + */ + public function createResult($resource, $isBuffered = null) + { + $result = clone $this->resultPrototype; + $result->initialize($resource, $this->connection->getLastGeneratedValue(), $isBuffered); + return $result; + } + + /** + * Get prepare type + * + * @return array + */ + public function getPrepareType() + { + return self::PARAMETERIZATION_POSITIONAL; + } + + /** + * Format parameter name + * + * @param string $name + * @param mixed $type + * @return string + */ + public function formatParameterName($name, $type = null) + { + return '?'; + } + + /** + * Get last generated value + * + * @return mixed + */ + public function getLastGeneratedValue() + { + return $this->getConnection()->getLastGeneratedValue(); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Result.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Result.php new file mode 100644 index 0000000000000000000000000000000000000000..7cd1118ceb8dfab415fab271bc88766665b4863f --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Result.php @@ -0,0 +1,342 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Mysqli; + +use Iterator; +use Zend\Db\Adapter\Driver\ResultInterface; +use Zend\Db\Adapter\Exception; + +class Result implements + Iterator, + ResultInterface +{ + + /** + * @var \mysqli|\mysqli_result|\mysqli_stmt + */ + protected $resource = null; + + /** + * @var bool + */ + protected $isBuffered = null; + + /** + * Cursor position + * @var int + */ + protected $position = 0; + + /** + * Number of known rows + * @var int + */ + protected $numberOfRows = -1; + + /** + * Is the current() operation already complete for this pointer position? + * @var bool + */ + protected $currentComplete = false; + + /** + * @var bool + */ + protected $nextComplete = false; + + /** + * @var bool + */ + protected $currentData = false; + + /** + * + * @var array + */ + protected $statementBindValues = array('keys' => null, 'values' => array()); + + /** + * @var mixed + */ + protected $generatedValue = null; + + /** + * Initialize + * + * @param mixed $resource + * @param mixed $generatedValue + * @param bool|null $isBuffered + * @throws Exception\InvalidArgumentException + * @return Result + */ + public function initialize($resource, $generatedValue, $isBuffered = null) + { + if (!$resource instanceof \mysqli && !$resource instanceof \mysqli_result && !$resource instanceof \mysqli_stmt) { + throw new Exception\InvalidArgumentException('Invalid resource provided.'); + } + + if ($isBuffered !== null) { + $this->isBuffered = $isBuffered; + } else { + if ($resource instanceof \mysqli || $resource instanceof \mysqli_result + || $resource instanceof \mysqli_stmt && $resource->num_rows != 0) { + $this->isBuffered = true; + } + } + + $this->resource = $resource; + $this->generatedValue = $generatedValue; + return $this; + } + + /** + * Force buffering + * + * @throws Exception\RuntimeException + */ + public function buffer() + { + if ($this->resource instanceof \mysqli_stmt && $this->isBuffered !== true) { + if ($this->position > 0) { + throw new Exception\RuntimeException('Cannot buffer a result set that has started iteration.'); + } + $this->resource->store_result(); + $this->isBuffered = true; + } + } + + /** + * Check if is buffered + * + * @return bool|null + */ + public function isBuffered() + { + return $this->isBuffered; + } + + /** + * Return the resource + * + * @return mixed + */ + public function getResource() + { + return $this->resource; + } + + /** + * Is query result? + * + * @return bool + */ + public function isQueryResult() + { + return ($this->resource->field_count > 0); + } + + /** + * Get affected rows + * + * @return int + */ + public function getAffectedRows() + { + if ($this->resource instanceof \mysqli || $this->resource instanceof \mysqli_stmt) { + return $this->resource->affected_rows; + } + + return $this->resource->num_rows; + } + + /** + * Current + * + * @return mixed + */ + public function current() + { + if ($this->currentComplete) { + return $this->currentData; + } + + if ($this->resource instanceof \mysqli_stmt) { + $this->loadDataFromMysqliStatement(); + return $this->currentData; + } else { + $this->loadFromMysqliResult(); + return $this->currentData; + } + } + + /** + * Mysqli's binding and returning of statement values + * + * Mysqli requires you to bind variables to the extension in order to + * get data out. These values have to be references: + * @see http://php.net/manual/en/mysqli-stmt.bind-result.php + * + * @throws Exception\RuntimeException + * @return bool + */ + protected function loadDataFromMysqliStatement() + { + $data = null; + // build the default reference based bind structure, if it does not already exist + if ($this->statementBindValues['keys'] === null) { + $this->statementBindValues['keys'] = array(); + $resultResource = $this->resource->result_metadata(); + foreach ($resultResource->fetch_fields() as $col) { + $this->statementBindValues['keys'][] = $col->name; + } + $this->statementBindValues['values'] = array_fill(0, count($this->statementBindValues['keys']), null); + $refs = array(); + foreach ($this->statementBindValues['values'] as $i => &$f) { + $refs[$i] = &$f; + } + call_user_func_array(array($this->resource, 'bind_result'), $this->statementBindValues['values']); + } + + if (($r = $this->resource->fetch()) === null) { + if (!$this->isBuffered) { + $this->resource->close(); + } + return false; + } elseif ($r === false) { + throw new Exception\RuntimeException($this->resource->error); + } + + // dereference + for ($i = 0, $count = count($this->statementBindValues['keys']); $i < $count; $i++) { + $this->currentData[$this->statementBindValues['keys'][$i]] = $this->statementBindValues['values'][$i]; + } + $this->currentComplete = true; + $this->nextComplete = true; + $this->position++; + return true; + } + + /** + * Load from mysqli result + * + * @return bool + */ + protected function loadFromMysqliResult() + { + $this->currentData = null; + + if (($data = $this->resource->fetch_assoc()) === null) { + return false; + } + + $this->position++; + $this->currentData = $data; + $this->currentComplete = true; + $this->nextComplete = true; + $this->position++; + return true; + } + + /** + * Next + * + * @return void + */ + public function next() + { + $this->currentComplete = false; + + if ($this->nextComplete == false) { + $this->position++; + } + + $this->nextComplete = false; + } + + /** + * Key + * + * @return mixed + */ + public function key() + { + return $this->position; + } + + /** + * Rewind + * + * @throws Exception\RuntimeException + * @return void + */ + public function rewind() + { + if ($this->position !== 0) { + if ($this->isBuffered === false) { + throw new Exception\RuntimeException('Unbuffered results cannot be rewound for multiple iterations'); + } + } + $this->resource->data_seek(0); // works for both mysqli_result & mysqli_stmt + $this->currentComplete = false; + $this->position = 0; + } + + /** + * Valid + * + * @return bool + */ + public function valid() + { + if ($this->currentComplete) { + return true; + } + + if ($this->resource instanceof \mysqli_stmt) { + return $this->loadDataFromMysqliStatement(); + } + + return $this->loadFromMysqliResult(); + } + + /** + * Count + * + * @throws Exception\RuntimeException + * @return int + */ + public function count() + { + if ($this->isBuffered === false) { + throw new Exception\RuntimeException('Row count is not available in unbuffered result sets.'); + } + return $this->resource->num_rows; + } + + /** + * Get field count + * + * @return int + */ + public function getFieldCount() + { + return $this->resource->field_count; + } + + /** + * Get generated value + * + * @return mixed|null + */ + public function getGeneratedValue() + { + return $this->generatedValue; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Statement.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Statement.php new file mode 100644 index 0000000000000000000000000000000000000000..5d750adcf3eb0049eae77d40d7c93a520a779745 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Mysqli/Statement.php @@ -0,0 +1,316 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Mysqli; + +use Zend\Db\Adapter\Driver\StatementInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Profiler; + +class Statement implements StatementInterface, Profiler\ProfilerAwareInterface +{ + + /** + * @var \mysqli + */ + protected $mysqli = null; + + /** + * @var Mysqli + */ + protected $driver = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * @var string + */ + protected $sql = ''; + + /** + * Parameter container + * + * @var ParameterContainer + */ + protected $parameterContainer = null; + + /** + * @var \mysqli_stmt + */ + protected $resource = null; + + /** + * Is prepared + * + * @var bool + */ + protected $isPrepared = false; + + /** + * @var bool + */ + protected $bufferResults = false; + + /** + * @param bool $bufferResults + */ + public function __construct($bufferResults = false) + { + $this->bufferResults = (bool) $bufferResults; + } + + /** + * Set driver + * + * @param Mysqli $driver + * @return Statement + */ + public function setDriver(Mysqli $driver) + { + $this->driver = $driver; + return $this; + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Statement + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Initialize + * + * @param \mysqli $mysqli + * @return Statement + */ + public function initialize(\mysqli $mysqli) + { + $this->mysqli = $mysqli; + return $this; + } + + /** + * Set sql + * + * @param string $sql + * @return Statement + */ + public function setSql($sql) + { + $this->sql = $sql; + return $this; + } + + /** + * Set Parameter container + * + * @param ParameterContainer $parameterContainer + * @return Statement + */ + public function setParameterContainer(ParameterContainer $parameterContainer) + { + $this->parameterContainer = $parameterContainer; + return $this; + } + + /** + * Get resource + * + * @return mixed + */ + public function getResource() + { + return $this->resource; + } + + /** + * Set resource + * + * @param \mysqli_stmt $mysqliStatement + * @return Statement + */ + public function setResource(\mysqli_stmt $mysqliStatement) + { + $this->resource = $mysqliStatement; + $this->isPrepared = true; + return $this; + } + + /** + * Get sql + * + * @return string + */ + public function getSql() + { + return $this->sql; + } + + /** + * Get parameter count + * + * @return ParameterContainer + */ + public function getParameterContainer() + { + return $this->parameterContainer; + } + + /** + * Is prepared + * + * @return bool + */ + public function isPrepared() + { + return $this->isPrepared; + } + + /** + * Prepare + * + * @param string $sql + * @throws Exception\InvalidQueryException + * @throws Exception\RuntimeException + * @return Statement + */ + public function prepare($sql = null) + { + if ($this->isPrepared) { + throw new Exception\RuntimeException('This statement has already been prepared'); + } + + $sql = ($sql) ?: $this->sql; + + $this->resource = $this->mysqli->prepare($sql); + if (!$this->resource instanceof \mysqli_stmt) { + throw new Exception\InvalidQueryException( + 'Statement couldn\'t be produced with sql: ' . $sql, + null, + new Exception\ErrorException($this->mysqli->error, $this->mysqli->errno) + ); + } + + $this->isPrepared = true; + return $this; + } + + /** + * Execute + * + * @param ParameterContainer|array $parameters + * @throws Exception\RuntimeException + * @return mixed + */ + public function execute($parameters = null) + { + if (!$this->isPrepared) { + $this->prepare(); + } + + /** START Standard ParameterContainer Merging Block */ + if (!$this->parameterContainer instanceof ParameterContainer) { + if ($parameters instanceof ParameterContainer) { + $this->parameterContainer = $parameters; + $parameters = null; + } else { + $this->parameterContainer = new ParameterContainer(); + } + } + + if (is_array($parameters)) { + $this->parameterContainer->setFromArray($parameters); + } + + if ($this->parameterContainer->count() > 0) { + $this->bindParametersFromContainer(); + } + /** END Standard ParameterContainer Merging Block */ + + if ($this->profiler) { + $this->profiler->profilerStart($this); + } + + $return = $this->resource->execute(); + + if ($this->profiler) { + $this->profiler->profilerFinish(); + } + + if ($return === false) { + throw new Exception\RuntimeException($this->resource->error); + } + + if ($this->bufferResults === true) { + $this->resource->store_result(); + $this->isPrepared = false; + $buffered = true; + } else { + $buffered = false; + } + + $result = $this->driver->createResult($this->resource, $buffered); + return $result; + } + + /** + * Bind parameters from container + * + * @return void + */ + protected function bindParametersFromContainer() + { + $parameters = $this->parameterContainer->getNamedArray(); + $type = ''; + $args = array(); + + foreach ($parameters as $name => &$value) { + if ($this->parameterContainer->offsetHasErrata($name)) { + switch ($this->parameterContainer->offsetGetErrata($name)) { + case ParameterContainer::TYPE_DOUBLE: + $type .= 'd'; + break; + case ParameterContainer::TYPE_NULL: + $value = null; // as per @see http://www.php.net/manual/en/mysqli-stmt.bind-param.php#96148 + case ParameterContainer::TYPE_INTEGER: + $type .= 'i'; + break; + case ParameterContainer::TYPE_STRING: + default: + $type .= 's'; + break; + } + } else { + $type .= 's'; + } + $args[] = &$value; + } + + if ($args) { + array_unshift($args, $type); + call_user_func_array(array($this->resource, 'bind_param'), $args); + } + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Connection.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Connection.php new file mode 100644 index 0000000000000000000000000000000000000000..73376521e25bb582bc1e63e441ab56a2a3acd5cc --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Connection.php @@ -0,0 +1,346 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Oci8; + +use Zend\Db\Adapter\Driver\ConnectionInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\Profiler; + +class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface +{ + /** + * @var Oci8 + */ + protected $driver = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * Connection parameters + * + * @var array + */ + protected $connectionParameters = array(); + + /** + * @var + */ + protected $resource = null; + + /** + * In transaction + * + * @var bool + */ + protected $inTransaction = false; + + /** + * Constructor + * + * @param array|resource|null $connectionInfo + * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException + */ + public function __construct($connectionInfo = null) + { + if (is_array($connectionInfo)) { + $this->setConnectionParameters($connectionInfo); + } elseif ($connectionInfo instanceof \oci8) { + $this->setResource($connectionInfo); + } elseif (null !== $connectionInfo) { + throw new Exception\InvalidArgumentException('$connection must be an array of parameters, an oci8 resource or null'); + } + } + + /** + * @param Oci8 $driver + * @return Connection + */ + public function setDriver(Oci8 $driver) + { + $this->driver = $driver; + return $this; + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Connection + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Set connection parameters + * + * @param array $connectionParameters + * @return Connection + */ + public function setConnectionParameters(array $connectionParameters) + { + $this->connectionParameters = $connectionParameters; + return $this; + } + + /** + * Get connection parameters + * + * @return array + */ + public function getConnectionParameters() + { + return $this->connectionParameters; + } + + /** + * Get current schema + * + * @return string + */ + public function getCurrentSchema() + { + if (!$this->isConnected()) { + $this->connect(); + } + + $query = "SELECT sys_context('USERENV', 'CURRENT_SCHEMA') as \"current_schema\" FROM DUAL"; + $stmt = oci_parse($this->resource, $query); + oci_execute($stmt); + $dbNameArray = oci_fetch_array($stmt, OCI_ASSOC); + return $dbNameArray['current_schema']; + } + + /** + * Set resource + * + * @param resource $resource + * @return Connection + */ + public function setResource($resource) + { + if (!is_resource($resource) || get_resource_type($resource) !== 'oci8 connection') { + throw new Exception\InvalidArgumentException('A resource of type "oci8 connection" was expected'); + } + $this->resource = $resource; + return $this; + } + + /** + * Get resource + * + * @return \oci8 + */ + public function getResource() + { + $this->connect(); + return $this->resource; + } + + /** + * Connect + * + * @return Connection + */ + public function connect() + { + if (is_resource($this->resource)) { + return $this; + } + + // localize + $p = $this->connectionParameters; + + // given a list of key names, test for existence in $p + $findParameterValue = function (array $names) use ($p) { + foreach ($names as $name) { + if (isset($p[$name])) { + return $p[$name]; + } + } + return null; + }; + + // http://www.php.net/manual/en/function.oci-connect.php + $username = $findParameterValue(array('username')); + $password = $findParameterValue(array('password')); + $connectionString = $findParameterValue(array('connection_string', 'connectionstring', 'connection', 'hostname', 'instance')); + $characterSet = $findParameterValue(array('character_set', 'charset', 'encoding')); + $sessionMode = $findParameterValue(array('session_mode')); + + // connection modifiers + $isUnique = $findParameterValue(array('unique')); + $isPersistent = $findParameterValue(array('persistent')); + + if ($isUnique == true) { + $this->resource = oci_new_connect($username, $password, $connectionString, $characterSet, $sessionMode); + } elseif ($isPersistent == true) { + $this->resource = oci_pconnect($username, $password, $connectionString, $characterSet, $sessionMode); + } else { + $this->resource = oci_connect($username, $password, $connectionString, $characterSet, $sessionMode); + } + + if (!$this->resource) { + $e = oci_error(); + throw new Exception\RuntimeException( + 'Connection error', + null, + new Exception\ErrorException($e['message'], $e['code']) + ); + } + + return $this; + } + + /** + * Is connected + * + * @return bool + */ + public function isConnected() + { + return (is_resource($this->resource)); + } + + /** + * Disconnect + */ + public function disconnect() + { + if (is_resource($this->resource)) { + oci_close($this->resource); + } + } + + /** + * Begin transaction + */ + public function beginTransaction() + { + if (!$this->isConnected()) { + $this->connect(); + } + + // A transaction begins when the first SQL statement that changes data is executed with oci_execute() using the OCI_NO_AUTO_COMMIT flag. + $this->inTransaction = true; + } + + /** + * In transaction + * + * @return bool + */ + public function inTransaction() + { + return $this->inTransaction; + } + + /** + * Commit + */ + public function commit() + { + if (!$this->resource) { + $this->connect(); + } + + if ($this->inTransaction) { + $valid = oci_commit($this->resource); + if ($valid === false) { + $e = oci_error($this->resource); + throw new Exception\InvalidQueryException($e['message'], $e['code']); + } + } + } + + /** + * Rollback + * + * @return Connection + */ + public function rollback() + { + if (!$this->resource) { + throw new Exception\RuntimeException('Must be connected before you can rollback.'); + } + + if (!$this->inTransaction) { + throw new Exception\RuntimeException('Must call commit() before you can rollback.'); + } + + $valid = oci_rollback($this->resource); + if ($valid === false) { + $e = oci_error($this->resource); + throw new Exception\InvalidQueryException($e['message'], $e['code']); + } + + return $this; + } + + /** + * Execute + * + * @param string $sql + * @return Result + */ + public function execute($sql) + { + if (!$this->isConnected()) { + $this->connect(); + } + + if ($this->profiler) { + $this->profiler->profilerStart($sql); + } + + $ociStmt = oci_parse($this->resource, $sql); + + if ($this->inTransaction) { + $valid = @oci_execute($ociStmt, OCI_NO_AUTO_COMMIT); + } else { + $valid = @oci_execute($ociStmt, OCI_COMMIT_ON_SUCCESS); + } + + if ($this->profiler) { + $this->profiler->profilerFinish($sql); + } + + if ($valid === false) { + $e = oci_error($ociStmt); + throw new Exception\InvalidQueryException($e['message'], $e['code']); + } + + $resultPrototype = $this->driver->createResult($ociStmt); + return $resultPrototype; + } + + /** + * Get last generated id + * + * @param null $name Ignored + * @return int + */ + public function getLastGeneratedValue($name = null) + { + // @todo Get Last Generated Value in Connection (this might not apply) + return null; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Oci8.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Oci8.php new file mode 100644 index 0000000000000000000000000000000000000000..79bc56d783e73da174d6990b9007f9e230c1e051 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Oci8.php @@ -0,0 +1,235 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Oci8; + +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\Profiler; + +class Oci8 implements DriverInterface, Profiler\ProfilerAwareInterface +{ + + /** + * @var Connection + */ + protected $connection = null; + + /** + * @var Statement + */ + protected $statementPrototype = null; + + /** + * @var Result + */ + protected $resultPrototype = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * @var array + */ + protected $options = array( + + ); + + /** + * @param array|Connection|\oci8 $connection + * @param null|Statement $statementPrototype + * @param null|Result $resultPrototype + * @param array $options + */ + public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null, array $options = array()) + { + if (!$connection instanceof Connection) { + $connection = new Connection($connection); + } + + $options = array_intersect_key(array_merge($this->options, $options), $this->options); + + $this->registerConnection($connection); + $this->registerStatementPrototype(($statementPrototype) ?: new Statement()); + $this->registerResultPrototype(($resultPrototype) ?: new Result()); + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Oci8 + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + if ($this->connection instanceof Profiler\ProfilerAwareInterface) { + $this->connection->setProfiler($profiler); + } + if ($this->statementPrototype instanceof Profiler\ProfilerAwareInterface) { + $this->statementPrototype->setProfiler($profiler); + } + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Register connection + * + * @param Connection $connection + * @return Oci8 + */ + public function registerConnection(Connection $connection) + { + $this->connection = $connection; + $this->connection->setDriver($this); // needs access to driver to createStatement() + return $this; + } + + /** + * Register statement prototype + * + * @param Statement $statementPrototype + * @return Oci8 + */ + public function registerStatementPrototype(Statement $statementPrototype) + { + $this->statementPrototype = $statementPrototype; + $this->statementPrototype->setDriver($this); // needs access to driver to createResult() + return $this; + } + + /** + * @return null|Statement + */ + public function getStatementPrototype() + { + return $this->statementPrototype; + } + + /** + * Register result prototype + * + * @param Result $resultPrototype + * @return Oci8 + */ + public function registerResultPrototype(Result $resultPrototype) + { + $this->resultPrototype = $resultPrototype; + return $this; + } + + /** + * @return null|Result + */ + public function getResultPrototype() + { + return $this->resultPrototype; + } + + /** + * Get database platform name + * + * @param string $nameFormat + * @return string + */ + public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE) + { + return 'Oracle'; + } + + /** + * Check environment + */ + public function checkEnvironment() + { + if (!extension_loaded('oci8')) { + throw new Exception\RuntimeException('The Oci8 extension is required for this adapter but the extension is not loaded'); + } + } + + /** + * @return Connection + */ + public function getConnection() + { + return $this->connection; + } + + /** + * @param string $sqlOrResource + * @return Statement + */ + public function createStatement($sqlOrResource = null) + { + $statement = clone $this->statementPrototype; + if (is_resource($sqlOrResource) && get_resource_type($sqlOrResource) == 'oci8 statement') { + $statement->setResource($sqlOrResource); + } else { + if (is_string($sqlOrResource)) { + $statement->setSql($sqlOrResource); + } elseif ($sqlOrResource !== null) { + throw new Exception\InvalidArgumentException( + 'Oci8 only accepts an SQL string or an oci8 resource in ' . __FUNCTION__ + ); + } + if (!$this->connection->isConnected()) { + $this->connection->connect(); + } + $statement->initialize($this->connection->getResource()); + } + return $statement; + } + + /** + * @param resource $resource + * @param null $isBuffered + * @return Result + */ + public function createResult($resource, $isBuffered = null) + { + $result = clone $this->resultPrototype; + $result->initialize($resource, $this->connection->getLastGeneratedValue(), $isBuffered); + return $result; + } + + /** + * @return array + */ + public function getPrepareType() + { + return self::PARAMETERIZATION_NAMED; + } + + /** + * @param string $name + * @param mixed $type + * @return string + */ + public function formatParameterName($name, $type = null) + { + return ':' . $name; + } + + /** + * @return mixed + */ + public function getLastGeneratedValue() + { + return $this->getConnection()->getLastGeneratedValue(); + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Result.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Result.php new file mode 100644 index 0000000000000000000000000000000000000000..98217d8a34faeb64c0c73025af5bc93bfe671d39 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Result.php @@ -0,0 +1,226 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Oci8; + +use Iterator; +use Zend\Db\Adapter\Driver\ResultInterface; +use Zend\Db\Adapter\Exception; + +class Result implements Iterator, ResultInterface +{ + + /** + * @var resource + */ + protected $resource = null; + + /** + * @var bool + */ + protected $isBuffered = null; + + /** + * Cursor position + * @var int + */ + protected $position = 0; + + /** + * Number of known rows + * @var int + */ + protected $numberOfRows = -1; + + /** + * Is the current() operation already complete for this pointer position? + * @var bool + */ + protected $currentComplete = false; + + /** + * @var bool + */ + protected $currentData = false; + + /** + * + * @var array + */ + protected $statementBindValues = array('keys' => null, 'values' => array()); + + /** + * @var mixed + */ + protected $generatedValue = null; + + /** + * Initialize + * @param resource $resource + * @return Result + */ + public function initialize($resource /*, $generatedValue, $isBuffered = null*/) + { + if (!is_resource($resource) && get_resource_type($resource) !== 'oci8 statement') { + throw new Exception\InvalidArgumentException('Invalid resource provided.'); + } + $this->resource = $resource; + return $this; + } + + /** + * Force buffering at driver level + * + * Oracle does not support this, to my knowledge (@ralphschindler) + * + * @throws Exception\RuntimeException + */ + public function buffer() + { + return null; + } + + /** + * Is the result buffered? + * + * @return bool + */ + public function isBuffered() + { + return false; + } + + /** + * Return the resource + * @return mixed + */ + public function getResource() + { + return $this->resource; + } + + /** + * Is query result? + * + * @return bool + */ + public function isQueryResult() + { + return (oci_num_fields($this->resource) > 0); + } + + /** + * Get affected rows + * @return int + */ + public function getAffectedRows() + { + return oci_num_rows($this->resource); + } + + /** + * Current + * @return mixed + */ + public function current() + { + if ($this->currentComplete == false) { + if ($this->loadData() === false) { + return false; + } + } + + return $this->currentData; + } + + /** + * Load from oci8 result + * + * @return bool + */ + protected function loadData() + { + $this->currentComplete = true; + $this->currentData = oci_fetch_assoc($this->resource); + + if ($this->currentData !== false) { + $this->position++; + return true; + } + return false; + } + + /** + * Next + */ + public function next() + { + return $this->loadData(); + } + + /** + * Key + * @return mixed + */ + public function key() + { + return $this->position; + } + + /** + * Rewind + */ + public function rewind() + { + if ($this->position > 0) { + throw new Exception\RuntimeException('Oci8 results cannot be rewound for multiple iterations'); + } + } + + /** + * Valid + * @return bool + */ + public function valid() + { + if ($this->currentComplete) { + return ($this->currentData !== false); + } + + return $this->loadData(); + } + + /** + * Count + * @return int + */ + public function count() + { + // @todo OCI8 row count in Driver Result + return null; + } + + /** + * @return int + */ + public function getFieldCount() + { + return oci_num_fields($this->resource); + } + + /** + * @return mixed|null + */ + public function getGeneratedValue() + { + // @todo OCI8 generated value in Driver Result + return null; + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Statement.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Statement.php new file mode 100644 index 0000000000000000000000000000000000000000..a9ebd0ca02f54a8a469a703ee2e8556846473ad9 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Oci8/Statement.php @@ -0,0 +1,307 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Oci8; + +use Zend\Db\Adapter\Driver\StatementInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Profiler; + +class Statement implements StatementInterface, Profiler\ProfilerAwareInterface +{ + + /** + * @var resource + */ + protected $oci8 = null; + + /** + * @var Oci8 + */ + protected $driver = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * @var string + */ + protected $sql = ''; + + /** + * Parameter container + * + * @var ParameterContainer + */ + protected $parameterContainer = null; + + /** + * @var resource + */ + protected $resource = null; + + /** + * Is prepared + * + * @var bool + */ + protected $isPrepared = false; + + /** + * @var bool + */ + protected $bufferResults = false; + + /** + * Set driver + * + * @param Oci8 $driver + * @return Statement + */ + public function setDriver($driver) + { + $this->driver = $driver; + return $this; + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Statement + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Initialize + * + * @param resource $oci8 + * @return Statement + */ + public function initialize($oci8) + { + $this->oci8 = $oci8; + return $this; + } + + /** + * Set sql + * + * @param string $sql + * @return Statement + */ + public function setSql($sql) + { + $this->sql = $sql; + return $this; + } + + /** + * Set Parameter container + * + * @param ParameterContainer $parameterContainer + * @return Statement + */ + public function setParameterContainer(ParameterContainer $parameterContainer) + { + $this->parameterContainer = $parameterContainer; + return $this; + } + + /** + * Get resource + * + * @return mixed + */ + public function getResource() + { + return $this->resource; + } + + /** + * Set resource + * + * @param resource $oci8Statement + * @return Statement + */ + public function setResource($oci8Statement) + { + $type = oci_statement_type($oci8Statement); + if (false === $type || 'UNKNOWN' == $type) { + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid statement provided to %s', + __METHOD__ + )); + } + $this->resource = $oci8Statement; + $this->isPrepared = true; + return $this; + } + + /** + * Get sql + * + * @return string + */ + public function getSql() + { + return $this->sql; + } + + /** + * @return ParameterContainer + */ + public function getParameterContainer() + { + return $this->parameterContainer; + } + + /** + * @return bool + */ + public function isPrepared() + { + return $this->isPrepared; + } + + /** + * @param string $sql + * @return Statement + */ + public function prepare($sql = null) + { + if ($this->isPrepared) { + throw new Exception\RuntimeException('This statement has already been prepared'); + } + + $sql = ($sql) ?: $this->sql; + + // get oci8 statement resource + $this->resource = oci_parse($this->oci8, $sql); + + if (!$this->resource) { + $e = oci_error($this->oci8); + throw new Exception\InvalidQueryException( + 'Statement couldn\'t be produced with sql: ' . $sql, + null, + new Exception\ErrorException($e['message'], $e['code']) + ); + } + + $this->isPrepared = true; + return $this; + } + + /** + * Execute + * + * @param ParameterContainer $parameters + * @return mixed + */ + public function execute($parameters = null) + { + if (!$this->isPrepared) { + $this->prepare(); + } + + /** START Standard ParameterContainer Merging Block */ + if (!$this->parameterContainer instanceof ParameterContainer) { + if ($parameters instanceof ParameterContainer) { + $this->parameterContainer = $parameters; + $parameters = null; + } else { + $this->parameterContainer = new ParameterContainer(); + } + } + + if (is_array($parameters)) { + $this->parameterContainer->setFromArray($parameters); + } + + if ($this->parameterContainer->count() > 0) { + $this->bindParametersFromContainer(); + } + /** END Standard ParameterContainer Merging Block */ + + if ($this->profiler) { + $this->profiler->profilerStart($this); + } + + if ($this->driver->getConnection()->inTransaction()) { + $ret = @oci_execute($this->resource, OCI_NO_AUTO_COMMIT); + } else { + $ret = @oci_execute($this->resource, OCI_COMMIT_ON_SUCCESS); + } + + if ($this->profiler) { + $this->profiler->profilerFinish(); + } + + if ($ret === false) { + $e = oci_error($this->resource); + throw new Exception\RuntimeException($e['message'], $e['code']); + } + + $result = $this->driver->createResult($this->resource); + return $result; + } + + /** + * Bind parameters from container + * + * @param ParameterContainer $pContainer + */ + protected function bindParametersFromContainer() + { + $parameters = $this->parameterContainer->getNamedArray(); + + foreach ($parameters as $name => &$value) { + if ($this->parameterContainer->offsetHasErrata($name)) { + switch ($this->parameterContainer->offsetGetErrata($name)) { + case ParameterContainer::TYPE_NULL: + $type = null; + $value = null; + break; + case ParameterContainer::TYPE_DOUBLE: + case ParameterContainer::TYPE_INTEGER: + $type = SQLT_INT; + if (is_string($value)) { + $value = (int) $value; + } + break; + case ParameterContainer::TYPE_BINARY: + $type = SQLT_BIN; + break; + case ParameterContainer::TYPE_STRING: + default: + $type = SQLT_CHR; + break; + } + } else { + $type = SQLT_CHR; + } + + oci_bind_by_name($this->resource, $name, $value, -1, $type); + } + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Connection.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Connection.php new file mode 100644 index 0000000000000000000000000000000000000000..e682b008cc29913e281b2d7e8c4ac3350a749da6 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Connection.php @@ -0,0 +1,487 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Pdo; + +use Zend\Db\Adapter\Driver\ConnectionInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\Profiler; + +class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface +{ + /** + * @var Pdo + */ + protected $driver = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * @var string + */ + protected $driverName = null; + + /** + * @var array + */ + protected $connectionParameters = array(); + + /** + * @var \PDO + */ + protected $resource = null; + + /** + * @var bool + */ + protected $inTransaction = false; + + /** + * @var string + */ + protected $dsn = null; + + /** + * Constructor + * + * @param array|\PDO|null $connectionParameters + * @throws Exception\InvalidArgumentException + */ + public function __construct($connectionParameters = null) + { + if (is_array($connectionParameters)) { + $this->setConnectionParameters($connectionParameters); + } elseif ($connectionParameters instanceof \PDO) { + $this->setResource($connectionParameters); + } elseif (null !== $connectionParameters) { + throw new Exception\InvalidArgumentException('$connection must be an array of parameters, a PDO object or null'); + } + } + + /** + * Set driver + * + * @param Pdo $driver + * @return Connection + */ + public function setDriver(Pdo $driver) + { + $this->driver = $driver; + return $this; + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Connection + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Get driver name + * + * @return null|string + */ + public function getDriverName() + { + return $this->driverName; + } + + /** + * Set connection parameters + * + * @param array $connectionParameters + * @return void + */ + public function setConnectionParameters(array $connectionParameters) + { + $this->connectionParameters = $connectionParameters; + if (isset($connectionParameters['dsn'])) { + $this->driverName = substr($connectionParameters['dsn'], 0, + strpos($connectionParameters['dsn'], ':') + ); + } elseif (isset($connectionParameters['pdodriver'])) { + $this->driverName = strtolower($connectionParameters['pdodriver']); + } elseif (isset($connectionParameters['driver'])) { + $this->driverName = strtolower(substr( + str_replace(array('-', '_', ' '), '', $connectionParameters['driver']), + 3 + )); + } + } + + /** + * Get connection parameters + * + * @return array + */ + public function getConnectionParameters() + { + return $this->connectionParameters; + } + + /** + * Get the dsn string for this connection + * @throws \Zend\Db\Adapter\Exception\RunTimeException + * @return string + */ + public function getDsn() + { + if (!$this->dsn) { + throw new Exception\RunTimeException("The DSN has not been set or constructed from parameters in connect() for this Connection"); + } + + return $this->dsn; + } + + /** + * Get current schema + * + * @return string + */ + public function getCurrentSchema() + { + if (!$this->isConnected()) { + $this->connect(); + } + + switch ($this->driverName) { + case 'mysql': + $sql = 'SELECT DATABASE()'; + break; + case 'sqlite': + return 'main'; + case 'sqlsrv': + case 'dblib': + $sql = 'SELECT SCHEMA_NAME()'; + break; + case 'pgsql': + default: + $sql = 'SELECT CURRENT_SCHEMA'; + break; + } + + /** @var $result \PDOStatement */ + $result = $this->resource->query($sql); + if ($result instanceof \PDOStatement) { + return $result->fetchColumn(); + } + return false; + } + + /** + * Set resource + * + * @param \PDO $resource + * @return Connection + */ + public function setResource(\PDO $resource) + { + $this->resource = $resource; + $this->driverName = strtolower($this->resource->getAttribute(\PDO::ATTR_DRIVER_NAME)); + return $this; + } + + /** + * Get resource + * + * @return \PDO + */ + public function getResource() + { + if (!$this->isConnected()) { + $this->connect(); + } + return $this->resource; + } + + /** + * Connect + * + * @return Connection + * @throws Exception\InvalidConnectionParametersException + * @throws Exception\RuntimeException + */ + public function connect() + { + if ($this->resource) { + return $this; + } + + $dsn = $username = $password = $hostname = $database = null; + $options = array(); + foreach ($this->connectionParameters as $key => $value) { + switch (strtolower($key)) { + case 'dsn': + $dsn = $value; + break; + case 'driver': + $value = strtolower($value); + if (strpos($value, 'pdo') === 0) { + $pdoDriver = strtolower(substr(str_replace(array('-', '_', ' '), '', $value), 3)); + } + break; + case 'pdodriver': + $pdoDriver = (string) $value; + break; + case 'user': + case 'username': + $username = (string) $value; + break; + case 'pass': + case 'password': + $password = (string) $value; + break; + case 'host': + case 'hostname': + $hostname = (string) $value; + break; + case 'port': + $port = (int) $value; + break; + case 'database': + case 'dbname': + $database = (string) $value; + break; + case 'charset': + $charset = (string) $value; + break; + case 'driver_options': + case 'options': + $value = (array) $value; + $options = array_diff_key($options, $value) + $value; + break; + default: + $options[$key] = $value; + break; + } + } + + if (!isset($dsn) && isset($pdoDriver)) { + $dsn = array(); + switch ($pdoDriver) { + case 'sqlite': + $dsn[] = $database; + break; + case 'sqlsrv': + if (isset($database)) { + $dsn[] = "database={$database}"; + } + if (isset($hostname)) { + $dsn[] = "server={$hostname}"; + } + break; + default: + if (isset($database)) { + $dsn[] = "dbname={$database}"; + } + if (isset($hostname)) { + $dsn[] = "host={$hostname}"; + } + if (isset($port)) { + $dsn[] = "port={$port}"; + } + if (isset($charset)) { + $dsn[] = "charset={$charset}"; + } + break; + } + $dsn = $pdoDriver . ':' . implode(';', $dsn); + } elseif (!isset($dsn)) { + throw new Exception\InvalidConnectionParametersException( + 'A dsn was not provided or could not be constructed from your parameters', + $this->connectionParameters + ); + } + + $this->dsn = $dsn; + + try { + $this->resource = new \PDO($dsn, $username, $password, $options); + $this->resource->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + $this->driverName = strtolower($this->resource->getAttribute(\PDO::ATTR_DRIVER_NAME)); + } catch (\PDOException $e) { + $code = $e->getCode(); + if (!is_long($code)) { + $code = null; + } + throw new Exception\RuntimeException('Connect Error: ' . $e->getMessage(), $code, $e); + } + + return $this; + } + + /** + * Is connected + * + * @return bool + */ + public function isConnected() + { + return ($this->resource instanceof \PDO); + } + + /** + * Disconnect + * + * @return Connection + */ + public function disconnect() + { + if ($this->isConnected()) { + $this->resource = null; + } + return $this; + } + + /** + * Begin transaction + * + * @return Connection + */ + public function beginTransaction() + { + if (!$this->isConnected()) { + $this->connect(); + } + $this->resource->beginTransaction(); + $this->inTransaction = true; + return $this; + } + + /** + * In transaction + * + * @return bool + */ + public function inTransaction() + { + return $this->inTransaction; + } + + /** + * Commit + * + * @return Connection + */ + public function commit() + { + if (!$this->isConnected()) { + $this->connect(); + } + + $this->resource->commit(); + $this->inTransaction = false; + return $this; + } + + /** + * Rollback + * + * @return Connection + * @throws Exception\RuntimeException + */ + public function rollback() + { + if (!$this->isConnected()) { + throw new Exception\RuntimeException('Must be connected before you can rollback'); + } + + if (!$this->inTransaction) { + throw new Exception\RuntimeException('Must call beginTransaction() before you can rollback'); + } + + $this->resource->rollBack(); + return $this; + } + + /** + * Execute + * + * @param $sql + * @return Result + * @throws Exception\InvalidQueryException + */ + public function execute($sql) + { + if (!$this->isConnected()) { + $this->connect(); + } + + if ($this->profiler) { + $this->profiler->profilerStart($sql); + } + + $resultResource = $this->resource->query($sql); + + if ($this->profiler) { + $this->profiler->profilerFinish($sql); + } + + if ($resultResource === false) { + $errorInfo = $this->resource->errorInfo(); + throw new Exception\InvalidQueryException($errorInfo[2]); + } + + $result = $this->driver->createResult($resultResource, $sql); + return $result; + + } + + /** + * Prepare + * + * @param string $sql + * @return Statement + */ + public function prepare($sql) + { + if (!$this->isConnected()) { + $this->connect(); + } + + $statement = $this->driver->createStatement($sql); + return $statement; + } + + /** + * Get last generated id + * + * @param string $name + * @return string|null|false + */ + public function getLastGeneratedValue($name = null) + { + if ($name === null && $this->driverName == 'pgsql') { + return null; + } + + try { + return $this->resource->lastInsertId($name); + } catch (\Exception $e) { + // do nothing + } + return false; + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Feature/OracleRowCounter.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Feature/OracleRowCounter.php new file mode 100644 index 0000000000000000000000000000000000000000..2412e3af67dceff5f3dea4be2c995a3979ff02c4 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Feature/OracleRowCounter.php @@ -0,0 +1,80 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Pdo\Feature; + +use Zend\Db\Adapter\Driver\Feature\AbstractFeature; +use Zend\Db\Adapter\Driver\Pdo; + +/** + * OracleRowCounter + */ +class OracleRowCounter extends AbstractFeature +{ + + /** + * @return string + */ + public function getName() + { + return 'OracleRowCounter'; + } + + /** + * @param \Zend\Db\Adapter\Driver\Pdo\Statement $statement + * @return int + */ + public function getCountForStatement(Pdo\Statement $statement) + { + $countStmt = clone $statement; + $sql = $statement->getSql(); + if ($sql == '' || stripos($sql, 'select') === false) { + return null; + } + $countSql = 'SELECT COUNT(*) as "count" FROM (' . $sql . ')'; + $countStmt->prepare($countSql); + $result = $countStmt->execute(); + $countRow = $result->getResource()->fetch(\PDO::FETCH_ASSOC); + unset($statement, $result); + return $countRow['count']; + } + + /** + * @param $sql + * @return null|int + */ + public function getCountForSql($sql) + { + if (stripos($sql, 'select') === false) { + return null; + } + $countSql = 'SELECT COUNT(*) as count FROM (' . $sql . ')'; + /** @var $pdo \PDO */ + $pdo = $this->driver->getConnection()->getResource(); + $result = $pdo->query($countSql); + $countRow = $result->fetch(\PDO::FETCH_ASSOC); + return $countRow['count']; + } + + /** + * @param $context + * @return \Closure + */ + public function getRowCountClosure($context) + { + $oracleRowCounter = $this; + return function () use ($oracleRowCounter, $context) { + /** @var $oracleRowCounter OracleRowCounter */ + return ($context instanceof Pdo\Statement) + ? $oracleRowCounter->getCountForStatement($context) + : $oracleRowCounter->getCountForSql($context); + }; + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Feature/SqliteRowCounter.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Feature/SqliteRowCounter.php new file mode 100644 index 0000000000000000000000000000000000000000..a78132ea5c2207930a3b240df5ea191adedb3148 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Feature/SqliteRowCounter.php @@ -0,0 +1,79 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Pdo\Feature; + +use Zend\Db\Adapter\Driver\Feature\AbstractFeature; +use Zend\Db\Adapter\Driver\Pdo; + +/** + * SqliteRowCounter + */ +class SqliteRowCounter extends AbstractFeature +{ + + /** + * @return string + */ + public function getName() + { + return 'SqliteRowCounter'; + } + + /** + * @param \Zend\Db\Adapter\Driver\Pdo\Statement $statement + * @return int + */ + public function getCountForStatement(Pdo\Statement $statement) + { + $countStmt = clone $statement; + $sql = $statement->getSql(); + if ($sql == '' || stripos($sql, 'select') === false) { + return null; + } + $countSql = 'SELECT COUNT(*) as "count" FROM (' . $sql . ')'; + $countStmt->prepare($countSql); + $result = $countStmt->execute(); + $countRow = $result->getResource()->fetch(\PDO::FETCH_ASSOC); + unset($statement, $result); + return $countRow['count']; + } + + /** + * @param $sql + * @return null|int + */ + public function getCountForSql($sql) + { + if (stripos($sql, 'select') === false) { + return null; + } + $countSql = 'SELECT COUNT(*) as count FROM (' . $sql . ')'; + /** @var $pdo \PDO */ + $pdo = $this->driver->getConnection()->getResource(); + $result = $pdo->query($countSql); + $countRow = $result->fetch(\PDO::FETCH_ASSOC); + return $countRow['count']; + } + + /** + * @param $context + * @return \Closure + */ + public function getRowCountClosure($context) + { + $sqliteRowCounter = $this; + return function () use ($sqliteRowCounter, $context) { + /** @var $sqliteRowCounter SqliteRowCounter */ + return ($context instanceof Pdo\Statement) + ? $sqliteRowCounter->getCountForStatement($context) + : $sqliteRowCounter->getCountForSql($context); + }; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Pdo.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Pdo.php new file mode 100644 index 0000000000000000000000000000000000000000..3de7beb498d1766a1009f222aedee51bc062d190 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Pdo.php @@ -0,0 +1,314 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Pdo; + +use PDOStatement; +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\Driver\Feature\AbstractFeature; +use Zend\Db\Adapter\Driver\Feature\DriverFeatureInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\Profiler; + +class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerAwareInterface +{ + /** + * @const + */ + const FEATURES_DEFAULT = 'default'; + + /** + * @var Connection + */ + protected $connection = null; + + /** + * @var Statement + */ + protected $statementPrototype = null; + + /** + * @var Result + */ + protected $resultPrototype = null; + + /** + * @var array + */ + protected $features = array(); + + /** + * @param array|Connection|\PDO $connection + * @param null|Statement $statementPrototype + * @param null|Result $resultPrototype + * @param string $features + */ + public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null, $features = self::FEATURES_DEFAULT) + { + if (!$connection instanceof Connection) { + $connection = new Connection($connection); + } + + $this->registerConnection($connection); + $this->registerStatementPrototype(($statementPrototype) ?: new Statement()); + $this->registerResultPrototype(($resultPrototype) ?: new Result()); + if (is_array($features)) { + foreach ($features as $name => $feature) { + $this->addFeature($name, $feature); + } + } elseif ($features instanceof AbstractFeature) { + $this->addFeature($features->getName(), $features); + } elseif ($features === self::FEATURES_DEFAULT) { + $this->setupDefaultFeatures(); + } + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Pdo + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + if ($this->connection instanceof Profiler\ProfilerAwareInterface) { + $this->connection->setProfiler($profiler); + } + if ($this->statementPrototype instanceof Profiler\ProfilerAwareInterface) { + $this->statementPrototype->setProfiler($profiler); + } + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Register connection + * + * @param Connection $connection + * @return Pdo + */ + public function registerConnection(Connection $connection) + { + $this->connection = $connection; + $this->connection->setDriver($this); + return $this; + } + + /** + * Register statement prototype + * + * @param Statement $statementPrototype + */ + public function registerStatementPrototype(Statement $statementPrototype) + { + $this->statementPrototype = $statementPrototype; + $this->statementPrototype->setDriver($this); + } + + /** + * Register result prototype + * + * @param Result $resultPrototype + */ + public function registerResultPrototype(Result $resultPrototype) + { + $this->resultPrototype = $resultPrototype; + } + + /** + * Add feature + * + * @param string $name + * @param AbstractFeature $feature + * @return Pdo + */ + public function addFeature($name, $feature) + { + if ($feature instanceof AbstractFeature) { + $name = $feature->getName(); // overwrite the name, just in case + $feature->setDriver($this); + } + $this->features[$name] = $feature; + return $this; + } + + /** + * Setup the default features for Pdo + * + * @return Pdo + */ + public function setupDefaultFeatures() + { + $driverName = $this->connection->getDriverName(); + if ($driverName == 'sqlite') { + $this->addFeature(null, new Feature\SqliteRowCounter); + } elseif ($driverName == 'oci') { + $this->addFeature(null, new Feature\OracleRowCounter); + } + return $this; + } + + /** + * Get feature + * + * @param $name + * @return AbstractFeature|false + */ + public function getFeature($name) + { + if (isset($this->features[$name])) { + return $this->features[$name]; + } + return false; + } + + /** + * Get database platform name + * + * @param string $nameFormat + * @return string + */ + public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE) + { + $name = $this->getConnection()->getDriverName(); + if ($nameFormat == self::NAME_FORMAT_CAMELCASE) { + switch ($name) { + case 'pgsql': + return 'Postgresql'; + case 'oci': + return 'Oracle'; + case 'dblib': + case 'sqlsrv': + return 'SqlServer'; + default: + return ucfirst($name); + } + } else { + switch ($name) { + case 'sqlite': + return 'SQLite'; + case 'mysql': + return 'MySQL'; + case 'pgsql': + return 'PostgreSQL'; + case 'oci': + return 'Oracle'; + case 'dblib': + case 'sqlsrv': + return 'SQLServer'; + default: + return ucfirst($name); + } + } + } + + /** + * Check environment + */ + public function checkEnvironment() + { + if (!extension_loaded('PDO')) { + throw new Exception\RuntimeException('The PDO extension is required for this adapter but the extension is not loaded'); + } + } + + /** + * @return Connection + */ + public function getConnection() + { + return $this->connection; + } + + /** + * @param string|PDOStatement $sqlOrResource + * @return Statement + */ + public function createStatement($sqlOrResource = null) + { + $statement = clone $this->statementPrototype; + if ($sqlOrResource instanceof PDOStatement) { + $statement->setResource($sqlOrResource); + } else { + if (is_string($sqlOrResource)) { + $statement->setSql($sqlOrResource); + } + if (!$this->connection->isConnected()) { + $this->connection->connect(); + } + $statement->initialize($this->connection->getResource()); + } + return $statement; + } + + /** + * @param resource $resource + * @param mixed $context + * @return Result + */ + public function createResult($resource, $context = null) + { + $result = clone $this->resultPrototype; + $rowCount = null; + + // special feature, sqlite PDO counter + if ($this->connection->getDriverName() == 'sqlite' + && ($sqliteRowCounter = $this->getFeature('SqliteRowCounter')) + && $resource->columnCount() > 0) { + $rowCount = $sqliteRowCounter->getRowCountClosure($context); + } + + // special feature, oracle PDO counter + if ($this->connection->getDriverName() == 'oci' + && ($oracleRowCounter = $this->getFeature('OracleRowCounter')) + && $resource->columnCount() > 0) { + $rowCount = $oracleRowCounter->getRowCountClosure($context); + } + + + $result->initialize($resource, $this->connection->getLastGeneratedValue(), $rowCount); + return $result; + } + + /** + * @return array + */ + public function getPrepareType() + { + return self::PARAMETERIZATION_NAMED; + } + + /** + * @param string $name + * @param string|null $type + * @return string + */ + public function formatParameterName($name, $type = null) + { + if ($type == null && !is_numeric($name) || $type == self::PARAMETERIZATION_NAMED) { + return ':' . $name; + } + + return '?'; + } + + /** + * @return mixed + */ + public function getLastGeneratedValue($name = null) + { + return $this->connection->getLastGeneratedValue($name); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Result.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Result.php new file mode 100644 index 0000000000000000000000000000000000000000..8a6879d8546af2bda4b4a543724e219be9728ce1 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Result.php @@ -0,0 +1,227 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Pdo; + +use Iterator; +use PDOStatement; +use Zend\Db\Adapter\Driver\ResultInterface; +use Zend\Db\Adapter\Exception; + +class Result implements Iterator, ResultInterface +{ + + const STATEMENT_MODE_SCROLLABLE = 'scrollable'; + const STATEMENT_MODE_FORWARD = 'forward'; + + /** + * + * @var string + */ + protected $statementMode = self::STATEMENT_MODE_FORWARD; + + /** + * @var \PDOStatement + */ + protected $resource = null; + + /** + * @var array Result options + */ + protected $options; + + /** + * Is the current complete? + * @var bool + */ + protected $currentComplete = false; + + /** + * Track current item in recordset + * @var mixed + */ + protected $currentData = null; + + /** + * Current position of scrollable statement + * @var int + */ + protected $position = -1; + + /** + * @var mixed + */ + protected $generatedValue = null; + + /** + * @var null + */ + protected $rowCount = null; + + /** + * Initialize + * + * @param PDOStatement $resource + * @param $generatedValue + * @param int $rowCount + * @return Result + */ + public function initialize(PDOStatement $resource, $generatedValue, $rowCount = null) + { + $this->resource = $resource; + $this->generatedValue = $generatedValue; + $this->rowCount = $rowCount; + + return $this; + } + + /** + * @return null + */ + public function buffer() + { + return null; + } + + /** + * @return bool|null + */ + public function isBuffered() + { + return false; + } + + /** + * Get resource + * + * @return mixed + */ + public function getResource() + { + return $this->resource; + } + + /** + * Get the data + * @return array + */ + public function current() + { + if ($this->currentComplete) { + return $this->currentData; + } + + $this->currentData = $this->resource->fetch(\PDO::FETCH_ASSOC); + $this->currentComplete = true; + return $this->currentData; + } + + /** + * Next + * + * @return mixed + */ + public function next() + { + $this->currentData = $this->resource->fetch(\PDO::FETCH_ASSOC); + $this->currentComplete = true; + $this->position++; + return $this->currentData; + } + + /** + * Key + * + * @return mixed + */ + public function key() + { + return $this->position; + } + + /** + * @throws Exception\RuntimeException + * @return void + */ + public function rewind() + { + if ($this->statementMode == self::STATEMENT_MODE_FORWARD && $this->position > 0) { + throw new Exception\RuntimeException( + 'This result is a forward only result set, calling rewind() after moving forward is not supported' + ); + } + $this->currentData = $this->resource->fetch(\PDO::FETCH_ASSOC); + $this->currentComplete = true; + $this->position = 0; + } + + /** + * Valid + * + * @return bool + */ + public function valid() + { + return ($this->currentData !== false); + } + + /** + * Count + * + * @return int + */ + public function count() + { + if (is_int($this->rowCount)) { + return $this->rowCount; + } + if ($this->rowCount instanceof \Closure) { + $this->rowCount = (int) call_user_func($this->rowCount); + } else { + $this->rowCount = (int) $this->resource->rowCount(); + } + return $this->rowCount; + } + + /** + * @return int + */ + public function getFieldCount() + { + return $this->resource->columnCount(); + } + + /** + * Is query result + * + * @return bool + */ + public function isQueryResult() + { + return ($this->resource->columnCount() > 0); + } + + /** + * Get affected rows + * + * @return int + */ + public function getAffectedRows() + { + return $this->resource->rowCount(); + } + + /** + * @return mixed|null + */ + public function getGeneratedValue() + { + return $this->generatedValue; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Statement.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Statement.php new file mode 100644 index 0000000000000000000000000000000000000000..634413caaf7d3b7366003a46e2fbac5c6a057caa --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pdo/Statement.php @@ -0,0 +1,313 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Pdo; + +use Zend\Db\Adapter\Driver\StatementInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Profiler; + +class Statement implements StatementInterface, Profiler\ProfilerAwareInterface +{ + + /** + * @var \PDO + */ + protected $pdo = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * @var Pdo + */ + protected $driver = null; + + /** + * + * @var string + */ + protected $sql = ''; + + /** + * + * @var bool + */ + protected $isQuery = null; + + /** + * + * @var ParameterContainer + */ + protected $parameterContainer = null; + + /** + * @var bool + */ + protected $parametersBound = false; + + /** + * @var \PDOStatement + */ + protected $resource = null; + + /** + * + * @var bool + */ + protected $isPrepared = false; + + /** + * Set driver + * + * @param Pdo $driver + * @return Statement + */ + public function setDriver(Pdo $driver) + { + $this->driver = $driver; + return $this; + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Statement + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Initialize + * + * @param \PDO $connectionResource + * @return Statement + */ + public function initialize(\PDO $connectionResource) + { + $this->pdo = $connectionResource; + return $this; + } + + /** + * Set resource + * + * @param \PDOStatement $pdoStatement + * @return Statement + */ + public function setResource(\PDOStatement $pdoStatement) + { + $this->resource = $pdoStatement; + return $this; + } + + /** + * Get resource + * + * @return mixed + */ + public function getResource() + { + return $this->resource; + } + + /** + * Set sql + * + * @param string $sql + * @return Statement + */ + public function setSql($sql) + { + $this->sql = $sql; + return $this; + } + + /** + * Get sql + * + * @return string + */ + public function getSql() + { + return $this->sql; + } + + /** + * @param ParameterContainer $parameterContainer + * @return Statement + */ + public function setParameterContainer(ParameterContainer $parameterContainer) + { + $this->parameterContainer = $parameterContainer; + return $this; + } + + /** + * @return ParameterContainer + */ + public function getParameterContainer() + { + return $this->parameterContainer; + } + + /** + * @param string $sql + * @throws Exception\RuntimeException + */ + public function prepare($sql = null) + { + if ($this->isPrepared) { + throw new Exception\RuntimeException('This statement has been prepared already'); + } + + if ($sql == null) { + $sql = $this->sql; + } + + $this->resource = $this->pdo->prepare($sql); + + if ($this->resource === false) { + $error = $this->pdo->errorInfo(); + throw new Exception\RuntimeException($error[2]); + } + + $this->isPrepared = true; + } + + /** + * @return bool + */ + public function isPrepared() + { + return $this->isPrepared; + } + + /** + * @param mixed $parameters + * @throws Exception\InvalidQueryException + * @return Result + */ + public function execute($parameters = null) + { + if (!$this->isPrepared) { + $this->prepare(); + } + + /** START Standard ParameterContainer Merging Block */ + if (!$this->parameterContainer instanceof ParameterContainer) { + if ($parameters instanceof ParameterContainer) { + $this->parameterContainer = $parameters; + $parameters = null; + } else { + $this->parameterContainer = new ParameterContainer(); + } + } + + if (is_array($parameters)) { + $this->parameterContainer->setFromArray($parameters); + } + + if ($this->parameterContainer->count() > 0) { + $this->bindParametersFromContainer(); + } + /** END Standard ParameterContainer Merging Block */ + + if ($this->profiler) { + $this->profiler->profilerStart($this); + } + + try { + $this->resource->execute(); + } catch (\PDOException $e) { + if ($this->profiler) { + $this->profiler->profilerFinish(); + } + throw new Exception\InvalidQueryException( + 'Statement could not be executed (' . implode(' - ', $this->resource->errorInfo()) . ')', + null, + $e + ); + } + + if ($this->profiler) { + $this->profiler->profilerFinish(); + } + + $result = $this->driver->createResult($this->resource, $this); + return $result; + } + + /** + * Bind parameters from container + */ + protected function bindParametersFromContainer() + { + if ($this->parametersBound) { + return; + } + + $parameters = $this->parameterContainer->getNamedArray(); + foreach ($parameters as $name => &$value) { + if (is_bool($value)) { + $type = \PDO::PARAM_BOOL; + } elseif (is_int($value)) { + $type = \PDO::PARAM_INT; + } else { + $type = \PDO::PARAM_STR; + } + if ($this->parameterContainer->offsetHasErrata($name)) { + switch ($this->parameterContainer->offsetGetErrata($name)) { + case ParameterContainer::TYPE_INTEGER: + $type = \PDO::PARAM_INT; + break; + case ParameterContainer::TYPE_NULL: + $type = \PDO::PARAM_NULL; + break; + case ParameterContainer::TYPE_LOB: + $type = \PDO::PARAM_LOB; + break; + } + } + + // parameter is named or positional, value is reference + $parameter = is_int($name) ? ($name + 1) : $name; + $this->resource->bindParam($parameter, $value, $type); + } + + } + + /** + * Perform a deep clone + * @return Statement A cloned statement + */ + public function __clone() + { + $this->isPrepared = false; + $this->parametersBound = false; + $this->resource = null; + if ($this->parameterContainer) { + $this->parameterContainer = clone $this->parameterContainer; + } + + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Connection.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Connection.php new file mode 100644 index 0000000000000000000000000000000000000000..fa91289a4389821b712a9f9f62a6920a77ce7564 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Connection.php @@ -0,0 +1,311 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Pgsql; + +use Zend\Db\Adapter\Driver\ConnectionInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\Profiler; + +class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface +{ + /** + * @var Pgsql + */ + protected $driver = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * Connection parameters + * + * @var array + */ + protected $connectionParameters = array(); + + /** + * @var resource + */ + protected $resource = null; + + /** + * In transaction + * + * @var bool + */ + protected $inTransaction = false; + + /** + * Constructor + * + * @param resource|array|null $connectionInfo + */ + public function __construct($connectionInfo = null) + { + if (is_array($connectionInfo)) { + $this->setConnectionParameters($connectionInfo); + } elseif (is_resource($connectionInfo)) { + $this->setResource($connectionInfo); + } + } + + /** + * Set connection parameters + * + * @param array $connectionParameters + * @return Connection + */ + public function setConnectionParameters(array $connectionParameters) + { + $this->connectionParameters = $connectionParameters; + return $this; + } + + /** + * Set driver + * + * @param Pgsql $driver + * @return Connection + */ + public function setDriver(Pgsql $driver) + { + $this->driver = $driver; + return $this; + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Connection + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Set resource + * + * @param resource $resource + * @return Connection + */ + public function setResource($resource) + { + $this->resource = $resource; + return; + } + + /** + * Get current schema + * + * @return null|string + */ + public function getCurrentSchema() + { + if (!$this->isConnected()) { + $this->connect(); + } + + $result = pg_query($this->resource, 'SELECT CURRENT_SCHEMA AS "currentschema"'); + if ($result == false) { + return null; + } + return pg_fetch_result($result, 0, 'currentschema'); + } + + /** + * Get resource + * + * @return resource + */ + public function getResource() + { + if (!$this->isConnected()) { + $this->connect(); + } + return $this->resource; + } + + /** + * Connect to the database + * + * @return Connection + * @throws Exception\RuntimeException on failure + */ + public function connect() + { + if (is_resource($this->resource)) { + return $this; + } + + // localize + $p = $this->connectionParameters; + + // given a list of key names, test for existence in $p + $findParameterValue = function (array $names) use ($p) { + foreach ($names as $name) { + if (isset($p[$name])) { + return $p[$name]; + } + } + return null; + }; + + $connection = array(); + $connection['host'] = $findParameterValue(array('hostname', 'host')); + $connection['user'] = $findParameterValue(array('username', 'user')); + $connection['password'] = $findParameterValue(array('password', 'passwd', 'pw')); + $connection['dbname'] = $findParameterValue(array('database', 'dbname', 'db', 'schema')); + $connection['port'] = (isset($p['port'])) ? (int) $p['port'] : null; + $connection['socket'] = (isset($p['socket'])) ? $p['socket'] : null; + + $connection = array_filter($connection); // remove nulls + $connection = http_build_query($connection, null, ' '); // @link http://php.net/pg_connect + + set_error_handler(function ($number, $string) { + throw new Exception\RuntimeException( + __METHOD__ . ': Unable to connect to database', null, new Exception\ErrorException($string, $number) + ); + }); + $this->resource = pg_connect($connection); + restore_error_handler(); + + if ($this->resource === false) { + throw new Exception\RuntimeException(sprintf( + '%s: Unable to connect to database', + __METHOD__ + )); + } + + return $this; + } + + /** + * @return bool + */ + public function isConnected() + { + return (is_resource($this->resource)); + } + + /** + * @return void + */ + public function disconnect() + { + pg_close($this->resource); + } + + /** + * @return void + */ + public function beginTransaction() + { + if ($this->inTransaction) { + throw new Exception\RuntimeException('Nested transactions are not supported'); + } + + if (!$this->isConnected()) { + $this->connect(); + } + + pg_query($this->resource, 'BEGIN'); + $this->inTransaction = true; + } + + /** + * In transaction + * + * @return bool + */ + public function inTransaction() + { + return $this->inTransaction; + } + + /** + * @return void + */ + public function commit() + { + if (!$this->inTransaction) { + return; // We ignore attempts to commit non-existing transaction + } + + pg_query($this->resource, 'COMMIT'); + $this->inTransaction = false; + } + + /** + * @return void + */ + public function rollback() + { + if (!$this->inTransaction) { + return; + } + + pg_query($this->resource, 'ROLLBACK'); + $this->inTransaction = false; + } + + /** + * @param string $sql + * @throws Exception\InvalidQueryException + * @return resource|\Zend\Db\ResultSet\ResultSetInterface + */ + public function execute($sql) + { + if (!$this->isConnected()) { + $this->connect(); + } + + if ($this->profiler) { + $this->profiler->profilerStart($sql); + } + + $resultResource = pg_query($this->resource, $sql); + + if ($this->profiler) { + $this->profiler->profilerFinish($sql); + } + + // if the returnValue is something other than a pg result resource, bypass wrapping it + if ($resultResource === false) { + throw new Exception\InvalidQueryException(pg_errormessage()); + } + + $resultPrototype = $this->driver->createResult(($resultResource === true) ? $this->resource : $resultResource); + return $resultPrototype; + } + + /** + * @param null $name Ignored + * @return string + */ + public function getLastGeneratedValue($name = null) + { + if ($name == null) { + return null; + } + $result = pg_query($this->resource, 'SELECT CURRVAL(\'' . str_replace('\'', '\\\'', $name) . '\') as "currval"'); + return pg_fetch_result($result, 0, 'currval'); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Pgsql.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Pgsql.php new file mode 100644 index 0000000000000000000000000000000000000000..36e5e0f294f46dca1731aeee1a5518a650d96206 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Pgsql.php @@ -0,0 +1,227 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Pgsql; + +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\Profiler; + +class Pgsql implements DriverInterface, Profiler\ProfilerAwareInterface +{ + /** + * @var Connection + */ + protected $connection = null; + + /** + * @var Statement + */ + protected $statementPrototype = null; + + /** + * @var Result + */ + protected $resultPrototype = null; + + /** + * @var null|Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * @var array + */ + protected $options = array( + 'buffer_results' => false + ); + + /** + * Constructor + * + * @param array|Connection|resource $connection + * @param null|Statement $statementPrototype + * @param null|Result $resultPrototype + * @param array $options + */ + public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null, $options = null) + { + if (!$connection instanceof Connection) { + $connection = new Connection($connection); + } + + $this->registerConnection($connection); + $this->registerStatementPrototype(($statementPrototype) ?: new Statement()); + $this->registerResultPrototype(($resultPrototype) ?: new Result()); + } + + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + if ($this->connection instanceof Profiler\ProfilerAwareInterface) { + $this->connection->setProfiler($profiler); + } + if ($this->statementPrototype instanceof Profiler\ProfilerAwareInterface) { + $this->statementPrototype->setProfiler($profiler); + } + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Register connection + * + * @param Connection $connection + * @return Pgsql + */ + public function registerConnection(Connection $connection) + { + $this->connection = $connection; + $this->connection->setDriver($this); + return $this; + } + + /** + * Register statement prototype + * + * @param Statement $statement + * @return Pgsql + */ + public function registerStatementPrototype(Statement $statement) + { + $this->statementPrototype = $statement; + $this->statementPrototype->setDriver($this); // needs access to driver to createResult() + return $this; + } + + /** + * Register result prototype + * + * @param Result $result + * @return Pgsql + */ + public function registerResultPrototype(Result $result) + { + $this->resultPrototype = $result; + return $this; + } + + /** + * Get database platform name + * + * @param string $nameFormat + * @return string + */ + public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE) + { + if ($nameFormat == self::NAME_FORMAT_CAMELCASE) { + return 'Postgresql'; + } + + return 'PostgreSQL'; + } + + /** + * Check environment + * + * @throws Exception\RuntimeException + * @return bool + */ + public function checkEnvironment() + { + if (!extension_loaded('pgsql')) { + throw new Exception\RuntimeException('The PostgreSQL (pgsql) extension is required for this adapter but the extension is not loaded'); + } + } + + /** + * Get connection + * + * @return Connection + */ + public function getConnection() + { + return $this->connection; + } + + /** + * Create statement + * + * @param string|null $sqlOrResource + * @return Statement + */ + public function createStatement($sqlOrResource = null) + { + $statement = clone $this->statementPrototype; + + if (is_string($sqlOrResource)) { + $statement->setSql($sqlOrResource); + } + + if (!$this->connection->isConnected()) { + $this->connection->connect(); + } + + $statement->initialize($this->connection->getResource()); + return $statement; + } + + /** + * Create result + * + * @param resource $resource + * @return Result + */ + public function createResult($resource) + { + $result = clone $this->resultPrototype; + $result->initialize($resource, $this->connection->getLastGeneratedValue()); + return $result; + } + + /** + * Get prepare Type + * + * @return array + */ + public function getPrepareType() + { + return self::PARAMETERIZATION_POSITIONAL; + } + + /** + * Format parameter name + * + * @param string $name + * @param mixed $type + * @return string + */ + public function formatParameterName($name, $type = null) + { + return '$#'; + } + + /** + * Get last generated value + * + * @param string $name + * @return mixed + */ + public function getLastGeneratedValue($name = null) + { + return $this->connection->getLastGeneratedValue($name); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Result.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Result.php new file mode 100644 index 0000000000000000000000000000000000000000..9a7f5685f142c60c38334427f8384ce0eea688d3 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Result.php @@ -0,0 +1,193 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Pgsql; + +use Zend\Db\Adapter\Driver\ResultInterface; +use Zend\Db\Adapter\Exception; + +class Result implements ResultInterface +{ + + /** + * @var resource + */ + protected $resource = null; + + /** + * @var int + */ + protected $position = 0; + + /** + * @var int + */ + protected $count = 0; + + /** + * @var null|mixed + */ + protected $generatedValue = null; + + /** + * Initialize + * + * @param $resource + * @param $generatedValue + * @return void + * @throws Exception\InvalidArgumentException + */ + public function initialize($resource, $generatedValue) + { + if (!is_resource($resource) || get_resource_type($resource) != 'pgsql result') { + throw new Exception\InvalidArgumentException('Resource not of the correct type.'); + } + + $this->resource = $resource; + $this->count = pg_num_rows($this->resource); + $this->generatedValue = $generatedValue; + } + + /** + * Current + * + * @return array|bool|mixed + */ + public function current() + { + if ($this->count === 0) { + return false; + } + return pg_fetch_assoc($this->resource, $this->position); + } + + /** + * Next + * + * @return void + */ + public function next() + { + $this->position++; + } + + /** + * Key + * + * @return int|mixed + */ + public function key() + { + return $this->position; + } + + /** + * Valid + * + * @return bool + */ + public function valid() + { + return ($this->position < $this->count); + } + + /** + * Rewind + * + * @return void + */ + public function rewind() + { + $this->position = 0; + } + + /** + * Buffer + * + * @return null + */ + public function buffer() + { + return null; + } + + /** + * Is buffered + * + * @return false + */ + public function isBuffered() + { + return false; + } + + /** + * Is query result + * + * @return bool + */ + public function isQueryResult() + { + return (pg_num_fields($this->resource) > 0); + } + + /** + * Get affected rows + * + * @return int + */ + public function getAffectedRows() + { + return pg_affected_rows($this->resource); + } + + /** + * Get generated value + * + * @return mixed|null + */ + public function getGeneratedValue() + { + return $this->generatedValue; + } + + /** + * Get resource + */ + public function getResource() + { + // TODO: Implement getResource() method. + } + + /** + * Count + * + * (PHP 5 >= 5.1.0)<br/> + * Count elements of an object + * @link http://php.net/manual/en/countable.count.php + * @return int The custom count as an integer. + * </p> + * <p> + * The return value is cast to an integer. + */ + public function count() + { + return $this->count; + } + + /** + * Get field count + * + * @return int + */ + public function getFieldCount() + { + return pg_num_fields($this->resource); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Statement.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Statement.php new file mode 100644 index 0000000000000000000000000000000000000000..c105a6647ed87452a0a621c46e4b813f74897089 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Pgsql/Statement.php @@ -0,0 +1,241 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Pgsql; + +use Zend\Db\Adapter\Driver\StatementInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Profiler; + +class Statement implements StatementInterface, Profiler\ProfilerAwareInterface +{ + /** + * @var int + */ + protected static $statementIndex = 0; + + /** + * @var string + */ + protected $statementName = ''; + + /** + * @var Pgsql + */ + protected $driver = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * @var resource + */ + protected $pgsql = null; + + /** + * @var resource + */ + protected $resource = null; + + /** + * @var string + */ + protected $sql; + + /** + * @var ParameterContainer + */ + protected $parameterContainer; + + /** + * @param Pgsql $driver + * @return Statement + */ + public function setDriver(Pgsql $driver) + { + $this->driver = $driver; + return $this; + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Statement + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Initialize + * + * @param resource $pgsql + * @return void + * @throws Exception\RuntimeException for invalid or missing postgresql connection + */ + public function initialize($pgsql) + { + if (!is_resource($pgsql) || get_resource_type($pgsql) !== 'pgsql link') { + throw new Exception\RuntimeException(sprintf( + '%s: Invalid or missing postgresql connection; received "%s"', + __METHOD__, + get_resource_type($pgsql) + )); + } + $this->pgsql = $pgsql; + } + + /** + * Get resource + * + * @return resource + */ + public function getResource() + { + // TODO: Implement getResource() method. + } + + /** + * Set sql + * + * @param string $sql + * @return Statement + */ + public function setSql($sql) + { + $this->sql = $sql; + return $this; + } + + /** + * Get sql + * + * @return string + */ + public function getSql() + { + return $this->sql; + } + + /** + * Set parameter container + * + * @param ParameterContainer $parameterContainer + * @return Statement + */ + public function setParameterContainer(ParameterContainer $parameterContainer) + { + $this->parameterContainer = $parameterContainer; + return $this; + } + + /** + * Get parameter container + * + * @return ParameterContainer + */ + public function getParameterContainer() + { + return $this->parameterContainer; + } + + /** + * Prepare + * + * @param string $sql + */ + public function prepare($sql = null) + { + $sql = ($sql) ?: $this->sql; + + $pCount = 1; + $sql = preg_replace_callback( + '#\$\##', function ($foo) use (&$pCount) { + return '$' . $pCount++; + }, + $sql + ); + + $this->sql = $sql; + $this->statementName = 'statement' . ++static::$statementIndex; + $this->resource = pg_prepare($this->pgsql, $this->statementName, $sql); + } + + /** + * Is prepared + * + * @return bool + */ + public function isPrepared() + { + return isset($this->resource); + } + + /** + * Execute + * + * @param ParameterContainer|null $parameters + * @throws Exception\InvalidQueryException + * @return Result + */ + public function execute($parameters = null) + { + if (!$this->isPrepared()) { + $this->prepare(); + } + + /** START Standard ParameterContainer Merging Block */ + if (!$this->parameterContainer instanceof ParameterContainer) { + if ($parameters instanceof ParameterContainer) { + $this->parameterContainer = $parameters; + $parameters = null; + } else { + $this->parameterContainer = new ParameterContainer(); + } + } + + if (is_array($parameters)) { + $this->parameterContainer->setFromArray($parameters); + } + + if ($this->parameterContainer->count() > 0) { + $parameters = $this->parameterContainer->getPositionalArray(); + } + /** END Standard ParameterContainer Merging Block */ + + if ($this->profiler) { + $this->profiler->profilerStart($this); + } + + $resultResource = pg_execute($this->pgsql, $this->statementName, (array) $parameters); + + if ($this->profiler) { + $this->profiler->profilerFinish(); + } + + if ($resultResource === false) { + throw new Exception\InvalidQueryException(pg_last_error()); + } + + $result = $this->driver->createResult($resultResource); + return $result; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/ResultInterface.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/ResultInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..cb1f40784992929699dd5a9a259095c9f045634f --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/ResultInterface.php @@ -0,0 +1,67 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver; + +use Countable; +use Iterator; + +interface ResultInterface extends + Countable, + Iterator +{ + /** + * Force buffering + * + * @return void + */ + public function buffer(); + + /** + * Check if is buffered + * + * @return bool|null + */ + public function isBuffered(); + + /** + * Is query result? + * + * @return bool + */ + public function isQueryResult(); + + /** + * Get affected rows + * + * @return int + */ + public function getAffectedRows(); + + /** + * Get generated value + * + * @return mixed|null + */ + public function getGeneratedValue(); + + /** + * Get the resource + * + * @return mixed + */ + public function getResource(); + + /** + * Get field count + * + * @return int + */ + public function getFieldCount(); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Connection.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Connection.php new file mode 100644 index 0000000000000000000000000000000000000000..fa88c6bcd888cda5adcfc29ac3bcbb577e3162d2 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Connection.php @@ -0,0 +1,364 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Sqlsrv; + +use Zend\Db\Adapter\Driver\ConnectionInterface; +use Zend\Db\Adapter\Driver\Sqlsrv\Exception\ErrorException; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\Profiler; + +class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface +{ + /** + * @var Sqlsrv + */ + protected $driver = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * @var array + */ + protected $connectionParameters = array(); + + /** + * @var resource + */ + protected $resource = null; + + /** + * @var bool + */ + protected $inTransaction = false; + + /** + * Constructor + * + * @param array|resource $connectionInfo + * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException + */ + public function __construct($connectionInfo) + { + if (is_array($connectionInfo)) { + $this->setConnectionParameters($connectionInfo); + } elseif (is_resource($connectionInfo)) { + $this->setResource($connectionInfo); + } else { + throw new Exception\InvalidArgumentException('$connection must be an array of parameters or a resource'); + } + } + + /** + * Set driver + * + * @param Sqlsrv $driver + * @return Connection + */ + public function setDriver(Sqlsrv $driver) + { + $this->driver = $driver; + return $this; + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Connection + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Set connection parameters + * + * @param array $connectionParameters + * @return Connection + */ + public function setConnectionParameters(array $connectionParameters) + { + $this->connectionParameters = $connectionParameters; + return $this; + } + + /** + * Get connection parameters + * + * @return array + */ + public function getConnectionParameters() + { + return $this->connectionParameters; + } + + /** + * Get current schema + * + * @return string + */ + public function getCurrentSchema() + { + if (!$this->isConnected()) { + $this->connect(); + } + + $result = sqlsrv_query($this->resource, 'SELECT SCHEMA_NAME()'); + $r = sqlsrv_fetch_array($result); + return $r[0]; + } + + /** + * Set resource + * + * @param resource $resource + * @throws Exception\InvalidArgumentException + * @return Connection + */ + public function setResource($resource) + { + if (get_resource_type($resource) !== 'SQL Server Connection') { + throw new Exception\InvalidArgumentException('Resource provided was not of type SQL Server Connection'); + } + $this->resource = $resource; + return $this; + } + + /** + * @return resource + */ + public function getResource() + { + if (!$this->isConnected()) { + $this->connect(); + } + return $this->resource; + } + + /** + * Connect + * + * @throws Exception\RuntimeException + * @return Connection + */ + public function connect() + { + if ($this->resource) { + return $this; + } + + $serverName = '.'; + $params = array( + 'ReturnDatesAsStrings' => true + ); + foreach ($this->connectionParameters as $key => $value) { + switch (strtolower($key)) { + case 'hostname': + case 'servername': + $serverName = (string) $value; + break; + case 'username': + case 'uid': + $params['UID'] = (string) $value; + break; + case 'password': + case 'pwd': + $params['PWD'] = (string) $value; + break; + case 'database': + case 'dbname': + $params['Database'] = (string) $value; + break; + case 'driver_options': + case 'options': + $params = array_merge($params, (array) $value); + break; + + } + } + + $this->resource = sqlsrv_connect($serverName, $params); + + if (!$this->resource) { + throw new Exception\RuntimeException( + 'Connect Error', + null, + new ErrorException(sqlsrv_errors()) + ); + } + + return $this; + } + + /** + * Is connected + * @return bool + */ + public function isConnected() + { + return (is_resource($this->resource)); + } + + /** + * Disconnect + */ + public function disconnect() + { + sqlsrv_close($this->resource); + $this->resource = null; + } + + /** + * Begin transaction + */ + public function beginTransaction() + { + // http://msdn.microsoft.com/en-us/library/cc296151.aspx + /* + $this->resource->autocommit(false); + $this->inTransaction = true; + */ + } + + /** + * In transaction + * + * @return bool + */ + public function inTransaction() + { + return $this->inTransaction; + } + + /** + * Commit + */ + public function commit() + { + // http://msdn.microsoft.com/en-us/library/cc296194.aspx + /* + if (!$this->resource) { + $this->connect(); + } + + $this->resource->commit(); + + $this->inTransaction = false; + */ + } + + /** + * Rollback + */ + public function rollback() + { + // http://msdn.microsoft.com/en-us/library/cc296176.aspx + /* + if (!$this->resource) { + throw new \Exception('Must be connected before you can rollback.'); + } + + if (!$this->_inCommit) { + throw new \Exception('Must call commit() before you can rollback.'); + } + + $this->resource->rollback(); + return $this; + */ + } + + /** + * Execute + * + * @param string $sql + * @throws Exception\RuntimeException + * @return mixed + */ + public function execute($sql) + { + if (!$this->isConnected()) { + $this->connect(); + } + + if (!$this->driver instanceof Sqlsrv) { + throw new Exception\RuntimeException('Connection is missing an instance of Sqlsrv'); + } + + if ($this->profiler) { + $this->profiler->profilerStart($sql); + } + + $returnValue = sqlsrv_query($this->resource, $sql); + + if ($this->profiler) { + $this->profiler->profilerFinish($sql); + } + + // if the returnValue is something other than a Sqlsrv_result, bypass wrapping it + if ($returnValue === false) { + $errors = sqlsrv_errors(); + // ignore general warnings + if ($errors[0]['SQLSTATE'] != '01000') { + throw new Exception\RuntimeException( + 'An exception occurred while trying to execute the provided $sql', + null, + new ErrorException($errors) + ); + } + } + + $result = $this->driver->createResult($returnValue); + return $result; + } + + /** + * Prepare + * + * @param string $sql + * @return string + */ + public function prepare($sql) + { + if (!$this->isConnected()) { + $this->connect(); + } + + $statement = $this->driver->createStatement($sql); + return $statement; + } + + /** + * Get last generated id + * + * @param string $name + * @return mixed + */ + public function getLastGeneratedValue($name = null) + { + if (!$this->resource) { + $this->connect(); + } + $sql = 'SELECT @@IDENTITY as Current_Identity'; + $result = sqlsrv_query($this->resource, $sql); + $row = sqlsrv_fetch_array($result); + return $row['Current_Identity']; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Exception/ErrorException.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Exception/ErrorException.php new file mode 100644 index 0000000000000000000000000000000000000000..8330559fed0890163fe75945d44cf27f006a3ec3 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Exception/ErrorException.php @@ -0,0 +1,33 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Sqlsrv\Exception; + +use Zend\Db\Adapter\Exception; + +class ErrorException extends Exception\ErrorException implements ExceptionInterface +{ + + /** + * Errors + * + * @var array + */ + protected $errors = array(); + + /** + * Construct + * + * @param bool $errors + */ + public function __construct($errors = false) + { + $this->errors = ($errors === false) ? sqlsrv_errors() : $errors; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Exception/ExceptionInterface.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Exception/ExceptionInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..a7168e8d6e0c4f8cca1cd362c48d2cf60a544936 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Exception/ExceptionInterface.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Sqlsrv\Exception; + +use Zend\Db\Adapter\Exception; + +interface ExceptionInterface extends Exception\ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Result.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Result.php new file mode 100644 index 0000000000000000000000000000000000000000..f7fa0ffb8b4ee5bfd34d4aee296b362ef6aa65f8 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Result.php @@ -0,0 +1,209 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Sqlsrv; + +use Iterator; +use Zend\Db\Adapter\Driver\ResultInterface; + +class Result implements Iterator, ResultInterface +{ + + /** + * @var resource + */ + protected $resource = null; + + /** + * @var bool + */ + protected $currentData = false; + + /** + * + * @var bool + */ + protected $currentComplete = false; + + /** + * + * @var int + */ + protected $position = -1; + + /** + * @var mixed + */ + protected $generatedValue = null; + + /** + * Initialize + * + * @param resource $resource + * @param mixed $generatedValue + * @return Result + */ + public function initialize($resource, $generatedValue = null) + { + $this->resource = $resource; + $this->generatedValue = $generatedValue; + return $this; + } + + /** + * @return null + */ + public function buffer() + { + return null; + } + + /** + * @return bool + */ + public function isBuffered() + { + return false; + } + + /** + * Get resource + * + * @return resource + */ + public function getResource() + { + return $this->resource; + } + + /** + * Current + * + * @return mixed + */ + public function current() + { + if ($this->currentComplete) { + return $this->currentData; + } + + $this->load(); + return $this->currentData; + } + + /** + * Next + * + * @return bool + */ + public function next() + { + $this->load(); + return true; + } + + /** + * Load + * + * @param int $row + * @return mixed + */ + protected function load($row = SQLSRV_SCROLL_NEXT) + { + $this->currentData = sqlsrv_fetch_array($this->resource, SQLSRV_FETCH_ASSOC, $row); + $this->currentComplete = true; + $this->position++; + return $this->currentData; + } + + /** + * Key + * + * @return mixed + */ + public function key() + { + return $this->position; + } + + /** + * Rewind + * + * @return bool + */ + public function rewind() + { + $this->position = 0; + $this->load(SQLSRV_SCROLL_FIRST); + return true; + } + + /** + * Valid + * + * @return bool + */ + public function valid() + { + if ($this->currentComplete && $this->currentData) { + return true; + } + + return $this->load(); + } + + /** + * Count + * + * @return int + */ + public function count() + { + return sqlsrv_num_rows($this->resource); + } + + /** + * @return bool|int + */ + public function getFieldCount() + { + return sqlsrv_num_fields($this->resource); + } + + /** + * Is query result + * + * @return bool + */ + public function isQueryResult() + { + if (is_bool($this->resource)) { + return false; + } + return (sqlsrv_num_fields($this->resource) > 0); + } + + /** + * Get affected rows + * + * @return int + */ + public function getAffectedRows() + { + return sqlsrv_rows_affected($this->resource); + } + + /** + * @return mixed|null + */ + public function getGeneratedValue() + { + return $this->generatedValue; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Sqlsrv.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Sqlsrv.php new file mode 100644 index 0000000000000000000000000000000000000000..bf8af428a702aade527d14372a5aff592503a9df --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Sqlsrv.php @@ -0,0 +1,212 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Sqlsrv; + +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\Profiler; + +class Sqlsrv implements DriverInterface, Profiler\ProfilerAwareInterface +{ + + /** + * @var Connection + */ + protected $connection = null; + + /** + * @var Statement + */ + protected $statementPrototype = null; + + /** + * @var Result + */ + protected $resultPrototype = null; + + /** + * @var null|Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * @param array|Connection|resource $connection + * @param null|Statement $statementPrototype + * @param null|Result $resultPrototype + */ + public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null) + { + if (!$connection instanceof Connection) { + $connection = new Connection($connection); + } + + $this->registerConnection($connection); + $this->registerStatementPrototype(($statementPrototype) ?: new Statement()); + $this->registerResultPrototype(($resultPrototype) ?: new Result()); + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Sqlsrv + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + if ($this->connection instanceof Profiler\ProfilerAwareInterface) { + $this->connection->setProfiler($profiler); + } + if ($this->statementPrototype instanceof Profiler\ProfilerAwareInterface) { + $this->statementPrototype->setProfiler($profiler); + } + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * Register connection + * + * @param Connection $connection + * @return Sqlsrv + */ + public function registerConnection(Connection $connection) + { + $this->connection = $connection; + $this->connection->setDriver($this); + return $this; + } + + /** + * Register statement prototype + * + * @param Statement $statementPrototype + * @return Sqlsrv + */ + public function registerStatementPrototype(Statement $statementPrototype) + { + $this->statementPrototype = $statementPrototype; + $this->statementPrototype->setDriver($this); + return $this; + } + + /** + * Register result prototype + * + * @param Result $resultPrototype + * @return Sqlsrv + */ + public function registerResultPrototype(Result $resultPrototype) + { + $this->resultPrototype = $resultPrototype; + return $this; + } + + /** + * Get database paltform name + * + * @param string $nameFormat + * @return string + */ + public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE) + { + if ($nameFormat == self::NAME_FORMAT_CAMELCASE) { + return 'SqlServer'; + } + + return 'SQLServer'; + } + + /** + * Check environment + * + * @throws Exception\RuntimeException + * @return void + */ + public function checkEnvironment() + { + if (!extension_loaded('sqlsrv')) { + throw new Exception\RuntimeException('The Sqlsrv extension is required for this adapter but the extension is not loaded'); + } + } + + /** + * @return Connection + */ + public function getConnection() + { + return $this->connection; + } + + /** + * @param string|resource $sqlOrResource + * @return Statement + */ + public function createStatement($sqlOrResource = null) + { + $statement = clone $this->statementPrototype; + if (is_resource($sqlOrResource)) { + $statement->initialize($sqlOrResource); + } else { + if (!$this->connection->isConnected()) { + $this->connection->connect(); + } + $statement->initialize($this->connection->getResource()); + if (is_string($sqlOrResource)) { + $statement->setSql($sqlOrResource); + } elseif ($sqlOrResource != null) { + throw new Exception\InvalidArgumentException('createStatement() only accepts an SQL string or a Sqlsrv resource'); + } + } + return $statement; + } + + /** + * @param resource $resource + * @return Result + */ + public function createResult($resource) + { + $result = clone $this->resultPrototype; + $result->initialize($resource, $this->connection->getLastGeneratedValue()); + return $result; + } + + /** + * @return array + */ + public function getPrepareType() + { + return self::PARAMETERIZATION_POSITIONAL; + } + + /** + * @param string $name + * @param mixed $type + * @return string + */ + public function formatParameterName($name, $type = null) + { + return '?'; + } + + /** + * @return mixed + */ + public function getLastGeneratedValue() + { + return $this->getConnection()->getLastGeneratedValue(); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Statement.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Statement.php new file mode 100644 index 0000000000000000000000000000000000000000..e3e157d3bd17ebe6ceef6c3a9b2ddd86f32cc678 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/Sqlsrv/Statement.php @@ -0,0 +1,289 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver\Sqlsrv; + +use Zend\Db\Adapter\Driver\StatementInterface; +use Zend\Db\Adapter\Exception; +use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Profiler; + +class Statement implements StatementInterface, Profiler\ProfilerAwareInterface +{ + + /** + * @var resource + */ + protected $sqlsrv = null; + + /** + * @var Sqlsrv + */ + protected $driver = null; + + /** + * @var Profiler\ProfilerInterface + */ + protected $profiler = null; + + /** + * @var string + */ + protected $sql = null; + + /** + * @var bool + */ + protected $isQuery = null; + + /** + * @var array + */ + protected $parameterReferences = array(); + + /** + * @var ParameterContainer + */ + protected $parameterContainer = null; + + /** + * @var resource + */ + protected $resource = null; + + /** + * + * @var bool + */ + protected $isPrepared = false; + + /** + * Set driver + * + * @param Sqlsrv $driver + * @return Statement + */ + public function setDriver(Sqlsrv $driver) + { + $this->driver = $driver; + return $this; + } + + /** + * @param Profiler\ProfilerInterface $profiler + * @return Statement + */ + public function setProfiler(Profiler\ProfilerInterface $profiler) + { + $this->profiler = $profiler; + return $this; + } + + /** + * @return null|Profiler\ProfilerInterface + */ + public function getProfiler() + { + return $this->profiler; + } + + /** + * + * One of two resource types will be provided here: + * a) "SQL Server Connection" when a prepared statement needs to still be produced + * b) "SQL Server Statement" when a prepared statement has been already produced + * (there will need to already be a bound param set if it applies to this query) + * + * @param resource $resource + * @throws Exception\InvalidArgumentException + * @return Statement + */ + public function initialize($resource) + { + $resourceType = get_resource_type($resource); + + if ($resourceType == 'SQL Server Connection') { + $this->sqlsrv = $resource; + } elseif ($resourceType == 'SQL Server Statement') { + $this->resource = $resource; + $this->isPrepared = true; + } else { + throw new Exception\InvalidArgumentException('Invalid resource provided to ' . __CLASS__); + } + + return $this; + } + + /** + * Set parameter container + * + * @param ParameterContainer $parameterContainer + * @return Statement + */ + public function setParameterContainer(ParameterContainer $parameterContainer) + { + $this->parameterContainer = $parameterContainer; + return $this; + } + + /** + * @return ParameterContainer + */ + public function getParameterContainer() + { + return $this->parameterContainer; + } + + /** + * @param $resource + * @return Statement + */ + public function setResource($resource) + { + $this->resource = $resource; + return $this; + } + + /** + * Get resource + * + * @return resource + */ + public function getResource() + { + return $this->resource; + } + + /** + * @param string $sql + * @return Statement + */ + public function setSql($sql) + { + $this->sql = $sql; + return $this; + } + + /** + * Get sql + * + * @return string + */ + public function getSql() + { + return $this->sql; + } + + /** + * @param string $sql + * @throws Exception\RuntimeException + * @return Statement + */ + public function prepare($sql = null) + { + if ($this->isPrepared) { + throw new Exception\RuntimeException('Already prepared'); + } + $sql = ($sql) ?: $this->sql; + + $pRef = &$this->parameterReferences; + for ($position = 0, $count = substr_count($sql, '?'); $position < $count; $position++) { + $pRef[$position] = array('', SQLSRV_PARAM_IN, null, null); + } + + $this->resource = sqlsrv_prepare($this->sqlsrv, $sql, $pRef); + + $this->isPrepared = true; + return $this; + } + + /** + * @return bool + */ + public function isPrepared() + { + return $this->isPrepared; + } + + /** + * Execute + * + * @param array|ParameterContainer $parameters + * @throws Exception\RuntimeException + * @return Result + */ + public function execute($parameters = null) + { + if (!$this->isPrepared) { + $this->prepare(); + } + + /** START Standard ParameterContainer Merging Block */ + if (!$this->parameterContainer instanceof ParameterContainer) { + if ($parameters instanceof ParameterContainer) { + $this->parameterContainer = $parameters; + $parameters = null; + } else { + $this->parameterContainer = new ParameterContainer(); + } + } + + if (is_array($parameters)) { + $this->parameterContainer->setFromArray($parameters); + } + + if ($this->parameterContainer->count() > 0) { + $this->bindParametersFromContainer(); + } + /** END Standard ParameterContainer Merging Block */ + + if ($this->profiler) { + $this->profiler->profilerStart($this); + } + + $resultValue = sqlsrv_execute($this->resource); + + if ($this->profiler) { + $this->profiler->profilerFinish(); + } + + if ($resultValue === false) { + $errors = sqlsrv_errors(); + // ignore general warnings + if ($errors[0]['SQLSTATE'] != '01000') { + throw new Exception\RuntimeException($errors[0]['message']); + } + } + + $result = $this->driver->createResult($this->resource); + return $result; + } + + /** + * Bind parameters from container + * + */ + protected function bindParametersFromContainer() + { + $values = $this->parameterContainer->getPositionalArray(); + $position = 0; + foreach ($values as $value) { + $this->parameterReferences[$position++][0] = $value; + } + + // @todo bind errata + //foreach ($this->parameterContainer as $name => &$value) { + // $p[$position][0] = $value; + // $position++; + // if ($this->parameterContainer->offsetHasErrata($name)) { + // $p[$position][3] = $this->parameterContainer->offsetGetErrata($name); + // } + //} + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/StatementInterface.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/StatementInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..e6fab35726a7735cc0ebc289f61fee233193f5ff --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Driver/StatementInterface.php @@ -0,0 +1,46 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Driver; + +use Zend\Db\Adapter\StatementContainerInterface; + +interface StatementInterface extends StatementContainerInterface +{ + + /** + * Get resource + * + * @return resource + */ + public function getResource(); + + /** + * Prepare sql + * + * @param string $sql + */ + public function prepare($sql = null); + + /** + * Check if is prepared + * + * @return bool + */ + public function isPrepared(); + + /** + * Execute + * + * @param null $parameters + * @return ResultInterface + */ + public function execute($parameters = null); + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/ErrorException.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/ErrorException.php new file mode 100644 index 0000000000000000000000000000000000000000..125550a24ce73790d94cbbfaa135d60279f9c90c --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/ErrorException.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Exception; + +use Zend\Db\Exception; + +class ErrorException extends Exception\ErrorException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/ExceptionInterface.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/ExceptionInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..3f3660d99e01cb0832f6fc690414612cc8929b06 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/ExceptionInterface.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Exception; + +use Zend\Db\Exception; + +interface ExceptionInterface extends Exception\ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidArgumentException.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidArgumentException.php new file mode 100644 index 0000000000000000000000000000000000000000..5cf7a4bfa38eb799a6633ab650371e312a338b81 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidArgumentException.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Exception; + +use Zend\Db\Exception; + +class InvalidArgumentException extends Exception\InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidConnectionParametersException.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidConnectionParametersException.php new file mode 100644 index 0000000000000000000000000000000000000000..152038a48ce28ebcb593104f703663bd316c2fb8 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidConnectionParametersException.php @@ -0,0 +1,29 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Exception; + +class InvalidConnectionParametersException extends RuntimeException implements ExceptionInterface +{ + + /** + * @var int + */ + protected $parameters; + + /** + * @param string $message + * @param int $parameters + */ + public function __construct($message, $parameters) + { + parent::__construct($message); + $this->parameters = $parameters; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidQueryException.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidQueryException.php new file mode 100644 index 0000000000000000000000000000000000000000..1372237fe17544e051ddccfb94d086c25cd20dda --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/InvalidQueryException.php @@ -0,0 +1,14 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Exception; + +class InvalidQueryException extends UnexpectedValueException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/RuntimeException.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/RuntimeException.php new file mode 100644 index 0000000000000000000000000000000000000000..e1ff785998e3359e04eb2cea800b218c3f853abf --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/RuntimeException.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Exception; + +use Zend\Db\Exception; + +class RuntimeException extends Exception\RuntimeException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/UnexpectedValueException.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/UnexpectedValueException.php new file mode 100644 index 0000000000000000000000000000000000000000..46859f26d2f8e7131606837419a4a6b626eaffc2 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Exception/UnexpectedValueException.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Exception; + +use Zend\Db\Exception; + +class UnexpectedValueException extends Exception\UnexpectedValueException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/ParameterContainer.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/ParameterContainer.php new file mode 100644 index 0000000000000000000000000000000000000000..491b4ad746f9ec459bb243802d6a024744aa0b21 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/ParameterContainer.php @@ -0,0 +1,336 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter; + +use ArrayAccess; +use Countable; +use Iterator; + +class ParameterContainer implements Iterator, ArrayAccess, Countable +{ + + const TYPE_AUTO = 'auto'; + const TYPE_NULL = 'null'; + const TYPE_DOUBLE = 'double'; + const TYPE_INTEGER = 'integer'; + const TYPE_BINARY = 'binary'; + const TYPE_STRING = 'string'; + const TYPE_LOB = 'lob'; + + /** + * Data + * + * @var array + */ + protected $data = array(); + + /** + * @var array + */ + protected $positions = array(); + + /** + * Errata + * + * @var array + */ + protected $errata = array(); + + /** + * Constructor + * + * @param array $data + */ + public function __construct(array $data = array()) + { + if ($data) { + $this->setFromArray($data); + } + } + + /** + * Offset exists + * + * @param string $name + * @return bool + */ + public function offsetExists($name) + { + return (isset($this->data[$name])); + } + + /** + * Offset get + * + * @param string $name + * @return mixed + */ + public function offsetGet($name) + { + return (isset($this->data[$name])) ? $this->data[$name] : null; + } + + /** + * @param $name + * @param $from + */ + public function offsetSetReference($name, $from) + { + $this->data[$name] =& $this->data[$from]; + } + + /** + * Offset set + * + * @param string|int $name + * @param mixed $value + * @param mixed $errata + */ + public function offsetSet($name, $value, $errata = null) + { + $position = false; + + // if integer, get name for this position + if (is_int($name)) { + if (isset($this->positions[$name])) { + $position = $name; + $name = $this->positions[$name]; + } else { + $name = (string) $name; + } + } elseif (is_string($name)) { + // is a string: + $currentNames = array_keys($this->data); + $position = array_search($name, $currentNames, true); + } elseif ($name === null) { + $name = (string) count($this->data); + } else { + throw new Exception\InvalidArgumentException('Keys must be string, integer or null'); + } + + if ($position === false) { + $this->positions[] = $name; + } + + $this->data[$name] = $value; + + if ($errata) { + $this->offsetSetErrata($name, $errata); + } + } + + /** + * Offset unset + * + * @param string $name + * @return ParameterContainer + */ + public function offsetUnset($name) + { + if (is_int($name) && isset($this->positions[$name])) { + $name = $this->positions[$name]; + } + unset($this->data[$name]); + return $this; + } + + /** + * Set from array + * + * @param array $data + * @return ParameterContainer + */ + public function setFromArray(Array $data) + { + foreach ($data as $n => $v) { + $this->offsetSet($n, $v); + } + return $this; + } + + /** + * Offset set errata + * + * @param string|int $name + * @param mixed $errata + */ + public function offsetSetErrata($name, $errata) + { + if (is_int($name)) { + $name = $this->positions[$name]; + } + $this->errata[$name] = $errata; + } + + /** + * Offset get errata + * + * @param string|int $name + * @throws Exception\InvalidArgumentException + * @return mixed + */ + public function offsetGetErrata($name) + { + if (is_int($name)) { + $name = $this->positions[$name]; + } + if (!array_key_exists($name, $this->data)) { + throw new Exception\InvalidArgumentException('Data does not exist for this name/position'); + } + return $this->errata[$name]; + } + + /** + * Offset has errata + * + * @param string|int $name + * @return bool + */ + public function offsetHasErrata($name) + { + if (is_int($name)) { + $name = $this->positions[$name]; + } + return (isset($this->errata[$name])); + } + + /** + * Offset unset errata + * + * @param string|int $name + * @throws Exception\InvalidArgumentException + */ + public function offsetUnsetErrata($name) + { + if (is_int($name)) { + $name = $this->positions[$name]; + } + if (!array_key_exists($name, $this->errata)) { + throw new Exception\InvalidArgumentException('Data does not exist for this name/position'); + } + $this->errata[$name] = null; + } + + /** + * Get errata iterator + * + * @return \ArrayIterator + */ + public function getErrataIterator() + { + return new \ArrayIterator($this->errata); + } + + /** + * getNamedArray + * + * @return array + */ + public function getNamedArray() + { + return $this->data; + } + + /** + * getNamedArray + * + * @return array + */ + public function getPositionalArray() + { + return array_values($this->data); + } + + /** + * count + * + * @return int + */ + public function count() + { + return count($this->data); + } + + /** + * Current + * + * @return mixed + */ + public function current() + { + return current($this->data); + } + + /** + * Next + * + * @return mixed + */ + public function next() + { + return next($this->data); + } + + /** + * Key + * + * @return mixed + */ + public function key() + { + return key($this->data); + } + + /** + * Valid + * + * @return bool + */ + public function valid() + { + return (current($this->data) !== false); + } + + /** + * Rewind + */ + public function rewind() + { + reset($this->data); + } + + /** + * @param array|ParameterContainer $parameters + * @throws Exception\InvalidArgumentException + * @return ParameterContainer + */ + public function merge($parameters) + { + if (!is_array($parameters) && !$parameters instanceof ParameterContainer) { + throw new Exception\InvalidArgumentException('$parameters must be an array or an instance of ParameterContainer'); + } + + if (count($parameters) == 0) { + return $this; + } + + if ($parameters instanceof ParameterContainer) { + $parameters = $parameters->getNamedArray(); + } + + foreach ($parameters as $key => $value) { + if (is_int($key)) { + $key = null; + } + $this->offsetSet($key, $value); + } + return $this; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/IbmDb2.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/IbmDb2.php new file mode 100644 index 0000000000000000000000000000000000000000..a888cb6d26a82135d6bba4fe65d6b2357431dc3d --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/IbmDb2.php @@ -0,0 +1,209 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Platform; + +class IbmDb2 implements PlatformInterface +{ + + protected $quoteValueAllowed = false; + + /** + * @var bool + */ + protected $quoteIdentifiers = true; + + /** + * @var string + */ + protected $identifierSeparator = '.'; + + /** + * @param array $options + */ + public function __construct($options = array()) + { + if (isset($options['quote_identifiers']) + && ($options['quote_identifiers'] == false + || $options['quote_identifiers'] === 'false') + ) { + $this->quoteIdentifiers = false; + } + + if (isset($options['identifier_separator'])) { + $this->identifierSeparator = $options['identifier_separator']; + } + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return 'IBM DB2'; + } + + /** + * Get quote indentifier symbol + * + * @return string + */ + public function getQuoteIdentifierSymbol() + { + return '"'; + } + + /** + * Quote identifier + * + * @param string $identifier + * @return string + */ + public function quoteIdentifier($identifier) + { + if ($this->quoteIdentifiers === false) { + return $identifier; + } + return '"' . str_replace('"', '\\' . '"', $identifier) . '"'; + } + + /** + * Quote identifier chain + * + * @param string|string[] $identifierChain + * @return string + */ + public function quoteIdentifierChain($identifierChain) + { + if ($this->quoteIdentifiers === false) { + return (is_array($identifierChain)) ? implode($this->identifierSeparator, $identifierChain) : $identifierChain; + } + $identifierChain = str_replace('"', '\\"', $identifierChain); + if (is_array($identifierChain)) { + $identifierChain = implode('"' . $this->identifierSeparator . '"', $identifierChain); + } + return '"' . $identifierChain . '"'; + } + + /** + * Get quote value symbol + * + * @return string + */ + public function getQuoteValueSymbol() + { + return '\''; + } + + /** + * Quote value + * + * @param string $value + * @return string + */ + public function quoteValue($value) + { + if (function_exists('db2_escape_string')) { + return '\'' . db2_escape_string($value) . '\''; + } + trigger_error( + 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' + . 'can introduce security vulnerabilities in a production environment.' + ); + return '\'' . str_replace("'", "''", $value) . '\''; + } + + /** + * Quote Trusted Value + * + * The ability to quote values without notices + * + * @param $value + * @return mixed + */ + public function quoteTrustedValue($value) + { + if (function_exists('db2_escape_string')) { + return '\'' . db2_escape_string($value) . '\''; + } + return '\'' . str_replace("'", "''", $value) . '\''; + } + + /** + * Quote value list + * + * @param string|string[] $valueList + * @return string + */ + public function quoteValueList($valueList) + { + if (!is_array($valueList)) { + return $this->quoteValue($valueList); + } + + $value = reset($valueList); + do { + $valueList[key($valueList)] = $this->quoteValue($value); + } while ($value = next($valueList)); + return implode(', ', $valueList); + } + + /** + * Get identifier separator + * + * @return string + */ + public function getIdentifierSeparator() + { + return $this->identifierSeparator; + } + + /** + * Quote identifier in fragment + * + * @param string $identifier + * @param array $safeWords + * @return string + */ + public function quoteIdentifierInFragment($identifier, array $safeWords = array()) + { + if ($this->quoteIdentifiers === false) { + return $identifier; + } + $parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + + if ($safeWords) { + $safeWords = array_flip($safeWords); + $safeWords = array_change_key_case($safeWords, CASE_LOWER); + } + foreach ($parts as $i => $part) { + if ($safeWords && isset($safeWords[strtolower($part)])) { + continue; + } + + switch ($part) { + case ' ': + case '.': + case '*': + case 'AS': + case 'As': + case 'aS': + case 'as': + break; + default: + $parts[$i] = '"' . str_replace('"', '\\' . '"', $part) . '"'; + } + } + + return implode('', $parts); + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Mysql.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Mysql.php new file mode 100644 index 0000000000000000000000000000000000000000..6e02f083abc84217e307980ccb21b6c7eeea9c19 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Mysql.php @@ -0,0 +1,214 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Platform; + +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\Driver\Mysqli; +use Zend\Db\Adapter\Driver\Pdo; +use Zend\Db\Adapter\Exception; + +class Mysql implements PlatformInterface +{ + /** @var \mysqli|\PDO */ + protected $resource = null; + + public function __construct($driver = null) + { + if ($driver) { + $this->setDriver($driver); + } + } + + /** + * @param \Zend\Db\Adapter\Driver\Mysqli\Mysqli|\Zend\Db\Adapter\Driver\Pdo\Pdo||\mysqli|\PDO $driver + * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException + * @return $this + */ + public function setDriver($driver) + { + // handle Zend\Db drivers + if ($driver instanceof Mysqli\Mysqli + || ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Mysql') + || ($driver instanceof \mysqli) + || ($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'mysql') + ) { + $this->resource = $driver; + return $this; + } + + throw new Exception\InvalidArgumentException('$driver must be a Mysqli or Mysql PDO Zend\Db\Adapter\Driver, Mysqli instance or MySQL PDO instance'); + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return 'MySQL'; + } + + /** + * Get quote identifier symbol + * + * @return string + */ + public function getQuoteIdentifierSymbol() + { + return '`'; + } + + /** + * Quote identifier + * + * @param string $identifier + * @return string + */ + public function quoteIdentifier($identifier) + { + return '`' . str_replace('`', '``', $identifier) . '`'; + } + + /** + * Quote identifier chain + * + * @param string|string[] $identifierChain + * @return string + */ + public function quoteIdentifierChain($identifierChain) + { + $identifierChain = str_replace('`', '``', $identifierChain); + if (is_array($identifierChain)) { + $identifierChain = implode('`.`', $identifierChain); + } + return '`' . $identifierChain . '`'; + } + + /** + * Get quote value symbol + * + * @return string + */ + public function getQuoteValueSymbol() + { + return '\''; + } + + /** + * Quote value + * + * @param string $value + * @return string + */ + public function quoteValue($value) + { + if ($this->resource instanceof DriverInterface) { + $this->resource = $this->resource->getConnection()->getResource(); + } + if ($this->resource instanceof \mysqli) { + return '\'' . $this->resource->real_escape_string($value) . '\''; + } + if ($this->resource instanceof \PDO) { + return $this->resource->quote($value); + } + trigger_error( + 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' + . 'can introduce security vulnerabilities in a production environment.' + ); + return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; + } + + /** + * Quote Trusted Value + * + * The ability to quote values without notices + * + * @param $value + * @return mixed + */ + public function quoteTrustedValue($value) + { + if ($this->resource instanceof DriverInterface) { + $this->resource = $this->resource->getConnection()->getResource(); + } + if ($this->resource instanceof \mysqli) { + return '\'' . $this->resource->real_escape_string($value) . '\''; + } + if ($this->resource instanceof \PDO) { + return $this->resource->quote($value); + } + return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; + } + + /** + * Quote value list + * + * @param string|string[] $valueList + * @return string + */ + public function quoteValueList($valueList) + { + if (!is_array($valueList)) { + return $this->quoteValue($valueList); + } + + $value = reset($valueList); + do { + $valueList[key($valueList)] = $this->quoteValue($value); + } while ($value = next($valueList)); + return implode(', ', $valueList); + } + + /** + * Get identifier separator + * + * @return string + */ + public function getIdentifierSeparator() + { + return '.'; + } + + /** + * Quote identifier in fragment + * + * @param string $identifier + * @param array $safeWords + * @return string + */ + public function quoteIdentifierInFragment($identifier, array $safeWords = array()) + { + // regex taken from @link http://dev.mysql.com/doc/refman/5.0/en/identifiers.html + $parts = preg_split('#([^0-9,a-z,A-Z$_])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + if ($safeWords) { + $safeWords = array_flip($safeWords); + $safeWords = array_change_key_case($safeWords, CASE_LOWER); + } + foreach ($parts as $i => $part) { + if ($safeWords && isset($safeWords[strtolower($part)])) { + continue; + } + switch ($part) { + case ' ': + case '.': + case '*': + case 'AS': + case 'As': + case 'aS': + case 'as': + break; + default: + $parts[$i] = '`' . str_replace('`', '``', $part) . '`'; + } + } + return implode('', $parts); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Oracle.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Oracle.php new file mode 100644 index 0000000000000000000000000000000000000000..828a2d645024cdd151944026324fc6fba099f742 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Oracle.php @@ -0,0 +1,189 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Platform; + +class Oracle implements PlatformInterface +{ + + /** + * @var bool + */ + protected $quoteIdentifiers = true; + + /** + * @param array $options + */ + public function __construct($options = array()) + { + if (isset($options['quote_identifiers']) + && ($options['quote_identifiers'] == false + || $options['quote_identifiers'] === 'false') + ) { + $this->quoteIdentifiers = false; + } + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return 'Oracle'; + } + + /** + * Get quote identifier symbol + * + * @return string + */ + public function getQuoteIdentifierSymbol() + { + return '"'; + } + + /** + * Quote identifier + * + * @param string $identifier + * @return string + */ + public function quoteIdentifier($identifier) + { + if ($this->quoteIdentifiers === false) { + return $identifier; + } + return '"' . str_replace('"', '\\' . '"', $identifier) . '"'; + } + + /** + * Quote identifier chain + * + * @param string|string[] $identifierChain + * @return string + */ + public function quoteIdentifierChain($identifierChain) + { + if ($this->quoteIdentifiers === false) { + return (is_array($identifierChain)) ? implode('.', $identifierChain) : $identifierChain; + } + $identifierChain = str_replace('"', '\\"', $identifierChain); + if (is_array($identifierChain)) { + $identifierChain = implode('"."', $identifierChain); + } + return '"' . $identifierChain . '"'; + } + + /** + * Get quote value symbol + * + * @return string + */ + public function getQuoteValueSymbol() + { + return '\''; + } + + /** + * Quote value + * + * @param string $value + * @return string + */ + public function quoteValue($value) + { + trigger_error( + 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' + . 'can introduce security vulnerabilities in a production environment.' + ); + return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; + } + + /** + * Quote Trusted Value + * + * The ability to quote values without notices + * + * @param $value + * @return mixed + */ + public function quoteTrustedValue($value) + { + return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; + } + + /** + * Quote value list + * + * @param string|string[] $valueList + * @return string + */ + public function quoteValueList($valueList) + { + if (!is_array($valueList)) { + return $this->quoteValue($valueList); + } + + $value = reset($valueList); + do { + $valueList[key($valueList)] = $this->quoteValue($value); + } while ($value = next($valueList)); + return implode(', ', $valueList); + } + + /** + * Get identifier separator + * + * @return string + */ + public function getIdentifierSeparator() + { + return '.'; + } + + /** + * Quote identifier in fragment + * + * @param string $identifier + * @param array $safeWords + * @return string + */ + public function quoteIdentifierInFragment($identifier, array $safeWords = array()) + { + if ($this->quoteIdentifiers === false) { + return $identifier; + } + $parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + if ($safeWords) { + $safeWords = array_flip($safeWords); + $safeWords = array_change_key_case($safeWords, CASE_LOWER); + } + foreach ($parts as $i => $part) { + if ($safeWords && isset($safeWords[strtolower($part)])) { + continue; + } + switch ($part) { + case ' ': + case '.': + case '*': + case 'AS': + case 'As': + case 'aS': + case 'as': + break; + default: + $parts[$i] = '"' . str_replace('"', '\\' . '"', $part) . '"'; + } + } + return implode('', $parts); + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/PlatformInterface.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/PlatformInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..d8ec05b2be037519db65e494841abec472cb2e30 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/PlatformInterface.php @@ -0,0 +1,94 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Platform; + +interface PlatformInterface +{ + /** + * Get name + * + * @return string + */ + public function getName(); + + /** + * Get quote identifier symbol + * + * @return string + */ + public function getQuoteIdentifierSymbol(); + + /** + * Quote identifier + * + * @param string $identifier + * @return string + */ + public function quoteIdentifier($identifier); + + /** + * Quote identifier chain + * + * @param string|string[] $identifierChain + * @return string + */ + public function quoteIdentifierChain($identifierChain); + + /** + * Get quote value symbol + * + * @return string + */ + public function getQuoteValueSymbol(); + + /** + * Quote value + * + * Will throw a notice when used in a workflow that can be considered "unsafe" + * + * @param string $value + * @return string + */ + public function quoteValue($value); + + /** + * Quote Trusted Value + * + * The ability to quote values without notices + * + * @param $value + * @return mixed + */ + public function quoteTrustedValue($value); + + /** + * Quote value list + * + * @param string|string[] $valueList + * @return string + */ + public function quoteValueList($valueList); + + /** + * Get identifier separator + * + * @return string + */ + public function getIdentifierSeparator(); + + /** + * Quote identifier in fragment + * + * @param string $identifier + * @param array $additionalSafeWords + * @return string + */ + public function quoteIdentifierInFragment($identifier, array $additionalSafeWords = array()); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Postgresql.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Postgresql.php new file mode 100644 index 0000000000000000000000000000000000000000..e4d1ce59c873e404640cbb48886b8951d1c4cea2 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Postgresql.php @@ -0,0 +1,213 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Platform; + +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\Driver\Pdo; +use Zend\Db\Adapter\Driver\Pgsql; +use Zend\Db\Adapter\Exception; + +class Postgresql implements PlatformInterface +{ + /** @var resource|\PDO */ + protected $resource = null; + + public function __construct($driver = null) + { + if ($driver) { + $this->setDriver($driver); + } + } + + /** + * @param \Zend\Db\Adapter\Driver\Pgsql\Pgsql|\Zend\Db\Adapter\Driver\Pdo\Pdo|resource|\PDO $driver + * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException + * @return $this + */ + public function setDriver($driver) + { + if ($driver instanceof Pgsql\Pgsql + || ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Postgresql') + || (is_resource($driver) && (in_array(get_resource_type($driver), array('pgsql link', 'pgsql link persistent')))) + || ($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'pgsql') + ) { + $this->resource = $driver; + return $this; + } + + throw new Exception\InvalidArgumentException('$driver must be a Pgsql or Postgresql PDO Zend\Db\Adapter\Driver, pgsql link resource or Postgresql PDO instance'); + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return 'PostgreSQL'; + } + + /** + * Get quote indentifier symbol + * + * @return string + */ + public function getQuoteIdentifierSymbol() + { + return '"'; + } + + /** + * Quote identifier + * + * @param string $identifier + * @return string + */ + public function quoteIdentifier($identifier) + { + return '"' . str_replace('"', '\\' . '"', $identifier) . '"'; + } + + /** + * Quote identifier chain + * + * @param string|string[] $identifierChain + * @return string + */ + public function quoteIdentifierChain($identifierChain) + { + $identifierChain = str_replace('"', '\\"', $identifierChain); + if (is_array($identifierChain)) { + $identifierChain = implode('"."', $identifierChain); + } + return '"' . $identifierChain . '"'; + } + + /** + * Get quote value symbol + * + * @return string + */ + public function getQuoteValueSymbol() + { + return '\''; + } + + /** + * Quote value + * + * @param string $value + * @return string + */ + public function quoteValue($value) + { + if ($this->resource instanceof DriverInterface) { + $this->resource = $this->resource->getConnection()->getResource(); + } + if (is_resource($this->resource)) { + return '\'' . pg_escape_string($this->resource, $value) . '\''; + } + if ($this->resource instanceof \PDO) { + return $this->resource->quote($value); + } + trigger_error( + 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' + . 'can introduce security vulnerabilities in a production environment.' + ); + return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; + } + + /** + * Quote Trusted Value + * + * The ability to quote values without notices + * + * @param $value + * @return mixed + */ + public function quoteTrustedValue($value) + { + if ($this->resource instanceof DriverInterface) { + $this->resource = $this->resource->getConnection()->getResource(); + } + if (is_resource($this->resource)) { + return '\'' . pg_escape_string($this->resource, $value) . '\''; + } + if ($this->resource instanceof \PDO) { + return $this->resource->quote($value); + } + return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; + } + + /** + * Quote value list + * + * @param string|string[] $valueList + * @return string + */ + public function quoteValueList($valueList) + { + if (!is_array($valueList)) { + return $this->quoteValue($valueList); + } + + $value = reset($valueList); + do { + $valueList[key($valueList)] = $this->quoteValue($value); + } while ($value = next($valueList)); + return implode(', ', $valueList); + } + + /** + * Get identifier separator + * + * @return string + */ + public function getIdentifierSeparator() + { + return '.'; + } + + /** + * Quote identifier in fragment + * + * @param string $identifier + * @param array $safeWords + * @return string + */ + public function quoteIdentifierInFragment($identifier, array $safeWords = array()) + { + $parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + if ($safeWords) { + $safeWords = array_flip($safeWords); + $safeWords = array_change_key_case($safeWords, CASE_LOWER); + } + foreach ($parts as $i => $part) { + if ($safeWords && isset($safeWords[strtolower($part)])) { + continue; + } + switch ($part) { + case ' ': + case '.': + case '*': + case 'AS': + case 'As': + case 'aS': + case 'as': + break; + default: + $parts[$i] = '"' . str_replace('"', '\\' . '"', $part) . '"'; + } + } + return implode('', $parts); + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Sql92.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Sql92.php new file mode 100644 index 0000000000000000000000000000000000000000..e1e95ded5ba161bc8c6a8e61d6fb0d858b69cf45 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Sql92.php @@ -0,0 +1,162 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Platform; + +class Sql92 implements PlatformInterface +{ + /** + * Get name + * + * @return string + */ + public function getName() + { + return 'SQL92'; + } + + /** + * Get quote indentifier symbol + * + * @return string + */ + public function getQuoteIdentifierSymbol() + { + return '"'; + } + + /** + * Quote identifier + * + * @param string $identifier + * @return string + */ + public function quoteIdentifier($identifier) + { + return '"' . str_replace('"', '\\' . '"', $identifier) . '"'; + } + + /** + * Quote identifier chain + * + * @param string|string[] $identifierChain + * @return string + */ + public function quoteIdentifierChain($identifierChain) + { + $identifierChain = str_replace('"', '\\"', $identifierChain); + if (is_array($identifierChain)) { + $identifierChain = implode('"."', $identifierChain); + } + return '"' . $identifierChain . '"'; + } + + /** + * Get quote value symbol + * + * @return string + */ + public function getQuoteValueSymbol() + { + return '\''; + } + + /** + * Quote value + * + * @param string $value + * @return string + */ + public function quoteValue($value) + { + trigger_error( + 'Attempting to quote a value without specific driver level support can introduce security vulnerabilities in a production environment.' + ); + return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; + } + + /** + * Quote Trusted Value + * + * The ability to quote values without notices + * + * @param $value + * @return mixed + */ + public function quoteTrustedValue($value) + { + return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; + } + + /** + * Quote value list + * + * @param string|string[] $valueList + * @return string + */ + public function quoteValueList($valueList) + { + if (!is_array($valueList)) { + return $this->quoteValue($valueList); + } + + $value = reset($valueList); + do { + $valueList[key($valueList)] = $this->quoteValue($value); + } while ($value = next($valueList)); + return implode(', ', $valueList); + } + + /** + * Get identifier separator + * + * @return string + */ + public function getIdentifierSeparator() + { + return '.'; + } + + /** + * Quote identifier in fragment + * + * @param string $identifier + * @param array $safeWords + * @return string + */ + public function quoteIdentifierInFragment($identifier, array $safeWords = array()) + { + $parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + if ($safeWords) { + $safeWords = array_flip($safeWords); + $safeWords = array_change_key_case($safeWords, CASE_LOWER); + } + foreach ($parts as $i => $part) { + if ($safeWords && isset($safeWords[strtolower($part)])) { + continue; + } + + switch ($part) { + case ' ': + case '.': + case '*': + case 'AS': + case 'As': + case 'aS': + case 'as': + break; + default: + $parts[$i] = '"' . str_replace('"', '\\' . '"', $part) . '"'; + } + } + + return implode('', $parts); + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/SqlServer.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/SqlServer.php new file mode 100644 index 0000000000000000000000000000000000000000..4abbd40362b9476ed8d48e3d92aab287e8b5d14f --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/SqlServer.php @@ -0,0 +1,204 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Platform; + +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\Driver\Pdo; +use Zend\Db\Adapter\Exception; + +class SqlServer implements PlatformInterface +{ + + /** @var resource|\PDO */ + protected $resource = null; + + public function __construct($driver = null) + { + if ($driver) { + $this->setDriver($driver); + } + } + + /** + * @param \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv|\Zend\Db\Adapter\Driver\Pdo\Pdo||resource|\PDO $driver + * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException + * @return $this + */ + public function setDriver($driver) + { + // handle Zend\Db drivers + if (($driver instanceof Pdo\Pdo && in_array($driver->getDatabasePlatformName(), array('SqlServer', 'Dblib'))) + || (($driver instanceof \PDO && in_array($driver->getAttribute(\PDO::ATTR_DRIVER_NAME), array('sqlsrv', 'dblib')))) + ) { + $this->resource = $driver; + return $this; + } + + throw new Exception\InvalidArgumentException('$driver must be a Sqlsrv PDO Zend\Db\Adapter\Driver or Sqlsrv PDO instance'); + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return 'SQLServer'; + } + + /** + * Get quote identifier symbol + * + * @return string + */ + public function getQuoteIdentifierSymbol() + { + return array('[', ']'); + } + + /** + * Quote identifier + * + * @param string $identifier + * @return string + */ + public function quoteIdentifier($identifier) + { + return '[' . $identifier . ']'; + } + + /** + * Quote identifier chain + * + * @param string|string[] $identifierChain + * @return string + */ + public function quoteIdentifierChain($identifierChain) + { + if (is_array($identifierChain)) { + $identifierChain = implode('].[', $identifierChain); + } + return '[' . $identifierChain . ']'; + } + + /** + * Get quote value symbol + * + * @return string + */ + public function getQuoteValueSymbol() + { + return '\''; + } + + /** + * Quote value + * + * @param string $value + * @return string + */ + public function quoteValue($value) + { + if ($this->resource instanceof DriverInterface) { + $this->resource = $this->resource->getConnection()->getResource(); + } + if ($this->resource instanceof \PDO) { + return $this->resource->quote($value); + } + trigger_error( + 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' + . 'can introduce security vulnerabilities in a production environment.' + ); + return '\'' . str_replace('\'', '\'\'', $value) . '\''; + } + + /** + * Quote Trusted Value + * + * The ability to quote values without notices + * + * @param $value + * @return mixed + */ + public function quoteTrustedValue($value) + { + if ($this->resource instanceof DriverInterface) { + $this->resource = $this->resource->getConnection()->getResource(); + } + if ($this->resource instanceof \PDO) { + return $this->resource->quote($value); + } + return '\'' . str_replace('\'', '\'\'', $value) . '\''; + } + + /** + * Quote value list + * + * @param string|string[] $valueList + * @return string + */ + public function quoteValueList($valueList) + { + if (!is_array($valueList)) { + return $this->quoteValue($valueList); + } + $value = reset($valueList); + do { + $valueList[key($valueList)] = $this->quoteValue($value); + } while ($value = next($valueList)); + return implode(', ', $valueList); + } + + /** + * Get identifier separator + * + * @return string + */ + public function getIdentifierSeparator() + { + return '.'; + } + + /** + * Quote identifier in fragment + * + * @param string $identifier + * @param array $safeWords + * @return string + */ + public function quoteIdentifierInFragment($identifier, array $safeWords = array()) + { + $parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + if ($safeWords) { + $safeWords = array_flip($safeWords); + $safeWords = array_change_key_case($safeWords, CASE_LOWER); + } + foreach ($parts as $i => $part) { + if ($safeWords && isset($safeWords[strtolower($part)])) { + continue; + } + switch ($part) { + case ' ': + case '.': + case '*': + case 'AS': + case 'As': + case 'aS': + case 'as': + break; + default: + $parts[$i] = '[' . $part . ']'; + } + } + return implode('', $parts); + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Sqlite.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Sqlite.php new file mode 100644 index 0000000000000000000000000000000000000000..4b1877100baa177d7aefa5dd2044351dd4932161 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Platform/Sqlite.php @@ -0,0 +1,212 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Platform; + +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\Driver\Pdo; +use Zend\Db\Adapter\Exception; + +class Sqlite implements PlatformInterface +{ + + /** @var \PDO */ + protected $resource = null; + + public function __construct($driver = null) + { + if ($driver) { + $this->setDriver($driver); + } + } + + /** + * @param \Zend\Db\Adapter\Driver\Pdo\Pdo||\PDO $driver + * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException + * @return $this + */ + public function setDriver($driver) + { + if (($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'sqlite') + || ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Sqlite') + ) { + $this->resource = $driver; + return $this; + } + + throw new Exception\InvalidArgumentException('$driver must be a Sqlite PDO Zend\Db\Adapter\Driver, Sqlite PDO instance'); + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return 'SQLite'; + } + + /** + * Get quote identifier symbol + * + * @return string + */ + public function getQuoteIdentifierSymbol() + { + return '"'; + } + + /** + * Quote identifier + * + * @param string $identifier + * @return string + */ + public function quoteIdentifier($identifier) + { + return '"' . str_replace('"', '\\' . '"', $identifier) . '"'; + } + + /** + * Quote identifier chain + * + * @param string|string[] $identifierChain + * @return string + */ + public function quoteIdentifierChain($identifierChain) + { + $identifierChain = str_replace('"', '\\"', $identifierChain); + if (is_array($identifierChain)) { + $identifierChain = implode('"."', $identifierChain); + } + return '"' . $identifierChain . '"'; + } + + /** + * Get quote value symbol + * + * @return string + */ + public function getQuoteValueSymbol() + { + return '\''; + } + + /** + * Quote value + * + * @param string $value + * @return string + */ + public function quoteValue($value) + { + $resource = $this->resource; + + if ($resource instanceof DriverInterface) { + $resource = $resource->getConnection()->getResource(); + } + + if ($resource instanceof \PDO) { + return $resource->quote($value); + } + + trigger_error( + 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support ' + . 'can introduce security vulnerabilities in a production environment.' + ); + return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; + } + + /** + * Quote Trusted Value + * + * The ability to quote values without notices + * + * @param $value + * @return mixed + */ + public function quoteTrustedValue($value) + { + $resource = $this->resource; + + if ($resource instanceof DriverInterface) { + $resource = $resource->getConnection()->getResource(); + } + + if ($resource instanceof \PDO) { + return $resource->quote($value); + } + + return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\''; + } + + /** + * Quote value list + * + * @param string|string[] $valueList + * @return string + */ + public function quoteValueList($valueList) + { + if (!is_array($valueList)) { + return $this->quoteValue($valueList); + } + $value = reset($valueList); + do { + $valueList[key($valueList)] = $this->quoteValue($value); + } while ($value = next($valueList)); + return implode(', ', $valueList); + } + + /** + * Get identifier separator + * + * @return string + */ + public function getIdentifierSeparator() + { + return '.'; + } + + /** + * Quote identifier in fragment + * + * @param string $identifier + * @param array $safeWords + * @return string + */ + public function quoteIdentifierInFragment($identifier, array $safeWords = array()) + { + $parts = preg_split('#([\.\s\W])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + if ($safeWords) { + $safeWords = array_flip($safeWords); + $safeWords = array_change_key_case($safeWords, CASE_LOWER); + } + foreach ($parts as $i => $part) { + if ($safeWords && isset($safeWords[strtolower($part)])) { + continue; + } + switch ($part) { + case ' ': + case '.': + case '*': + case 'AS': + case 'As': + case 'aS': + case 'as': + break; + default: + $parts[$i] = '"' . str_replace('"', '\\' . '"', $part) . '"'; + } + } + return implode('', $parts); + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Profiler/Profiler.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Profiler/Profiler.php new file mode 100644 index 0000000000000000000000000000000000000000..5115e3f3f16965a4a38d226d5a51fce214ea03f7 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Profiler/Profiler.php @@ -0,0 +1,85 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Profiler; + +use Zend\Db\Adapter\StatementContainerInterface; +use Zend\Db\Adapter\Exception; + +class Profiler implements ProfilerInterface +{ + /** + * @var array + */ + protected $profiles = array(); + + /** + * @var null + */ + protected $currentIndex = 0; + + /** + * @param string|StatementContainerInterface $target + * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException + * @return Profiler + */ + public function profilerStart($target) + { + $profileInformation = array( + 'sql' => '', + 'parameters' => null, + 'start' => microtime(true), + 'end' => null, + 'elapse' => null + ); + if ($target instanceof StatementContainerInterface) { + $profileInformation['sql'] = $target->getSql(); + $profileInformation['parameters'] = clone $target->getParameterContainer(); + } elseif (is_string($target)) { + $profileInformation['sql'] = $target; + } else { + throw new Exception\InvalidArgumentException(__FUNCTION__ . ' takes either a StatementContainer or a string'); + } + + $this->profiles[$this->currentIndex] = $profileInformation; + + return $this; + } + + /** + * @return Profiler + */ + public function profilerFinish() + { + if (!isset($this->profiles[$this->currentIndex])) { + throw new Exception\RuntimeException('A profile must be started before ' . __FUNCTION__ . ' can be called.'); + } + $current = &$this->profiles[$this->currentIndex]; + $current['end'] = microtime(true); + $current['elapse'] = $current['end'] - $current['start']; + $this->currentIndex++; + return $this; + } + + /** + * @return array|null + */ + public function getLastProfile() + { + return end($this->profiles); + } + + /** + * @return array + */ + public function getProfiles() + { + return $this->profiles; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Profiler/ProfilerAwareInterface.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Profiler/ProfilerAwareInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..a0b631d94b607613ae38f8c15de6fefb483617b5 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Profiler/ProfilerAwareInterface.php @@ -0,0 +1,15 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Profiler; + +interface ProfilerAwareInterface +{ + public function setProfiler(ProfilerInterface $profiler); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/Profiler/ProfilerInterface.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/Profiler/ProfilerInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..5f8ee90e21fbaf0ef25370ed19b5f5c6ed5bd348 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/Profiler/ProfilerInterface.php @@ -0,0 +1,20 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter\Profiler; + +interface ProfilerInterface +{ + /** + * @param string|\Zend\Db\Adapter\StatementContainerInterface $target + * @return mixed + */ + public function profilerStart($target); + public function profilerFinish(); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/StatementContainer.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/StatementContainer.php new file mode 100644 index 0000000000000000000000000000000000000000..e1f033b07ec1ba08a1490556b4b685e4ce52234d --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/StatementContainer.php @@ -0,0 +1,72 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter; + +class StatementContainer implements StatementContainerInterface +{ + + /** + * @var string + */ + protected $sql = ''; + + /** + * @var ParameterContainer + */ + protected $parameterContainer = null; + + /** + * @param string|null $sql + * @param ParameterContainer|null $parameterContainer + */ + public function __construct($sql = null, ParameterContainer $parameterContainer = null) + { + if ($sql) { + $this->setSql($sql); + } + $this->parameterContainer = ($parameterContainer) ?: new ParameterContainer; + } + + /** + * @param $sql + * @return StatementContainer + */ + public function setSql($sql) + { + $this->sql = $sql; + return $this; + } + + /** + * @return string + */ + public function getSql() + { + return $this->sql; + } + + /** + * @param ParameterContainer $parameterContainer + * @return StatementContainer + */ + public function setParameterContainer(ParameterContainer $parameterContainer) + { + $this->parameterContainer = $parameterContainer; + return $this; + } + + /** + * @return null|ParameterContainer + */ + public function getParameterContainer() + { + return $this->parameterContainer; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Adapter/StatementContainerInterface.php b/vendor/zendframework/zend-db/Zend/Db/Adapter/StatementContainerInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..098d6a6fdec7bc14302d16cd42d2b7325a50eb58 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Adapter/StatementContainerInterface.php @@ -0,0 +1,43 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Adapter; + +interface StatementContainerInterface +{ + /** + * Set sql + * + * @param $sql + * @return mixed + */ + public function setSql($sql); + + /** + * Get sql + * + * @return mixed + */ + public function getSql(); + + /** + * Set parameter container + * + * @param ParameterContainer $parameterContainer + * @return mixed + */ + public function setParameterContainer(ParameterContainer $parameterContainer); + + /** + * Get parameter container + * + * @return mixed + */ + public function getParameterContainer(); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Exception/ErrorException.php b/vendor/zendframework/zend-db/Zend/Db/Exception/ErrorException.php new file mode 100644 index 0000000000000000000000000000000000000000..f6915a8c2b9c17458967a52c9aa762dd5d2a2c72 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Exception/ErrorException.php @@ -0,0 +1,14 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Exception; + +class ErrorException extends \Exception implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Exception/ExceptionInterface.php b/vendor/zendframework/zend-db/Zend/Db/Exception/ExceptionInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..9f480dd4e98f479e9c2ded28798dd463ccb12b43 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Exception/ExceptionInterface.php @@ -0,0 +1,14 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Exception; + +interface ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Exception/InvalidArgumentException.php b/vendor/zendframework/zend-db/Zend/Db/Exception/InvalidArgumentException.php new file mode 100644 index 0000000000000000000000000000000000000000..efeba3a770f0860bb4d8e987f41cab0c18bae03c --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Exception/InvalidArgumentException.php @@ -0,0 +1,14 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Exception; + +class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Exception/RuntimeException.php b/vendor/zendframework/zend-db/Zend/Db/Exception/RuntimeException.php new file mode 100644 index 0000000000000000000000000000000000000000..57ed5847699988c9002ddfc53e6e7c31b7c61806 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Exception/RuntimeException.php @@ -0,0 +1,14 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Exception; + +class RuntimeException extends \RuntimeException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Exception/UnexpectedValueException.php b/vendor/zendframework/zend-db/Zend/Db/Exception/UnexpectedValueException.php new file mode 100644 index 0000000000000000000000000000000000000000..9671d8a46635b0875b6af21fef67b8898af779c6 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Exception/UnexpectedValueException.php @@ -0,0 +1,14 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Exception; + +class UnexpectedValueException extends \UnexpectedValueException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/Metadata.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/Metadata.php new file mode 100644 index 0000000000000000000000000000000000000000..1d7053ddd0878622d9cca429363a1b589ac11eb0 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/Metadata.php @@ -0,0 +1,251 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata; + +use Zend\Db\Adapter\Adapter; + +class Metadata implements MetadataInterface +{ + /** + * Adapter + * + * @var Adapter + */ + protected $adapter = null; + + /** + * @var MetadataInterface + */ + protected $source = null; + + /** + * Constructor + * + * @param Adapter $adapter + */ + public function __construct(Adapter $adapter) + { + $this->adapter = $adapter; + $this->source = $this->createSourceFromAdapter($adapter); + } + + /** + * Create source from adapter + * + * @param Adapter $adapter + * @return Source\AbstractSource + */ + protected function createSourceFromAdapter(Adapter $adapter) + { + switch ($adapter->getPlatform()->getName()) { + case 'MySQL': + return new Source\MysqlMetadata($adapter); + case 'SQLServer': + return new Source\SqlServerMetadata($adapter); + case 'SQLite': + return new Source\SqliteMetadata($adapter); + case 'PostgreSQL': + return new Source\PostgresqlMetadata($adapter); + case 'Oracle': + return new Source\OracleMetadata($adapter); + } + + throw new \Exception('cannot create source from adapter'); + } + + // @todo methods + + /** + * Get base tables and views + * + * @param string $schema + * @param bool $includeViews + * @return Object\TableObject[] + */ + public function getTables($schema = null, $includeViews = false) + { + return $this->source->getTables($schema, $includeViews); + } + + /** + * Get base tables and views + * + * @param string $schema + * @return Object\TableObject[] + */ + public function getViews($schema = null) + { + return $this->source->getViews($schema); + } + + /** + * Get triggers + * + * @param string $schema + * @return array + */ + public function getTriggers($schema = null) + { + return $this->source->getTriggers($schema); + } + + /** + * Get constraints + * + * @param string $table + * @param string $schema + * @return array + */ + public function getConstraints($table, $schema = null) + { + return $this->source->getConstraints($table, $schema); + } + + /** + * Get columns + * + * @param string $table + * @param string $schema + * @return array + */ + public function getColumns($table, $schema = null) + { + return $this->source->getColumns($table, $schema); + } + + /** + * Get constraint keys + * + * @param string $constraint + * @param string $table + * @param string $schema + * @return array + */ + public function getConstraintKeys($constraint, $table, $schema = null) + { + return $this->source->getConstraintKeys($constraint, $table, $schema); + } + + /** + * Get constraints + * + * @param string $constraintName + * @param string $table + * @param string $schema + * @return Object\ConstraintObject + */ + public function getConstraint($constraintName, $table, $schema = null) + { + return $this->source->getConstraint($constraintName, $table, $schema); + } + + /** + * Get schemas + */ + public function getSchemas() + { + return $this->source->getSchemas(); + } + + /** + * Get table names + * + * @param string $schema + * @param bool $includeViews + * @return array + */ + public function getTableNames($schema = null, $includeViews = false) + { + return $this->source->getTableNames($schema, $includeViews); + } + + /** + * Get table + * + * @param string $tableName + * @param string $schema + * @return Object\TableObject + */ + public function getTable($tableName, $schema = null) + { + return $this->source->getTable($tableName, $schema); + } + + /** + * Get views names + * + * @param string $schema + * @return \Zend\Db\Metadata\Object\TableObject + */ + public function getViewNames($schema = null) + { + return $this->source->getTable($schema); + } + + /** + * Get view + * + * @param string $viewName + * @param string $schema + * @return \Zend\Db\Metadata\Object\TableObject + */ + public function getView($viewName, $schema = null) + { + return $this->source->getView($viewName, $schema); + } + + /** + * Get trigger names + * + * @param string $schema + * @return array + */ + public function getTriggerNames($schema = null) + { + return $this->source->getTriggerNames($schema); + } + + /** + * Get trigger + * + * @param string $triggerName + * @param string $schema + * @return \Zend\Db\Metadata\Object\TriggerObject + */ + public function getTrigger($triggerName, $schema = null) + { + return $this->source->getTrigger($triggerName, $schema); + } + + /** + * Get column names + * + * @param string $table + * @param string $schema + * @return array + */ + public function getColumnNames($table, $schema = null) + { + return $this->source->getColumnNames($table, $schema); + } + + /** + * Get column + * + * @param string $columnName + * @param string $table + * @param string $schema + * @return \Zend\Db\Metadata\Object\ColumnObject + */ + public function getColumn($columnName, $table, $schema = null) + { + return $this->source->getColumn($columnName, $table, $schema); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/MetadataInterface.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/MetadataInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..cc82db2fefb1a2931edc471c2ebd2a87a41fc403 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/MetadataInterface.php @@ -0,0 +1,36 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata; + +interface MetadataInterface +{ + public function getSchemas(); + + public function getTableNames($schema = null, $includeViews = false); + public function getTables($schema = null, $includeViews = false); + public function getTable($tableName, $schema = null); + + public function getViewNames($schema = null); + public function getViews($schema = null); + public function getView($viewName, $schema = null); + + public function getColumnNames($table, $schema = null); + public function getColumns($table, $schema = null); + public function getColumn($columnName, $table, $schema = null); + + public function getConstraints($table, $schema = null); + public function getConstraint($constraintName, $table, $schema = null); + public function getConstraintKeys($constraint, $table, $schema = null); + + public function getTriggerNames($schema = null); + public function getTriggers($schema = null); + public function getTrigger($triggerName, $schema = null); + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/AbstractTableObject.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/AbstractTableObject.php new file mode 100644 index 0000000000000000000000000000000000000000..17da65d1eb190ad78673416b3e81feaa014eccec --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/AbstractTableObject.php @@ -0,0 +1,115 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata\Object; + +abstract class AbstractTableObject +{ + + /* + protected $catalogName = null; + protected $schemaName = null; + */ + + /** + * + * @var string + */ + protected $name = null; + + /** + * + * @var string + */ + protected $type = null; + + /** + * + * @var array + */ + protected $columns = null; + + /** + * + * @var array + */ + protected $constraints = null; + + /** + * Constructor + * + * @param string $name + */ + public function __construct($name) + { + if ($name) { + $this->setName($name); + } + } + + /** + * Set columns + * + * @param array $columns + */ + public function setColumns(array $columns) + { + $this->columns = $columns; + } + + /** + * Get columns + * + * @return array + */ + public function getColumns() + { + return $this->columns; + } + + /** + * Set constraints + * + * @param array $constraints + */ + public function setConstraints($constraints) + { + $this->constraints = $constraints; + } + + /** + * Get constraints + * + * @return array + */ + public function getConstraints() + { + return $this->constraints; + } + + /** + * Set name + * + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/ColumnObject.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/ColumnObject.php new file mode 100644 index 0000000000000000000000000000000000000000..34ebb41dba46b0bfadaa842ac512c36b5caad6ec --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/ColumnObject.php @@ -0,0 +1,389 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata\Object; + +class ColumnObject +{ + + /** + * + * @var string + */ + protected $name = null; + + /** + * + * @var string + */ + protected $tableName = null; + + /** + * + * @var string + */ + protected $schemaName = null; + + /** + * + * @var + */ + protected $ordinalPosition = null; + + /** + * + * @var string + */ + protected $columnDefault = null; + + /** + * + * @var bool + */ + protected $isNullable = null; + + /** + * + * @var string + */ + protected $dataType = null; + + /** + * + * @var int + */ + protected $characterMaximumLength = null; + + /** + * + * @var int + */ + protected $characterOctetLength = null; + + /** + * + * @var int + */ + protected $numericPrecision = null; + + /** + * + * @var int + */ + protected $numericScale = null; + + /** + * + * @var bool + */ + protected $numericUnsigned = null; + + /** + * + * @var array + */ + protected $errata = array(); + + /** + * Constructor + * + * @param string $name + * @param string $tableName + * @param string $schemaName + */ + public function __construct($name, $tableName, $schemaName = null) + { + $this->setName($name); + $this->setTableName($tableName); + $this->setSchemaName($schemaName); + } + + /** + * Set name + * + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Get table name + * + * @return string + */ + public function getTableName() + { + return $this->tableName; + } + + /** + * Set table name + * + * @param string $tableName + * @return ColumnObject + */ + public function setTableName($tableName) + { + $this->tableName = $tableName; + return $this; + } + + /** + * Set schema name + * + * @param string $schemaName + */ + public function setSchemaName($schemaName) + { + $this->schemaName = $schemaName; + } + + /** + * Get schema name + * + * @return string + */ + public function getSchemaName() + { + return $this->schemaName; + } + + /** + * @return int $ordinalPosition + */ + public function getOrdinalPosition() + { + return $this->ordinalPosition; + } + + /** + * @param int $ordinalPosition to set + * @return ColumnObject + */ + public function setOrdinalPosition($ordinalPosition) + { + $this->ordinalPosition = $ordinalPosition; + return $this; + } + + /** + * @return null|string the $columnDefault + */ + public function getColumnDefault() + { + return $this->columnDefault; + } + + /** + * @param mixed $columnDefault to set + * @return ColumnObject + */ + public function setColumnDefault($columnDefault) + { + $this->columnDefault = $columnDefault; + return $this; + } + + /** + * @return bool $isNullable + */ + public function getIsNullable() + { + return $this->isNullable; + } + + /** + * @param bool $isNullable to set + * @return ColumnObject + */ + public function setIsNullable($isNullable) + { + $this->isNullable = $isNullable; + return $this; + } + + /** + * @return bool $isNullable + */ + public function isNullable() + { + return $this->isNullable; + } + + /** + * @return null|string the $dataType + */ + public function getDataType() + { + return $this->dataType; + } + + /** + * @param string $dataType the $dataType to set + * @return ColumnObject + */ + public function setDataType($dataType) + { + $this->dataType = $dataType; + return $this; + } + + /** + * @return int|null the $characterMaximumLength + */ + public function getCharacterMaximumLength() + { + return $this->characterMaximumLength; + } + + /** + * @param int $characterMaximumLength the $characterMaximumLength to set + * @return ColumnObject + */ + public function setCharacterMaximumLength($characterMaximumLength) + { + $this->characterMaximumLength = $characterMaximumLength; + return $this; + } + + /** + * @return int|null the $characterOctetLength + */ + public function getCharacterOctetLength() + { + return $this->characterOctetLength; + } + + /** + * @param int $characterOctetLength the $characterOctetLength to set + * @return ColumnObject + */ + public function setCharacterOctetLength($characterOctetLength) + { + $this->characterOctetLength = $characterOctetLength; + return $this; + } + + /** + * @return int the $numericPrecision + */ + public function getNumericPrecision() + { + return $this->numericPrecision; + } + + /** + * @param int $numericPrecision the $numericPrevision to set + * @return ColumnObject + */ + public function setNumericPrecision($numericPrecision) + { + $this->numericPrecision = $numericPrecision; + return $this; + } + + /** + * @return int the $numericScale + */ + public function getNumericScale() + { + return $this->numericScale; + } + + /** + * @param int $numericScale the $numericScale to set + * @return ColumnObject + */ + public function setNumericScale($numericScale) + { + $this->numericScale = $numericScale; + return $this; + } + + /** + * @return bool + */ + public function getNumericUnsigned() + { + return $this->numericUnsigned; + } + + /** + * @param bool $numericUnsigned + * @return ColumnObject + */ + public function setNumericUnsigned($numericUnsigned) + { + $this->numericUnsigned = $numericUnsigned; + return $this; + } + + /** + * @return bool + */ + public function isNumericUnsigned() + { + return $this->numericUnsigned; + } + + /** + * @return array the $errata + */ + public function getErratas() + { + return $this->errata; + } + + /** + * @param array $erratas + * @return ColumnObject + */ + public function setErratas(array $erratas) + { + foreach ($erratas as $name => $value) { + $this->setErrata($name, $value); + } + return $this; + } + + /** + * @param string $errataName + * @return mixed + */ + public function getErrata($errataName) + { + if (array_key_exists($errataName, $this->errata)) { + return $this->errata[$errataName]; + } + return null; + } + + /** + * @param string $errataName + * @param mixed $errataValue + * @return ColumnObject + */ + public function setErrata($errataName, $errataValue) + { + $this->errata[$errataName] = $errataValue; + return $this; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/ConstraintKeyObject.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/ConstraintKeyObject.php new file mode 100644 index 0000000000000000000000000000000000000000..c0a4d26552006a9d66440ee00fca34752838afdc --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/ConstraintKeyObject.php @@ -0,0 +1,250 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata\Object; + +class ConstraintKeyObject +{ + const FK_CASCADE = 'CASCADE'; + const FK_SET_NULL = 'SET NULL'; + const FK_NO_ACTION = 'NO ACTION'; + const FK_RESTRICT = 'RESTRICT'; + const FK_SET_DEFAULT = 'SET DEFAULT'; + + /** + * + * @var string + */ + protected $columnName = null; + + /** + * + * @var int + */ + protected $ordinalPosition = null; + + /** + * + * @var bool + */ + protected $positionInUniqueConstraint = null; + + /** + * + * @var string + */ + protected $referencedTableSchema = null; + + /** + * + * @var string + */ + protected $referencedTableName = null; + + /** + * + * @var string + */ + protected $referencedColumnName = null; + + /** + * + * @var string + */ + protected $foreignKeyUpdateRule = null; + + /** + * + * @var string + */ + protected $foreignKeyDeleteRule = null; + + /** + * Constructor + * + * @param string $column + */ + public function __construct($column) + { + $this->setColumnName($column); + } + + /** + * Get column name + * + * @return string + */ + public function getColumnName() + { + return $this->columnName; + } + + /** + * Set column name + * + * @param string $columnName + * @return ConstraintKeyObject + */ + public function setColumnName($columnName) + { + $this->columnName = $columnName; + return $this; + } + + /** + * Get ordinal position + * + * @return int + */ + public function getOrdinalPosition() + { + return $this->ordinalPosition; + } + + /** + * Set ordinal position + * + * @param int $ordinalPosition + * @return ConstraintKeyObject + */ + public function setOrdinalPosition($ordinalPosition) + { + $this->ordinalPosition = $ordinalPosition; + return $this; + } + + /** + * Get position in unique constraint + * + * @return bool + */ + public function getPositionInUniqueConstraint() + { + return $this->positionInUniqueConstraint; + } + + /** + * Set position in unique constraint + * + * @param bool $positionInUniqueConstraint + * @return ConstraintKeyObject + */ + public function setPositionInUniqueConstraint($positionInUniqueConstraint) + { + $this->positionInUniqueConstraint = $positionInUniqueConstraint; + return $this; + } + + /** + * Get referencred table schema + * + * @return string + */ + public function getReferencedTableSchema() + { + return $this->referencedTableSchema; + } + + /** + * Set referenced table schema + * + * @param string $referencedTableSchema + * @return ConstraintKeyObject + */ + public function setReferencedTableSchema($referencedTableSchema) + { + $this->referencedTableSchema = $referencedTableSchema; + return $this; + } + + /** + * Get referenced table name + * + * @return string + */ + public function getReferencedTableName() + { + return $this->referencedTableName; + } + + /** + * Set Referenced table name + * + * @param string $referencedTableName + * @return ConstraintKeyObject + */ + public function setReferencedTableName($referencedTableName) + { + $this->referencedTableName = $referencedTableName; + return $this; + } + + /** + * Get referenced column name + * + * @return string + */ + public function getReferencedColumnName() + { + return $this->referencedColumnName; + } + + /** + * Set referenced column name + * + * @param string $referencedColumnName + * @return ConstraintKeyObject + */ + public function setReferencedColumnName($referencedColumnName) + { + $this->referencedColumnName = $referencedColumnName; + return $this; + } + + /** + * set foreign key update rule + * + * @param string $foreignKeyUpdateRule + */ + public function setForeignKeyUpdateRule($foreignKeyUpdateRule) + { + $this->foreignKeyUpdateRule = $foreignKeyUpdateRule; + } + + /** + * Get foreign key update rule + * + * @return string + */ + public function getForeignKeyUpdateRule() + { + return $this->foreignKeyUpdateRule; + } + + /** + * Set foreign key delete rule + * + * @param string $foreignKeyDeleteRule + */ + public function setForeignKeyDeleteRule($foreignKeyDeleteRule) + { + $this->foreignKeyDeleteRule = $foreignKeyDeleteRule; + } + + /** + * get foreign key delete rule + * + * @return string + */ + public function getForeignKeyDeleteRule() + { + return $this->foreignKeyDeleteRule; + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/ConstraintObject.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/ConstraintObject.php new file mode 100644 index 0000000000000000000000000000000000000000..089c5ea1fb5e2e72c8ed28ad54e56b4e5d627f43 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/ConstraintObject.php @@ -0,0 +1,411 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata\Object; + +class ConstraintObject +{ + /** + * + * @var string + */ + protected $name = null; + + /** + * + * @var string + */ + protected $tableName = null; + + /** + * + * @var string + */ + protected $schemaName = null; + + /** + * One of "PRIMARY KEY", "UNIQUE", "FOREIGN KEY", or "CHECK" + * + * @var string + */ + protected $type = null; + + /** + * + * + * @var string[] + */ + protected $columns = array(); + + /** + * + * + * @var string + */ + protected $referencedTableSchema; + + /** + * + * + * @var string + */ + protected $referencedTableName; + + /** + * + * + * @var string[] + */ + protected $referencedColumns; + + /** + * + * + * @var string + */ + protected $matchOption; + + /** + * + * + * @var string + */ + protected $updateRule; + + /** + * + * + * @var string + */ + protected $deleteRule; + + /** + * + * + * @var string + */ + protected $checkClause; + + /** + * Constructor + * + * @param string $name + * @param string $tableName + * @param string $schemaName + */ + public function __construct($name, $tableName, $schemaName = null) + { + $this->setName($name); + $this->setTableName($tableName); + $this->setSchemaName($schemaName); + } + + /** + * Set name + * + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set schema name + * + * @param string $schemaName + */ + public function setSchemaName($schemaName) + { + $this->schemaName = $schemaName; + } + + /** + * Get schema name + * + * @return string + */ + public function getSchemaName() + { + return $this->schemaName; + } + + /** + * Get table name + * + * @return string + */ + public function getTableName() + { + return $this->tableName; + } + + /** + * Set table name + * + * @param string $tableName + * @return ConstraintObject + */ + public function setTableName($tableName) + { + $this->tableName = $tableName; + return $this; + } + + /** + * Set type + * + * @param string $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * Get type + * + * @return string + */ + public function getType() + { + return $this->type; + } + + public function hasColumns() + { + return (!empty($this->columns)); + } + + /** + * Get Columns. + * + * @return string[] + */ + public function getColumns() + { + return $this->columns; + } + + /** + * Set Columns. + * + * @param string[] $columns + * @return ConstraintObject + */ + public function setColumns(array $columns) + { + $this->columns = $columns; + return $this; + } + + /** + * Get Referenced Table Schema. + * + * @return string + */ + public function getReferencedTableSchema() + { + return $this->referencedTableSchema; + } + + /** + * Set Referenced Table Schema. + * + * @param string $referencedTableSchema + * @return ConstraintObject + */ + public function setReferencedTableSchema($referencedTableSchema) + { + $this->referencedTableSchema = $referencedTableSchema; + return $this; + } + + /** + * Get Referenced Table Name. + * + * @return string + */ + public function getReferencedTableName() + { + return $this->referencedTableName; + } + + /** + * Set Referenced Table Name. + * + * @param string $referencedTableName + * @return ConstraintObject + */ + public function setReferencedTableName($referencedTableName) + { + $this->referencedTableName = $referencedTableName; + return $this; + } + + /** + * Get Referenced Columns. + * + * @return string[] + */ + public function getReferencedColumns() + { + return $this->referencedColumns; + } + + /** + * Set Referenced Columns. + * + * @param string[] $referencedColumns + * @return ConstraintObject + */ + public function setReferencedColumns(array $referencedColumns) + { + $this->referencedColumns = $referencedColumns; + return $this; + } + + /** + * Get Match Option. + * + * @return string + */ + public function getMatchOption() + { + return $this->matchOption; + } + + /** + * Set Match Option. + * + * @param string $matchOption + * @return ConstraintObject + */ + public function setMatchOption($matchOption) + { + $this->matchOption = $matchOption; + return $this; + } + + /** + * Get Update Rule. + * + * @return string + */ + public function getUpdateRule() + { + return $this->updateRule; + } + + /** + * Set Update Rule. + * + * @param string $updateRule + * @return ConstraintObject + */ + public function setUpdateRule($updateRule) + { + $this->updateRule = $updateRule; + return $this; + } + + /** + * Get Delete Rule. + * + * @return string + */ + public function getDeleteRule() + { + return $this->deleteRule; + } + + /** + * Set Delete Rule. + * + * @param string $deleteRule + * @return ConstraintObject + */ + public function setDeleteRule($deleteRule) + { + $this->deleteRule = $deleteRule; + return $this; + } + + /** + * Get Check Clause. + * + * @return string + */ + public function getCheckClause() + { + return $this->checkClause; + } + + /** + * Set Check Clause. + * + * @param string $checkClause + * @return ConstraintObject + */ + public function setCheckClause($checkClause) + { + $this->checkClause = $checkClause; + return $this; + } + + /** + * Is primary key + * + * @return bool + */ + public function isPrimaryKey() + { + return ('PRIMARY KEY' == $this->type); + } + + /** + * Is unique key + * + * @return bool + */ + public function isUnique() + { + return ('UNIQUE' == $this->type); + } + + /** + * Is foreign key + * + * @return bool + */ + public function isForeignKey() + { + return ('FOREIGN KEY' == $this->type); + } + + /** + * Is foreign key + * + * @return bool + */ + public function isCheck() + { + return ('CHECK' == $this->type); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/TableObject.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/TableObject.php new file mode 100644 index 0000000000000000000000000000000000000000..8735fbfc8c35f6f6975227246455d13f899fd5b0 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/TableObject.php @@ -0,0 +1,14 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata\Object; + +class TableObject extends AbstractTableObject +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/TriggerObject.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/TriggerObject.php new file mode 100644 index 0000000000000000000000000000000000000000..eece8c4f42c02b66cc5bc02fea47d40b3c112ce9 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/TriggerObject.php @@ -0,0 +1,448 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata\Object; + +class TriggerObject +{ + /** + * + * + * @var string + */ + protected $name; + + /** + * + * + * @var string + */ + protected $eventManipulation; + + /** + * + * + * @var string + */ + protected $eventObjectCatalog; + + /** + * + * + * @var string + */ + protected $eventObjectSchema; + + /** + * + * + * @var string + */ + protected $eventObjectTable; + + /** + * + * + * @var string + */ + protected $actionOrder; + + /** + * + * + * @var string + */ + protected $actionCondition; + + /** + * + * + * @var string + */ + protected $actionStatement; + + /** + * + * + * @var string + */ + protected $actionOrientation; + + /** + * + * + * @var string + */ + protected $actionTiming; + + /** + * + * + * @var string + */ + protected $actionReferenceOldTable; + + /** + * + * + * @var string + */ + protected $actionReferenceNewTable; + + /** + * + * + * @var string + */ + protected $actionReferenceOldRow; + + /** + * + * + * @var string + */ + protected $actionReferenceNewRow; + + /** + * + * + * @var \DateTime + */ + protected $created; + + /** + * Get Name. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set Name. + * + * @param string $name + * @return TriggerObject + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * Get Event Manipulation. + * + * @return string + */ + public function getEventManipulation() + { + return $this->eventManipulation; + } + + /** + * Set Event Manipulation. + * + * @param string $eventManipulation + * @return TriggerObject + */ + public function setEventManipulation($eventManipulation) + { + $this->eventManipulation = $eventManipulation; + return $this; + } + + /** + * Get Event Object Catalog. + * + * @return string + */ + public function getEventObjectCatalog() + { + return $this->eventObjectCatalog; + } + + /** + * Set Event Object Catalog. + * + * @param string $eventObjectCatalog + * @return TriggerObject + */ + public function setEventObjectCatalog($eventObjectCatalog) + { + $this->eventObjectCatalog = $eventObjectCatalog; + return $this; + } + + /** + * Get Event Object Schema. + * + * @return string + */ + public function getEventObjectSchema() + { + return $this->eventObjectSchema; + } + + /** + * Set Event Object Schema. + * + * @param string $eventObjectSchema + * @return TriggerObject + */ + public function setEventObjectSchema($eventObjectSchema) + { + $this->eventObjectSchema = $eventObjectSchema; + return $this; + } + + /** + * Get Event Object Table. + * + * @return string + */ + public function getEventObjectTable() + { + return $this->eventObjectTable; + } + + /** + * Set Event Object Table. + * + * @param string $eventObjectTable + * @return TriggerObject + */ + public function setEventObjectTable($eventObjectTable) + { + $this->eventObjectTable = $eventObjectTable; + return $this; + } + + /** + * Get Action Order. + * + * @return string + */ + public function getActionOrder() + { + return $this->actionOrder; + } + + /** + * Set Action Order. + * + * @param string $actionOrder + * @return TriggerObject + */ + public function setActionOrder($actionOrder) + { + $this->actionOrder = $actionOrder; + return $this; + } + + /** + * Get Action Condition. + * + * @return string + */ + public function getActionCondition() + { + return $this->actionCondition; + } + + /** + * Set Action Condition. + * + * @param string $actionCondition + * @return TriggerObject + */ + public function setActionCondition($actionCondition) + { + $this->actionCondition = $actionCondition; + return $this; + } + + /** + * Get Action Statement. + * + * @return string + */ + public function getActionStatement() + { + return $this->actionStatement; + } + + /** + * Set Action Statement. + * + * @param string $actionStatement + * @return TriggerObject + */ + public function setActionStatement($actionStatement) + { + $this->actionStatement = $actionStatement; + return $this; + } + + /** + * Get Action Orientation. + * + * @return string + */ + public function getActionOrientation() + { + return $this->actionOrientation; + } + + /** + * Set Action Orientation. + * + * @param string $actionOrientation + * @return TriggerObject + */ + public function setActionOrientation($actionOrientation) + { + $this->actionOrientation = $actionOrientation; + return $this; + } + + /** + * Get Action Timing. + * + * @return string + */ + public function getActionTiming() + { + return $this->actionTiming; + } + + /** + * Set Action Timing. + * + * @param string $actionTiming + * @return TriggerObject + */ + public function setActionTiming($actionTiming) + { + $this->actionTiming = $actionTiming; + return $this; + } + + /** + * Get Action Reference Old Table. + * + * @return string + */ + public function getActionReferenceOldTable() + { + return $this->actionReferenceOldTable; + } + + /** + * Set Action Reference Old Table. + * + * @param string $actionReferenceOldTable + * @return TriggerObject + */ + public function setActionReferenceOldTable($actionReferenceOldTable) + { + $this->actionReferenceOldTable = $actionReferenceOldTable; + return $this; + } + + /** + * Get Action Reference New Table. + * + * @return string + */ + public function getActionReferenceNewTable() + { + return $this->actionReferenceNewTable; + } + + /** + * Set Action Reference New Table. + * + * @param string $actionReferenceNewTable + * @return TriggerObject + */ + public function setActionReferenceNewTable($actionReferenceNewTable) + { + $this->actionReferenceNewTable = $actionReferenceNewTable; + return $this; + } + + /** + * Get Action Reference Old Row. + * + * @return string + */ + public function getActionReferenceOldRow() + { + return $this->actionReferenceOldRow; + } + + /** + * Set Action Reference Old Row. + * + * @param string $actionReferenceOldRow + * @return TriggerObject + */ + public function setActionReferenceOldRow($actionReferenceOldRow) + { + $this->actionReferenceOldRow = $actionReferenceOldRow; + return $this; + } + + /** + * Get Action Reference New Row. + * + * @return string + */ + public function getActionReferenceNewRow() + { + return $this->actionReferenceNewRow; + } + + /** + * Set Action Reference New Row. + * + * @param string $actionReferenceNewRow + * @return TriggerObject + */ + public function setActionReferenceNewRow($actionReferenceNewRow) + { + $this->actionReferenceNewRow = $actionReferenceNewRow; + return $this; + } + + /** + * Get Created. + * + * @return \DateTime + */ + public function getCreated() + { + return $this->created; + } + + /** + * Set Created. + * + * @param \DateTime $created + * @return TriggerObject + */ + public function setCreated($created) + { + $this->created = $created; + return $this; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/ViewObject.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/ViewObject.php new file mode 100644 index 0000000000000000000000000000000000000000..5130e9ecc62ed56337a2e4573dae9010d588b807 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/Object/ViewObject.php @@ -0,0 +1,76 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata\Object; + +class ViewObject extends AbstractTableObject +{ + protected $viewDefinition; + protected $checkOption; + protected $isUpdatable; + + /** + * @return string $viewDefinition + */ + public function getViewDefinition() + { + return $this->viewDefinition; + } + + /** + * @param string $viewDefinition to set + * @return ViewObject + */ + public function setViewDefinition($viewDefinition) + { + $this->viewDefinition = $viewDefinition; + return $this; + } + + /** + * @return string $checkOption + */ + public function getCheckOption() + { + return $this->checkOption; + } + + /** + * @param string $checkOption to set + * @return ViewObject + */ + public function setCheckOption($checkOption) + { + $this->checkOption = $checkOption; + return $this; + } + + /** + * @return bool $isUpdatable + */ + public function getIsUpdatable() + { + return $this->isUpdatable; + } + + /** + * @param bool $isUpdatable to set + * @return ViewObject + */ + public function setIsUpdatable($isUpdatable) + { + $this->isUpdatable = $isUpdatable; + return $this; + } + + public function isUpdatable() + { + return $this->isUpdatable; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/AbstractSource.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/AbstractSource.php new file mode 100644 index 0000000000000000000000000000000000000000..6d3063781b9dbc503f4e8740dcfc54ebcbb0b105 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/AbstractSource.php @@ -0,0 +1,602 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata\Source; + +use Zend\Db\Adapter\Adapter; +use Zend\Db\Metadata\MetadataInterface; +use Zend\Db\Metadata\Object; + +abstract class AbstractSource implements MetadataInterface +{ + const DEFAULT_SCHEMA = '__DEFAULT_SCHEMA__'; + + /** + * + * @var Adapter + */ + protected $adapter = null; + + /** + * + * @var string + */ + protected $defaultSchema = null; + + /** + * + * @var array + */ + protected $data = array(); + + /** + * Constructor + * + * @param Adapter $adapter + */ + public function __construct(Adapter $adapter) + { + $this->adapter = $adapter; + $this->defaultSchema = ($adapter->getCurrentSchema()) ?: self::DEFAULT_SCHEMA; + } + + /** + * Get schemas + * + */ + public function getSchemas() + { + $this->loadSchemaData(); + + return $this->data['schemas']; + } + + /** + * Get table names + * + * @param string $schema + * @param bool $includeViews + * @return string[] + */ + public function getTableNames($schema = null, $includeViews = false) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $this->loadTableNameData($schema); + + if ($includeViews) { + return array_keys($this->data['table_names'][$schema]); + } + + $tableNames = array(); + foreach ($this->data['table_names'][$schema] as $tableName => $data) { + if ('BASE TABLE' == $data['table_type']) { + $tableNames[] = $tableName; + } + } + return $tableNames; + + } + + /** + * Get tables + * + * @param string $schema + * @param bool $includeViews + * @return Object\TableObject[] + */ + public function getTables($schema = null, $includeViews = false) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $tables = array(); + foreach ($this->getTableNames($schema, $includeViews) as $tableName) { + $tables[] = $this->getTable($tableName, $schema); + } + return $tables; + } + + /** + * Get table + * + * @param string $tableName + * @param string $schema + * @return Object\TableObject + */ + public function getTable($tableName, $schema = null) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $this->loadTableNameData($schema); + + if (!isset($this->data['table_names'][$schema][$tableName])) { + throw new \Exception('Table "' . $tableName . '" does not exist'); + } + + $data = $this->data['table_names'][$schema][$tableName]; + switch ($data['table_type']) { + case 'BASE TABLE': + $table = new Object\TableObject($tableName); + break; + case 'VIEW': + $table = new Object\ViewObject($tableName); + $table->setViewDefinition($data['view_definition']); + $table->setCheckOption($data['check_option']); + $table->setIsUpdatable($data['is_updatable']); + break; + default: + throw new \Exception('Table "' . $tableName . '" is of an unsupported type "' . $data['table_type'] . '"'); + } + $table->setColumns($this->getColumns($tableName, $schema)); + $table->setConstraints($this->getConstraints($tableName, $schema)); + return $table; + } + + /** + * Get view names + * + * @param string $schema + * @return array + */ + public function getViewNames($schema = null) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $this->loadTableNameData($schema); + + $viewNames = array(); + foreach ($this->data['table_names'][$schema] as $tableName => $data) { + if ('VIEW' == $data['table_type']) { + $viewNames[] = $tableName; + } + } + return $viewNames; + } + + /** + * Get views + * + * @param string $schema + * @return array + */ + public function getViews($schema = null) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $views = array(); + foreach ($this->getViewNames($schema) as $tableName) { + $views[] = $this->getTable($tableName, $schema); + } + return $views; + } + + /** + * Get view + * + * @param string $viewName + * @param string $schema + * @return \Zend\Db\Metadata\Object\TableObject + */ + public function getView($viewName, $schema = null) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $this->loadTableNameData($schema); + + $tableNames = $this->data['table_names'][$schema]; + if (isset($tableNames[$viewName]) && 'VIEW' == $tableNames[$viewName]['table_type']) { + return $this->getTable($viewName, $schema); + } + throw new \Exception('View "' . $viewName . '" does not exist'); + } + + /** + * Gt column names + * + * @param string $table + * @param string $schema + * @return array + */ + public function getColumnNames($table, $schema = null) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $this->loadColumnData($table, $schema); + + if (!isset($this->data['columns'][$schema][$table])) { + throw new \Exception('"' . $table . '" does not exist'); + } + + return array_keys($this->data['columns'][$schema][$table]); + } + + /** + * Get columns + * + * @param string $table + * @param string $schema + * @return array + */ + public function getColumns($table, $schema = null) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $this->loadColumnData($table, $schema); + + $columns = array(); + foreach ($this->getColumnNames($table, $schema) as $columnName) { + $columns[] = $this->getColumn($columnName, $table, $schema); + } + return $columns; + } + + /** + * Get column + * + * @param string $columnName + * @param string $table + * @param string $schema + * @return Object\ColumnObject + */ + public function getColumn($columnName, $table, $schema = null) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $this->loadColumnData($table, $schema); + + if (!isset($this->data['columns'][$schema][$table][$columnName])) { + throw new \Exception('A column by that name was not found.'); + } + + $info = $this->data['columns'][$schema][$table][$columnName]; + + $column = new Object\ColumnObject($columnName, $table, $schema); + $props = array( + 'ordinal_position', 'column_default', 'is_nullable', + 'data_type', 'character_maximum_length', 'character_octet_length', + 'numeric_precision', 'numeric_scale', 'numeric_unsigned', + 'erratas' + ); + foreach ($props as $prop) { + if (isset($info[$prop])) { + $column->{'set' . str_replace('_', '', $prop)}($info[$prop]); + } + } + + $column->setOrdinalPosition($info['ordinal_position']); + $column->setColumnDefault($info['column_default']); + $column->setIsNullable($info['is_nullable']); + $column->setDataType($info['data_type']); + $column->setCharacterMaximumLength($info['character_maximum_length']); + $column->setCharacterOctetLength($info['character_octet_length']); + $column->setNumericPrecision($info['numeric_precision']); + $column->setNumericScale($info['numeric_scale']); + $column->setNumericUnsigned($info['numeric_unsigned']); + $column->setErratas($info['erratas']); + + return $column; + } + + /** + * Get constraints + * + * @param string $table + * @param string $schema + * @return array + */ + public function getConstraints($table, $schema = null) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $this->loadConstraintData($table, $schema); + + $constraints = array(); + foreach (array_keys($this->data['constraints'][$schema][$table]) as $constraintName) { + $constraints[] = $this->getConstraint($constraintName, $table, $schema); + } + + return $constraints; + } + + /** + * Get constraint + * + * @param string $constraintName + * @param string $table + * @param string $schema + * @return Object\ConstraintObject + */ + public function getConstraint($constraintName, $table, $schema = null) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $this->loadConstraintData($table, $schema); + + if (!isset($this->data['constraints'][$schema][$table][$constraintName])) { + throw new \Exception('Cannot find a constraint by that name in this table'); + } + + $info = $this->data['constraints'][$schema][$table][$constraintName]; + $constraint = new Object\ConstraintObject($constraintName, $table, $schema); + + foreach (array( + 'constraint_type' => 'setType', + 'match_option' => 'setMatchOption', + 'update_rule' => 'setUpdateRule', + 'delete_rule' => 'setDeleteRule', + 'columns' => 'setColumns', + 'referenced_table_schema' => 'setReferencedTableSchema', + 'referenced_table_name' => 'setReferencedTableName', + 'referenced_columns' => 'setReferencedColumns', + 'check_clause' => 'setCheckClause', + ) as $key => $setMethod) { + if (isset($info[$key])) { + $constraint->{$setMethod}($info[$key]); + } + } + + return $constraint; + } + + /** + * Get constraint keys + * + * @param string $constraint + * @param string $table + * @param string $schema + * @return array + */ + public function getConstraintKeys($constraint, $table, $schema = null) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $this->loadConstraintReferences($table, $schema); + + // organize references first + $references = array(); + foreach ($this->data['constraint_references'][$schema] as $refKeyInfo) { + if ($refKeyInfo['constraint_name'] == $constraint) { + $references[$refKeyInfo['constraint_name']] = $refKeyInfo; + } + } + + $this->loadConstraintDataKeys($schema); + + $keys = array(); + foreach ($this->data['constraint_keys'][$schema] as $constraintKeyInfo) { + if ($constraintKeyInfo['table_name'] == $table && $constraintKeyInfo['constraint_name'] === $constraint) { + $keys[] = $key = new Object\ConstraintKeyObject($constraintKeyInfo['column_name']); + $key->setOrdinalPosition($constraintKeyInfo['ordinal_position']); + if (isset($references[$constraint])) { + //$key->setReferencedTableSchema($constraintKeyInfo['referenced_table_schema']); + $key->setForeignKeyUpdateRule($references[$constraint]['update_rule']); + $key->setForeignKeyDeleteRule($references[$constraint]['delete_rule']); + //$key->setReferencedTableSchema($references[$constraint]['referenced_table_schema']); + $key->setReferencedTableName($references[$constraint]['referenced_table_name']); + $key->setReferencedColumnName($references[$constraint]['referenced_column_name']); + } + } + } + + return $keys; + } + + /** + * Get trigger names + * + * @param string $schema + * @return array + */ + public function getTriggerNames($schema = null) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $this->loadTriggerData($schema); + + return array_keys($this->data['triggers'][$schema]); + } + + /** + * Get triggers + * + * @param string $schema + * @return array + */ + public function getTriggers($schema = null) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $triggers = array(); + foreach ($this->getTriggerNames($schema) as $triggerName) { + $triggers[] = $this->getTrigger($triggerName, $schema); + } + return $triggers; + } + + /** + * Get trigger + * + * @param string $triggerName + * @param string $schema + * @return Object\TriggerObject + */ + public function getTrigger($triggerName, $schema = null) + { + if ($schema === null) { + $schema = $this->defaultSchema; + } + + $this->loadTriggerData($schema); + + if (!isset($this->data['triggers'][$schema][$triggerName])) { + throw new \Exception('Trigger "' . $triggerName . '" does not exist'); + } + + $info = $this->data['triggers'][$schema][$triggerName]; + + $trigger = new Object\TriggerObject(); + + $trigger->setName($triggerName); + $trigger->setEventManipulation($info['event_manipulation']); + $trigger->setEventObjectCatalog($info['event_object_catalog']); + $trigger->setEventObjectSchema($info['event_object_schema']); + $trigger->setEventObjectTable($info['event_object_table']); + $trigger->setActionOrder($info['action_order']); + $trigger->setActionCondition($info['action_condition']); + $trigger->setActionStatement($info['action_statement']); + $trigger->setActionOrientation($info['action_orientation']); + $trigger->setActionTiming($info['action_timing']); + $trigger->setActionReferenceOldTable($info['action_reference_old_table']); + $trigger->setActionReferenceNewTable($info['action_reference_new_table']); + $trigger->setActionReferenceOldRow($info['action_reference_old_row']); + $trigger->setActionReferenceNewRow($info['action_reference_new_row']); + $trigger->setCreated($info['created']); + + return $trigger; + } + + /** + * Prepare data hierarchy + * + * @param string $type + * @param string $key ... + */ + protected function prepareDataHierarchy($type) + { + $data = &$this->data; + foreach (func_get_args() as $key) { + if (!isset($data[$key])) { + $data[$key] = array(); + } + $data = &$data[$key]; + } + } + + /** + * Load schema data + */ + protected function loadSchemaData() + { + } + + /** + * Load table name data + * + * @param string $schema + */ + protected function loadTableNameData($schema) + { + if (isset($this->data['table_names'][$schema])) { + return; + } + + $this->prepareDataHierarchy('table_names', $schema); + } + + /** + * Load column data + * + * @param string $table + * @param string $schema + */ + protected function loadColumnData($table, $schema) + { + if (isset($this->data['columns'][$schema][$table])) { + return; + } + + $this->prepareDataHierarchy('columns', $schema, $table); + } + + /** + * Load constraint data + * + * @param string $table + * @param string $schema + */ + protected function loadConstraintData($table, $schema) + { + if (isset($this->data['constraints'][$schema])) { + return; + } + + $this->prepareDataHierarchy('constraints', $schema); + } + + /** + * Load constraint data keys + * + * @param string $schema + */ + protected function loadConstraintDataKeys($schema) + { + if (isset($this->data['constraint_keys'][$schema])) { + return; + } + + $this->prepareDataHierarchy('constraint_keys', $schema); + } + + /** + * Load constraint references + * + * @param string $table + * @param string $schema + */ + protected function loadConstraintReferences($table, $schema) + { + if (isset($this->data['constraint_references'][$schema])) { + return; + } + + $this->prepareDataHierarchy('constraint_references', $schema); + } + + /** + * Load trigger data + * + * @param string $schema + */ + protected function loadTriggerData($schema) + { + if (isset($this->data['triggers'][$schema])) { + return; + } + + $this->prepareDataHierarchy('triggers', $schema); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/MysqlMetadata.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/MysqlMetadata.php new file mode 100644 index 0000000000000000000000000000000000000000..ac9642f9c1f85d4b5800a6cdc8eb9ff145fd32a4 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/MysqlMetadata.php @@ -0,0 +1,493 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata\Source; + +use Zend\Db\Adapter\Adapter; + +class MysqlMetadata extends AbstractSource +{ + protected function loadSchemaData() + { + if (isset($this->data['schemas'])) { + return; + } + $this->prepareDataHierarchy('schemas'); + + $p = $this->adapter->getPlatform(); + + $sql = 'SELECT ' . $p->quoteIdentifier('SCHEMA_NAME') + . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'SCHEMATA')) + . ' WHERE ' . $p->quoteIdentifier('SCHEMA_NAME') + . ' != \'INFORMATION_SCHEMA\''; + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $schemas = array(); + foreach ($results->toArray() as $row) { + $schemas[] = $row['SCHEMA_NAME']; + } + + $this->data['schemas'] = $schemas; + } + + protected function loadTableNameData($schema) + { + if (isset($this->data['table_names'][$schema])) { + return; + } + $this->prepareDataHierarchy('table_names', $schema); + + $p = $this->adapter->getPlatform(); + + $isColumns = array( + array('T', 'TABLE_NAME'), + array('T', 'TABLE_TYPE'), + array('V', 'VIEW_DEFINITION'), + array('V', 'CHECK_OPTION'), + array('V', 'IS_UPDATABLE'), + ); + + array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . 'T' + + . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'VIEWS')) . ' V' + . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('V', 'TABLE_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('V', 'TABLE_NAME')) + + . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' IN (\'BASE TABLE\', \'VIEW\')'; + + if ($schema != self::DEFAULT_SCHEMA) { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' != \'INFORMATION_SCHEMA\''; + } + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $tables = array(); + foreach ($results->toArray() as $row) { + $tables[$row['TABLE_NAME']] = array( + 'table_type' => $row['TABLE_TYPE'], + 'view_definition' => $row['VIEW_DEFINITION'], + 'check_option' => $row['CHECK_OPTION'], + 'is_updatable' => ('YES' == $row['IS_UPDATABLE']), + ); + } + + $this->data['table_names'][$schema] = $tables; + } + + protected function loadColumnData($table, $schema) + { + if (isset($this->data['columns'][$schema][$table])) { + return; + } + $this->prepareDataHierarchy('columns', $schema, $table); + $p = $this->adapter->getPlatform(); + + $isColumns = array( + array('C', 'ORDINAL_POSITION'), + array('C', 'COLUMN_DEFAULT'), + array('C', 'IS_NULLABLE'), + array('C', 'DATA_TYPE'), + array('C', 'CHARACTER_MAXIMUM_LENGTH'), + array('C', 'CHARACTER_OCTET_LENGTH'), + array('C', 'NUMERIC_PRECISION'), + array('C', 'NUMERIC_SCALE'), + array('C', 'COLUMN_NAME'), + array('C', 'COLUMN_TYPE'), + ); + + array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . 'T' + . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'COLUMNS')) . 'C' + . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('C', 'TABLE_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('C', 'TABLE_NAME')) + . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' IN (\'BASE TABLE\', \'VIEW\')' + . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' = ' . $p->quoteTrustedValue($table); + + if ($schema != self::DEFAULT_SCHEMA) { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' != \'INFORMATION_SCHEMA\''; + } + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + $columns = array(); + foreach ($results->toArray() as $row) { + $erratas = array(); + $matches = array(); + if (preg_match('/^(?:enum|set)\((.+)\)$/i', $row['COLUMN_TYPE'], $matches)) { + $permittedValues = $matches[1]; + if (preg_match_all("/\\s*'((?:[^']++|'')*+)'\\s*(?:,|\$)/", $permittedValues, $matches, PREG_PATTERN_ORDER)) { + $permittedValues = str_replace("''", "'", $matches[1]); + } else { + $permittedValues = array($permittedValues); + } + $erratas['permitted_values'] = $permittedValues; + } + $columns[$row['COLUMN_NAME']] = array( + 'ordinal_position' => $row['ORDINAL_POSITION'], + 'column_default' => $row['COLUMN_DEFAULT'], + 'is_nullable' => ('YES' == $row['IS_NULLABLE']), + 'data_type' => $row['DATA_TYPE'], + 'character_maximum_length' => $row['CHARACTER_MAXIMUM_LENGTH'], + 'character_octet_length' => $row['CHARACTER_OCTET_LENGTH'], + 'numeric_precision' => $row['NUMERIC_PRECISION'], + 'numeric_scale' => $row['NUMERIC_SCALE'], + 'numeric_unsigned' => (false !== strpos($row['COLUMN_TYPE'], 'unsigned')), + 'erratas' => $erratas, + ); + } + + $this->data['columns'][$schema][$table] = $columns; + } + + protected function loadConstraintData($table, $schema) + { + if (isset($this->data['constraints'][$schema][$table])) { + return; + } + + $this->prepareDataHierarchy('constraints', $schema, $table); + + $isColumns = array( + array('T', 'TABLE_NAME'), + array('TC', 'CONSTRAINT_NAME'), + array('TC', 'CONSTRAINT_TYPE'), + array('KCU', 'COLUMN_NAME'), + array('RC', 'MATCH_OPTION'), + array('RC', 'UPDATE_RULE'), + array('RC', 'DELETE_RULE'), + array('KCU', 'REFERENCED_TABLE_SCHEMA'), + array('KCU', 'REFERENCED_TABLE_NAME'), + array('KCU', 'REFERENCED_COLUMN_NAME'), + ); + + $p = $this->adapter->getPlatform(); + + array_walk($isColumns, function (&$c) use ($p) { + $c = $p->quoteIdentifierChain($c); + }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . ' T' + + . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLE_CONSTRAINTS')) . ' TC' + . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('TC', 'TABLE_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('TC', 'TABLE_NAME')) + + . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE')) . ' KCU' + . ' ON ' . $p->quoteIdentifierChain(array('TC', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('TC', 'TABLE_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_NAME')) + . ' AND ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('KCU', 'CONSTRAINT_NAME')) + + . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'REFERENTIAL_CONSTRAINTS')) . ' RC' + . ' ON ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_NAME')) + + . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' = ' . $p->quoteTrustedValue($table) + . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' IN (\'BASE TABLE\', \'VIEW\')'; + + if ($schema != self::DEFAULT_SCHEMA) { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' != \'INFORMATION_SCHEMA\''; + } + + $sql .= ' ORDER BY CASE ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_TYPE')) + . " WHEN 'PRIMARY KEY' THEN 1" + . " WHEN 'UNIQUE' THEN 2" + . " WHEN 'FOREIGN KEY' THEN 3" + . " ELSE 4 END" + + . ', ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_NAME')) + . ', ' . $p->quoteIdentifierChain(array('KCU', 'ORDINAL_POSITION')); + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $realName = null; + $constraints = array(); + foreach ($results->toArray() as $row) { + if ($row['CONSTRAINT_NAME'] !== $realName) { + $realName = $row['CONSTRAINT_NAME']; + $isFK = ('FOREIGN KEY' == $row['CONSTRAINT_TYPE']); + if ($isFK) { + $name = $realName; + } else { + $name = '_zf_' . $row['TABLE_NAME'] . '_' . $realName; + } + $constraints[$name] = array( + 'constraint_name' => $name, + 'constraint_type' => $row['CONSTRAINT_TYPE'], + 'table_name' => $row['TABLE_NAME'], + 'columns' => array(), + ); + if ($isFK) { + $constraints[$name]['referenced_table_schema'] = $row['REFERENCED_TABLE_SCHEMA']; + $constraints[$name]['referenced_table_name'] = $row['REFERENCED_TABLE_NAME']; + $constraints[$name]['referenced_columns'] = array(); + $constraints[$name]['match_option'] = $row['MATCH_OPTION']; + $constraints[$name]['update_rule'] = $row['UPDATE_RULE']; + $constraints[$name]['delete_rule'] = $row['DELETE_RULE']; + } + } + $constraints[$name]['columns'][] = $row['COLUMN_NAME']; + if ($isFK) { + $constraints[$name]['referenced_columns'][] = $row['REFERENCED_COLUMN_NAME']; + } + } + + $this->data['constraints'][$schema][$table] = $constraints; + } + + protected function loadConstraintDataNames($schema) + { + if (isset($this->data['constraint_names'][$schema])) { + return; + } + + $this->prepareDataHierarchy('constraint_names', $schema); + + $p = $this->adapter->getPlatform(); + + $isColumns = array( + array('TC', 'TABLE_NAME'), + array('TC', 'CONSTRAINT_NAME'), + array('TC', 'CONSTRAINT_TYPE'), + ); + + array_walk($isColumns, function (&$c) use ($p) { + $c = $p->quoteIdentifierChain($c); + }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . 'T' + . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLE_CONSTRAINTS')) . 'TC' + . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('TC', 'TABLE_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('TC', 'TABLE_NAME')) + . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' IN (\'BASE TABLE\', \'VIEW\')'; + + if ($schema != self::DEFAULT_SCHEMA) { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' != \'INFORMATION_SCHEMA\''; + } + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $data = array(); + foreach ($results->toArray() as $row) { + $data[] = array_change_key_case($row, CASE_LOWER); + } + + $this->data['constraint_names'][$schema] = $data; + } + + protected function loadConstraintDataKeys($schema) + { + if (isset($this->data['constraint_keys'][$schema])) { + return; + } + + $this->prepareDataHierarchy('constraint_keys', $schema); + + $p = $this->adapter->getPlatform(); + + $isColumns = array( + array('T', 'TABLE_NAME'), + array('KCU', 'CONSTRAINT_NAME'), + array('KCU', 'COLUMN_NAME'), + array('KCU', 'ORDINAL_POSITION'), + ); + + array_walk($isColumns, function (&$c) use ($p) { + $c = $p->quoteIdentifierChain($c); + }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . 'T' + + . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE')) . 'KCU' + . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_NAME')) + + . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' IN (\'BASE TABLE\', \'VIEW\')'; + + if ($schema != self::DEFAULT_SCHEMA) { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' != \'INFORMATION_SCHEMA\''; + } + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $data = array(); + foreach ($results->toArray() as $row) { + $data[] = array_change_key_case($row, CASE_LOWER); + } + + $this->data['constraint_keys'][$schema] = $data; + } + + protected function loadConstraintReferences($table, $schema) + { + parent::loadConstraintReferences($table, $schema); + + $p = $this->adapter->getPlatform(); + + $isColumns = array( + array('RC', 'TABLE_NAME'), + array('RC', 'CONSTRAINT_NAME'), + array('RC', 'UPDATE_RULE'), + array('RC', 'DELETE_RULE'), + array('KCU', 'REFERENCED_TABLE_SCHEMA'), + array('KCU', 'REFERENCED_TABLE_NAME'), + array('KCU', 'REFERENCED_COLUMN_NAME'), + ); + + array_walk($isColumns, function (&$c) use ($p) { + $c = $p->quoteIdentifierChain($c); + }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . 'FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . 'T' + + . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'REFERENTIAL_CONSTRAINTS')) . 'RC' + . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('RC', 'TABLE_NAME')) + + . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE')) . 'KCU' + . ' ON ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('RC', 'TABLE_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_NAME')) + . ' AND ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('KCU', 'CONSTRAINT_NAME')) + + . 'WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' IN (\'BASE TABLE\', \'VIEW\')'; + + if ($schema != self::DEFAULT_SCHEMA) { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' != \'INFORMATION_SCHEMA\''; + } + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $data = array(); + foreach ($results->toArray() as $row) { + $data[] = array_change_key_case($row, CASE_LOWER); + } + + $this->data['constraint_references'][$schema] = $data; + } + + protected function loadTriggerData($schema) + { + if (isset($this->data['triggers'][$schema])) { + return; + } + + $this->prepareDataHierarchy('triggers', $schema); + + $p = $this->adapter->getPlatform(); + + $isColumns = array( +// 'TRIGGER_CATALOG', +// 'TRIGGER_SCHEMA', + 'TRIGGER_NAME', + 'EVENT_MANIPULATION', + 'EVENT_OBJECT_CATALOG', + 'EVENT_OBJECT_SCHEMA', + 'EVENT_OBJECT_TABLE', + 'ACTION_ORDER', + 'ACTION_CONDITION', + 'ACTION_STATEMENT', + 'ACTION_ORIENTATION', + 'ACTION_TIMING', + 'ACTION_REFERENCE_OLD_TABLE', + 'ACTION_REFERENCE_NEW_TABLE', + 'ACTION_REFERENCE_OLD_ROW', + 'ACTION_REFERENCE_NEW_ROW', + 'CREATED', + ); + + array_walk($isColumns, function (&$c) use ($p) { + $c = $p->quoteIdentifier($c); + }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TRIGGERS')) + . ' WHERE '; + + if ($schema != self::DEFAULT_SCHEMA) { + $sql .= $p->quoteIdentifier('TRIGGER_SCHEMA') + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= $p->quoteIdentifier('TRIGGER_SCHEMA') + . ' != \'INFORMATION_SCHEMA\''; + } + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $data = array(); + foreach ($results->toArray() as $row) { + $row = array_change_key_case($row, CASE_LOWER); + if (null !== $row['created']) { + $row['created'] = new \DateTime($row['created']); + } + $data[$row['trigger_name']] = $row; + } + + $this->data['triggers'][$schema] = $data; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/OracleMetadata.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/OracleMetadata.php new file mode 100644 index 0000000000000000000000000000000000000000..44deac13d2c56733b6506a3d731187fa60df2fc5 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/OracleMetadata.php @@ -0,0 +1,256 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata\Source; + +use Zend\Db\Adapter\Adapter; + +/** + * Metadata source for Oracle + */ +class OracleMetadata extends AbstractSource +{ + /** + * @var array + */ + protected $constraintTypeMap = array( + 'C' => 'CHECK', + 'P' => 'PRIMARY KEY', + 'R' => 'FOREIGN_KEY' + ); + + /** + * {@inheritdoc} + * @see \Zend\Db\Metadata\Source\AbstractSource::loadColumnData() + */ + protected function loadColumnData($table, $schema) + { + if (isset($this->data['columns'][$schema][$table])) { + return; + } + + $isColumns = array( + 'COLUMN_ID', + 'COLUMN_NAME', + 'DATA_DEFAULT', + 'NULLABLE', + 'DATA_TYPE', + 'DATA_LENGTH', + 'DATA_PRECISION', + 'DATA_SCALE' + ); + + $this->prepareDataHierarchy('columns', $schema, $table); + $parameters = array( + ':ownername' => $schema, + ':tablename' => $table + ); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM all_tab_columns' + . ' WHERE owner = :ownername AND table_name = :tablename'; + + $result = $this->adapter->query($sql)->execute($parameters); + $columns = array(); + + foreach ($result as $row) { + $columns[$row['COLUMN_NAME']] = array( + 'ordinal_position' => $row['COLUMN_ID'], + 'column_default' => $row['DATA_DEFAULT'], + 'is_nullable' => ('Y' == $row['NULLABLE']), + 'data_type' => $row['DATA_TYPE'], + 'character_maximum_length' => $row['DATA_LENGTH'], + 'character_octet_length' => null, + 'numeric_precision' => $row['DATA_PRECISION'], + 'numeric_scale' => $row['DATA_SCALE'], + 'numeric_unsigned' => false, + 'erratas' => array(), + ); + } + + $this->data['columns'][$schema][$table] = $columns; + return $this; + } + + /** + * Constraint type + * + * @param string $type + * @return string + */ + protected function getConstraintType($type) + { + if (isset($this->constraintTypeMap[$type])) { + return $this->constraintTypeMap[$type]; + } + + return $type; + } + + /** + * {@inheritdoc} + * @see \Zend\Db\Metadata\Source\AbstractSource::loadConstraintData() + */ + protected function loadConstraintData($table, $schema) + { + if (isset($this->data['constraints'][$schema][$table])) { + return; + } + + $this->prepareDataHierarchy('constraints', $schema, $table); + $sql = ' + SELECT + ac.owner, + ac.constraint_name, + ac.constraint_type, + ac.search_condition check_clause, + ac.table_name, + ac.delete_rule, + cc1.column_name, + cc2.table_name as ref_table, + cc2.column_name as ref_column, + cc2.owner as ref_owner + FROM all_constraints ac + INNER JOIN all_cons_columns cc1 + ON cc1.constraint_name = ac.constraint_name + LEFT JOIN all_cons_columns cc2 + ON cc2.constraint_name = ac.r_constraint_name + AND cc2.position = cc1.position + + WHERE + ac.owner = :schema AND ac.table_name = :table + + ORDER BY ac.constraint_name; + '; + + $parameters = array( + ':schema' => $schema, + ':table' => $table + ); + + $results = $this->adapter->query($sql)->execute($parameters); + $isFK = false; + $name = null; + $constraints = array(); + + foreach ($results as $row) { + if ($row['CONSTRAINT_NAME'] !== $name) { + $name = $row['CONSTRAINT_NAME']; + $constraints[$name] = array( + 'constraint_name' => $name, + 'constraint_type' => $this->getConstraintType($row['CONSTRAINT_TYPE']), + 'table_name' => $row['TABLE_NAME'], + ); + + if ('C' == $row['CONSTRAINT_TYPE']) { + $constraints[$name]['CHECK_CLAUSE'] = $row['CHECK_CLAUSE']; + continue; + } + + $constraints[$name]['columns'] = array(); + + $isFK = ('R' == $row['CONSTRAINT_TYPE']); + if ($isFK) { + $constraints[$name]['referenced_table_schema'] = $row['REF_OWNER']; + $constraints[$name]['referenced_table_name'] = $row['REF_TABLE']; + $constraints[$name]['referenced_columns'] = array(); + $constraints[$name]['match_option'] = 'NONE'; + $constraints[$name]['update_rule'] = null; + $constraints[$name]['delete_rule'] = $row['DELETE_RULE']; + } + } + + $constraints[$name]['columns'][] = $row['COLUMN_NAME']; + if ($isFK) { + $constraints[$name]['referenced_columns'][] = $row['REF_COLUMN']; + } + } + + return $this; + } + + /** + * {@inheritdoc} + * @see \Zend\Db\Metadata\Source\AbstractSource::loadSchemaData() + */ + protected function loadSchemaData() + { + if (isset($this->data['schemas'])) { + return; + } + + $this->prepareDataHierarchy('schemas'); + $sql = 'SELECT USERNAME FROM ALL_USERS'; + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $schemas = array(); + foreach ($results->toArray() as $row) { + $schemas[] = $row['USERNAME']; + } + + $this->data['schemas'] = $schemas; + } + + /** + * {@inheritdoc} + * @see \Zend\Db\Metadata\Source\AbstractSource::loadTableNameData() + */ + protected function loadTableNameData($schema) + { + if (isset($this->data['table_names'][$schema])) { + return $this; + } + + $this->prepareDataHierarchy('table_names', $schema); + $tables = array(); + + // Tables + $bind = array(':OWNER' => strtoupper($schema)); + $result = $this->adapter->query('SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER=:OWNER')->execute($bind); + + foreach ($result as $row) { + $tables[$row['TABLE_NAME']] = array( + 'table_type' => 'BASE TABLE', + 'view_definition' => null, + 'check_option' => null, + 'is_updatable' => false, + ); + } + + // Views + $result = $this->adapter->query('SELECT VIEW_NAME, TEXT FROM ALL_VIEWS WHERE OWNER=:OWNER', $bind); + foreach ($result as $row) { + $tables[$row['VIEW_NAME']] = array( + 'table_type' => 'VIEW', + 'view_definition' => null, + 'check_option' => 'NONE', + 'is_updatable' => false, + ); + } + + $this->data['table_names'][$schema] = $tables; + return $this; + } + + /** + * FIXME: load trigger data + * + * {@inheritdoc} + * + * @see \Zend\Db\Metadata\Source\AbstractSource::loadTriggerData() + */ + protected function loadTriggerData($schema) + { + if (isset($this->data['triggers'][$schema])) { + return; + } + + $this->prepareDataHierarchy('triggers', $schema); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/PostgresqlMetadata.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/PostgresqlMetadata.php new file mode 100644 index 0000000000000000000000000000000000000000..6fb731b4b55b9dcaf45c9651b70616e28c7c111d --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/PostgresqlMetadata.php @@ -0,0 +1,348 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata\Source; + +use Zend\Db\Adapter\Adapter; + +class PostgresqlMetadata extends AbstractSource +{ + + protected function loadSchemaData() + { + if (isset($this->data['schemas'])) { + return; + } + $this->prepareDataHierarchy('schemas'); + + $p = $this->adapter->getPlatform(); + + $sql = 'SELECT ' . $p->quoteIdentifier('schema_name') + . ' FROM ' . $p->quoteIdentifierChain(array('information_schema', 'schemata')) + . ' WHERE ' . $p->quoteIdentifier('schema_name') + . ' != \'information_schema\'' + . ' AND ' . $p->quoteIdentifier('schema_name') . " NOT LIKE 'pg_%'"; + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $schemas = array(); + foreach ($results->toArray() as $row) { + $schemas[] = $row['schema_name']; + } + + $this->data['schemas'] = $schemas; + } + + protected function loadTableNameData($schema) + { + if (isset($this->data['table_names'][$schema])) { + return; + } + $this->prepareDataHierarchy('table_names', $schema); + + $p = $this->adapter->getPlatform(); + + $isColumns = array( + array('t', 'table_name'), + array('t', 'table_type'), + array('v', 'view_definition'), + array('v', 'check_option'), + array('v', 'is_updatable'), + ); + + array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $p->quoteIdentifierChain(array('information_schema', 'tables')) . ' t' + + . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('information_schema', 'views')) . ' v' + . ' ON ' . $p->quoteIdentifierChain(array('t', 'table_schema')) + . ' = ' . $p->quoteIdentifierChain(array('v', 'table_schema')) + . ' AND ' . $p->quoteIdentifierChain(array('t', 'table_name')) + . ' = ' . $p->quoteIdentifierChain(array('v', 'table_name')) + + . ' WHERE ' . $p->quoteIdentifierChain(array('t', 'table_type')) + . ' IN (\'BASE TABLE\', \'VIEW\')'; + + if ($schema != self::DEFAULT_SCHEMA) { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('t', 'table_schema')) + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('t', 'table_schema')) + . ' != \'information_schema\''; + } + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $tables = array(); + foreach ($results->toArray() as $row) { + $tables[$row['table_name']] = array( + 'table_type' => $row['table_type'], + 'view_definition' => $row['view_definition'], + 'check_option' => $row['check_option'], + 'is_updatable' => ('YES' == $row['is_updatable']), + ); + } + + $this->data['table_names'][$schema] = $tables; + } + + protected function loadColumnData($table, $schema) + { + if (isset($this->data['columns'][$schema][$table])) { + return; + } + + $this->prepareDataHierarchy('columns', $schema, $table); + + $platform = $this->adapter->getPlatform(); + + $isColumns = array( + 'table_name', + 'column_name', + 'ordinal_position', + 'column_default', + 'is_nullable', + 'data_type', + 'character_maximum_length', + 'character_octet_length', + 'numeric_precision', + 'numeric_scale', + ); + + array_walk($isColumns, function (&$c) use ($platform) { $c = $platform->quoteIdentifier($c); }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $platform->quoteIdentifier('information_schema') + . $platform->getIdentifierSeparator() . $platform->quoteIdentifier('columns') + . ' WHERE ' . $platform->quoteIdentifier('table_schema') + . ' != \'information\'' + . ' AND ' . $platform->quoteIdentifier('table_name') + . ' = ' . $platform->quoteTrustedValue($table); + + if ($schema != '__DEFAULT_SCHEMA__') { + $sql .= ' AND ' . $platform->quoteIdentifier('table_schema') + . ' = ' . $platform->quoteTrustedValue($schema); + } + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + $columns = array(); + foreach ($results->toArray() as $row) { + $columns[$row['column_name']] = array( + 'ordinal_position' => $row['ordinal_position'], + 'column_default' => $row['column_default'], + 'is_nullable' => ('YES' == $row['is_nullable']), + 'data_type' => $row['data_type'], + 'character_maximum_length' => $row['character_maximum_length'], + 'character_octet_length' => $row['character_octet_length'], + 'numeric_precision' => $row['numeric_precision'], + 'numeric_scale' => $row['numeric_scale'], + 'numeric_unsigned' => null, + 'erratas' => array(), + ); + } + + $this->data['columns'][$schema][$table] = $columns; + } + + protected function loadConstraintData($table, $schema) + { + if (isset($this->data['constraints'][$schema][$table])) { + return; + } + + $this->prepareDataHierarchy('constraints', $schema, $table); + + $isColumns = array( + array('t', 'table_name'), + array('tc', 'constraint_name'), + array('tc', 'constraint_type'), + array('kcu', 'column_name'), + array('cc', 'check_clause'), + array('rc', 'match_option'), + array('rc', 'update_rule'), + array('rc', 'delete_rule'), + array('referenced_table_schema' => 'kcu2', 'table_schema'), + array('referenced_table_name' => 'kcu2', 'table_name'), + array('referenced_column_name' => 'kcu2', 'column_name'), + ); + + $p = $this->adapter->getPlatform(); + + array_walk($isColumns, function (&$c) use ($p) { + $alias = key($c); + $c = $p->quoteIdentifierChain($c); + if (is_string($alias)) { + $c .= ' ' . $p->quoteIdentifier($alias); + } + }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $p->quoteIdentifierChain(array('information_schema', 'tables')) . ' t' + + . ' INNER JOIN ' . $p->quoteIdentifierChain(array('information_schema', 'table_constraints')) . ' tc' + . ' ON ' . $p->quoteIdentifierChain(array('t', 'table_schema')) + . ' = ' . $p->quoteIdentifierChain(array('tc', 'table_schema')) + . ' AND ' . $p->quoteIdentifierChain(array('t', 'table_name')) + . ' = ' . $p->quoteIdentifierChain(array('tc', 'table_name')) + + . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('information_schema', 'key_column_usage')) . ' kcu' + . ' ON ' . $p->quoteIdentifierChain(array('tc', 'table_schema')) + . ' = ' . $p->quoteIdentifierChain(array('kcu', 'table_schema')) + . ' AND ' . $p->quoteIdentifierChain(array('tc', 'table_name')) + . ' = ' . $p->quoteIdentifierChain(array('kcu', 'table_name')) + . ' AND ' . $p->quoteIdentifierChain(array('tc', 'constraint_name')) + . ' = ' . $p->quoteIdentifierChain(array('kcu', 'constraint_name')) + + . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('information_schema', 'check_constraints')) . ' cc' + . ' ON ' . $p->quoteIdentifierChain(array('tc', 'constraint_schema')) + . ' = ' . $p->quoteIdentifierChain(array('cc', 'constraint_schema')) + . ' AND ' . $p->quoteIdentifierChain(array('tc', 'constraint_name')) + . ' = ' . $p->quoteIdentifierChain(array('cc', 'constraint_name')) + + . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('information_schema', 'referential_constraints')) . ' rc' + . ' ON ' . $p->quoteIdentifierChain(array('tc', 'constraint_schema')) + . ' = ' . $p->quoteIdentifierChain(array('rc', 'constraint_schema')) + . ' AND ' . $p->quoteIdentifierChain(array('tc', 'constraint_name')) + . ' = ' . $p->quoteIdentifierChain(array('rc', 'constraint_name')) + + . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('information_schema', 'key_column_usage')) . ' kcu2' + . ' ON ' . $p->quoteIdentifierChain(array('rc', 'unique_constraint_schema')) + . ' = ' . $p->quoteIdentifierChain(array('kcu2', 'constraint_schema')) + . ' AND ' . $p->quoteIdentifierChain(array('rc', 'unique_constraint_name')) + . ' = ' . $p->quoteIdentifierChain(array('kcu2', 'constraint_name')) + . ' AND ' . $p->quoteIdentifierChain(array('kcu', 'position_in_unique_constraint')) + . ' = ' . $p->quoteIdentifierChain(array('kcu2', 'ordinal_position')) + + . ' WHERE ' . $p->quoteIdentifierChain(array('t', 'table_name')) + . ' = ' . $p->quoteTrustedValue($table) + . ' AND ' . $p->quoteIdentifierChain(array('t', 'table_type')) + . ' IN (\'BASE TABLE\', \'VIEW\')'; + + if ($schema != self::DEFAULT_SCHEMA) { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('t', 'table_schema')) + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('t', 'table_schema')) + . ' != \'information_schema\''; + } + + $sql .= ' ORDER BY CASE ' . $p->quoteIdentifierChain(array('tc', 'constraint_type')) + . " WHEN 'PRIMARY KEY' THEN 1" + . " WHEN 'UNIQUE' THEN 2" + . " WHEN 'FOREIGN KEY' THEN 3" + . " WHEN 'CHECK' THEN 4" + . " ELSE 5 END" + . ', ' . $p->quoteIdentifierChain(array('tc', 'constraint_name')) + . ', ' . $p->quoteIdentifierChain(array('kcu', 'ordinal_position')); + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $name = null; + $constraints = array(); + foreach ($results->toArray() as $row) { + if ($row['constraint_name'] !== $name) { + $name = $row['constraint_name']; + $constraints[$name] = array( + 'constraint_name' => $name, + 'constraint_type' => $row['constraint_type'], + 'table_name' => $row['table_name'], + ); + if ('CHECK' == $row['constraint_type']) { + $constraints[$name]['check_clause'] = $row['check_clause']; + continue; + } + $constraints[$name]['columns'] = array(); + $isFK = ('FOREIGN KEY' == $row['constraint_type']); + if ($isFK) { + $constraints[$name]['referenced_table_schema'] = $row['referenced_table_schema']; + $constraints[$name]['referenced_table_name'] = $row['referenced_table_name']; + $constraints[$name]['referenced_columns'] = array(); + $constraints[$name]['match_option'] = $row['match_option']; + $constraints[$name]['update_rule'] = $row['update_rule']; + $constraints[$name]['delete_rule'] = $row['delete_rule']; + } + } + $constraints[$name]['columns'][] = $row['column_name']; + if ($isFK) { + $constraints[$name]['referenced_columns'][] = $row['referenced_column_name']; + } + } + + $this->data['constraints'][$schema][$table] = $constraints; + } + + protected function loadTriggerData($schema) + { + if (isset($this->data['triggers'][$schema])) { + return; + } + + $this->prepareDataHierarchy('triggers', $schema); + + $p = $this->adapter->getPlatform(); + + $isColumns = array( + 'trigger_name', + 'event_manipulation', + 'event_object_catalog', + 'event_object_schema', + 'event_object_table', + 'action_order', + 'action_condition', + 'action_statement', + 'action_orientation', + array('action_timing' => 'condition_timing'), + array('action_reference_old_table' => 'condition_reference_old_table'), + array('action_reference_new_table' => 'condition_reference_new_table'), + 'created', + ); + + array_walk($isColumns, function (&$c) use ($p) { + if (is_array($c)) { + $alias = key($c); + $c = $p->quoteIdentifierChain($c); + if (is_string($alias)) { + $c .= ' ' . $p->quoteIdentifier($alias); + } + } else { + $c = $p->quoteIdentifier($c); + } + }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $p->quoteIdentifierChain(array('information_schema', 'triggers')) + . ' WHERE '; + + if ($schema != self::DEFAULT_SCHEMA) { + $sql .= $p->quoteIdentifier('trigger_schema') + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= $p->quoteIdentifier('trigger_schema') + . ' != \'information_schema\''; + } + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $data = array(); + foreach ($results->toArray() as $row) { + $row = array_change_key_case($row, CASE_LOWER); + $row['action_reference_old_row'] = 'OLD'; + $row['action_reference_new_row'] = 'NEW'; + if (null !== $row['created']) { + $row['created'] = new \DateTime($row['created']); + } + $data[$row['trigger_name']] = $row; + } + + $this->data['triggers'][$schema] = $data; + } + + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/SqlServerMetadata.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/SqlServerMetadata.php new file mode 100644 index 0000000000000000000000000000000000000000..16937bc5d9fe9869d3769d4973ce4f80d28e397b --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/SqlServerMetadata.php @@ -0,0 +1,343 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata\Source; + +use Zend\Db\Adapter\Adapter; + +class SqlServerMetadata extends AbstractSource +{ + + + protected function loadSchemaData() + { + if (isset($this->data['schemas'])) { + return; + } + $this->prepareDataHierarchy('schemas'); + + $p = $this->adapter->getPlatform(); + + $sql = 'SELECT ' . $p->quoteIdentifier('SCHEMA_NAME') + . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'SCHEMATA')) + . ' WHERE ' . $p->quoteIdentifier('SCHEMA_NAME') + . ' != \'INFORMATION_SCHEMA\''; + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $schemas = array(); + foreach ($results->toArray() as $row) { + $schemas[] = $row['SCHEMA_NAME']; + } + + $this->data['schemas'] = $schemas; + } + + protected function loadTableNameData($schema) + { + if (isset($this->data['table_names'][$schema])) { + return; + } + $this->prepareDataHierarchy('table_names', $schema); + + $p = $this->adapter->getPlatform(); + + $isColumns = array( + array('T', 'TABLE_NAME'), + array('T', 'TABLE_TYPE'), + array('V', 'VIEW_DEFINITION'), + array('V', 'CHECK_OPTION'), + array('V', 'IS_UPDATABLE'), + ); + + array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . ' t' + + . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'VIEWS')) . ' v' + . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('V', 'TABLE_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('V', 'TABLE_NAME')) + + . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' IN (\'BASE TABLE\', \'VIEW\')'; + + if ($schema != self::DEFAULT_SCHEMA) { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' != \'INFORMATION_SCHEMA\''; + } + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $tables = array(); + foreach ($results->toArray() as $row) { + $tables[$row['TABLE_NAME']] = array( + 'table_type' => $row['TABLE_TYPE'], + 'view_definition' => $row['VIEW_DEFINITION'], + 'check_option' => $row['CHECK_OPTION'], + 'is_updatable' => ('YES' == $row['IS_UPDATABLE']), + ); + } + + $this->data['table_names'][$schema] = $tables; + } + + protected function loadColumnData($table, $schema) + { + if (isset($this->data['columns'][$schema][$table])) { + return; + } + $this->prepareDataHierarchy('columns', $schema, $table); + $p = $this->adapter->getPlatform(); + + $isColumns = array( + array('C', 'ORDINAL_POSITION'), + array('C', 'COLUMN_DEFAULT'), + array('C', 'IS_NULLABLE'), + array('C', 'DATA_TYPE'), + array('C', 'CHARACTER_MAXIMUM_LENGTH'), + array('C', 'CHARACTER_OCTET_LENGTH'), + array('C', 'NUMERIC_PRECISION'), + array('C', 'NUMERIC_SCALE'), + array('C', 'COLUMN_NAME'), + ); + + array_walk($isColumns, function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . 'T' + . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'COLUMNS')) . 'C' + . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('C', 'TABLE_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('C', 'TABLE_NAME')) + . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' IN (\'BASE TABLE\', \'VIEW\')' + . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' = ' . $p->quoteTrustedValue($table); + + if ($schema != self::DEFAULT_SCHEMA) { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' != \'INFORMATION_SCHEMA\''; + } + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + $columns = array(); + foreach ($results->toArray() as $row) { + $columns[$row['COLUMN_NAME']] = array( + 'ordinal_position' => $row['ORDINAL_POSITION'], + 'column_default' => $row['COLUMN_DEFAULT'], + 'is_nullable' => ('YES' == $row['IS_NULLABLE']), + 'data_type' => $row['DATA_TYPE'], + 'character_maximum_length' => $row['CHARACTER_MAXIMUM_LENGTH'], + 'character_octet_length' => $row['CHARACTER_OCTET_LENGTH'], + 'numeric_precision' => $row['NUMERIC_PRECISION'], + 'numeric_scale' => $row['NUMERIC_SCALE'], + 'numeric_unsigned' => null, + 'erratas' => array(), + ); + } + + $this->data['columns'][$schema][$table] = $columns; + } + + protected function loadConstraintData($table, $schema) + { + if (isset($this->data['constraints'][$schema][$table])) { + return; + } + + $this->prepareDataHierarchy('constraints', $schema, $table); + + $isColumns = array( + array('T', 'TABLE_NAME'), + array('TC', 'CONSTRAINT_NAME'), + array('TC', 'CONSTRAINT_TYPE'), + array('KCU', 'COLUMN_NAME'), + array('CC', 'CHECK_CLAUSE'), + array('RC', 'MATCH_OPTION'), + array('RC', 'UPDATE_RULE'), + array('RC', 'DELETE_RULE'), + array('REFERENCED_TABLE_SCHEMA' => 'KCU2', 'TABLE_SCHEMA'), + array('REFERENCED_TABLE_NAME' => 'KCU2', 'TABLE_NAME'), + array('REFERENCED_COLUMN_NAME' => 'KCU2', 'COLUMN_NAME'), + ); + + $p = $this->adapter->getPlatform(); + + array_walk($isColumns, function (&$c) use ($p) { + $alias = key($c); + $c = $p->quoteIdentifierChain($c); + if (is_string($alias)) { + $c .= ' ' . $p->quoteIdentifier($alias); + } + }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLES')) . ' T' + + . ' INNER JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TABLE_CONSTRAINTS')) . ' TC' + . ' ON ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('TC', 'TABLE_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('TC', 'TABLE_NAME')) + + . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE')) . ' KCU' + . ' ON ' . $p->quoteIdentifierChain(array('TC', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('TC', 'TABLE_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('KCU', 'TABLE_NAME')) + . ' AND ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('KCU', 'CONSTRAINT_NAME')) + + . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'CHECK_CONSTRAINTS')) . ' CC' + . ' ON ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('CC', 'CONSTRAINT_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('CC', 'CONSTRAINT_NAME')) + + . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'REFERENTIAL_CONSTRAINTS')) . ' RC' + . ' ON ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('RC', 'CONSTRAINT_NAME')) + + . ' LEFT JOIN ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'KEY_COLUMN_USAGE')) . ' KCU2' + . ' ON ' . $p->quoteIdentifierChain(array('RC', 'UNIQUE_CONSTRAINT_SCHEMA')) + . ' = ' . $p->quoteIdentifierChain(array('KCU2', 'CONSTRAINT_SCHEMA')) + . ' AND ' . $p->quoteIdentifierChain(array('RC', 'UNIQUE_CONSTRAINT_NAME')) + . ' = ' . $p->quoteIdentifierChain(array('KCU2', 'CONSTRAINT_NAME')) + . ' AND ' . $p->quoteIdentifierChain(array('KCU', 'ORDINAL_POSITION')) + . ' = ' . $p->quoteIdentifierChain(array('KCU2', 'ORDINAL_POSITION')) + + . ' WHERE ' . $p->quoteIdentifierChain(array('T', 'TABLE_NAME')) + . ' = ' . $p->quoteTrustedValue($table) + . ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_TYPE')) + . ' IN (\'BASE TABLE\', \'VIEW\')'; + + if ($schema != self::DEFAULT_SCHEMA) { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= ' AND ' . $p->quoteIdentifierChain(array('T', 'TABLE_SCHEMA')) + . ' != \'INFORMATION_SCHEMA\''; + } + + $sql .= ' ORDER BY CASE ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_TYPE')) + . " WHEN 'PRIMARY KEY' THEN 1" + . " WHEN 'UNIQUE' THEN 2" + . " WHEN 'FOREIGN KEY' THEN 3" + . " WHEN 'CHECK' THEN 4" + . " ELSE 5 END" + . ', ' . $p->quoteIdentifierChain(array('TC', 'CONSTRAINT_NAME')) + . ', ' . $p->quoteIdentifierChain(array('KCU', 'ORDINAL_POSITION')); + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $name = null; + $constraints = array(); + $isFK = false; + foreach ($results->toArray() as $row) { + if ($row['CONSTRAINT_NAME'] !== $name) { + $name = $row['CONSTRAINT_NAME']; + $constraints[$name] = array( + 'constraint_name' => $name, + 'constraint_type' => $row['CONSTRAINT_TYPE'], + 'table_name' => $row['TABLE_NAME'], + ); + if ('CHECK' == $row['CONSTRAINT_TYPE']) { + $constraints[$name]['check_clause'] = $row['CHECK_CLAUSE']; + continue; + } + $constraints[$name]['columns'] = array(); + $isFK = ('FOREIGN KEY' == $row['CONSTRAINT_TYPE']); + if ($isFK) { + $constraints[$name]['referenced_table_schema'] = $row['REFERENCED_TABLE_SCHEMA']; + $constraints[$name]['referenced_table_name'] = $row['REFERENCED_TABLE_NAME']; + $constraints[$name]['referenced_columns'] = array(); + $constraints[$name]['match_option'] = $row['MATCH_OPTION']; + $constraints[$name]['update_rule'] = $row['UPDATE_RULE']; + $constraints[$name]['delete_rule'] = $row['DELETE_RULE']; + } + } + $constraints[$name]['columns'][] = $row['COLUMN_NAME']; + if ($isFK) { + $constraints[$name]['referenced_columns'][] = $row['REFERENCED_COLUMN_NAME']; + } + } + + $this->data['constraints'][$schema][$table] = $constraints; + } + + protected function loadTriggerData($schema) + { + if (isset($this->data['triggers'][$schema])) { + return; + } + + $this->prepareDataHierarchy('triggers', $schema); + + $p = $this->adapter->getPlatform(); + + $isColumns = array( + 'TRIGGER_NAME', + 'EVENT_MANIPULATION', + 'EVENT_OBJECT_CATALOG', + 'EVENT_OBJECT_SCHEMA', + 'EVENT_OBJECT_TABLE', + 'ACTION_ORDER', + 'ACTION_CONDITION', + 'ACTION_STATEMENT', + 'ACTION_ORIENTATION', + 'ACTION_TIMING', + 'ACTION_REFERENCE_OLD_TABLE', + 'ACTION_REFERENCE_NEW_TABLE', + 'ACTION_REFERENCE_OLD_ROW', + 'ACTION_REFERENCE_NEW_ROW', + 'CREATED', + ); + + array_walk($isColumns, function (&$c) use ($p) { + $c = $p->quoteIdentifier($c); + }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $p->quoteIdentifierChain(array('INFORMATION_SCHEMA', 'TRIGGERS')) + . ' WHERE '; + + if ($schema != self::DEFAULT_SCHEMA) { + $sql .= $p->quoteIdentifier('TRIGGER_SCHEMA') + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= $p->quoteIdentifier('TRIGGER_SCHEMA') + . ' != \'INFORMATION_SCHEMA\''; + } + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + + $data = array(); + foreach ($results->toArray() as $row) { + $row = array_change_key_case($row, CASE_LOWER); + if (null !== $row['created']) { + $row['created'] = new \DateTime($row['created']); + } + $data[$row['trigger_name']] = $row; + } + + $this->data['triggers'][$schema] = $data; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/SqliteMetadata.php b/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/SqliteMetadata.php new file mode 100644 index 0000000000000000000000000000000000000000..16589616973ef2dd3e58726a4662632a51832378 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Metadata/Source/SqliteMetadata.php @@ -0,0 +1,392 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Metadata\Source; + +use Zend\Db\Adapter\Adapter; +use Zend\Db\ResultSet\ResultSetInterface; + +class SqliteMetadata extends AbstractSource +{ + protected function loadSchemaData() + { + if (isset($this->data['schemas'])) { + return; + } + $this->prepareDataHierarchy('schemas'); + + $results = $this->fetchPragma('database_list'); + foreach ($results as $row) { + $schemas[] = $row['name']; + } + $this->data['schemas'] = $schemas; + } + + protected function loadTableNameData($schema) + { + if (isset($this->data['table_names'][$schema])) { + return; + } + $this->prepareDataHierarchy('table_names', $schema); + + // FEATURE: Filename? + + $p = $this->adapter->getPlatform(); + + $sql = 'SELECT "name", "type", "sql" FROM ' . $p->quoteIdentifierChain(array($schema, 'sqlite_master')) + . ' WHERE "type" IN (\'table\',\'view\') AND "name" NOT LIKE \'sqlite_%\''; + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + $tables = array(); + foreach ($results->toArray() as $row) { + if ('table' == $row['type']) { + $table = array( + 'table_type' => 'BASE TABLE', + 'view_definition' => null, // VIEW only + 'check_option' => null, // VIEW only + 'is_updatable' => null, // VIEW only + ); + } else { + $table = array( + 'table_type' => 'VIEW', + 'view_definition' => null, + 'check_option' => 'NONE', + 'is_updatable' => false, + ); + + // Parse out extra data + if (null !== ($data = $this->parseView($row['sql']))) { + $table = array_merge($table, $data); + } + } + $tables[$row['name']] = $table; + } + $this->data['table_names'][$schema] = $tables; + } + + protected function loadColumnData($table, $schema) + { + if (isset($this->data['columns'][$schema][$table])) { + return; + } + $this->prepareDataHierarchy('columns', $schema, $table); + $this->prepareDataHierarchy('sqlite_columns', $schema, $table); + + $p = $this->adapter->getPlatform(); + + + $results = $this->fetchPragma('table_info', $table, $schema); + + $columns = array(); + + foreach ($results as $row) { + $columns[$row['name']] = array( + // cid appears to be zero-based, ordinal position needs to be one-based + 'ordinal_position' => $row['cid'] + 1, + 'column_default' => $row['dflt_value'], + 'is_nullable' => !((bool) $row['notnull']), + 'data_type' => $row['type'], + 'character_maximum_length' => null, + 'character_octet_length' => null, + 'numeric_precision' => null, + 'numeric_scale' => null, + 'numeric_unsigned' => null, + 'erratas' => array(), + ); + // TODO: populate character_ and numeric_values with correct info + } + + $this->data['columns'][$schema][$table] = $columns; + $this->data['sqlite_columns'][$schema][$table] = $results; + } + + protected function loadConstraintData($table, $schema) + { + if (isset($this->data['constraints'][$schema][$table])) { + return; + } + + $this->prepareDataHierarchy('constraints', $schema, $table); + + $this->loadColumnData($table, $schema); + $primaryKey = array(); + + foreach ($this->data['sqlite_columns'][$schema][$table] as $col) { + if ((bool) $col['pk']) { + $primaryKey[] = $col['name']; + } + } + + if (empty($primaryKey)) { + $primaryKey = null; + } + $constraints = array(); + $indexes = $this->fetchPragma('index_list', $table, $schema); + foreach ($indexes as $index) { + if (!((bool) $index['unique'])) { + continue; + } + $constraint = array( + 'constraint_name' => $index['name'], + 'constraint_type' => 'UNIQUE', + 'table_name' => $table, + 'columns' => array(), + ); + + $info = $this->fetchPragma('index_info', $index['name'], $schema); + + foreach ($info as $column) { + $constraint['columns'][] = $column['name']; + } + if ($primaryKey === $constraint['columns']) { + $constraint['constraint_type'] = 'PRIMARY KEY'; + $primaryKey = null; + } + $constraints[$constraint['constraint_name']] = $constraint; + } + + if (null !== $primaryKey) { + $constraintName = '_zf_' . $table . '_PRIMARY'; + $constraints[$constraintName] = array( + 'constraint_name' => $constraintName, + 'constraint_type' => 'PRIMARY KEY', + 'table_name' => $table, + 'columns' => $primaryKey, + ); + } + + $foreignKeys = $this->fetchPragma('foreign_key_list', $table, $schema); + + $id = $name = null; + foreach ($foreignKeys as $fk) { + if ($id !== $fk['id']) { + $id = $fk['id']; + $name = '_zf_' . $table . '_FOREIGN_KEY_' . ($id + 1); + $constraints[$name] = array( + 'constraint_name' => $name, + 'constraint_type' => 'FOREIGN KEY', + 'table_name' => $table, + 'columns' => array(), + 'referenced_table_schema' => $schema, + 'referenced_table_name' => $fk['table'], + 'referenced_columns' => array(), + // TODO: Verify match, on_update, and on_delete values conform to SQL Standard + 'match_option' => strtoupper($fk['match']), + 'update_rule' => strtoupper($fk['on_update']), + 'delete_rule' => strtoupper($fk['on_delete']), + ); + } + $constraints[$name]['columns'][] = $fk['from']; + $constraints[$name]['referenced_columns'][] = $fk['to']; + } + + $this->data['constraints'][$schema][$table] = $constraints; + } + + protected function loadTriggerData($schema) + { + if (isset($this->data['triggers'][$schema])) { + return; + } + + $this->prepareDataHierarchy('triggers', $schema); + + $p = $this->adapter->getPlatform(); + + $sql = 'SELECT "name", "tbl_name", "sql" FROM ' + . $p->quoteIdentifierChain(array($schema, 'sqlite_master')) + . ' WHERE "type" = \'trigger\''; + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + $triggers = array(); + foreach ($results->toArray() as $row) { + $trigger = array( + 'trigger_name' => $row['name'], + 'event_manipulation' => null, // in $row['sql'] + 'event_object_catalog' => null, + 'event_object_schema' => $schema, + 'event_object_table' => $row['tbl_name'], + 'action_order' => 0, + 'action_condition' => null, // in $row['sql'] + 'action_statement' => null, // in $row['sql'] + 'action_orientation' => 'ROW', + 'action_timing' => null, // in $row['sql'] + 'action_reference_old_table' => null, + 'action_reference_new_table' => null, + 'action_reference_old_row' => 'OLD', + 'action_reference_new_row' => 'NEW', + 'created' => null, + ); + + // Parse out extra data + if (null !== ($data = $this->parseTrigger($row['sql']))) { + $trigger = array_merge($trigger, $data); + } + $triggers[$trigger['trigger_name']] = $trigger; + } + + $this->data['triggers'][$schema] = $triggers; + } + + protected function fetchPragma($name, $value = null, $schema = null) + { + $p = $this->adapter->getPlatform(); + + $sql = 'PRAGMA '; + + if (null !== $schema) { + $sql .= $p->quoteIdentifier($schema) . '.'; + } + $sql .= $name; + + if (null !== $value) { + $sql .= '(' . $p->quoteTrustedValue($value) . ')'; + } + + $results = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); + if ($results instanceof ResultSetInterface) { + return $results->toArray(); + } + return array(); + } + + protected function parseView($sql) + { + static $re = null; + if (null === $re) { + $identifier = $this->getIdentifierRegularExpression(); + $identifierList = $this->getIdentifierListRegularExpression(); + $identifierChain = $this->getIdentifierChainRegularExpression(); + $re = $this->buildRegularExpression(array( + 'CREATE', + array('TEMP|TEMPORARY'), + 'VIEW', + array('IF', 'NOT', 'EXISTS'), + $identifierChain, + 'AS', + '(?<view_definition>.+)', + array(';'), + )); + } + + if (!preg_match($re, $sql, $matches)) { + return null; + } + return array( + 'view_definition' => $matches['view_definition'], + ); + } + + protected function parseTrigger($sql) + { + static $re = null; + if (null === $re) { + $identifier = $this->getIdentifierRegularExpression(); + $identifierList = $this->getIdentifierListRegularExpression(); + $identifierChain = $this->getIdentifierChainRegularExpression(); + $re = $this->buildRegularExpression(array( + 'CREATE', + array('TEMP|TEMPORARY'), + 'TRIGGER', + array('IF', 'NOT', 'EXISTS'), + $identifierChain, + array('(?<action_timing>BEFORE|AFTER|INSTEAD\\s+OF)',), + '(?<event_manipulation>DELETE|INSERT|UPDATE)', + array('OF', '(?<column_usage>' . $identifierList . ')'), + 'ON', + '(?<event_object_table>' . $identifier . ')', + array('FOR', 'EACH', 'ROW'), + array('WHEN', '(?<action_condition>.+)'), + '(?<action_statement>BEGIN', + '.+', + 'END)', + array(';'), + )); + } + + if (!preg_match($re, $sql, $matches)) { + return null; + } + $data = array(); + + foreach ($matches as $key => $value) { + if (is_string($key)) { + $data[$key] = $value; + } + } + + // Normalize data and populate defaults, if necessary + + $data['event_manipulation'] = strtoupper($data['event_manipulation']); + if (empty($data['action_condition'])) { + $data['action_condition'] = null; + } + if (!empty($data['action_timing'])) { + $data['action_timing'] = strtoupper($data['action_timing']); + if ('I' == $data['action_timing'][0]) { + // normalize the white-space between the two words + $data['action_timing'] = 'INSTEAD OF'; + } + } else { + $data['action_timing'] = 'AFTER'; + } + unset($data['column_usage']); + + return $data; + } + + protected function buildRegularExpression(array $re) + { + foreach ($re as &$value) { + if (is_array($value)) { + $value = '(?:' . implode('\\s*+', $value) . '\\s*+)?'; + } else { + $value .= '\\s*+'; + } + } + unset($value); + $re = '/^' . implode('\\s*+', $re) . '$/'; + return $re; + } + + protected function getIdentifierRegularExpression() + { + static $re = null; + if (null === $re) { + $re = '(?:' . implode('|', array( + '"(?:[^"\\\\]++|\\\\.)*+"', + '`(?:[^`]++|``)*+`', + '\\[[^\\]]+\\]', + '[^\\s\\.]+', + )) . ')'; + } + + return $re; + } + + protected function getIdentifierChainRegularExpression() + { + static $re = null; + if (null === $re) { + $identifier = $this->getIdentifierRegularExpression(); + $re = $identifier . '(?:\\s*\\.\\s*' . $identifier . ')*+'; + } + return $re; + } + + protected function getIdentifierListRegularExpression() + { + static $re = null; + if (null === $re) { + $identifier = $this->getIdentifierRegularExpression(); + $re = $identifier . '(?:\\s*,\\s*' . $identifier . ')*+'; + } + return $re; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/README.md b/vendor/zendframework/zend-db/Zend/Db/README.md new file mode 100644 index 0000000000000000000000000000000000000000..5c67884071b97abd9d83402d9472be8b1b24e331 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/README.md @@ -0,0 +1,15 @@ +DB Component from ZF2 +===================== + +This is the DB component for ZF2. + +- File issues at https://github.com/zendframework/zf2/issues +- Create pull requests against https://github.com/zendframework/zf2 +- Documentation is at http://framework.zend.com/docs + +LICENSE +------- + +The files in this archive are released under the [Zend Framework +license](http://framework.zend.com/license), which is a 3-clause BSD license. + diff --git a/vendor/zendframework/zend-db/Zend/Db/ResultSet/AbstractResultSet.php b/vendor/zendframework/zend-db/Zend/Db/ResultSet/AbstractResultSet.php new file mode 100644 index 0000000000000000000000000000000000000000..0db4c2d385bcf23a8572ac7fe8e65cedd123b4ba --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/ResultSet/AbstractResultSet.php @@ -0,0 +1,280 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\ResultSet; + +use ArrayIterator; +use Countable; +use Iterator; +use IteratorAggregate; +use Zend\Db\Adapter\Driver\ResultInterface; + +abstract class AbstractResultSet implements Iterator, ResultSetInterface +{ + /** + * if -1, datasource is already buffered + * if -2, implicitly disabling buffering in ResultSet + * if false, explicitly disabled + * if null, default state - nothing, but can buffer until iteration started + * if array, already buffering + * @var mixed + */ + protected $buffer = null; + + /** + * @var null|int + */ + protected $count = null; + + /** + * @var Iterator|IteratorAggregate|ResultInterface + */ + protected $dataSource = null; + + /** + * @var int + */ + protected $fieldCount = null; + + /** + * @var int + */ + protected $position = 0; + + /** + * Set the data source for the result set + * + * @param Iterator|IteratorAggregate|ResultInterface $dataSource + * @return ResultSet + * @throws Exception\InvalidArgumentException + */ + public function initialize($dataSource) + { + // reset buffering + if (is_array($this->buffer)) { + $this->buffer = array(); + } + + if ($dataSource instanceof ResultInterface) { + $this->count = $dataSource->count(); + $this->fieldCount = $dataSource->getFieldCount(); + $this->dataSource = $dataSource; + if ($dataSource->isBuffered()) { + $this->buffer = -1; + } + if (is_array($this->buffer)) { + $this->dataSource->rewind(); + } + return $this; + } + + if (is_array($dataSource)) { + // its safe to get numbers from an array + $first = current($dataSource); + reset($dataSource); + $this->count = count($dataSource); + $this->fieldCount = count($first); + $this->dataSource = new ArrayIterator($dataSource); + $this->buffer = -1; // array's are a natural buffer + } elseif ($dataSource instanceof IteratorAggregate) { + $this->dataSource = $dataSource->getIterator(); + } elseif ($dataSource instanceof Iterator) { + $this->dataSource = $dataSource; + } else { + throw new Exception\InvalidArgumentException('DataSource provided is not an array, nor does it implement Iterator or IteratorAggregate'); + } + + if ($this->count == null && $this->dataSource instanceof Countable) { + $this->count = $this->dataSource->count(); + } + + return $this; + } + + public function buffer() + { + if ($this->buffer === -2) { + throw new Exception\RuntimeException('Buffering must be enabled before iteration is started'); + } elseif ($this->buffer === null) { + $this->buffer = array(); + if ($this->dataSource instanceof ResultInterface) { + $this->dataSource->rewind(); + } + } + return $this; + } + + public function isBuffered() + { + if ($this->buffer === -1 || is_array($this->buffer)) { + return true; + } + return false; + } + + /** + * Get the data source used to create the result set + * + * @return null|Iterator + */ + public function getDataSource() + { + return $this->dataSource; + } + + /** + * Retrieve count of fields in individual rows of the result set + * + * @return int + */ + public function getFieldCount() + { + if (null !== $this->fieldCount) { + return $this->fieldCount; + } + + $dataSource = $this->getDataSource(); + if (null === $dataSource) { + return 0; + } + + $dataSource->rewind(); + if (!$dataSource->valid()) { + $this->fieldCount = 0; + return 0; + } + + $row = $dataSource->current(); + if (is_object($row) && $row instanceof Countable) { + $this->fieldCount = $row->count(); + return $this->fieldCount; + } + + $row = (array) $row; + $this->fieldCount = count($row); + return $this->fieldCount; + } + + /** + * Iterator: move pointer to next item + * + * @return void + */ + public function next() + { + if ($this->buffer === null) { + $this->buffer = -2; // implicitly disable buffering from here on + } + $this->dataSource->next(); + $this->position++; + } + + /** + * Iterator: retrieve current key + * + * @return mixed + */ + public function key() + { + return $this->position; + } + + /** + * Iterator: get current item + * + * @return array + */ + public function current() + { + if ($this->buffer === null) { + $this->buffer = -2; // implicitly disable buffering from here on + } elseif (is_array($this->buffer) && isset($this->buffer[$this->position])) { + return $this->buffer[$this->position]; + } + $data = $this->dataSource->current(); + if (is_array($this->buffer)) { + $this->buffer[$this->position] = $data; + } + return $data; + } + + /** + * Iterator: is pointer valid? + * + * @return bool + */ + public function valid() + { + if (is_array($this->buffer) && isset($this->buffer[$this->position])) { + return true; + } + if ($this->dataSource instanceof Iterator) { + return $this->dataSource->valid(); + } else { + $key = key($this->dataSource); + return ($key !== null); + } + } + + /** + * Iterator: rewind + * + * @return void + */ + public function rewind() + { + if (!is_array($this->buffer)) { + if ($this->dataSource instanceof Iterator) { + $this->dataSource->rewind(); + } else { + reset($this->dataSource); + } + } + $this->position = 0; + } + + /** + * Countable: return count of rows + * + * @return int + */ + public function count() + { + if ($this->count !== null) { + return $this->count; + } + $this->count = count($this->dataSource); + return $this->count; + } + + /** + * Cast result set to array of arrays + * + * @return array + * @throws Exception\RuntimeException if any row is not castable to an array + */ + public function toArray() + { + $return = array(); + foreach ($this as $row) { + if (is_array($row)) { + $return[] = $row; + } elseif (method_exists($row, 'toArray')) { + $return[] = $row->toArray(); + } elseif (method_exists($row, 'getArrayCopy')) { + $return[] = $row->getArrayCopy(); + } else { + throw new Exception\RuntimeException( + 'Rows as part of this DataSource, with type ' . gettype($row) . ' cannot be cast to an array' + ); + } + } + return $return; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/ResultSet/Exception/ExceptionInterface.php b/vendor/zendframework/zend-db/Zend/Db/ResultSet/Exception/ExceptionInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..7f7648b33fdd09475c808f192be444f78ea76be2 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/ResultSet/Exception/ExceptionInterface.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\ResultSet\Exception; + +use Zend\Db\Exception; + +interface ExceptionInterface extends Exception\ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/ResultSet/Exception/InvalidArgumentException.php b/vendor/zendframework/zend-db/Zend/Db/ResultSet/Exception/InvalidArgumentException.php new file mode 100644 index 0000000000000000000000000000000000000000..42f3c93ae354b40037b339ccb18d646dba4977df --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/ResultSet/Exception/InvalidArgumentException.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\ResultSet\Exception; + +use Zend\Db\Exception; + +class InvalidArgumentException extends Exception\InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/ResultSet/Exception/RuntimeException.php b/vendor/zendframework/zend-db/Zend/Db/ResultSet/Exception/RuntimeException.php new file mode 100644 index 0000000000000000000000000000000000000000..f201ac10f7f55a41dc9c32eaaeb1e9a801fc627c --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/ResultSet/Exception/RuntimeException.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\ResultSet\Exception; + +use Zend\Db\Exception; + +class RuntimeException extends Exception\RuntimeException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/ResultSet/HydratingResultSet.php b/vendor/zendframework/zend-db/Zend/Db/ResultSet/HydratingResultSet.php new file mode 100644 index 0000000000000000000000000000000000000000..a4bd91629823268da29f35b668aba2453c00f496 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/ResultSet/HydratingResultSet.php @@ -0,0 +1,116 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\ResultSet; + +use ArrayObject; +use Zend\Stdlib\Hydrator\ArraySerializable; +use Zend\Stdlib\Hydrator\HydratorInterface; + +class HydratingResultSet extends AbstractResultSet +{ + /** + * @var HydratorInterface + */ + protected $hydrator = null; + + /** + * @var null + */ + protected $objectPrototype = null; + + /** + * Constructor + * + * @param null|HydratorInterface $hydrator + * @param null|object $objectPrototype + */ + public function __construct(HydratorInterface $hydrator = null, $objectPrototype = null) + { + $this->setHydrator(($hydrator) ?: new ArraySerializable); + $this->setObjectPrototype(($objectPrototype) ?: new ArrayObject); + } + + /** + * Set the row object prototype + * + * @param object $objectPrototype + * @throws Exception\InvalidArgumentException + * @return ResultSet + */ + public function setObjectPrototype($objectPrototype) + { + if (!is_object($objectPrototype)) { + throw new Exception\InvalidArgumentException( + 'An object must be set as the object prototype, a ' . gettype($objectPrototype) . ' was provided.' + ); + } + $this->objectPrototype = $objectPrototype; + return $this; + } + + /** + * Set the hydrator to use for each row object + * + * @param HydratorInterface $hydrator + * @return HydratingResultSet + */ + public function setHydrator(HydratorInterface $hydrator) + { + $this->hydrator = $hydrator; + return $this; + } + + /** + * Get the hydrator to use for each row object + * + * @return HydratorInterface + */ + public function getHydrator() + { + return $this->hydrator; + } + + /** + * Iterator: get current item + * + * @return object + */ + public function current() + { + if ($this->buffer === null) { + $this->buffer = -2; // implicitly disable buffering from here on + } elseif (is_array($this->buffer) && isset($this->buffer[$this->position])) { + return $this->buffer[$this->position]; + } + $data = $this->dataSource->current(); + $object = is_array($data) ? $this->hydrator->hydrate($data, clone $this->objectPrototype) : false; + + if (is_array($this->buffer)) { + $this->buffer[$this->position] = $object; + } + + return $object; + } + + /** + * Cast result set to array of arrays + * + * @return array + * @throws Exception\RuntimeException if any row is not castable to an array + */ + public function toArray() + { + $return = array(); + foreach ($this as $row) { + $return[] = $this->getHydrator()->extract($row); + } + return $return; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/ResultSet/ResultSet.php b/vendor/zendframework/zend-db/Zend/Db/ResultSet/ResultSet.php new file mode 100644 index 0000000000000000000000000000000000000000..2286410c659e8e9792c126e69e889b77dbcf67d2 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/ResultSet/ResultSet.php @@ -0,0 +1,112 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\ResultSet; + +use ArrayObject; + +class ResultSet extends AbstractResultSet +{ + const TYPE_ARRAYOBJECT = 'arrayobject'; + const TYPE_ARRAY = 'array'; + + /** + * Allowed return types + * + * @var array + */ + protected $allowedReturnTypes = array( + self::TYPE_ARRAYOBJECT, + self::TYPE_ARRAY, + ); + + /** + * @var ArrayObject + */ + protected $arrayObjectPrototype = null; + + /** + * Return type to use when returning an object from the set + * + * @var ResultSet::TYPE_ARRAYOBJECT|ResultSet::TYPE_ARRAY + */ + protected $returnType = self::TYPE_ARRAYOBJECT; + + /** + * Constructor + * + * @param string $returnType + * @param null|ArrayObject $arrayObjectPrototype + */ + public function __construct($returnType = self::TYPE_ARRAYOBJECT, $arrayObjectPrototype = null) + { + $this->returnType = (in_array($returnType, array(self::TYPE_ARRAY, self::TYPE_ARRAYOBJECT))) ? $returnType : self::TYPE_ARRAYOBJECT; + if ($this->returnType === self::TYPE_ARRAYOBJECT) { + $this->setArrayObjectPrototype(($arrayObjectPrototype) ?: new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS)); + } + } + + /** + * Set the row object prototype + * + * @param ArrayObject $arrayObjectPrototype + * @throws Exception\InvalidArgumentException + * @return ResultSet + */ + public function setArrayObjectPrototype($arrayObjectPrototype) + { + if (!is_object($arrayObjectPrototype) + || (!$arrayObjectPrototype instanceof ArrayObject && !method_exists($arrayObjectPrototype, 'exchangeArray')) + + ) { + throw new Exception\InvalidArgumentException('Object must be of type ArrayObject, or at least implement exchangeArray'); + } + $this->arrayObjectPrototype = $arrayObjectPrototype; + return $this; + } + + /** + * Get the row object prototype + * + * @return ArrayObject + */ + public function getArrayObjectPrototype() + { + return $this->arrayObjectPrototype; + } + + /** + * Get the return type to use when returning objects from the set + * + * @return string + */ + public function getReturnType() + { + return $this->returnType; + } + + /** + * @return array|\ArrayObject|null + */ + public function current() + { + $data = parent::current(); + + if ($this->returnType === self::TYPE_ARRAYOBJECT && is_array($data)) { + /** @var $ao ArrayObject */ + $ao = clone $this->arrayObjectPrototype; + if ($ao instanceof ArrayObject || method_exists($ao, 'exchangeArray')) { + $ao->exchangeArray($data); + } + return $ao; + } + + return $data; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/ResultSet/ResultSetInterface.php b/vendor/zendframework/zend-db/Zend/Db/ResultSet/ResultSetInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..c2bbd73b273e052d049d7aae20c07f044c630888 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/ResultSet/ResultSetInterface.php @@ -0,0 +1,33 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\ResultSet; + +use Countable; +use Traversable; + +interface ResultSetInterface extends Traversable, Countable +{ + /** + * Can be anything traversable|array + * @abstract + * @param $dataSource + * @return mixed + */ + public function initialize($dataSource); + + /** + * Field terminology is more correct as information coming back + * from the database might be a column, and/or the result of an + * operation or intersection of some data + * @abstract + * @return mixed + */ + public function getFieldCount(); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/RowGateway/AbstractRowGateway.php b/vendor/zendframework/zend-db/Zend/Db/RowGateway/AbstractRowGateway.php new file mode 100644 index 0000000000000000000000000000000000000000..4183bbf2c2e7e254ee77e6fb246404cfc5256d06 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/RowGateway/AbstractRowGateway.php @@ -0,0 +1,364 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\RowGateway; + +use ArrayAccess; +use Countable; +use Zend\Db\Sql\Sql; +use Zend\Db\Sql\TableIdentifier; + +abstract class AbstractRowGateway implements ArrayAccess, Countable, RowGatewayInterface +{ + + /** + * @var bool + */ + protected $isInitialized = false; + + /** + * @var string|TableIdentifier + */ + protected $table = null; + + /** + * @var array + */ + protected $primaryKeyColumn = null; + + /** + * @var array + */ + protected $primaryKeyData = null; + + /** + * @var array + */ + protected $data = array(); + + /** + * @var Sql + */ + protected $sql = null; + + /** + * @var Feature\FeatureSet + */ + protected $featureSet = null; + + /** + * initialize() + */ + public function initialize() + { + if ($this->isInitialized) { + return; + } + + if (!$this->featureSet instanceof Feature\FeatureSet) { + $this->featureSet = new Feature\FeatureSet; + } + + $this->featureSet->setRowGateway($this); + $this->featureSet->apply('preInitialize', array()); + + if (!is_string($this->table) && !$this->table instanceof TableIdentifier) { + throw new Exception\RuntimeException('This row object does not have a valid table set.'); + } + + if ($this->primaryKeyColumn == null) { + throw new Exception\RuntimeException('This row object does not have a primary key column set.'); + } elseif (is_string($this->primaryKeyColumn)) { + $this->primaryKeyColumn = (array) $this->primaryKeyColumn; + } + + if (!$this->sql instanceof Sql) { + throw new Exception\RuntimeException('This row object does not have a Sql object set.'); + } + + $this->featureSet->apply('postInitialize', array()); + + $this->isInitialized = true; + } + + /** + * Populate Data + * + * @param array $rowData + * @param bool $rowExistsInDatabase + * @return AbstractRowGateway + */ + public function populate(array $rowData, $rowExistsInDatabase = false) + { + $this->initialize(); + + $this->data = $rowData; + if ($rowExistsInDatabase == true) { + $this->processPrimaryKeyData(); + } else { + $this->primaryKeyData = null; + } + + return $this; + } + + /** + * @param mixed $array + * @return array|void + */ + public function exchangeArray($array) + { + return $this->populate($array, true); + } + + /** + * Save + * + * @return int + */ + public function save() + { + $this->initialize(); + + if ($this->rowExistsInDatabase()) { + + // UPDATE + + $data = $this->data; + $where = array(); + $isPkModified = false; + + // primary key is always an array even if its a single column + foreach ($this->primaryKeyColumn as $pkColumn) { + $where[$pkColumn] = $this->primaryKeyData[$pkColumn]; + if ($data[$pkColumn] == $this->primaryKeyData[$pkColumn]) { + unset($data[$pkColumn]); + } else { + $isPkModified = true; + } + } + + $statement = $this->sql->prepareStatementForSqlObject($this->sql->update()->set($data)->where($where)); + $result = $statement->execute(); + $rowsAffected = $result->getAffectedRows(); + unset($statement, $result); // cleanup + + // If one or more primary keys are modified, we update the where clause + if ($isPkModified) { + foreach ($this->primaryKeyColumn as $pkColumn) { + if ($data[$pkColumn] != $this->primaryKeyData[$pkColumn]) { + $where[$pkColumn] = $data[$pkColumn]; + } + } + } + } else { + + // INSERT + $insert = $this->sql->insert(); + $insert->values($this->data); + + $statement = $this->sql->prepareStatementForSqlObject($insert); + + $result = $statement->execute(); + if (($primaryKeyValue = $result->getGeneratedValue()) && count($this->primaryKeyColumn) == 1) { + $this->primaryKeyData = array($this->primaryKeyColumn[0] => $primaryKeyValue); + } else { + // make primary key data available so that $where can be complete + $this->processPrimaryKeyData(); + } + $rowsAffected = $result->getAffectedRows(); + unset($statement, $result); // cleanup + + $where = array(); + // primary key is always an array even if its a single column + foreach ($this->primaryKeyColumn as $pkColumn) { + $where[$pkColumn] = $this->primaryKeyData[$pkColumn]; + } + + } + + // refresh data + $statement = $this->sql->prepareStatementForSqlObject($this->sql->select()->where($where)); + $result = $statement->execute(); + $rowData = $result->current(); + unset($statement, $result); // cleanup + + // make sure data and original data are in sync after save + $this->populate($rowData, true); + + // return rows affected + return $rowsAffected; + } + + /** + * Delete + * + * @return int + */ + public function delete() + { + $this->initialize(); + + $where = array(); + // primary key is always an array even if its a single column + foreach ($this->primaryKeyColumn as $pkColumn) { + $where[$pkColumn] = $this->primaryKeyData[$pkColumn]; + } + + // @todo determine if we need to do a select to ensure 1 row will be affected + + $statement = $this->sql->prepareStatementForSqlObject($this->sql->delete()->where($where)); + $result = $statement->execute(); + + $affectedRows = $result->getAffectedRows(); + if ($affectedRows == 1) { + // detach from database + $this->primaryKeyData = null; + } + + return $affectedRows; + } + + /** + * Offset Exists + * + * @param string $offset + * @return bool + */ + public function offsetExists($offset) + { + return array_key_exists($offset, $this->data); + } + + /** + * Offset get + * + * @param string $offset + * @return mixed + */ + public function offsetGet($offset) + { + return $this->data[$offset]; + } + + /** + * Offset set + * + * @param string $offset + * @param mixed $value + * @return RowGateway + */ + public function offsetSet($offset, $value) + { + $this->data[$offset] = $value; + return $this; + } + + /** + * Offset unset + * + * @param string $offset + * @return AbstractRowGateway + */ + public function offsetUnset($offset) + { + $this->data[$offset] = null; + return $this; + } + + /** + * @return int + */ + public function count() + { + return count($this->data); + } + + /** + * To array + * + * @return array + */ + public function toArray() + { + return $this->data; + } + + /** + * __get + * + * @param string $name + * @throws Exception\InvalidArgumentException + * @return mixed + */ + public function __get($name) + { + if (array_key_exists($name, $this->data)) { + return $this->data[$name]; + } else { + throw new Exception\InvalidArgumentException('Not a valid column in this row: ' . $name); + } + } + + /** + * __set + * + * @param string $name + * @param mixed $value + * @return void + */ + public function __set($name, $value) + { + $this->offsetSet($name, $value); + } + + /** + * __isset + * + * @param string $name + * @return bool + */ + public function __isset($name) + { + return $this->offsetExists($name); + } + + /** + * __unset + * + * @param string $name + * @return void + */ + public function __unset($name) + { + $this->offsetUnset($name); + } + + /** + * @return bool + */ + public function rowExistsInDatabase() + { + return ($this->primaryKeyData !== null); + } + + /** + * @throws Exception\RuntimeException + */ + protected function processPrimaryKeyData() + { + $this->primaryKeyData = array(); + foreach ($this->primaryKeyColumn as $column) { + if (!isset($this->data[$column])) { + throw new Exception\RuntimeException('While processing primary key data, a known key ' . $column . ' was not found in the data array'); + } + $this->primaryKeyData[$column] = $this->data[$column]; + } + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/RowGateway/Exception/ExceptionInterface.php b/vendor/zendframework/zend-db/Zend/Db/RowGateway/Exception/ExceptionInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..7bb37fc982cfc83a0fd5ac7be81f3e11c11fa250 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/RowGateway/Exception/ExceptionInterface.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\RowGateway\Exception; + +use Zend\Db\Exception; + +interface ExceptionInterface extends Exception\ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/RowGateway/Exception/InvalidArgumentException.php b/vendor/zendframework/zend-db/Zend/Db/RowGateway/Exception/InvalidArgumentException.php new file mode 100644 index 0000000000000000000000000000000000000000..7db3117deea8188eaded1661a9fd866698d28acc --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/RowGateway/Exception/InvalidArgumentException.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\RowGateway\Exception; + +use Zend\Db\Exception; + +class InvalidArgumentException extends Exception\InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/RowGateway/Exception/RuntimeException.php b/vendor/zendframework/zend-db/Zend/Db/RowGateway/Exception/RuntimeException.php new file mode 100644 index 0000000000000000000000000000000000000000..0b698c64585e0633f3da10597744db255f07f70a --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/RowGateway/Exception/RuntimeException.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\RowGateway\Exception; + +use Zend\Db\Exception; + +class RuntimeException extends Exception\RuntimeException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/RowGateway/Feature/AbstractFeature.php b/vendor/zendframework/zend-db/Zend/Db/RowGateway/Feature/AbstractFeature.php new file mode 100644 index 0000000000000000000000000000000000000000..c52e7fc2a92bb74d3f0f1c2b3410a58de7958208 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/RowGateway/Feature/AbstractFeature.php @@ -0,0 +1,59 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\RowGateway\Feature; + +use Zend\Db\RowGateway\AbstractRowGateway; +use Zend\Db\RowGateway\Exception; + +abstract class AbstractFeature extends AbstractRowGateway +{ + + /** + * @var AbstractRowGateway + */ + protected $rowGateway = null; + + /** + * @var array + */ + protected $sharedData = array(); + + /** + * @return string + */ + public function getName() + { + return get_class($this); + } + + /** + * @param AbstractRowGateway $rowGateway + */ + public function setRowGateway(AbstractRowGateway $rowGateway) + { + $this->rowGateway = $rowGateway; + } + + /** + * @throws \Zend\Db\RowGateway\Exception\RuntimeException + */ + public function initialize() + { + throw new Exception\RuntimeException('This method is not intended to be called on this object.'); + } + + /** + * @return array + */ + public function getMagicMethodSpecifications() + { + return array(); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/RowGateway/Feature/FeatureSet.php b/vendor/zendframework/zend-db/Zend/Db/RowGateway/Feature/FeatureSet.php new file mode 100644 index 0000000000000000000000000000000000000000..de3b2344fb0ccd79da6f6574fe417bb3b910e6fe --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/RowGateway/Feature/FeatureSet.php @@ -0,0 +1,149 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\RowGateway\Feature; + +use Zend\Db\RowGateway\AbstractRowGateway; + +class FeatureSet +{ + const APPLY_HALT = 'halt'; + + /** + * @var AbstractRowGateway + */ + protected $rowGateway = null; + + /** + * @var AbstractFeature[] + */ + protected $features = array(); + + /** + * @var array + */ + protected $magicSpecifications = array(); + + /** + * @param array $features + */ + public function __construct(array $features = array()) + { + if ($features) { + $this->addFeatures($features); + } + } + + public function setRowGateway(AbstractRowGateway $rowGateway) + { + $this->rowGateway = $rowGateway; + foreach ($this->features as $feature) { + $feature->setRowGateway($this->rowGateway); + } + return $this; + } + + public function getFeatureByClassName($featureClassName) + { + $feature = false; + foreach ($this->features as $potentialFeature) { + if ($potentialFeature instanceof $featureClassName) { + $feature = $potentialFeature; + break; + } + } + return $feature; + } + + public function addFeatures(array $features) + { + foreach ($features as $feature) { + $this->addFeature($feature); + } + return $this; + } + + public function addFeature(AbstractFeature $feature) + { + $this->features[] = $feature; + $feature->setRowGateway($feature); + return $this; + } + + public function apply($method, $args) + { + foreach ($this->features as $feature) { + if (method_exists($feature, $method)) { + $return = call_user_func_array(array($feature, $method), $args); + if ($return === self::APPLY_HALT) { + break; + } + } + } + } + + /** + * @param string $property + * @return bool + */ + public function canCallMagicGet($property) + { + return false; + } + + /** + * @param string $property + * @return mixed + */ + public function callMagicGet($property) + { + $return = null; + return $return; + } + + /** + * @param string $property + * @return bool + */ + public function canCallMagicSet($property) + { + return false; + } + + /** + * @param $property + * @param $value + * @return mixed + */ + public function callMagicSet($property, $value) + { + $return = null; + return $return; + } + + /** + * @param string $method + * @return bool + */ + public function canCallMagicCall($method) + { + return false; + } + + /** + * @param string $method + * @param array $arguments + * @return mixed + */ + public function callMagicCall($method, $arguments) + { + $return = null; + return $return; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/RowGateway/RowGateway.php b/vendor/zendframework/zend-db/Zend/Db/RowGateway/RowGateway.php new file mode 100644 index 0000000000000000000000000000000000000000..1415d6995e7b4377d773b615ce29501667eb0616 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/RowGateway/RowGateway.php @@ -0,0 +1,49 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\RowGateway; + +use Zend\Db\Adapter\Adapter; +use Zend\Db\Sql\Sql; + +class RowGateway extends AbstractRowGateway +{ + + /** + * Constructor + * + * @param string $primaryKeyColumn + * @param string|\Zend\Db\Sql\TableIdentifier $table + * @param Adapter|Sql $adapterOrSql + * @throws Exception\InvalidArgumentException + */ + public function __construct($primaryKeyColumn, $table, $adapterOrSql = null) + { + // setup primary key + $this->primaryKeyColumn = (array) $primaryKeyColumn; + + // set table + $this->table = $table; + + // set Sql object + if ($adapterOrSql instanceof Sql) { + $this->sql = $adapterOrSql; + } elseif ($adapterOrSql instanceof Adapter) { + $this->sql = new Sql($adapterOrSql, $this->table); + } else { + throw new Exception\InvalidArgumentException('A valid Sql object was not provided.'); + } + + if ($this->sql->getTable() !== $this->table) { + throw new Exception\InvalidArgumentException('The Sql object provided does not have a table that matches this row object'); + } + + $this->initialize(); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/RowGateway/RowGatewayInterface.php b/vendor/zendframework/zend-db/Zend/Db/RowGateway/RowGatewayInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..e0a20b554d4fe90f25d3351fe85a28a23fb712a4 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/RowGateway/RowGatewayInterface.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\RowGateway; + +interface RowGatewayInterface +{ + public function save(); + public function delete(); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/AbstractSql.php b/vendor/zendframework/zend-db/Zend/Db/Sql/AbstractSql.php new file mode 100644 index 0000000000000000000000000000000000000000..a64942f8e710b7ccccf293cf9defd80067ee1fc2 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/AbstractSql.php @@ -0,0 +1,196 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql; + +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\Adapter\StatementContainer; +use Zend\Db\Sql\Platform\PlatformDecoratorInterface; + +abstract class AbstractSql +{ + /** + * @var array + */ + protected $specifications = array(); + + /** + * @var string + */ + protected $processInfo = array('paramPrefix' => '', 'subselectCount' => 0); + + /** + * @var array + */ + protected $instanceParameterIndex = array(); + + protected function processExpression(ExpressionInterface $expression, PlatformInterface $platform, DriverInterface $driver = null, $namedParameterPrefix = null) + { + // static counter for the number of times this method was invoked across the PHP runtime + static $runtimeExpressionPrefix = 0; + + if ($driver && ((!is_string($namedParameterPrefix) || $namedParameterPrefix == ''))) { + $namedParameterPrefix = sprintf('expr%04dParam', ++$runtimeExpressionPrefix); + } + + $sql = ''; + $statementContainer = new StatementContainer; + $parameterContainer = $statementContainer->getParameterContainer(); + + // initialize variables + $parts = $expression->getExpressionData(); + + if (!isset($this->instanceParameterIndex[$namedParameterPrefix])) { + $this->instanceParameterIndex[$namedParameterPrefix] = 1; + } + + $expressionParamIndex = &$this->instanceParameterIndex[$namedParameterPrefix]; + + foreach ($parts as $part) { + + // if it is a string, simply tack it onto the return sql "specification" string + if (is_string($part)) { + $sql .= $part; + continue; + } + + if (!is_array($part)) { + throw new Exception\RuntimeException('Elements returned from getExpressionData() array must be a string or array.'); + } + + // process values and types (the middle and last position of the expression data) + $values = $part[1]; + $types = (isset($part[2])) ? $part[2] : array(); + foreach ($values as $vIndex => $value) { + if (isset($types[$vIndex]) && $types[$vIndex] == ExpressionInterface::TYPE_IDENTIFIER) { + $values[$vIndex] = $platform->quoteIdentifierInFragment($value); + } elseif (isset($types[$vIndex]) && $types[$vIndex] == ExpressionInterface::TYPE_VALUE && $value instanceof Select) { + // process sub-select + if ($driver) { + $values[$vIndex] = '(' . $this->processSubSelect($value, $platform, $driver, $parameterContainer) . ')'; + } else { + $values[$vIndex] = '(' . $this->processSubSelect($value, $platform) . ')'; + } + } elseif (isset($types[$vIndex]) && $types[$vIndex] == ExpressionInterface::TYPE_VALUE && $value instanceof ExpressionInterface) { + // recursive call to satisfy nested expressions + $innerStatementContainer = $this->processExpression($value, $platform, $driver, $namedParameterPrefix . $vIndex . 'subpart'); + $values[$vIndex] = $innerStatementContainer->getSql(); + if ($driver) { + $parameterContainer->merge($innerStatementContainer->getParameterContainer()); + } + } elseif (isset($types[$vIndex]) && $types[$vIndex] == ExpressionInterface::TYPE_VALUE) { + + // if prepareType is set, it means that this particular value must be + // passed back to the statement in a way it can be used as a placeholder value + if ($driver) { + $name = $namedParameterPrefix . $expressionParamIndex++; + $parameterContainer->offsetSet($name, $value); + $values[$vIndex] = $driver->formatParameterName($name); + continue; + } + + // if not a preparable statement, simply quote the value and move on + $values[$vIndex] = $platform->quoteValue($value); + } elseif (isset($types[$vIndex]) && $types[$vIndex] == ExpressionInterface::TYPE_LITERAL) { + $values[$vIndex] = $value; + } + } + + // after looping the values, interpolate them into the sql string (they might be placeholder names, or values) + $sql .= vsprintf($part[0], $values); + } + + $statementContainer->setSql($sql); + return $statementContainer; + } + + /** + * @param $specifications + * @param $parameters + * @return string + * @throws Exception\RuntimeException + */ + protected function createSqlFromSpecificationAndParameters($specifications, $parameters) + { + if (is_string($specifications)) { + return vsprintf($specifications, $parameters); + } + + $parametersCount = count($parameters); + foreach ($specifications as $specificationString => $paramSpecs) { + if ($parametersCount == count($paramSpecs)) { + break; + } + unset($specificationString, $paramSpecs); + } + + if (!isset($specificationString)) { + throw new Exception\RuntimeException( + 'A number of parameters was found that is not supported by this specification' + ); + } + + $topParameters = array(); + foreach ($parameters as $position => $paramsForPosition) { + if (isset($paramSpecs[$position]['combinedby'])) { + $multiParamValues = array(); + foreach ($paramsForPosition as $multiParamsForPosition) { + $ppCount = count($multiParamsForPosition); + if (!isset($paramSpecs[$position][$ppCount])) { + throw new Exception\RuntimeException('A number of parameters (' . $ppCount . ') was found that is not supported by this specification'); + } + $multiParamValues[] = vsprintf($paramSpecs[$position][$ppCount], $multiParamsForPosition); + } + $topParameters[] = implode($paramSpecs[$position]['combinedby'], $multiParamValues); + } elseif ($paramSpecs[$position] !== null) { + $ppCount = count($paramsForPosition); + if (!isset($paramSpecs[$position][$ppCount])) { + throw new Exception\RuntimeException('A number of parameters (' . $ppCount . ') was found that is not supported by this specification'); + } + $topParameters[] = vsprintf($paramSpecs[$position][$ppCount], $paramsForPosition); + } else { + $topParameters[] = $paramsForPosition; + } + } + return vsprintf($specificationString, $topParameters); + } + + protected function processSubSelect(Select $subselect, PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + if ($driver) { + $stmtContainer = new StatementContainer; + + // Track subselect prefix and count for parameters + $this->processInfo['subselectCount']++; + $subselect->processInfo['subselectCount'] = $this->processInfo['subselectCount']; + $subselect->processInfo['paramPrefix'] = 'subselect' . $subselect->processInfo['subselectCount']; + + // call subselect + if ($this instanceof PlatformDecoratorInterface) { + /** @var Select|PlatformDecoratorInterface $subselectDecorator */ + $subselectDecorator = clone $this; + $subselectDecorator->setSubject($subselect); + $subselectDecorator->prepareStatement(new \Zend\Db\Adapter\Adapter($driver, $platform), $stmtContainer); + } else { + $subselect->prepareStatement(new \Zend\Db\Adapter\Adapter($driver, $platform), $stmtContainer); + } + + // copy count + $this->processInfo['subselectCount'] = $subselect->processInfo['subselectCount']; + + $parameterContainer->merge($stmtContainer->getParameterContainer()->getNamedArray()); + $sql = $stmtContainer->getSql(); + } else { + $sql = $subselect->getSqlString($platform); + } + return $sql; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/AlterTable.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/AlterTable.php new file mode 100644 index 0000000000000000000000000000000000000000..0c9d630f9ee912a46a5c873bec2520a516ac6492 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/AlterTable.php @@ -0,0 +1,268 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl; + +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\Adapter\Platform\Sql92 as AdapterSql92Platform; +use Zend\Db\Sql\AbstractSql; + +class AlterTable extends AbstractSql implements SqlInterface +{ + const ADD_COLUMNS = 'addColumns'; + const ADD_CONSTRAINTS = 'addConstraints'; + const CHANGE_COLUMNS = 'changeColumns'; + const DROP_COLUMNS = 'dropColumns'; + const DROP_CONSTRAINTS = 'dropConstraints'; + const TABLE = 'table'; + + /** + * @var array + */ + protected $addColumns = array(); + + /** + * @var array + */ + protected $addConstraints = array(); + + /** + * @var array + */ + protected $changeColumns = array(); + + /** + * @var array + */ + protected $dropColumns = array(); + + /** + * @var array + */ + protected $dropConstraints = array(); + + /** + * Specifications for Sql String generation + * @var array + */ + protected $specifications = array( + self::TABLE => "ALTER TABLE %1\$s\n", + self::ADD_COLUMNS => array( + "%1\$s" => array( + array(1 => 'ADD COLUMN %1$s', 'combinedby' => ",\n") + ) + ), + self::CHANGE_COLUMNS => array( + "%1\$s" => array( + array(2 => 'CHANGE COLUMN %1$s %2$s', 'combinedby' => ",\n"), + ) + ), + self::DROP_COLUMNS => array( + "%1\$s" => array( + array(1 => 'DROP COLUMN %1$s', 'combinedby' => ",\n"), + ) + ), + self::ADD_CONSTRAINTS => array( + "%1\$s" => array( + array(1 => 'ADD %1$s', 'combinedby' => ",\n"), + ) + ), + self::DROP_CONSTRAINTS => array( + "%1\$s" => array( + array(1 => 'DROP CONSTRAINT %1$s', 'combinedby' => ",\n"), + ) + ) + ); + + /** + * @var string + */ + protected $table = ''; + + /** + * @param string $table + */ + public function __construct($table = '') + { + ($table) ? $this->setTable($table) : null; + } + + /** + * @param string $name + * @return self + */ + public function setTable($name) + { + $this->table = $name; + + return $this; + } + + /** + * @param Column\ColumnInterface $column + * @return self + */ + public function addColumn(Column\ColumnInterface $column) + { + $this->addColumns[] = $column; + + return $this; + } + + /** + * @param string $name + * @param Column\ColumnInterface $column + * @return self + */ + public function changeColumn($name, Column\ColumnInterface $column) + { + $this->changeColumns[$name] = $column; + + return $this; + } + + /** + * @param string $name + * @return self + */ + public function dropColumn($name) + { + $this->dropColumns[] = $name; + + return $this; + } + + /** + * @param string $name + * @return self + */ + public function dropConstraint($name) + { + $this->dropConstraints[] = $name; + + return $this; + } + + /** + * @param Constraint\ConstraintInterface $constraint + * @return self + */ + public function addConstraint(Constraint\ConstraintInterface $constraint) + { + $this->addConstraints[] = $constraint; + + return $this; + } + + /** + * @param string|null $key + * @return array + */ + public function getRawState($key = null) + { + $rawState = array( + self::TABLE => $this->table, + self::ADD_COLUMNS => $this->addColumns, + self::DROP_COLUMNS => $this->dropColumns, + self::CHANGE_COLUMNS => $this->changeColumns, + self::ADD_CONSTRAINTS => $this->addConstraints, + self::DROP_CONSTRAINTS => $this->dropConstraints, + ); + + return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; + } + + /** + * @param PlatformInterface $adapterPlatform + * @return string + */ + public function getSqlString(PlatformInterface $adapterPlatform = null) + { + // get platform, or create default + $adapterPlatform = ($adapterPlatform) ?: new AdapterSql92Platform; + + $sqls = array(); + $parameters = array(); + + foreach ($this->specifications as $name => $specification) { + $parameters[$name] = $this->{'process' . $name}($adapterPlatform, null, null, $sqls, $parameters); + if ($specification && is_array($parameters[$name]) && ($parameters[$name] != array(array()))) { + $sqls[$name] = $this->createSqlFromSpecificationAndParameters($specification, $parameters[$name]); + } + if (stripos($name, 'table') === false && $parameters[$name] !== array(array())) { + $sqls[] = ",\n"; + } + } + + // remove last ,\n + array_pop($sqls); + + $sql = implode('', $sqls); + + return $sql; + } + + protected function processTable(PlatformInterface $adapterPlatform = null) + { + return array($adapterPlatform->quoteIdentifier($this->table)); + } + + protected function processAddColumns(PlatformInterface $adapterPlatform = null) + { + $sqls = array(); + foreach ($this->addColumns as $column) { + $sqls[] = $this->processExpression($column, $adapterPlatform)->getSql(); + } + + return array($sqls); + } + + protected function processChangeColumns(PlatformInterface $adapterPlatform = null) + { + $sqls = array(); + foreach ($this->changeColumns as $name => $column) { + $sqls[] = array( + $adapterPlatform->quoteIdentifier($name), + $this->processExpression($column, $adapterPlatform)->getSql() + ); + } + + return array($sqls); + } + + protected function processDropColumns(PlatformInterface $adapterPlatform = null) + { + $sqls = array(); + foreach ($this->dropColumns as $column) { + $sqls[] = $adapterPlatform->quoteIdentifier($column); + } + + return array($sqls); + } + + protected function processAddConstraints(PlatformInterface $adapterPlatform = null) + { + $sqls = array(); + foreach ($this->addConstraints as $constraint) { + $sqls[] = $this->processExpression($constraint, $adapterPlatform); + } + + return array($sqls); + } + + protected function processDropConstraints(PlatformInterface $adapterPlatform = null) + { + $sqls = array(); + foreach ($this->dropConstraints as $constraint) { + $sqls[] = $adapterPlatform->quoteIdentifier($constraint); + } + + return array($sqls); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/BigInteger.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/BigInteger.php new file mode 100644 index 0000000000000000000000000000000000000000..d915a948f30aa8cf10ea4929d86920f5e45c8184 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/BigInteger.php @@ -0,0 +1,18 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Column; + +class BigInteger extends Integer +{ + /** + * @var string + */ + protected $type = 'BIGINT'; +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Blob.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Blob.php new file mode 100644 index 0000000000000000000000000000000000000000..1892ca6039b70483316e6b72861cbed6de5912db --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Blob.php @@ -0,0 +1,91 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Column; + +class Blob extends Column +{ + /** + * @var int + */ + protected $length; + + /** + * @var string Change type to blob + */ + protected $type = 'BLOB'; + + /** + * @param null $name + * @param int $length + * @param bool $nullable + * @param null $default + * @param array $options + */ + public function __construct($name, $length, $nullable = false, $default = null, array $options = array()) + { + $this->setName($name); + $this->setLength($length); + $this->setNullable($nullable); + $this->setDefault($default); + $this->setOptions($options); + } + + /** + * @param int $length + * @return self + */ + public function setLength($length) + { + $this->length = $length; + return $this; + } + + /** + * @return int + */ + public function getLength() + { + return $this->length; + } + + /** + * @return array + */ + public function getExpressionData() + { + $spec = $this->specification; + + $params = array(); + $params[] = $this->name; + $params[] = $this->type; + + if ($this->length) { + $params[1] .= ' ' . $this->length; + } + + $types = array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL); + + if (!$this->isNullable) { + $params[1] .= ' NOT NULL'; + } + + if ($this->default !== null) { + $spec .= ' DEFAULT %s'; + $params[] = $this->default; + $types[] = self::TYPE_VALUE; + } + + return array(array( + $spec, + $params, + $types, + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Boolean.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Boolean.php new file mode 100644 index 0000000000000000000000000000000000000000..36c07187cbd79e4d383b9dad8e6c3e8a08272fd7 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Boolean.php @@ -0,0 +1,42 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Column; + +class Boolean extends Column +{ + /** + * @var string specification + */ + protected $specification = '%s TINYINT NOT NULL'; + + /** + * @param string $name + */ + public function __construct($name) + { + $this->name = $name; + } + + /** + * @return array + */ + public function getExpressionData() + { + $spec = $this->specification; + $params = array($this->name); + $types = array(self::TYPE_IDENTIFIER); + + return array(array( + $spec, + $params, + $types, + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Char.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Char.php new file mode 100644 index 0000000000000000000000000000000000000000..507cfe2c609da9dc42558b66f9091b05deecfd72 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Char.php @@ -0,0 +1,58 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Column; + +class Char extends Column +{ + /** + * @var string + */ + protected $specification = '%s CHAR(%s) %s %s'; + + /** + * @var int + */ + protected $length; + + /** + * @param string $name + * @param int $length + */ + public function __construct($name, $length) + { + $this->name = $name; + $this->length = $length; + } + + /** + * @return array + */ + public function getExpressionData() + { + $spec = $this->specification; + $params = array(); + + $types = array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL); + $params[] = $this->name; + $params[] = $this->length; + + $types[] = self::TYPE_LITERAL; + $params[] = (!$this->isNullable) ? 'NOT NULL' : ''; + + $types[] = ($this->default !== null) ? self::TYPE_VALUE : self::TYPE_LITERAL; + $params[] = ($this->default !== null) ? $this->default : ''; + + return array(array( + $spec, + $params, + $types, + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Column.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Column.php new file mode 100644 index 0000000000000000000000000000000000000000..de2f852b0d072cf9b664df67bc9c66da1f743cab --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Column.php @@ -0,0 +1,164 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Column; + +class Column implements ColumnInterface +{ + /** + * @var null|string|int + */ + protected $default = null; + + /** + * @var bool + */ + protected $isNullable = false; + + /** + * @var string + */ + protected $name = null; + + /** + * @var array + */ + protected $options = array(); + + /** + * @var string + */ + protected $specification = '%s %s'; + + /** + * @var string + */ + protected $type = 'INTEGER'; + + /** + * @param null|string $name + */ + public function __construct($name = null) + { + (!$name) ?: $this->setName($name); + } + + /** + * @param string $name + * @return self + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return null|string + */ + public function getName() + { + return $this->name; + } + + /** + * @param bool $nullable + * @return self + */ + public function setNullable($nullable) + { + $this->isNullable = (bool) $nullable; + return $this; + } + + /** + * @return bool + */ + public function isNullable() + { + return $this->isNullable; + } + + /** + * @param null|string|int $default + * @return self + */ + public function setDefault($default) + { + $this->default = $default; + return $this; + } + + /** + * @return null|string|int + */ + public function getDefault() + { + return $this->default; + } + + /** + * @param array $options + * @return self + */ + public function setOptions(array $options) + { + $this->options = $options; + return $this; + } + + /** + * @param string $name + * @param string $value + * @return self + */ + public function setOption($name, $value) + { + $this->options[$name] = $value; + return $this; + } + + /** + * @return array + */ + public function getOptions() + { + return $this->options; + } + + /** + * @return array + */ + public function getExpressionData() + { + $spec = $this->specification; + + $params = array(); + $params[] = $this->name; + $params[] = $this->type; + + $types = array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL); + + if (!$this->isNullable) { + $params[1] .= ' NOT NULL'; + } + + if ($this->default !== null) { + $spec .= ' DEFAULT %s'; + $params[] = $this->default; + $types[] = self::TYPE_VALUE; + } + + return array(array( + $spec, + $params, + $types, + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/ColumnInterface.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/ColumnInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..331e5254f4489f0b00a38b68b49199ef3bd99e90 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/ColumnInterface.php @@ -0,0 +1,20 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Column; + +use Zend\Db\Sql\ExpressionInterface; + +interface ColumnInterface extends ExpressionInterface +{ + public function getName(); + public function isNullable(); + public function getDefault(); + public function getOptions(); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Date.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Date.php new file mode 100644 index 0000000000000000000000000000000000000000..489a11439e2128bb3c664379a7fe9dc37fa34b49 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Date.php @@ -0,0 +1,50 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Column; + +class Date extends Column +{ + /** + * @var string + */ + protected $specification = '%s DATE %s %s'; + + /** + * @param string $name + */ + public function __construct($name) + { + $this->name = $name; + } + + /** + * @return array + */ + public function getExpressionData() + { + $spec = $this->specification; + $params = array(); + + $types = array(self::TYPE_IDENTIFIER); + $params[] = $this->name; + + $types[] = self::TYPE_LITERAL; + $params[] = (!$this->isNullable) ? 'NOT NULL' : ''; + + $types[] = ($this->default !== null) ? self::TYPE_VALUE : self::TYPE_LITERAL; + $params[] = ($this->default !== null) ? $this->default : ''; + + return array(array( + $spec, + $params, + $types, + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Decimal.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Decimal.php new file mode 100644 index 0000000000000000000000000000000000000000..8a0ff25e3c7e7dc64e56321ca022717e2cb159f9 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Decimal.php @@ -0,0 +1,69 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Column; + +class Decimal extends Column +{ + /** + * @var int + */ + protected $precision; + + /** + * @var int + */ + protected $scale; + + /** + * @var string + */ + protected $specification = '%s DECIMAL(%s) %s %s'; + + /** + * @param null|string $name + * @param int $precision + * @param null|int $scale + */ + public function __construct($name, $precision, $scale = null) + { + $this->name = $name; + $this->precision = $precision; + $this->scale = $scale; + } + + /** + * @return array + */ + public function getExpressionData() + { + $spec = $this->specification; + $params = array(); + + $types = array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL); + $params[] = $this->name; + $params[] = $this->precision; + + if ($this->scale !== null) { + $params[1] .= ', ' . $this->scale; + } + + $types[] = self::TYPE_LITERAL; + $params[] = (!$this->isNullable) ? 'NOT NULL' : ''; + + $types[] = ($this->default !== null) ? self::TYPE_VALUE : self::TYPE_LITERAL; + $params[] = ($this->default !== null) ? $this->default : ''; + + return array(array( + $spec, + $params, + $types, + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Float.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Float.php new file mode 100644 index 0000000000000000000000000000000000000000..e866abcf558d34eccadcdd6758f932a0c87667f2 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Float.php @@ -0,0 +1,66 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Column; + +class Float extends Column +{ + /** + * @var int + */ + protected $decimal; + + /** + * @var int + */ + protected $digits; + + /** + * @var string + */ + protected $specification = '%s DECIMAL(%s) %s %s'; + + /** + * @param null|string $name + * @param int $digits + * @param int $decimal + */ + public function __construct($name, $digits, $decimal) + { + $this->name = $name; + $this->digits = $digits; + $this->decimal = $decimal; + } + + /** + * @return array + */ + public function getExpressionData() + { + $spec = $this->specification; + $params = array(); + + $types = array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL); + $params[] = $this->name; + $params[] = $this->digits; + $params[1] .= ', ' . $this->decimal; + + $types[] = self::TYPE_LITERAL; + $params[] = (!$this->isNullable) ? 'NOT NULL' : ''; + + $types[] = ($this->default !== null) ? self::TYPE_VALUE : self::TYPE_LITERAL; + $params[] = ($this->default !== null) ? $this->default : ''; + + return array(array( + $spec, + $params, + $types, + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Integer.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Integer.php new file mode 100644 index 0000000000000000000000000000000000000000..5e424285c0dcd878ee2b3bb288f412994552d487 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Integer.php @@ -0,0 +1,32 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Column; + +class Integer extends Column +{ + /** + * @var int + */ + protected $length; + + /** + * @param null|string $name + * @param bool $nullable + * @param null|string|int $default + * @param array $options + */ + public function __construct($name, $nullable = false, $default = null, array $options = array()) + { + $this->setName($name); + $this->setNullable($nullable); + $this->setDefault($default); + $this->setOptions($options); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Text.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Text.php new file mode 100644 index 0000000000000000000000000000000000000000..3e4070909378a2f164b171db45e71ef5729ad538 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Text.php @@ -0,0 +1,51 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Column; + + +class Text extends Column +{ + /** + * @var string + */ + protected $specification = '%s TEXT %s %s'; + + /** + * @param null|string $name + */ + public function __construct($name) + { + $this->name = $name; + } + + /** + * @return array + */ + public function getExpressionData() + { + $spec = $this->specification; + $params = array(); + + $types = array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL); + $params[] = $this->name; + + $types[] = self::TYPE_LITERAL; + $params[] = (!$this->isNullable) ? 'NOT NULL' : ''; + + $types[] = ($this->default !== null) ? self::TYPE_VALUE : self::TYPE_LITERAL; + $params[] = ($this->default !== null) ? $this->default : ''; + + return array(array( + $spec, + $params, + $types, + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Time.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Time.php new file mode 100644 index 0000000000000000000000000000000000000000..68d3c66484ed7723d880058bdfa13d99049f3660 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Time.php @@ -0,0 +1,50 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Column; + +class Time extends Column +{ + /** + * @var string + */ + protected $specification = '%s TIME %s %s'; + + /** + * @param string $name + */ + public function __construct($name) + { + $this->name = $name; + } + + /** + * @return array + */ + public function getExpressionData() + { + $spec = $this->specification; + $params = array(); + + $types = array(self::TYPE_IDENTIFIER); + $params[] = $this->name; + + $types[] = self::TYPE_LITERAL; + $params[] = (!$this->isNullable) ? 'NOT NULL' : ''; + + $types[] = ($this->default !== null) ? self::TYPE_VALUE : self::TYPE_LITERAL; + $params[] = ($this->default !== null) ? $this->default : ''; + + return array(array( + $spec, + $params, + $types, + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Varchar.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Varchar.php new file mode 100644 index 0000000000000000000000000000000000000000..49a718c78cb689efd1861020f2c8245e94890193 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Column/Varchar.php @@ -0,0 +1,58 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Column; + +class Varchar extends Column +{ + /** + * @var int + */ + protected $length; + + /** + * @var string + */ + protected $specification = '%s VARCHAR(%s) %s %s'; + + /** + * @param null|string $name + * @param int $length + */ + public function __construct($name, $length) + { + $this->name = $name; + $this->length = $length; + } + + /** + * @return array + */ + public function getExpressionData() + { + $spec = $this->specification; + $params = array(); + + $types = array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL); + $params[] = $this->name; + $params[] = $this->length; + + $types[] = self::TYPE_LITERAL; + $params[] = (!$this->isNullable) ? 'NOT NULL' : ''; + + $types[] = ($this->default !== null) ? self::TYPE_VALUE : self::TYPE_LITERAL; + $params[] = ($this->default !== null) ? $this->default : ''; + + return array(array( + $spec, + $params, + $types, + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/AbstractConstraint.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/AbstractConstraint.php new file mode 100644 index 0000000000000000000000000000000000000000..19909fadb227c6dab480031f54e074b7377bf686 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/AbstractConstraint.php @@ -0,0 +1,58 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Constraint; + +abstract class AbstractConstraint implements ConstraintInterface +{ + /** + * @var array + */ + protected $columns = array(); + + /** + * @param null|string|array $columns + */ + public function __construct($columns = null) + { + (!$columns) ?: $this->setColumns($columns); + } + + /** + * @param null|string|array $columns + * @return self + */ + public function setColumns($columns) + { + if (!is_array($columns)) { + $columns = array($columns); + } + + $this->columns = $columns; + return $this; + } + + /** + * @param string $column + * @return self + */ + public function addColumn($column) + { + $this->columns[] = $column; + return $this; + } + + /** + * @return array + */ + public function getColumns() + { + return $this->columns; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/Check.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/Check.php new file mode 100644 index 0000000000000000000000000000000000000000..1afbeb39cbdf4429096d14d6a3c03155b29e4c82 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/Check.php @@ -0,0 +1,45 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Constraint; + +class Check extends AbstractConstraint +{ + /** + * @var string|\Zend\Db\Sql\ExpressionInterface + */ + protected $expression; + + /** + * @var string + */ + protected $specification = 'CONSTRAINT %s CHECK (%s)'; + + /** + * @param string|\Zend\Db\Sql\ExpressionInterface $expression + * @param null|string $name + */ + public function __construct($expression, $name) + { + $this->expression = $expression; + $this->name = $name; + } + + /** + * @return array + */ + public function getExpressionData() + { + return array(array( + $this->specification, + array($this->name, $this->expression), + array(self::TYPE_IDENTIFIER, self::TYPE_LITERAL), + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/ConstraintInterface.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/ConstraintInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..bcb96439432f2fc0d4ccb25bebb79f80ce724621 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/ConstraintInterface.php @@ -0,0 +1,17 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Constraint; + +use Zend\Db\Sql\ExpressionInterface; + +interface ConstraintInterface extends ExpressionInterface +{ + public function getColumns(); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/ForeignKey.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/ForeignKey.php new file mode 100644 index 0000000000000000000000000000000000000000..1d0c0cad4737ec4ef1eb6caac711dd60463e9a87 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/ForeignKey.php @@ -0,0 +1,177 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Constraint; + +class ForeignKey extends AbstractConstraint +{ + /** + * @var string + */ + protected $name; + + /** + * @var string + */ + protected $onDeleteRule = 'NO ACTION'; + + /** + * @var string + */ + protected $onUpdateRule = 'NO ACTION'; + + /** + * @var string + */ + protected $referenceColumn; + + /** + * @var string + */ + protected $referenceTable; + + /** + * @var string + */ + protected $specification = 'CONSTRAINT %1$s FOREIGN KEY (%2$s) REFERENCES %3$s (%4$s) ON DELETE %5$s ON UPDATE %6$s'; + + /** + * @param array|null|string $name + * @param string $column + * @param string $referenceTable + * @param string $referenceColumn + * @param null|string $onDeleteRule + * @param null|string $onUpdateRule + */ + public function __construct($name, $column, $referenceTable, $referenceColumn, $onDeleteRule = null, $onUpdateRule = null) + { + $this->setName($name); + $this->setColumns($column); + $this->setReferenceTable($referenceTable); + $this->setReferenceColumn($referenceColumn); + (!$onDeleteRule) ?: $this->setOnDeleteRule($onDeleteRule); + (!$onUpdateRule) ?: $this->setOnUpdateRule($onUpdateRule); + } + + /** + * @param string $name + * @return self + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $referenceTable + * @return self + */ + public function setReferenceTable($referenceTable) + { + $this->referenceTable = $referenceTable; + return $this; + } + + /** + * @return string + */ + public function getReferenceTable() + { + return $this->referenceTable; + } + + /** + * @param string $referenceColumn + * @return self + */ + public function setReferenceColumn($referenceColumn) + { + $this->referenceColumn = $referenceColumn; + return $this; + } + + /** + * @return string + */ + public function getReferenceColumn() + { + return $this->referenceColumn; + } + + /** + * @param string $onDeleteRule + * @return self + */ + public function setOnDeleteRule($onDeleteRule) + { + $this->onDeleteRule = $onDeleteRule; + return $this; + } + + /** + * @return string + */ + public function getOnDeleteRule() + { + return $this->onDeleteRule; + } + + /** + * @param string $onUpdateRule + * @return self + */ + public function setOnUpdateRule($onUpdateRule) + { + $this->onUpdateRule = $onUpdateRule; + return $this; + } + + /** + * @return string + */ + public function getOnUpdateRule() + { + return $this->onUpdateRule; + } + + /** + * @return array + */ + public function getExpressionData() + { + return array(array( + $this->specification, + array( + $this->name, + $this->columns[0], + $this->referenceTable, + $this->referenceColumn, + $this->onDeleteRule, + $this->onUpdateRule, + ), + array( + self::TYPE_IDENTIFIER, + self::TYPE_IDENTIFIER, + self::TYPE_IDENTIFIER, + self::TYPE_IDENTIFIER, + self::TYPE_LITERAL, + self::TYPE_LITERAL, + ), + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/PrimaryKey.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/PrimaryKey.php new file mode 100644 index 0000000000000000000000000000000000000000..84124a4d0a148e62f49e32960f0ce6233a097de6 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/PrimaryKey.php @@ -0,0 +1,36 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Constraint; + +class PrimaryKey extends AbstractConstraint +{ + /** + * @var string + */ + protected $specification = 'PRIMARY KEY (%s)'; + + /** + * @return array + */ + public function getExpressionData() + { + $colCount = count($this->columns); + $newSpecParts = array_fill(0, $colCount, '%s'); + $newSpecTypes = array_fill(0, $colCount, self::TYPE_IDENTIFIER); + + $newSpec = sprintf($this->specification, implode(', ', $newSpecParts)); + + return array(array( + $newSpec, + $this->columns, + $newSpecTypes, + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/UniqueKey.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/UniqueKey.php new file mode 100644 index 0000000000000000000000000000000000000000..8d871054e18389f912ccbf11a4038d3fe094e525 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/Constraint/UniqueKey.php @@ -0,0 +1,55 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl\Constraint; + +class UniqueKey extends AbstractConstraint +{ + /** + * @var string + */ + protected $specification = 'CONSTRAINT UNIQUE KEY %s(...)'; + + /** + * @param string $column + * @param null|string $name + */ + public function __construct($column, $name = null) + { + $this->setColumns($column); + $this->name = $name; + } + + /** + * @return array + */ + public function getExpressionData() + { + $colCount = count($this->columns); + + $values = array(); + $values[] = ($this->name) ? $this->name : ''; + + $newSpecTypes = array(self::TYPE_IDENTIFIER); + $newSpecParts = array(); + + for ($i = 0; $i < $colCount; $i++) { + $newSpecParts[] = '%s'; + $newSpecTypes[] = self::TYPE_IDENTIFIER; + } + + $newSpec = str_replace('...', implode(', ', $newSpecParts), $this->specification); + + return array(array( + $newSpec, + array_merge($values, $this->columns), + $newSpecTypes, + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/CreateTable.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/CreateTable.php new file mode 100644 index 0000000000000000000000000000000000000000..45bfd982d9d14c6db8c72e9665b03a5f3a87e260 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/CreateTable.php @@ -0,0 +1,218 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl; + +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\Adapter\Platform\Sql92 as AdapterSql92Platform; +use Zend\Db\Sql\AbstractSql; + +class CreateTable extends AbstractSql implements SqlInterface +{ + const COLUMNS = 'columns'; + const CONSTRAINTS = 'constraints'; + const TABLE = 'table'; + + /** + * @var array + */ + protected $columns = array(); + + /** + * @var array + */ + protected $constraints = array(); + + /** + * @var bool + */ + protected $isTemporary = false; + + /** + * Specifications for Sql String generation + * @var array + */ + protected $specifications = array( + self::TABLE => 'CREATE %1$sTABLE %2$s (', + self::COLUMNS => array( + "\n %1\$s" => array( + array(1 => '%1$s', 'combinedby' => ",\n ") + ) + ), + self::CONSTRAINTS => array( + "\n %1\$s" => array( + array(1 => '%1$s', 'combinedby' => ",\n ") + ) + ), + ); + + /** + * @var string + */ + protected $table = ''; + + /** + * @param string $table + * @param bool $isTemporary + */ + public function __construct($table = '', $isTemporary = false) + { + $this->table = $table; + $this->setTemporary($isTemporary); + } + + /** + * @param bool $temporary + * @return self + */ + public function setTemporary($temporary) + { + $this->isTemporary = (bool) $temporary; + return $this; + } + + /** + * @return bool + */ + public function isTemporary() + { + return $this->isTemporary; + } + + /** + * @param string $name + * @return self + */ + public function setTable($name) + { + $this->table = $name; + return $this; + } + + /** + * @param Column\ColumnInterface $column + * @return self + */ + public function addColumn(Column\ColumnInterface $column) + { + $this->columns[] = $column; + return $this; + } + + /** + * @param Constraint\ConstraintInterface $constraint + * @return self + */ + public function addConstraint(Constraint\ConstraintInterface $constraint) + { + $this->constraints[] = $constraint; + return $this; + } + + /** + * @param string|null $key + * @return array + */ + public function getRawState($key = null) + { + $rawState = array( + self::COLUMNS => $this->columns, + self::CONSTRAINTS => $this->constraints, + self::TABLE => $this->table, + ); + + return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; + } + + /** + * @param PlatformInterface $adapterPlatform + * @return string + */ + public function getSqlString(PlatformInterface $adapterPlatform = null) + { + // get platform, or create default + $adapterPlatform = ($adapterPlatform) ?: new AdapterSql92Platform; + + $sqls = array(); + $parameters = array(); + + foreach ($this->specifications as $name => $specification) { + if (is_int($name)) { + $sqls[] = $specification; + continue; + } + + $parameters[$name] = $this->{'process' . $name}( + $adapterPlatform, + null, + null, + $sqls, + $parameters + ); + + + if ($specification + && is_array($parameters[$name]) + && ($parameters[$name] != array(array())) + ) { + $sqls[$name] = $this->createSqlFromSpecificationAndParameters( + $specification, + $parameters[$name] + ); + } + + if (stripos($name, 'table') === false + && $parameters[$name] !== array(array()) + ) { + $sqls[] = ",\n"; + } + } + + + // remove last , + if (count($sqls) > 2) { + array_pop($sqls); + } + + $sql = implode('', $sqls) . "\n)"; + + return $sql; + } + + protected function processTable(PlatformInterface $adapterPlatform = null) + { + $ret = array(); + if ($this->isTemporary) { + $ret[] = 'TEMPORARY '; + } else { + $ret[] = ''; + } + + $ret[] = $adapterPlatform->quoteIdentifier($this->table); + return $ret; + } + + protected function processColumns(PlatformInterface $adapterPlatform = null) + { + $sqls = array(); + foreach ($this->columns as $column) { + $sqls[] = $this->processExpression($column, $adapterPlatform)->getSql(); + } + return array($sqls); + } + + protected function processConstraints(PlatformInterface $adapterPlatform = null) + { + $sqls = array(); + foreach ($this->constraints as $constraint) { + $sqls[] = $this->processExpression($constraint, $adapterPlatform)->getSql(); + } + return array($sqls); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/DropTable.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/DropTable.php new file mode 100644 index 0000000000000000000000000000000000000000..e38425c6bbb84a29b6dd815c678f8b610cd5b576 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/DropTable.php @@ -0,0 +1,77 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl; + +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\Adapter\Platform\Sql92 as AdapterSql92Platform; +use Zend\Db\Sql\AbstractSql; + +class DropTable extends AbstractSql implements SqlInterface +{ + const TABLE = 'table'; + + /** + * @var array + */ + protected $specifications = array( + self::TABLE => 'DROP TABLE %1$s' + ); + + /** + * @var string + */ + protected $table = ''; + + /** + * @param string $table + */ + public function __construct($table = '') + { + $this->table = $table; + } + + /** + * @param null|PlatformInterface $adapterPlatform + * @return string + */ + public function getSqlString(PlatformInterface $adapterPlatform = null) + { + // get platform, or create default + $adapterPlatform = ($adapterPlatform) ?: new AdapterSql92Platform; + + $sqls = array(); + $parameters = array(); + + foreach ($this->specifications as $name => $specification) { + $parameters[$name] = $this->{'process' . $name}( + $adapterPlatform, + null, + null, + $sqls, + $parameters + ); + + if ($specification && is_array($parameters[$name])) { + $sqls[$name] = $this->createSqlFromSpecificationAndParameters( + $specification, + $parameters[$name] + ); + } + } + + $sql = implode(' ', $sqls); + return $sql; + } + + protected function processTable(PlatformInterface $adapterPlatform = null) + { + return array($adapterPlatform->quoteIdentifier($this->table)); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/SqlInterface.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/SqlInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..761312458a93dd72204c98953b6bfac5461a0bcb --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Ddl/SqlInterface.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Ddl; + +use Zend\Db\Sql\SqlInterface as BaseSqlInterface; + +interface SqlInterface extends BaseSqlInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Delete.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Delete.php new file mode 100644 index 0000000000000000000000000000000000000000..1187277da1195fd09e5d22c82f30291e5e529219 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Delete.php @@ -0,0 +1,205 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql; + +use Zend\Db\Adapter\AdapterInterface; +use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\Adapter\Platform\Sql92; +use Zend\Db\Adapter\StatementContainerInterface; + +/** + * + * @property Where $where + */ +class Delete extends AbstractSql implements SqlInterface, PreparableSqlInterface +{ + /**@#+ + * @const + */ + const SPECIFICATION_DELETE = 'delete'; + const SPECIFICATION_WHERE = 'where'; + /**@#-*/ + + /** + * @var array Specifications + */ + protected $specifications = array( + self::SPECIFICATION_DELETE => 'DELETE FROM %1$s', + self::SPECIFICATION_WHERE => 'WHERE %1$s' + ); + + /** + * @var string|TableIdentifier + */ + protected $table = ''; + + /** + * @var bool + */ + protected $emptyWhereProtection = true; + + /** + * @var array + */ + protected $set = array(); + + /** + * @var null|string|Where + */ + protected $where = null; + + /** + * Constructor + * + * @param null|string|TableIdentifier $table + */ + public function __construct($table = null) + { + if ($table) { + $this->from($table); + } + $this->where = new Where(); + } + + /** + * Create from statement + * + * @param string|TableIdentifier $table + * @return Delete + */ + public function from($table) + { + $this->table = $table; + return $this; + } + + public function getRawState($key = null) + { + $rawState = array( + 'emptyWhereProtection' => $this->emptyWhereProtection, + 'table' => $this->table, + 'set' => $this->set, + 'where' => $this->where + ); + return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; + } + + /** + * Create where clause + * + * @param Where|\Closure|string|array $predicate + * @param string $combination One of the OP_* constants from Predicate\PredicateSet + * @return Delete + */ + public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) + { + if ($predicate instanceof Where) { + $this->where = $predicate; + } else { + $this->where->addPredicates($predicate, $combination); + } + return $this; + } + + /** + * Prepare the delete statement + * + * @param AdapterInterface $adapter + * @param StatementContainerInterface $statementContainer + * @return void + */ + public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) + { + $driver = $adapter->getDriver(); + $platform = $adapter->getPlatform(); + $parameterContainer = $statementContainer->getParameterContainer(); + + if (!$parameterContainer instanceof ParameterContainer) { + $parameterContainer = new ParameterContainer(); + $statementContainer->setParameterContainer($parameterContainer); + } + + $table = $this->table; + $schema = null; + + // create quoted table name to use in delete processing + if ($table instanceof TableIdentifier) { + list($table, $schema) = $table->getTableAndSchema(); + } + + $table = $platform->quoteIdentifier($table); + + if ($schema) { + $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table; + } + + $sql = sprintf($this->specifications[static::SPECIFICATION_DELETE], $table); + + // process where + if ($this->where->count() > 0) { + $whereParts = $this->processExpression($this->where, $platform, $driver, 'where'); + $parameterContainer->merge($whereParts->getParameterContainer()); + $sql .= ' ' . sprintf($this->specifications[static::SPECIFICATION_WHERE], $whereParts->getSql()); + } + $statementContainer->setSql($sql); + } + + /** + * Get the SQL string, based on the platform + * + * Platform defaults to Sql92 if none provided + * + * @param null|PlatformInterface $adapterPlatform + * @return string + */ + public function getSqlString(PlatformInterface $adapterPlatform = null) + { + $adapterPlatform = ($adapterPlatform) ?: new Sql92; + $table = $this->table; + $schema = null; + + // create quoted table name to use in delete processing + if ($table instanceof TableIdentifier) { + list($table, $schema) = $table->getTableAndSchema(); + } + + $table = $adapterPlatform->quoteIdentifier($table); + + if ($schema) { + $table = $adapterPlatform->quoteIdentifier($schema) . $adapterPlatform->getIdentifierSeparator() . $table; + } + + $sql = sprintf($this->specifications[static::SPECIFICATION_DELETE], $table); + + if ($this->where->count() > 0) { + $whereParts = $this->processExpression($this->where, $adapterPlatform, null, 'where'); + $sql .= ' ' . sprintf($this->specifications[static::SPECIFICATION_WHERE], $whereParts->getSql()); + } + + return $sql; + } + + /** + * Property overloading + * + * Overloads "where" only. + * + * @param string $name + * @return mixed + */ + public function __get($name) + { + switch (strtolower($name)) { + case 'where': + return $this->where; + } + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Exception/ExceptionInterface.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Exception/ExceptionInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..337266de87a3ca7255d27ed1a5fff1f3d0dba59a --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Exception/ExceptionInterface.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Exception; + +use Zend\Db\Exception; + +interface ExceptionInterface extends Exception\ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Exception/InvalidArgumentException.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Exception/InvalidArgumentException.php new file mode 100644 index 0000000000000000000000000000000000000000..0892d68b7fad0c82610da1ba193285b32e50ac22 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Exception/InvalidArgumentException.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Exception; + +use Zend\Db\Exception; + +class InvalidArgumentException extends Exception\InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Exception/RuntimeException.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Exception/RuntimeException.php new file mode 100644 index 0000000000000000000000000000000000000000..b6546b09083cb9ac3bf2da294e7fbbeb36574913 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Exception/RuntimeException.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Exception; + +use Zend\Db\Exception; + +class RuntimeException extends Exception\RuntimeException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Expression.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Expression.php new file mode 100644 index 0000000000000000000000000000000000000000..b9f935b409cba2c4be0ca260047802c535fcee8c --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Expression.php @@ -0,0 +1,153 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql; + +class Expression implements ExpressionInterface +{ + /** + * @const + */ + const PLACEHOLDER = '?'; + + /** + * @var string + */ + protected $expression = ''; + + /** + * @var array + */ + protected $parameters = array(); + + /** + * @var array + */ + protected $types = array(); + + /** + * @param string $expression + * @param string|array $parameters + * @param array $types + */ + public function __construct($expression = '', $parameters = null, array $types = array()) + { + if ($expression) { + $this->setExpression($expression); + } + if ($parameters) { + $this->setParameters($parameters); + } + if ($types) { + $this->setTypes($types); + } + } + + /** + * @param $expression + * @return Expression + * @throws Exception\InvalidArgumentException + */ + public function setExpression($expression) + { + if (!is_string($expression) || $expression == '') { + throw new Exception\InvalidArgumentException('Supplied expression must be a string.'); + } + $this->expression = $expression; + return $this; + } + + /** + * @return string + */ + public function getExpression() + { + return $this->expression; + } + + /** + * @param $parameters + * @return Expression + * @throws Exception\InvalidArgumentException + */ + public function setParameters($parameters) + { + if (!is_scalar($parameters) && !is_array($parameters)) { + throw new Exception\InvalidArgumentException('Expression parameters must be a scalar or array.'); + } + $this->parameters = $parameters; + return $this; + } + + /** + * @return array + */ + public function getParameters() + { + return $this->parameters; + } + + /** + * @param array $types + * @return Expression + */ + public function setTypes(array $types) + { + $this->types = $types; + return $this; + } + + /** + * @return array + */ + public function getTypes() + { + return $this->types; + } + + /** + * @return array + * @throws Exception\RuntimeException + */ + public function getExpressionData() + { + $parameters = (is_scalar($this->parameters)) ? array($this->parameters) : $this->parameters; + + $types = array(); + $parametersCount = count($parameters); + + if ($parametersCount == 0 && strpos($this->expression, self::PLACEHOLDER) !== false) { + // if there are no parameters, but there is a placeholder + $parametersCount = substr_count($this->expression, self::PLACEHOLDER); + $parameters = array_fill(0, $parametersCount, null); + } + + for ($i = 0; $i < $parametersCount; $i++) { + $types[$i] = (isset($this->types[$i]) && ($this->types[$i] == self::TYPE_IDENTIFIER || $this->types[$i] == self::TYPE_LITERAL)) + ? $this->types[$i] : self::TYPE_VALUE; + } + + // assign locally, escaping % signs + $expression = str_replace('%', '%%', $this->expression); + + if ($parametersCount > 0) { + $count = 0; + $expression = str_replace(self::PLACEHOLDER, '%s', $expression, $count); + if ($count !== $parametersCount) { + throw new Exception\RuntimeException('The number of replacements in the expression does not match the number of parameters'); + } + } + + return array(array( + $expression, + $parameters, + $types + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/ExpressionInterface.php b/vendor/zendframework/zend-db/Zend/Db/Sql/ExpressionInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..99c92993926e7c77a3b452549ae9541c88be2ef1 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/ExpressionInterface.php @@ -0,0 +1,36 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql; + +interface ExpressionInterface +{ + const TYPE_IDENTIFIER = 'identifier'; + const TYPE_VALUE = 'value'; + const TYPE_LITERAL = 'literal'; + + /** + * @abstract + * + * @return array of array|string should return an array in the format: + * + * array ( + * // a sprintf formatted string + * string $specification, + * + * // the values for the above sprintf formatted string + * array $values, + * + * // an array of equal length of the $values array, with either TYPE_IDENTIFIER or TYPE_VALUE for each value + * array $types, + * ) + * + */ + public function getExpressionData(); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Having.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Having.php new file mode 100644 index 0000000000000000000000000000000000000000..bf440f3d64370d7d65f8b43b518e2430cdd63504 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Having.php @@ -0,0 +1,15 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql; + +class Having extends Predicate\Predicate +{ + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Insert.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Insert.php new file mode 100644 index 0000000000000000000000000000000000000000..8704678f67cdf2f7e2eea2d787dfd877be6925ad --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Insert.php @@ -0,0 +1,372 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql; + +use Zend\Db\Adapter\AdapterInterface; +use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\Adapter\Platform\Sql92; +use Zend\Db\Adapter\StatementContainerInterface; + +class Insert extends AbstractSql implements SqlInterface, PreparableSqlInterface +{ + /**#@+ + * Constants + * + * @const + */ + const SPECIFICATION_INSERT = 'insert'; + const SPECIFICATION_SELECT = 'select'; + const VALUES_MERGE = 'merge'; + const VALUES_SET = 'set'; + /**#@-*/ + + /** + * @var array Specification array + */ + protected $specifications = array( + self::SPECIFICATION_INSERT => 'INSERT INTO %1$s (%2$s) VALUES (%3$s)', + self::SPECIFICATION_SELECT => 'INSERT INTO %1$s %2$s %3$s', + ); + + /** + * @var string|TableIdentifier + */ + protected $table = null; + protected $columns = array(); + + /** + * @var array|Select + */ + protected $values = null; + + /** + * Constructor + * + * @param null|string|TableIdentifier $table + */ + public function __construct($table = null) + { + if ($table) { + $this->into($table); + } + } + + /** + * Create INTO clause + * + * @param string|TableIdentifier $table + * @return Insert + */ + public function into($table) + { + $this->table = $table; + return $this; + } + + /** + * Specify columns + * + * @param array $columns + * @return Insert + */ + public function columns(array $columns) + { + $this->columns = $columns; + return $this; + } + + /** + * Specify values to insert + * + * @param array|Select $values + * @param string $flag one of VALUES_MERGE or VALUES_SET; defaults to VALUES_SET + * @throws Exception\InvalidArgumentException + * @return Insert + */ + public function values($values, $flag = self::VALUES_SET) + { + if (!is_array($values) && !$values instanceof Select) { + throw new Exception\InvalidArgumentException('values() expects an array of values or Zend\Db\Sql\Select instance'); + } + + if ($values instanceof Select) { + if ($flag == self::VALUES_MERGE && (is_array($this->values) && !empty($this->values))) { + throw new Exception\InvalidArgumentException( + 'A Zend\Db\Sql\Select instance cannot be provided with the merge flag when values already exist.' + ); + } + $this->values = $values; + return $this; + } + + // determine if this is assoc or a set of values + $keys = array_keys($values); + $firstKey = current($keys); + + if ($flag == self::VALUES_SET) { + $this->columns = array(); + $this->values = array(); + } elseif ($this->values instanceof Select) { + throw new Exception\InvalidArgumentException( + 'An array of values cannot be provided with the merge flag when a Zend\Db\Sql\Select' + . ' instance already exists as the value source.' + ); + } + + if (is_string($firstKey)) { + foreach ($keys as $key) { + if (($index = array_search($key, $this->columns)) !== false) { + $this->values[$index] = $values[$key]; + } else { + $this->columns[] = $key; + $this->values[] = $values[$key]; + } + } + } elseif (is_int($firstKey)) { + // determine if count of columns should match count of values + $this->values = array_merge($this->values, array_values($values)); + } + + return $this; + } + + /** + * Create INTO SELECT clause + * + * @param Select $select + * @return self + */ + public function select(Select $select) + { + return $this->values($select); + } + + /** + * Get raw state + * + * @param string $key + * @return mixed + */ + public function getRawState($key = null) + { + $rawState = array( + 'table' => $this->table, + 'columns' => $this->columns, + 'values' => $this->values + ); + return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; + } + + /** + * Prepare statement + * + * @param AdapterInterface $adapter + * @param StatementContainerInterface $statementContainer + * @return void + */ + public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) + { + $driver = $adapter->getDriver(); + $platform = $adapter->getPlatform(); + $parameterContainer = $statementContainer->getParameterContainer(); + + if (!$parameterContainer instanceof ParameterContainer) { + $parameterContainer = new ParameterContainer(); + $statementContainer->setParameterContainer($parameterContainer); + } + + $table = $this->table; + $schema = null; + + // create quoted table name to use in insert processing + if ($table instanceof TableIdentifier) { + list($table, $schema) = $table->getTableAndSchema(); + } + + $table = $platform->quoteIdentifier($table); + + if ($schema) { + $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table; + } + + $columns = array(); + $values = array(); + + if (is_array($this->values)) { + foreach ($this->columns as $cIndex => $column) { + $columns[$cIndex] = $platform->quoteIdentifier($column); + if (isset($this->values[$cIndex]) && $this->values[$cIndex] instanceof Expression) { + $exprData = $this->processExpression($this->values[$cIndex], $platform, $driver); + $values[$cIndex] = $exprData->getSql(); + $parameterContainer->merge($exprData->getParameterContainer()); + } else { + $values[$cIndex] = $driver->formatParameterName($column); + if (isset($this->values[$cIndex])) { + $parameterContainer->offsetSet($column, $this->values[$cIndex]); + } else { + $parameterContainer->offsetSet($column, null); + } + } + } + $sql = sprintf( + $this->specifications[static::SPECIFICATION_INSERT], + $table, + implode(', ', $columns), + implode(', ', $values) + ); + } elseif ($this->values instanceof Select) { + $this->values->prepareStatement($adapter, $statementContainer); + + $columns = array_map(array($platform, 'quoteIdentifier'), $this->columns); + $columns = implode(', ', $columns); + + $sql = sprintf( + $this->specifications[static::SPECIFICATION_SELECT], + $table, + $columns ? "($columns)" : "", + $statementContainer->getSql() + ); + } else { + throw new Exception\InvalidArgumentException('values or select should be present'); + } + $statementContainer->setSql($sql); + } + + /** + * Get SQL string for this statement + * + * @param null|PlatformInterface $adapterPlatform Defaults to Sql92 if none provided + * @return string + */ + public function getSqlString(PlatformInterface $adapterPlatform = null) + { + $adapterPlatform = ($adapterPlatform) ?: new Sql92; + $table = $this->table; + $schema = null; + + // create quoted table name to use in insert processing + if ($table instanceof TableIdentifier) { + list($table, $schema) = $table->getTableAndSchema(); + } + + $table = $adapterPlatform->quoteIdentifier($table); + + if ($schema) { + $table = $adapterPlatform->quoteIdentifier($schema) . $adapterPlatform->getIdentifierSeparator() . $table; + } + + $columns = array_map(array($adapterPlatform, 'quoteIdentifier'), $this->columns); + $columns = implode(', ', $columns); + + if (is_array($this->values)) { + $values = array(); + foreach ($this->values as $value) { + if ($value instanceof Expression) { + $exprData = $this->processExpression($value, $adapterPlatform); + $values[] = $exprData->getSql(); + } elseif ($value === null) { + $values[] = 'NULL'; + } else { + $values[] = $adapterPlatform->quoteValue($value); + } + } + return sprintf( + $this->specifications[static::SPECIFICATION_INSERT], + $table, + $columns, + implode(', ', $values) + ); + } elseif ($this->values instanceof Select) { + $selectString = $this->values->getSqlString($adapterPlatform); + if ($columns) { + $columns = "($columns)"; + } + return sprintf( + $this->specifications[static::SPECIFICATION_SELECT], + $table, + $columns, + $selectString + ); + } else { + throw new Exception\InvalidArgumentException('values or select should be present'); + } + } + + /** + * Overloading: variable setting + * + * Proxies to values, using VALUES_MERGE strategy + * + * @param string $name + * @param mixed $value + * @return Insert + */ + public function __set($name, $value) + { + $values = array($name => $value); + $this->values($values, self::VALUES_MERGE); + return $this; + } + + /** + * Overloading: variable unset + * + * Proxies to values and columns + * + * @param string $name + * @throws Exception\InvalidArgumentException + * @return void + */ + public function __unset($name) + { + if (($position = array_search($name, $this->columns)) === false) { + throw new Exception\InvalidArgumentException('The key ' . $name . ' was not found in this objects column list'); + } + + unset($this->columns[$position]); + if (is_array($this->values)) { + unset($this->values[$position]); + } + } + + /** + * Overloading: variable isset + * + * Proxies to columns; does a column of that name exist? + * + * @param string $name + * @return bool + */ + public function __isset($name) + { + return in_array($name, $this->columns); + } + + /** + * Overloading: variable retrieval + * + * Retrieves value by column name + * + * @param string $name + * @throws Exception\InvalidArgumentException + * @return mixed + */ + public function __get($name) + { + if (!is_array($this->values)) { + return null; + } + if (($position = array_search($name, $this->columns)) === false) { + throw new Exception\InvalidArgumentException('The key ' . $name . ' was not found in this objects column list'); + } + return $this->values[$position]; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Literal.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Literal.php new file mode 100644 index 0000000000000000000000000000000000000000..ba67415a3d4f135eadf72bf307bafaa307537759 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Literal.php @@ -0,0 +1,56 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql; + +class Literal implements ExpressionInterface +{ + /** + * @var string + */ + protected $literal = ''; + + /** + * @param $literal + */ + public function __construct($literal = '') + { + $this->literal = $literal; + } + + /** + * @param string $literal + * @return Literal + */ + public function setLiteral($literal) + { + $this->literal = $literal; + return $this; + } + + /** + * @return string + */ + public function getLiteral() + { + return $this->literal; + } + + /** + * @return array + */ + public function getExpressionData() + { + return array(array( + str_replace('%', '%%', $this->literal), + array(), + array() + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/AbstractPlatform.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/AbstractPlatform.php new file mode 100644 index 0000000000000000000000000000000000000000..c5ddd6ce608e8daa235948fbc4c7a46bd795f8c8 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/AbstractPlatform.php @@ -0,0 +1,110 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Platform; + +use Zend\Db\Adapter\AdapterInterface; +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\Adapter\StatementContainerInterface; +use Zend\Db\Sql\Exception; +use Zend\Db\Sql\PreparableSqlInterface; +use Zend\Db\Sql\SqlInterface; + +class AbstractPlatform implements PlatformDecoratorInterface, PreparableSqlInterface, SqlInterface +{ + /** + * @var object + */ + protected $subject = null; + + /** + * @var PlatformDecoratorInterface[] + */ + protected $decorators = array(); + + /** + * @param $subject + */ + public function setSubject($subject) + { + $this->subject = $subject; + } + + /** + * @param $type + * @param PlatformDecoratorInterface $decorator + */ + public function setTypeDecorator($type, PlatformDecoratorInterface $decorator) + { + $this->decorators[$type] = $decorator; + } + + /** + * @return array|PlatformDecoratorInterface[] + */ + public function getDecorators() + { + return $this->decorators; + } + + /** + * @param AdapterInterface $adapter + * @param StatementContainerInterface $statementContainer + * @throws Exception\RuntimeException + * @return void + */ + public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) + { + if (!$this->subject instanceof PreparableSqlInterface) { + throw new Exception\RuntimeException('The subject does not appear to implement Zend\Db\Sql\PreparableSqlInterface, thus calling prepareStatement() has no effect'); + } + + $decoratorForType = false; + foreach ($this->decorators as $type => $decorator) { + if ($this->subject instanceof $type && $decorator instanceof PreparableSqlInterface) { + /** @var $decoratorForType PreparableSqlInterface|PlatformDecoratorInterface */ + $decoratorForType = $decorator; + break; + } + } + if ($decoratorForType) { + $decoratorForType->setSubject($this->subject); + $decoratorForType->prepareStatement($adapter, $statementContainer); + } else { + $this->subject->prepareStatement($adapter, $statementContainer); + } + } + + /** + * @param null|\Zend\Db\Adapter\Platform\PlatformInterface $adapterPlatform + * @return mixed + * @throws Exception\RuntimeException + */ + public function getSqlString(PlatformInterface $adapterPlatform = null) + { + if (!$this->subject instanceof SqlInterface) { + throw new Exception\RuntimeException('The subject does not appear to implement Zend\Db\Sql\PreparableSqlInterface, thus calling prepareStatement() has no effect'); + } + + $decoratorForType = false; + foreach ($this->decorators as $type => $decorator) { + if ($this->subject instanceof $type && $decorator instanceof SqlInterface) { + /** @var $decoratorForType SqlInterface|PlatformDecoratorInterface */ + $decoratorForType = $decorator; + break; + } + } + if ($decoratorForType) { + $decoratorForType->setSubject($this->subject); + return $decoratorForType->getSqlString($adapterPlatform); + } + + return $this->subject->getSqlString($adapterPlatform); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php new file mode 100644 index 0000000000000000000000000000000000000000..d9cfa15563fc8976f1ebf1aff9a74b9d8b344ca6 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php @@ -0,0 +1,86 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Platform\Mysql\Ddl; + +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\Sql\Ddl\CreateTable; +use Zend\Db\Sql\Platform\PlatformDecoratorInterface; + +class CreateTableDecorator extends CreateTable implements PlatformDecoratorInterface +{ + /** + * @var CreateTable + */ + protected $createTable; + + /** + * @param CreateTable $subject + */ + public function setSubject($subject) + { + $this->createTable = $subject; + } + + /** + * @param null|PlatformInterface $platform + * @return string + */ + public function getSqlString(PlatformInterface $platform = null) + { + // localize variables + foreach (get_object_vars($this->createTable) as $name => $value) { + $this->{$name} = $value; + } + return parent::getSqlString($platform); + } + + protected function processColumns(PlatformInterface $platform = null) + { + $sqls = array(); + foreach ($this->columns as $i => $column) { + $stmtContainer = $this->processExpression($column, $platform); + $sql = $stmtContainer->getSql(); + $columnOptions = $column->getOptions(); + + foreach ($columnOptions as $coName => $coValue) { + switch (strtolower(str_replace(array('-', '_', ' '), '', $coName))) { + case 'identity': + case 'serial': + case 'autoincrement': + $sql .= ' AUTO_INCREMENT'; + break; + /* + case 'primary': + case 'primarykey': + $sql .= ' PRIMARY KEY'; + break; + case 'unique': + case 'uniquekey': + $sql .= ' UNIQUE KEY'; + break; + */ + case 'comment': + $sql .= ' COMMENT \'' . $coValue . '\''; + break; + case 'columnformat': + case 'format': + $sql .= ' COLUMN_FORMAT ' . strtoupper($coValue); + break; + case 'storage': + $sql .= ' STORAGE ' . strtoupper($coValue); + break; + } + } + $stmtContainer->setSql($sql); + $sqls[$i] = $stmtContainer; + } + return array($sqls); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/Mysql.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/Mysql.php new file mode 100644 index 0000000000000000000000000000000000000000..80455869a41154a3d60e4a14ec8db9b45c533ba2 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/Mysql.php @@ -0,0 +1,21 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Platform\Mysql; + +use Zend\Db\Sql\Platform\AbstractPlatform; + +class Mysql extends AbstractPlatform +{ + public function __construct() + { + $this->setTypeDecorator('Zend\Db\Sql\Select', new SelectDecorator()); + $this->setTypeDecorator('Zend\Db\Sql\Ddl\CreateTable', new Ddl\CreateTableDecorator()); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/SelectDecorator.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/SelectDecorator.php new file mode 100644 index 0000000000000000000000000000000000000000..5c4678a730af7dc0cf24e0e232d5f44d13845bd8 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Mysql/SelectDecorator.php @@ -0,0 +1,97 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Platform\Mysql; + +use Zend\Db\Adapter\AdapterInterface; +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\Adapter\StatementContainerInterface; +use Zend\Db\Sql\Platform\PlatformDecoratorInterface; +use Zend\Db\Sql\Select; + +class SelectDecorator extends Select implements PlatformDecoratorInterface +{ + /** + * @var Select + */ + protected $select = null; + + /** + * @param Select $select + */ + public function setSubject($select) + { + $this->select = $select; + } + + /** + * @param AdapterInterface $adapter + * @param StatementContainerInterface $statementContainer + */ + public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) + { + // localize variables + foreach (get_object_vars($this->select) as $name => $value) { + $this->{$name} = $value; + } + if ($this->limit === null && $this->offset !== null) { + $this->specifications[self::LIMIT] = 'LIMIT 18446744073709551615'; + } + parent::prepareStatement($adapter, $statementContainer); + } + + /** + * @param PlatformInterface $platform + * @return string + */ + public function getSqlString(PlatformInterface $platform = null) + { + // localize variables + foreach (get_object_vars($this->select) as $name => $value) { + $this->{$name} = $value; + } + if ($this->limit === null && $this->offset !== null) { + $this->specifications[self::LIMIT] = 'LIMIT 18446744073709551615'; + } + return parent::getSqlString($platform); + } + + protected function processLimit(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + if ($this->limit === null && $this->offset !== null) { + return array(''); + } + if ($this->limit === null) { + return null; + } + if ($driver) { + $sql = $driver->formatParameterName('limit'); + $parameterContainer->offsetSet('limit', $this->limit, ParameterContainer::TYPE_INTEGER); + } else { + $sql = $this->limit; + } + + return array($sql); + } + + protected function processOffset(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + if ($this->offset === null) { + return null; + } + if ($driver) { + $parameterContainer->offsetSet('offset', $this->offset, ParameterContainer::TYPE_INTEGER); + return array($driver->formatParameterName('offset')); + } + + return array($this->offset); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Oracle/Oracle.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Oracle/Oracle.php new file mode 100644 index 0000000000000000000000000000000000000000..e8dee3ceb3bd14b7aedf0e9c0332e8db52fa4c45 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Oracle/Oracle.php @@ -0,0 +1,22 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Platform\Oracle; + +use Zend\Db\Sql\Platform\AbstractPlatform; + +class Oracle extends AbstractPlatform +{ + + public function __construct(SelectDecorator $selectDecorator = null) + { + $this->setTypeDecorator('Zend\Db\Sql\Select', ($selectDecorator) ?: new SelectDecorator()); + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Oracle/SelectDecorator.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Oracle/SelectDecorator.php new file mode 100644 index 0000000000000000000000000000000000000000..69c1700978fe613171337e0f7c1a87fabca45cea --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Oracle/SelectDecorator.php @@ -0,0 +1,182 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Platform\Oracle; + +use Zend\Db\Adapter\AdapterInterface; +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\Adapter\StatementContainerInterface; +use Zend\Db\Sql\ExpressionInterface; +use Zend\Db\Sql\Platform\PlatformDecoratorInterface; +use Zend\Db\Sql\Select; + +class SelectDecorator extends Select implements PlatformDecoratorInterface +{ + + /** + * @var Select + */ + protected $select = null; + + /** + * @param Select $select + */ + public function setSubject($select) + { + $this->select = $select; + } + + /** + * @see \Zend\Db\Sql\Select::renderTable + */ + protected function renderTable($table, $alias = null) + { + return $table . ' ' . $alias; + } + + /** + * @param AdapterInterface $adapter + * @param StatementContainerInterface $statementContainer + */ + public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) + { + // localize variables + foreach (get_object_vars($this->select) as $name => $value) { + $this->{$name} = $value; + } + // set specifications + unset($this->specifications[self::LIMIT]); + unset($this->specifications[self::OFFSET]); + + $this->specifications['LIMITOFFSET'] = null; + parent::prepareStatement($adapter, $statementContainer); + } + + /** + * @param PlatformInterface $platform + * @return string + */ + public function getSqlString(PlatformInterface $platform = null) + { + // localize variables + foreach (get_object_vars($this->select) as $name => $value) { + $this->{$name} = $value; + } + + // set specifications + unset($this->specifications[self::LIMIT]); + unset($this->specifications[self::OFFSET]); + + $this->specifications['LIMITOFFSET'] = null; + return parent::getSqlString($platform); + } + + /** + * @param PlatformInterface $platform + * @param DriverInterface $driver + * @param ParameterContainer $parameterContainer + * @param $sqls + * @param $parameters + * @return null + */ + protected function processLimitOffset(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null, &$sqls, &$parameters) + { + if ($this->limit === null && $this->offset === null) { + return null; + } + + $selectParameters = $parameters[self::SELECT]; + + $starSuffix = $platform->getIdentifierSeparator() . self::SQL_STAR; + foreach ($selectParameters[0] as $i => $columnParameters) { + if ($columnParameters[0] == self::SQL_STAR || (isset($columnParameters[1]) && $columnParameters[1] == self::SQL_STAR) || strpos($columnParameters[0], $starSuffix)) { + $selectParameters[0] = array(array(self::SQL_STAR)); + break; + } + if (isset($columnParameters[1])) { + array_shift($columnParameters); + $selectParameters[0][$i] = $columnParameters; + } + } + + if ($this->offset === null) { + $this->offset = 0; + } + + // first, produce column list without compound names (using the AS portion only) + array_unshift($sqls, $this->createSqlFromSpecificationAndParameters( + array('SELECT %1$s FROM (SELECT b.%1$s, rownum b_rownum FROM (' => current($this->specifications[self::SELECT])), $selectParameters + )); + + if ($parameterContainer) { + if ($this->limit === null) { + array_push($sqls, ') b ) WHERE b_rownum > (:offset)'); + $parameterContainer->offsetSet('offset', $this->offset, $parameterContainer::TYPE_INTEGER); + } else { + // create bottom part of query, with offset and limit using row_number + array_push($sqls, ') b WHERE rownum <= (:offset+:limit)) WHERE b_rownum >= (:offset + 1)'); + $parameterContainer->offsetSet('offset', $this->offset, $parameterContainer::TYPE_INTEGER); + $parameterContainer->offsetSet('limit', $this->limit, $parameterContainer::TYPE_INTEGER); + } + } else { + if ($this->limit === null) { + array_push($sqls, ') b ) WHERE b_rownum > ('. (int) $this->offset. ')' + ); + } else { + array_push($sqls, ') b WHERE rownum <= (' + . (int) $this->offset + . '+' + . (int) $this->limit + . ')) WHERE b_rownum >= (' + . (int) $this->offset + . ' + 1)' + ); + } + } + + $sqls[self::SELECT] = $this->createSqlFromSpecificationAndParameters( + $this->specifications[self::SELECT], $parameters[self::SELECT] + ); + } + + + protected function processJoins(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + if (!$this->joins) { + return null; + } + + // process joins + $joinSpecArgArray = array(); + foreach ($this->joins as $j => $join) { + $joinSpecArgArray[$j] = array(); + // type + $joinSpecArgArray[$j][] = strtoupper($join['type']); + // table name + $joinSpecArgArray[$j][] = (is_array($join['name'])) + ? $platform->quoteIdentifier(current($join['name'])) . ' ' . $platform->quoteIdentifier(key($join['name'])) + : $platform->quoteIdentifier($join['name']); + // on expression + $joinSpecArgArray[$j][] = ($join['on'] instanceof ExpressionInterface) + ? $this->processExpression($join['on'], $platform, $driver, $this->processInfo['paramPrefix'] . 'join') + : $platform->quoteIdentifierInFragment($join['on'], array('=', 'AND', 'OR', '(', ')', 'BETWEEN')); // on + if ($joinSpecArgArray[$j][2] instanceof StatementContainerInterface) { + if ($parameterContainer) { + $parameterContainer->merge($joinSpecArgArray[$j][2]->getParameterContainer()); + } + $joinSpecArgArray[$j][2] = $joinSpecArgArray[$j][2]->getSql(); + } + } + + return array($joinSpecArgArray); + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Platform.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Platform.php new file mode 100644 index 0000000000000000000000000000000000000000..1342c731a16427b726df14ea4d73f195e3548be0 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/Platform.php @@ -0,0 +1,42 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Platform; + +use Zend\Db\Adapter\AdapterInterface; + +class Platform extends AbstractPlatform +{ + + /** + * @var AdapterInterface + */ + protected $adapter = null; + + public function __construct(AdapterInterface $adapter) + { + $this->adapter = $adapter; + $platform = $adapter->getPlatform(); + switch (strtolower($platform->getName())) { + case 'mysql': + $platform = new Mysql\Mysql(); + $this->decorators = $platform->decorators; + break; + case 'sqlserver': + $platform = new SqlServer\SqlServer(); + $this->decorators = $platform->decorators; + break; + case 'oracle': + $platform = new Oracle\Oracle(); + $this->decorators = $platform->decorators; + break; + default: + } + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/PlatformDecoratorInterface.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/PlatformDecoratorInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..2ff7c97ce6d835f6201a3e78528654532c788ed4 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/PlatformDecoratorInterface.php @@ -0,0 +1,15 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Platform; + +interface PlatformDecoratorInterface +{ + public function setSubject($subject); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/Ddl/CreateTableDecorator.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/Ddl/CreateTableDecorator.php new file mode 100644 index 0000000000000000000000000000000000000000..c84742dfd60373f46b3c69d4c4b34eca435c97e7 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/Ddl/CreateTableDecorator.php @@ -0,0 +1,61 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Platform\SqlServer\Ddl; + +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\Sql\Ddl\CreateTable; +use Zend\Db\Sql\Platform\PlatformDecoratorInterface; + +class CreateTableDecorator extends CreateTable implements PlatformDecoratorInterface +{ + /** + * @var CreateTable + */ + protected $createTable; + + /** + * @param CreateTable $subject + * @return self + */ + public function setSubject($subject) + { + $this->createTable = $subject; + return $this; + } + + /** + * @param null|PlatformInterface $platform + * @return string + */ + public function getSqlString(PlatformInterface $platform = null) + { + // localize variables + foreach (get_object_vars($this->createTable) as $name => $value) { + $this->{$name} = $value; + } + return parent::getSqlString($platform); + } + + /** + * @param PlatformInterface $adapterPlatform + * @return array + */ + protected function processTable(PlatformInterface $adapterPlatform = null) + { + $ret = array(''); + if ($this->isTemporary) { + $table = '#'; + } else { + $table = ''; + } + $ret[] = $adapterPlatform->quoteIdentifier($table . ltrim($this->table, '#')); + return $ret; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/SelectDecorator.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/SelectDecorator.php new file mode 100644 index 0000000000000000000000000000000000000000..8619321b8c4207b0b50093396e8b12407ee260ae --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/SelectDecorator.php @@ -0,0 +1,140 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Platform\SqlServer; + +use Zend\Db\Adapter\AdapterInterface; +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\Adapter\StatementContainerInterface; +use Zend\Db\Sql\Platform\PlatformDecoratorInterface; +use Zend\Db\Sql\Select; + +class SelectDecorator extends Select implements PlatformDecoratorInterface +{ + /** + * @var Select + */ + protected $select = null; + + /** + * @param Select $select + */ + public function setSubject($select) + { + $this->select = $select; + } + + /** + * @param AdapterInterface $adapter + * @param StatementContainerInterface $statementContainer + */ + public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) + { + // localize variables + foreach (get_object_vars($this->select) as $name => $value) { + $this->{$name} = $value; + } + + // set specifications + unset($this->specifications[self::LIMIT]); + unset($this->specifications[self::OFFSET]); + + $this->specifications['LIMITOFFSET'] = null; + parent::prepareStatement($adapter, $statementContainer); + } + + /** + * @param PlatformInterface $platform + * @return string + */ + public function getSqlString(PlatformInterface $platform = null) + { + // localize variables + foreach (get_object_vars($this->select) as $name => $value) { + $this->{$name} = $value; + } + + // set specifications + unset($this->specifications[self::LIMIT]); + unset($this->specifications[self::OFFSET]); + + $this->specifications['LIMITOFFSET'] = null; + return parent::getSqlString($platform); + } + + /** + * @param PlatformInterface $platform + * @param DriverInterface $driver + * @param ParameterContainer $parameterContainer + * @param $sqls + * @param $parameters + * @return null + */ + protected function processLimitOffset(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null, &$sqls, &$parameters) + { + if ($this->limit === null && $this->offset === null) { + return null; + } + + $selectParameters = $parameters[self::SELECT]; + + $starSuffix = $platform->getIdentifierSeparator() . self::SQL_STAR; + foreach ($selectParameters[0] as $i => $columnParameters) { + if ($columnParameters[0] == self::SQL_STAR || (isset($columnParameters[1]) && $columnParameters[1] == self::SQL_STAR) || strpos($columnParameters[0], $starSuffix)) { + $selectParameters[0] = array(array(self::SQL_STAR)); + break; + } + if (isset($columnParameters[1])) { + array_shift($columnParameters); + $selectParameters[0][$i] = $columnParameters; + } + } + + // first, produce column list without compound names (using the AS portion only) + array_unshift($sqls, $this->createSqlFromSpecificationAndParameters( + array('SELECT %1$s FROM (' => current($this->specifications[self::SELECT])), + $selectParameters + )); + + if ($parameterContainer) { + // create bottom part of query, with offset and limit using row_number + $limitParamName = $driver->formatParameterName('limit'); + $offsetParamName = $driver->formatParameterName('offset'); + $offsetForSumParamName = $driver->formatParameterName('offsetForSum'); + array_push($sqls, ') AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ' + . $offsetParamName . '+1 AND ' . $limitParamName . '+' . $offsetForSumParamName); + $parameterContainer->offsetSet('offset', $this->offset); + $parameterContainer->offsetSet('limit', $this->limit); + $parameterContainer->offsetSetReference('offsetForSum', 'offset'); + } else { + array_push($sqls, ') AS [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION] WHERE [ZEND_SQL_SERVER_LIMIT_OFFSET_EMULATION].[__ZEND_ROW_NUMBER] BETWEEN ' + . (int) $this->offset . '+1 AND ' + . (int) $this->limit . '+' . (int) $this->offset + ); + } + + if (isset($sqls[self::ORDER])) { + $orderBy = $sqls[self::ORDER]; + unset($sqls[self::ORDER]); + } else { + $orderBy = 'ORDER BY (SELECT 1)'; + } + + // add a column for row_number() using the order specification + $parameters[self::SELECT][0][] = array('ROW_NUMBER() OVER (' . $orderBy . ')', '[__ZEND_ROW_NUMBER]'); + + $sqls[self::SELECT] = $this->createSqlFromSpecificationAndParameters( + $this->specifications[self::SELECT], + $parameters[self::SELECT] + ); + + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/SqlServer.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/SqlServer.php new file mode 100644 index 0000000000000000000000000000000000000000..23d4011bfd1068ecdf196ec190623f963c3ce2c0 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Platform/SqlServer/SqlServer.php @@ -0,0 +1,22 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Platform\SqlServer; + +use Zend\Db\Sql\Platform\AbstractPlatform; + +class SqlServer extends AbstractPlatform +{ + + public function __construct(SelectDecorator $selectDecorator = null) + { + $this->setTypeDecorator('Zend\Db\Sql\Select', ($selectDecorator) ?: new SelectDecorator()); + $this->setTypeDecorator('Zend\Db\Sql\Ddl\CreateTable', new Ddl\CreateTableDecorator()); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Between.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Between.php new file mode 100644 index 0000000000000000000000000000000000000000..686b65db58d43122087588059d4ed4c001c3dccb --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Between.php @@ -0,0 +1,142 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Predicate; + +class Between implements PredicateInterface +{ + protected $specification = '%1$s BETWEEN %2$s AND %3$s'; + protected $identifier = null; + protected $minValue = null; + protected $maxValue = null; + + /** + * Constructor + * + * @param string $identifier + * @param int|float|string $minValue + * @param int|float|string $maxValue + */ + public function __construct($identifier = null, $minValue = null, $maxValue = null) + { + if ($identifier) { + $this->setIdentifier($identifier); + } + if ($minValue !== null) { + $this->setMinValue($minValue); + } + if ($maxValue !== null) { + $this->setMaxValue($maxValue); + } + } + + /** + * Set identifier for comparison + * + * @param string $identifier + * @return Between + */ + public function setIdentifier($identifier) + { + $this->identifier = $identifier; + return $this; + } + + /** + * Get identifier of comparison + * + * @return null|string + */ + public function getIdentifier() + { + return $this->identifier; + } + + /** + * Set minimum boundary for comparison + * + * @param int|float|string $minValue + * @return Between + */ + public function setMinValue($minValue) + { + $this->minValue = $minValue; + return $this; + } + + /** + * Get minimum boundary for comparison + * + * @return null|int|float|string + */ + public function getMinValue() + { + return $this->minValue; + } + + /** + * Set maximum boundary for comparison + * + * @param int|float|string $maxValue + * @return Between + */ + public function setMaxValue($maxValue) + { + $this->maxValue = $maxValue; + return $this; + } + + /** + * Get maximum boundary for comparison + * + * @return null|int|float|string + */ + public function getMaxValue() + { + return $this->maxValue; + } + + /** + * Set specification string to use in forming SQL predicate + * + * @param string $specification + * @return Between + */ + public function setSpecification($specification) + { + $this->specification = $specification; + return $this; + } + + /** + * Get specification string to use in forming SQL predicate + * + * @return string + */ + public function getSpecification() + { + return $this->specification; + } + + /** + * Return "where" parts + * + * @return array + */ + public function getExpressionData() + { + return array( + array( + $this->getSpecification(), + array($this->identifier, $this->minValue, $this->maxValue), + array(self::TYPE_IDENTIFIER, self::TYPE_VALUE, self::TYPE_VALUE), + ), + ); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Expression.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Expression.php new file mode 100644 index 0000000000000000000000000000000000000000..58ceadbfc9e7e6914d8a5e12e78551c94345a969 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Expression.php @@ -0,0 +1,42 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Predicate; + +use Zend\Db\Sql\Expression as BaseExpression; + +class Expression extends BaseExpression implements PredicateInterface +{ + + /** + * Constructor + * + * @param string $expression + * @param int|float|bool|string|array $valueParameter + */ + public function __construct($expression = null, $valueParameter = null /*[, $valueParameter, ... ]*/) + { + if ($expression) { + $this->setExpression($expression); + } + + if (is_array($valueParameter)) { + $this->setParameters($valueParameter); + } else { + $argNum = func_num_args(); + if ($argNum > 2 || is_scalar($valueParameter)) { + $parameters = array(); + for ($i = 1; $i < $argNum; $i++) { + $parameters[] = func_get_arg($i); + } + $this->setParameters($parameters); + } + } + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/In.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/In.php new file mode 100644 index 0000000000000000000000000000000000000000..eb7ccc36c364577179489c7a8cafb04c4f46ba4b --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/In.php @@ -0,0 +1,133 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Predicate; + +use Zend\Db\Sql\Exception; +use Zend\Db\Sql\Select; + +class In implements PredicateInterface +{ + protected $identifier; + protected $valueSet; + + protected $specification = '%s IN %s'; + + /** + * Constructor + * + * @param null|string|array $identifier + * @param null|array|Select $valueSet + */ + public function __construct($identifier = null, $valueSet = null) + { + if ($identifier) { + $this->setIdentifier($identifier); + } + if ($valueSet) { + $this->setValueSet($valueSet); + } + } + + /** + * Set identifier for comparison + * + * @param string|array $identifier + * @return In + */ + public function setIdentifier($identifier) + { + $this->identifier = $identifier; + + return $this; + } + + /** + * Get identifier of comparison + * + * @return null|string|array + */ + public function getIdentifier() + { + return $this->identifier; + } + + /** + * Set set of values for IN comparison + * + * @param array|Select $valueSet + * @throws Exception\InvalidArgumentException + * @return In + */ + public function setValueSet($valueSet) + { + if (!is_array($valueSet) && !$valueSet instanceof Select) { + throw new Exception\InvalidArgumentException( + '$valueSet must be either an array or a Zend\Db\Sql\Select object, ' . gettype($valueSet) . ' given' + ); + } + $this->valueSet = $valueSet; + + return $this; + } + + /** + * Gets set of values in IN comparision + * + * @return array|Select + */ + public function getValueSet() + { + return $this->valueSet; + } + + /** + * Return array of parts for where statement + * + * @return array + */ + public function getExpressionData() + { + $identifier = $this->getIdentifier(); + $values = $this->getValueSet(); + $replacements = array(); + + if (is_array($identifier)) { + $identifierSpecFragment = '(' . implode(', ', array_fill(0, count($identifier), '%s')) . ')'; + $types = array_fill(0, count($identifier), self::TYPE_IDENTIFIER); + $replacements = $identifier; + } else { + $identifierSpecFragment = '%s'; + $replacements[] = $identifier; + $types = array(self::TYPE_IDENTIFIER); + } + + if ($values instanceof Select) { + $specification = vsprintf( + $this->specification, + array($identifierSpecFragment, '%s') + ); + $replacements[] = $values; + $types[] = self::TYPE_VALUE; + } else { + $specification = vsprintf( + $this->specification, + array($identifierSpecFragment, '(' . implode(', ', array_fill(0, count($values), '%s')) . ')') + ); + $replacements = array_merge($replacements, $values); + $types = array_merge($types, array_fill(0, count($values), self::TYPE_VALUE)); + } + + return array(array( + $specification, + $replacements, + $types, + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/IsNotNull.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/IsNotNull.php new file mode 100644 index 0000000000000000000000000000000000000000..e09f34912a0306c7eabb8578048ac3c59349da14 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/IsNotNull.php @@ -0,0 +1,15 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Predicate; + +class IsNotNull extends IsNull +{ + protected $specification = '%1$s IS NOT NULL'; +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/IsNull.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/IsNull.php new file mode 100644 index 0000000000000000000000000000000000000000..007586d14f98b7ab9d6717028c5cc7342b346d0a --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/IsNull.php @@ -0,0 +1,94 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Predicate; + +class IsNull implements PredicateInterface +{ + + /** + * @var string + */ + protected $specification = '%1$s IS NULL'; + + /** + * @var + */ + protected $identifier; + + /** + * Constructor + * + * @param string $identifier + */ + public function __construct($identifier = null) + { + if ($identifier) { + $this->setIdentifier($identifier); + } + } + + /** + * Set identifier for comparison + * + * @param string $identifier + * @return IsNull + */ + public function setIdentifier($identifier) + { + $this->identifier = $identifier; + return $this; + } + + /** + * Get identifier of comparison + * + * @return null|string + */ + public function getIdentifier() + { + return $this->identifier; + } + + /** + * Set specification string to use in forming SQL predicate + * + * @param string $specification + * @return IsNull + */ + public function setSpecification($specification) + { + $this->specification = $specification; + return $this; + } + + /** + * Get specification string to use in forming SQL predicate + * + * @return string + */ + public function getSpecification() + { + return $this->specification; + } + + /** + * Get parts for where statement + * + * @return array + */ + public function getExpressionData() + { + return array(array( + $this->getSpecification(), + array($this->identifier), + array(self::TYPE_IDENTIFIER), + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Like.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Like.php new file mode 100644 index 0000000000000000000000000000000000000000..ba5e64793878284b8d0d8e02f0e7bf7f7afe5586 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Like.php @@ -0,0 +1,107 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Predicate; + +class Like implements PredicateInterface +{ + + /** + * @var string + */ + protected $specification = '%1$s LIKE %2$s'; + + /** + * @var string + */ + protected $identifier = ''; + + /** + * @var string + */ + protected $like = ''; + + /** + * @param string $identifier + * @param string $like + */ + public function __construct($identifier = null, $like = null) + { + if ($identifier) { + $this->setIdentifier($identifier); + } + if ($like) { + $this->setLike($like); + } + } + + /** + * @param string $identifier + * @return self + */ + public function setIdentifier($identifier) + { + $this->identifier = $identifier; + return $this; + } + + /** + * @return string + */ + public function getIdentifier() + { + return $this->identifier; + } + + /** + * @param string $like + * @return self + */ + public function setLike($like) + { + $this->like = $like; + return $this; + } + + /** + * @return string + */ + public function getLike() + { + return $this->like; + } + + /** + * @param string $specification + * @return self + */ + public function setSpecification($specification) + { + $this->specification = $specification; + return $this; + } + + /** + * @return string + */ + public function getSpecification() + { + return $this->specification; + } + + /** + * @return array + */ + public function getExpressionData() + { + return array( + array($this->specification, array($this->identifier, $this->like), array(self::TYPE_IDENTIFIER, self::TYPE_VALUE)) + ); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Literal.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Literal.php new file mode 100644 index 0000000000000000000000000000000000000000..cb4c080c8334c37e509f69bdda5bf3214f823062 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Literal.php @@ -0,0 +1,17 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Predicate; + +use Zend\Db\Sql\Literal as BaseLiteral; + +class Literal extends BaseLiteral implements PredicateInterface +{ + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/NotIn.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/NotIn.php new file mode 100644 index 0000000000000000000000000000000000000000..09555590084178587f46a26eb191669d51ef3bc3 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/NotIn.php @@ -0,0 +1,15 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Predicate; + +class NotIn extends In +{ + protected $specification = '%s NOT IN %s'; +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/NotLike.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/NotLike.php new file mode 100644 index 0000000000000000000000000000000000000000..329de23ed76ec4bf245b108292333e43d83921f5 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/NotLike.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Predicate; + + +class NotLike extends Like +{ + protected $specification = '%1$s NOT LIKE %2$s'; +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Operator.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Operator.php new file mode 100644 index 0000000000000000000000000000000000000000..acd941406df7e2d303e737ccdf75f05fa7a11a5e --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Operator.php @@ -0,0 +1,218 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Predicate; + +use Zend\Db\Sql\Exception; + +class Operator implements PredicateInterface +{ + const OPERATOR_EQUAL_TO = '='; + const OP_EQ = '='; + + const OPERATOR_NOT_EQUAL_TO = '!='; + const OP_NE = '!='; + + const OPERATOR_LESS_THAN = '<'; + const OP_LT = '<'; + + const OPERATOR_LESS_THAN_OR_EQUAL_TO = '<='; + const OP_LTE = '<='; + + const OPERATOR_GREATER_THAN = '>'; + const OP_GT = '>'; + + const OPERATOR_GREATER_THAN_OR_EQUAL_TO = '>='; + const OP_GTE = '>='; + + protected $allowedTypes = array( + self::TYPE_IDENTIFIER, + self::TYPE_VALUE, + ); + + protected $left = null; + protected $leftType = self::TYPE_IDENTIFIER; + protected $operator = self::OPERATOR_EQUAL_TO; + protected $right = null; + protected $rightType = self::TYPE_VALUE; + + /** + * Constructor + * + * @param int|float|bool|string $left + * @param string $operator + * @param int|float|bool|string $right + * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} + * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} + */ + public function __construct($left = null, $operator = self::OPERATOR_EQUAL_TO, $right = null, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE) + { + if ($left !== null) { + $this->setLeft($left); + } + + if ($operator !== self::OPERATOR_EQUAL_TO) { + $this->setOperator($operator); + } + + if ($right !== null) { + $this->setRight($right); + } + + if ($leftType !== self::TYPE_IDENTIFIER) { + $this->setLeftType($leftType); + } + + if ($rightType !== self::TYPE_VALUE) { + $this->setRightType($rightType); + } + } + + /** + * Set left side of operator + * + * @param int|float|bool|string $left + * @return Operator + */ + public function setLeft($left) + { + $this->left = $left; + return $this; + } + + /** + * Get left side of operator + * + * @return int|float|bool|string + */ + public function getLeft() + { + return $this->left; + } + + /** + * Set parameter type for left side of operator + * + * @param string $type TYPE_IDENTIFIER or TYPE_VALUE {@see allowedTypes} + * @throws Exception\InvalidArgumentException + * @return Operator + */ + public function setLeftType($type) + { + if (!in_array($type, $this->allowedTypes)) { + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid type "%s" provided; must be of type "%s" or "%s"', + $type, + __CLASS__ . '::TYPE_IDENTIFIER', + __CLASS__ . '::TYPE_VALUE' + )); + } + $this->leftType = $type; + return $this; + } + + /** + * Get parameter type on left side of operator + * + * @return string + */ + public function getLeftType() + { + return $this->leftType; + } + + /** + * Set operator string + * + * @param string $operator + * @return Operator + */ + public function setOperator($operator) + { + $this->operator = $operator; + return $this; + } + + /** + * Get operator string + * + * @return string + */ + public function getOperator() + { + return $this->operator; + } + + /** + * Set right side of operator + * + * @param int|float|bool|string $value + * @return Operator + */ + public function setRight($value) + { + $this->right = $value; + return $this; + } + + /** + * Get right side of operator + * + * @return int|float|bool|string + */ + public function getRight() + { + return $this->right; + } + + /** + * Set parameter type for right side of operator + * + * @param string $type TYPE_IDENTIFIER or TYPE_VALUE {@see allowedTypes} + * @throws Exception\InvalidArgumentException + * @return Operator + */ + public function setRightType($type) + { + if (!in_array($type, $this->allowedTypes)) { + throw new Exception\InvalidArgumentException(sprintf( + 'Invalid type "%s" provided; must be of type "%s" or "%s"', + $type, + __CLASS__ . '::TYPE_IDENTIFIER', + __CLASS__ . '::TYPE_VALUE' + )); + } + $this->rightType = $type; + return $this; + } + + /** + * Get parameter type on right side of operator + * + * @return string + */ + public function getRightType() + { + return $this->rightType; + } + + /** + * Get predicate parts for where statement + * + * @return array + */ + public function getExpressionData() + { + return array(array( + '%s ' . $this->operator . ' %s', + array($this->left, $this->right), + array($this->leftType, $this->rightType) + )); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Predicate.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Predicate.php new file mode 100644 index 0000000000000000000000000000000000000000..e9ef5757dccc84fb77427143e1b544d73d5327df --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/Predicate.php @@ -0,0 +1,409 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Predicate; + +use Zend\Db\Sql\Exception\RuntimeException; + +/** + * @property Predicate $and + * @property Predicate $or + * @property Predicate $AND + * @property Predicate $OR + * @property Predicate $NEST + * @property Predicate $UNNEST + */ +class Predicate extends PredicateSet +{ + protected $unnest = null; + protected $nextPredicateCombineOperator = null; + + /** + * Begin nesting predicates + * + * @return Predicate + */ + public function nest() + { + $predicateSet = new Predicate(); + $predicateSet->setUnnest($this); + $this->addPredicate($predicateSet, ($this->nextPredicateCombineOperator) ?: $this->defaultCombination); + $this->nextPredicateCombineOperator = null; + return $predicateSet; + } + + /** + * Indicate what predicate will be unnested + * + * @param Predicate $predicate + * @return void + */ + public function setUnnest(Predicate $predicate) + { + $this->unnest = $predicate; + } + + /** + * Indicate end of nested predicate + * + * @return Predicate + * @throws RuntimeException + */ + public function unnest() + { + if ($this->unnest == null) { + throw new RuntimeException('Not nested'); + } + $unnset = $this->unnest; + $this->unnest = null; + return $unnset; + } + + /** + * Create "Equal To" predicate + * + * Utilizes Operator predicate + * + * @param int|float|bool|string $left + * @param int|float|bool|string $right + * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} + * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} + * @return Predicate + */ + public function equalTo($left, $right, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE) + { + $this->addPredicate( + new Operator($left, Operator::OPERATOR_EQUAL_TO, $right, $leftType, $rightType), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + + /** + * Create "Not Equal To" predicate + * + * Utilizes Operator predicate + * + * @param int|float|bool|string $left + * @param int|float|bool|string $right + * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} + * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} + * @return Predicate + */ + public function notEqualTo($left, $right, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE) + { + $this->addPredicate( + new Operator($left, Operator::OPERATOR_NOT_EQUAL_TO, $right, $leftType, $rightType), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + + /** + * Create "Less Than" predicate + * + * Utilizes Operator predicate + * + * @param int|float|bool|string $left + * @param int|float|bool|string $right + * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} + * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} + * @return Predicate + */ + public function lessThan($left, $right, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE) + { + $this->addPredicate( + new Operator($left, Operator::OPERATOR_LESS_THAN, $right, $leftType, $rightType), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + + /** + * Create "Greater Than" predicate + * + * Utilizes Operator predicate + * + * @param int|float|bool|string $left + * @param int|float|bool|string $right + * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} + * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} + * @return Predicate + */ + public function greaterThan($left, $right, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE) + { + $this->addPredicate( + new Operator($left, Operator::OPERATOR_GREATER_THAN, $right, $leftType, $rightType), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + + /** + * Create "Less Than Or Equal To" predicate + * + * Utilizes Operator predicate + * + * @param int|float|bool|string $left + * @param int|float|bool|string $right + * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} + * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} + * @return Predicate + */ + public function lessThanOrEqualTo($left, $right, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE) + { + $this->addPredicate( + new Operator($left, Operator::OPERATOR_LESS_THAN_OR_EQUAL_TO, $right, $leftType, $rightType), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + + /** + * Create "Greater Than Or Equal To" predicate + * + * Utilizes Operator predicate + * + * @param int|float|bool|string $left + * @param int|float|bool|string $right + * @param string $leftType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_IDENTIFIER {@see allowedTypes} + * @param string $rightType TYPE_IDENTIFIER or TYPE_VALUE by default TYPE_VALUE {@see allowedTypes} + * @return Predicate + */ + public function greaterThanOrEqualTo($left, $right, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE) + { + $this->addPredicate( + new Operator($left, Operator::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $right, $leftType, $rightType), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + + /** + * Create "Like" predicate + * + * Utilizes Like predicate + * + * @param string $identifier + * @param string $like + * @return Predicate + */ + public function like($identifier, $like) + { + $this->addPredicate( + new Like($identifier, $like), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + /** + * Create "notLike" predicate + * + * Utilizes In predicate + * + * @param string $identifier + * @param string $notLike + * @return Predicate + */ + public function notLike($identifier, $notLike) + { + $this->addPredicate( + new NotLike($identifier, $notLike), + ($this->nextPredicateCombineOperator) ? : $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + return $this; + } + + /** + * Create an expression, with parameter placeholders + * + * @param $expression + * @param $parameters + * @return $this + */ + public function expression($expression, $parameters) + { + $this->addPredicate( + new Expression($expression, $parameters), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + + /** + * Create "Literal" predicate + * + * Literal predicate, for parameters, use expression() + * + * @param string $literal + * @return Predicate + */ + public function literal($literal) + { + // process deprecated parameters from previous literal($literal, $parameters = null) signature + if (func_num_args() >= 2) { + $parameters = func_get_arg(1); + $predicate = new Expression($literal, $parameters); + } + + // normal workflow for "Literals" here + if (!isset($predicate)) { + $predicate = new Literal($literal); + } + + $this->addPredicate( + $predicate, + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + + /** + * Create "IS NULL" predicate + * + * Utilizes IsNull predicate + * + * @param string $identifier + * @return Predicate + */ + public function isNull($identifier) + { + $this->addPredicate( + new IsNull($identifier), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + + /** + * Create "IS NOT NULL" predicate + * + * Utilizes IsNotNull predicate + * + * @param string $identifier + * @return Predicate + */ + public function isNotNull($identifier) + { + $this->addPredicate( + new IsNotNull($identifier), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + + /** + * Create "IN" predicate + * + * Utilizes In predicate + * + * @param string $identifier + * @param array|\Zend\Db\Sql\Select $valueSet + * @return Predicate + */ + public function in($identifier, $valueSet = null) + { + $this->addPredicate( + new In($identifier, $valueSet), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + + /** + * Create "NOT IN" predicate + * + * Utilizes NotIn predicate + * + * @param string $identifier + * @param array|\Zend\Db\Sql\Select $valueSet + * @return Predicate + */ + public function notIn($identifier, $valueSet = null) + { + $this->addPredicate( + new NotIn($identifier, $valueSet), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + + /** + * Create "between" predicate + * + * Utilizes Between predicate + * + * @param string $identifier + * @param int|float|string $minValue + * @param int|float|string $maxValue + * @return Predicate + */ + public function between($identifier, $minValue, $maxValue) + { + $this->addPredicate( + new Between($identifier, $minValue, $maxValue), + ($this->nextPredicateCombineOperator) ?: $this->defaultCombination + ); + $this->nextPredicateCombineOperator = null; + + return $this; + } + + /** + * Overloading + * + * Overloads "or", "and", "nest", and "unnest" + * + * @param string $name + * @return Predicate + */ + public function __get($name) + { + switch (strtolower($name)) { + case 'or': + $this->nextPredicateCombineOperator = self::OP_OR; + break; + case 'and': + $this->nextPredicateCombineOperator = self::OP_AND; + break; + case 'nest': + return $this->nest(); + case 'unnest': + return $this->unnest(); + } + return $this; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/PredicateInterface.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/PredicateInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..5d4eac6d200ed29a79c3da6cc8f81177d5fa9213 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/PredicateInterface.php @@ -0,0 +1,17 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Predicate; + +use Zend\Db\Sql\ExpressionInterface; + +interface PredicateInterface extends ExpressionInterface +{ + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/PredicateSet.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/PredicateSet.php new file mode 100644 index 0000000000000000000000000000000000000000..60d48ab733ad896cea10c9059a0384d95f38ac41 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Predicate/PredicateSet.php @@ -0,0 +1,193 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql\Predicate; + +use Countable; +use Zend\Db\Sql\Exception; + +class PredicateSet implements PredicateInterface, Countable +{ + const COMBINED_BY_AND = 'AND'; + const OP_AND = 'AND'; + + const COMBINED_BY_OR = 'OR'; + const OP_OR = 'OR'; + + protected $defaultCombination = self::COMBINED_BY_AND; + protected $predicates = array(); + + /** + * Constructor + * + * @param null|array $predicates + * @param string $defaultCombination + */ + public function __construct(array $predicates = null, $defaultCombination = self::COMBINED_BY_AND) + { + $this->defaultCombination = $defaultCombination; + if ($predicates) { + foreach ($predicates as $predicate) { + $this->addPredicate($predicate); + } + } + } + + /** + * Add predicate to set + * + * @param PredicateInterface $predicate + * @param string $combination + * @return PredicateSet + */ + public function addPredicate(PredicateInterface $predicate, $combination = null) + { + if ($combination === null || !in_array($combination, array(self::OP_AND, self::OP_OR))) { + $combination = $this->defaultCombination; + } + + if ($combination == self::OP_OR) { + $this->orPredicate($predicate); + return $this; + } + + $this->andPredicate($predicate); + return $this; + } + + public function addPredicates($predicates, $combination = self::OP_AND) + { + if ($predicates === null) { + throw new Exception\InvalidArgumentException('Predicate cannot be null'); + } + if ($predicates instanceof PredicateInterface) { + $this->addPredicate($predicates, $combination); + return $this; + } + if ($predicates instanceof \Closure) { + $predicates($this); + return $this; + } + if (is_string($predicates)) { + // String $predicate should be passed as an expression + $predicates = (strpos($predicates, Expression::PLACEHOLDER) !== false) + ? new Expression($predicates) : new Literal($predicates); + $this->addPredicate($predicates, $combination); + return $this; + } + if (is_array($predicates)) { + foreach ($predicates as $pkey => $pvalue) { + // loop through predicates + if (is_string($pkey)) { + if (strpos($pkey, '?') !== false) { + // First, process strings that the abstraction replacement character ? + // as an Expression predicate + $predicates = new Expression($pkey, $pvalue); + } elseif ($pvalue === null) { // Otherwise, if still a string, do something intelligent with the PHP type provided + // map PHP null to SQL IS NULL expression + $predicates = new IsNull($pkey, $pvalue); + } elseif (is_array($pvalue)) { + // if the value is an array, assume IN() is desired + $predicates = new In($pkey, $pvalue); + } elseif ($pvalue instanceof PredicateInterface) { + throw new Exception\InvalidArgumentException( + 'Using Predicate must not use string keys' + ); + } else { + // otherwise assume that array('foo' => 'bar') means "foo" = 'bar' + $predicates = new Operator($pkey, Operator::OP_EQ, $pvalue); + } + } elseif ($pvalue instanceof PredicateInterface) { + // Predicate type is ok + $predicates = $pvalue; + } else { + // must be an array of expressions (with int-indexed array) + $predicates = (strpos($pvalue, Expression::PLACEHOLDER) !== false) + ? new Expression($pvalue) : new Literal($pvalue); + } + $this->addPredicate($predicates, $combination); + } + } + return $this; + } + + /** + * Return the predicates + * + * @return PredicateInterface[] + */ + public function getPredicates() + { + return $this->predicates; + } + + /** + * Add predicate using OR operator + * + * @param PredicateInterface $predicate + * @return PredicateSet + */ + public function orPredicate(PredicateInterface $predicate) + { + $this->predicates[] = array(self::OP_OR, $predicate); + return $this; + } + + /** + * Add predicate using AND operator + * + * @param PredicateInterface $predicate + * @return PredicateSet + */ + public function andPredicate(PredicateInterface $predicate) + { + $this->predicates[] = array(self::OP_AND, $predicate); + return $this; + } + + /** + * Get predicate parts for where statement + * + * @return array + */ + public function getExpressionData() + { + $parts = array(); + for ($i = 0, $count = count($this->predicates); $i < $count; $i++) { + + /** @var $predicate PredicateInterface */ + $predicate = $this->predicates[$i][1]; + + if ($predicate instanceof PredicateSet) { + $parts[] = '('; + } + + $parts = array_merge($parts, $predicate->getExpressionData()); + + if ($predicate instanceof PredicateSet) { + $parts[] = ')'; + } + + if (isset($this->predicates[$i+1])) { + $parts[] = sprintf(' %s ', $this->predicates[$i+1][0]); + } + } + return $parts; + } + + /** + * Get count of attached predicates + * + * @return int + */ + public function count() + { + return count($this->predicates); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/PreparableSqlInterface.php b/vendor/zendframework/zend-db/Zend/Db/Sql/PreparableSqlInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..b8c3a50d9ce29b6932e8984b5ee136fe500df963 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/PreparableSqlInterface.php @@ -0,0 +1,24 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql; + +use Zend\Db\Adapter\AdapterInterface; +use Zend\Db\Adapter\StatementContainerInterface; + +interface PreparableSqlInterface +{ + + /** + * @param AdapterInterface $adapter + * @param StatementContainerInterface $statementContainer + * @return void + */ + public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Select.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Select.php new file mode 100644 index 0000000000000000000000000000000000000000..cc454316b393e590dca8b9fbbaf953875060c55d --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Select.php @@ -0,0 +1,940 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql; + +use Zend\Db\Adapter\AdapterInterface; +use Zend\Db\Adapter\Driver\DriverInterface; +use Zend\Db\Adapter\StatementContainerInterface; +use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\Adapter\Platform\Sql92 as AdapterSql92Platform; + +/** + * + * @property Where $where + * @property Having $having + */ +class Select extends AbstractSql implements SqlInterface, PreparableSqlInterface +{ + /**#@+ + * Constant + * @const + */ + const SELECT = 'select'; + const QUANTIFIER = 'quantifier'; + const COLUMNS = 'columns'; + const TABLE = 'table'; + const JOINS = 'joins'; + const WHERE = 'where'; + const GROUP = 'group'; + const HAVING = 'having'; + const ORDER = 'order'; + const LIMIT = 'limit'; + const OFFSET = 'offset'; + const QUANTIFIER_DISTINCT = 'DISTINCT'; + const QUANTIFIER_ALL = 'ALL'; + const JOIN_INNER = 'inner'; + const JOIN_OUTER = 'outer'; + const JOIN_LEFT = 'left'; + const JOIN_RIGHT = 'right'; + const SQL_STAR = '*'; + const ORDER_ASCENDING = 'ASC'; + const ORDER_DESCENDING = 'DESC'; + const COMBINE = 'combine'; + const COMBINE_UNION = 'union'; + const COMBINE_EXCEPT = 'except'; + const COMBINE_INTERSECT = 'intersect'; + /**#@-*/ + + /** + * @var array Specifications + */ + protected $specifications = array( + 'statementStart' => '%1$s', + self::SELECT => array( + 'SELECT %1$s FROM %2$s' => array( + array(1 => '%1$s', 2 => '%1$s AS %2$s', 'combinedby' => ', '), + null + ), + 'SELECT %1$s %2$s FROM %3$s' => array( + null, + array(1 => '%1$s', 2 => '%1$s AS %2$s', 'combinedby' => ', '), + null + ), + 'SELECT %1$s' => array( + array(1 => '%1$s', 2 => '%1$s AS %2$s', 'combinedby' => ', '), + ), + ), + self::JOINS => array( + '%1$s' => array( + array(3 => '%1$s JOIN %2$s ON %3$s', 'combinedby' => ' ') + ) + ), + self::WHERE => 'WHERE %1$s', + self::GROUP => array( + 'GROUP BY %1$s' => array( + array(1 => '%1$s', 'combinedby' => ', ') + ) + ), + self::HAVING => 'HAVING %1$s', + self::ORDER => array( + 'ORDER BY %1$s' => array( + array(1 => '%1$s', 2 => '%1$s %2$s', 'combinedby' => ', ') + ) + ), + self::LIMIT => 'LIMIT %1$s', + self::OFFSET => 'OFFSET %1$s', + 'statementEnd' => '%1$s', + self::COMBINE => '%1$s ( %2$s )', + ); + + /** + * @var bool + */ + protected $tableReadOnly = false; + + /** + * @var bool + */ + protected $prefixColumnsWithTable = true; + + /** + * @var string|array|TableIdentifier + */ + protected $table = null; + + /** + * @var null|string|Expression + */ + protected $quantifier = null; + + /** + * @var array + */ + protected $columns = array(self::SQL_STAR); + + /** + * @var array + */ + protected $joins = array(); + + /** + * @var Where + */ + protected $where = null; + + /** + * @var array + */ + protected $order = array(); + + /** + * @var null|array + */ + protected $group = null; + + /** + * @var null|string|array + */ + protected $having = null; + + /** + * @var int|null + */ + protected $limit = null; + + /** + * @var int|null + */ + protected $offset = null; + + /** + * @var array + */ + protected $combine = array(); + + /** + * Constructor + * + * @param null|string|array|TableIdentifier $table + */ + public function __construct($table = null) + { + if ($table) { + $this->from($table); + $this->tableReadOnly = true; + } + + $this->where = new Where; + $this->having = new Having; + } + + /** + * Create from clause + * + * @param string|array|TableIdentifier $table + * @throws Exception\InvalidArgumentException + * @return Select + */ + public function from($table) + { + if ($this->tableReadOnly) { + throw new Exception\InvalidArgumentException('Since this object was created with a table and/or schema in the constructor, it is read only.'); + } + + if (!is_string($table) && !is_array($table) && !$table instanceof TableIdentifier) { + throw new Exception\InvalidArgumentException('$table must be a string, array, or an instance of TableIdentifier'); + } + + if (is_array($table) && (!is_string(key($table)) || count($table) !== 1)) { + throw new Exception\InvalidArgumentException('from() expects $table as an array is a single element associative array'); + } + + $this->table = $table; + return $this; + } + + /** + * @param string|Expression $quantifier DISTINCT|ALL + * @return Select + */ + public function quantifier($quantifier) + { + if (!is_string($quantifier) && !$quantifier instanceof Expression) { + throw new Exception\InvalidArgumentException( + 'Quantifier must be one of DISTINCT, ALL, or some platform specific Expression object' + ); + } + $this->quantifier = $quantifier; + return $this; + } + + /** + * Specify columns from which to select + * + * Possible valid states: + * + * array(*) + * + * array(value, ...) + * value can be strings or Expression objects + * + * array(string => value, ...) + * key string will be use as alias, + * value can be string or Expression objects + * + * @param array $columns + * @param bool $prefixColumnsWithTable + * @return Select + */ + public function columns(array $columns, $prefixColumnsWithTable = true) + { + $this->columns = $columns; + $this->prefixColumnsWithTable = (bool) $prefixColumnsWithTable; + return $this; + } + + /** + * Create join clause + * + * @param string|array $name + * @param string $on + * @param string|array $columns + * @param string $type one of the JOIN_* constants + * @throws Exception\InvalidArgumentException + * @return Select + */ + public function join($name, $on, $columns = self::SQL_STAR, $type = self::JOIN_INNER) + { + if (is_array($name) && (!is_string(key($name)) || count($name) !== 1)) { + throw new Exception\InvalidArgumentException( + sprintf("join() expects '%s' as an array is a single element associative array", array_shift($name)) + ); + } + if (!is_array($columns)) { + $columns = array($columns); + } + $this->joins[] = array( + 'name' => $name, + 'on' => $on, + 'columns' => $columns, + 'type' => $type + ); + return $this; + } + + /** + * Create where clause + * + * @param Where|\Closure|string|array|Predicate\PredicateInterface $predicate + * @param string $combination One of the OP_* constants from Predicate\PredicateSet + * @throws Exception\InvalidArgumentException + * @return Select + */ + public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) + { + if ($predicate instanceof Where) { + $this->where = $predicate; + } else { + $this->where->addPredicates($predicate, $combination); + } + return $this; + } + + public function group($group) + { + if (is_array($group)) { + foreach ($group as $o) { + $this->group[] = $o; + } + } else { + $this->group[] = $group; + } + return $this; + } + + /** + * Create where clause + * + * @param Where|\Closure|string|array $predicate + * @param string $combination One of the OP_* constants from Predicate\PredicateSet + * @return Select + */ + public function having($predicate, $combination = Predicate\PredicateSet::OP_AND) + { + if ($predicate instanceof Having) { + $this->having = $predicate; + } else { + $this->having->addPredicates($predicate, $combination); + } + return $this; + } + + /** + * @param string|array $order + * @return Select + */ + public function order($order) + { + if (is_string($order)) { + if (strpos($order, ',') !== false) { + $order = preg_split('#,\s+#', $order); + } else { + $order = (array) $order; + } + } elseif (!is_array($order)) { + $order = array($order); + } + foreach ($order as $k => $v) { + if (is_string($k)) { + $this->order[$k] = $v; + } else { + $this->order[] = $v; + } + } + return $this; + } + + /** + * @param int $limit + * @return Select + */ + public function limit($limit) + { + if (!is_numeric($limit)) { + throw new Exception\InvalidArgumentException(sprintf( + '%s expects parameter to be numeric, "%s" given', + __METHOD__, + (is_object($limit) ? get_class($limit) : gettype($limit)) + )); + } + + $this->limit = $limit; + return $this; + } + + /** + * @param int $offset + * @return Select + */ + public function offset($offset) + { + if (!is_numeric($offset)) { + throw new Exception\InvalidArgumentException(sprintf( + '%s expects parameter to be numeric, "%s" given', + __METHOD__, + (is_object($offset) ? get_class($offset) : gettype($offset)) + )); + } + + $this->offset = $offset; + return $this; + } + + /** + * @param Select $select + * @param string $type + * @param string $modifier + * @return Select + * @throws Exception\InvalidArgumentException + */ + public function combine(Select $select, $type = self::COMBINE_UNION, $modifier = '') + { + if ($this->combine !== array()) { + throw new Exception\InvalidArgumentException('This Select object is already combined and cannot be combined with multiple Selects objects'); + } + $this->combine = array( + 'select' => $select, + 'type' => $type, + 'modifier' => $modifier + ); + return $this; + } + + /** + * @param string $part + * @return Select + * @throws Exception\InvalidArgumentException + */ + public function reset($part) + { + switch ($part) { + case self::TABLE: + if ($this->tableReadOnly) { + throw new Exception\InvalidArgumentException( + 'Since this object was created with a table and/or schema in the constructor, it is read only.' + ); + } + $this->table = null; + break; + case self::QUANTIFIER: + $this->quantifier = null; + break; + case self::COLUMNS: + $this->columns = array(); + break; + case self::JOINS: + $this->joins = array(); + break; + case self::WHERE: + $this->where = new Where; + break; + case self::GROUP: + $this->group = null; + break; + case self::HAVING: + $this->having = new Having; + break; + case self::LIMIT: + $this->limit = null; + break; + case self::OFFSET: + $this->offset = null; + break; + case self::ORDER: + $this->order = array(); + break; + case self::COMBINE: + $this->combine = array(); + break; + } + return $this; + } + + public function setSpecification($index, $specification) + { + if (!method_exists($this, 'process' . $index)) { + throw new Exception\InvalidArgumentException('Not a valid specification name.'); + } + $this->specifications[$index] = $specification; + return $this; + } + + public function getRawState($key = null) + { + $rawState = array( + self::TABLE => $this->table, + self::QUANTIFIER => $this->quantifier, + self::COLUMNS => $this->columns, + self::JOINS => $this->joins, + self::WHERE => $this->where, + self::ORDER => $this->order, + self::GROUP => $this->group, + self::HAVING => $this->having, + self::LIMIT => $this->limit, + self::OFFSET => $this->offset, + self::COMBINE => $this->combine + ); + return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; + } + + /** + * Prepare statement + * + * @param AdapterInterface $adapter + * @param StatementContainerInterface $statementContainer + * @return void + */ + public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) + { + // ensure statement has a ParameterContainer + $parameterContainer = $statementContainer->getParameterContainer(); + if (!$parameterContainer instanceof ParameterContainer) { + $parameterContainer = new ParameterContainer(); + $statementContainer->setParameterContainer($parameterContainer); + } + + $sqls = array(); + $parameters = array(); + $platform = $adapter->getPlatform(); + $driver = $adapter->getDriver(); + + foreach ($this->specifications as $name => $specification) { + $parameters[$name] = $this->{'process' . $name}($platform, $driver, $parameterContainer, $sqls, $parameters); + if ($specification && is_array($parameters[$name])) { + $sqls[$name] = $this->createSqlFromSpecificationAndParameters($specification, $parameters[$name]); + } + } + + $sql = implode(' ', $sqls); + + $statementContainer->setSql($sql); + return; + } + + /** + * Get SQL string for statement + * + * @param null|PlatformInterface $adapterPlatform If null, defaults to Sql92 + * @return string + */ + public function getSqlString(PlatformInterface $adapterPlatform = null) + { + // get platform, or create default + $adapterPlatform = ($adapterPlatform) ?: new AdapterSql92Platform; + + $sqls = array(); + $parameters = array(); + + foreach ($this->specifications as $name => $specification) { + $parameters[$name] = $this->{'process' . $name}($adapterPlatform, null, null, $sqls, $parameters); + if ($specification && is_array($parameters[$name])) { + $sqls[$name] = $this->createSqlFromSpecificationAndParameters($specification, $parameters[$name]); + } + } + + $sql = implode(' ', $sqls); + return $sql; + } + + /** + * Returns whether the table is read only or not. + * + * @return bool + */ + public function isTableReadOnly() + { + return $this->tableReadOnly; + } + + /** + * Render table with alias in from/join parts + * + * @todo move TableIdentifier concatination here + * @param string $table + * @param string $alias + * @return string + */ + protected function renderTable($table, $alias = null) + { + $sql = $table; + if ($alias) { + $sql .= ' AS ' . $alias; + } + return $sql; + } + + protected function processStatementStart(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + if ($this->combine !== array()) { + return array('('); + } + } + + protected function processStatementEnd(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + if ($this->combine !== array()) { + return array(')'); + } + } + + /** + * Process the select part + * + * @param PlatformInterface $platform + * @param DriverInterface $driver + * @param ParameterContainer $parameterContainer + * @return null|array + */ + protected function processSelect(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + $expr = 1; + + if ($this->table) { + $table = $this->table; + $schema = $alias = null; + + if (is_array($table)) { + $alias = key($this->table); + $table = current($this->table); + } + + // create quoted table name to use in columns processing + if ($table instanceof TableIdentifier) { + list($table, $schema) = $table->getTableAndSchema(); + } + + if ($table instanceof Select) { + $table = '(' . $this->processSubselect($table, $platform, $driver, $parameterContainer) . ')'; + } else { + $table = $platform->quoteIdentifier($table); + } + + if ($schema) { + $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table; + } + + if ($alias) { + $fromTable = $platform->quoteIdentifier($alias); + $table = $this->renderTable($table, $fromTable); + } else { + $fromTable = $table; + } + } else { + $fromTable = ''; + } + + if ($this->prefixColumnsWithTable) { + $fromTable .= $platform->getIdentifierSeparator(); + } else { + $fromTable = ''; + } + + // process table columns + $columns = array(); + foreach ($this->columns as $columnIndexOrAs => $column) { + + $columnName = ''; + if ($column === self::SQL_STAR) { + $columns[] = array($fromTable . self::SQL_STAR); + continue; + } + + if ($column instanceof ExpressionInterface) { + $columnParts = $this->processExpression( + $column, + $platform, + $driver, + $this->processInfo['paramPrefix'] . ((is_string($columnIndexOrAs)) ? $columnIndexOrAs : 'column') + ); + if ($parameterContainer) { + $parameterContainer->merge($columnParts->getParameterContainer()); + } + $columnName .= $columnParts->getSql(); + } else { + $columnName .= $fromTable . $platform->quoteIdentifier($column); + } + + // process As portion + if (is_string($columnIndexOrAs)) { + $columnAs = $platform->quoteIdentifier($columnIndexOrAs); + } elseif (stripos($columnName, ' as ') === false) { + $columnAs = (is_string($column)) ? $platform->quoteIdentifier($column) : 'Expression' . $expr++; + } + $columns[] = (isset($columnAs)) ? array($columnName, $columnAs) : array($columnName); + } + + $separator = $platform->getIdentifierSeparator(); + + // process join columns + foreach ($this->joins as $join) { + foreach ($join['columns'] as $jKey => $jColumn) { + $jColumns = array(); + if ($jColumn instanceof ExpressionInterface) { + $jColumnParts = $this->processExpression( + $jColumn, + $platform, + $driver, + $this->processInfo['paramPrefix'] . ((is_string($jKey)) ? $jKey : 'column') + ); + if ($parameterContainer) { + $parameterContainer->merge($jColumnParts->getParameterContainer()); + } + $jColumns[] = $jColumnParts->getSql(); + } else { + $name = (is_array($join['name'])) ? key($join['name']) : $name = $join['name']; + if ($name instanceof TableIdentifier) { + $name = ($name->hasSchema() ? $platform->quoteIdentifier($name->getSchema()) . $separator : '') . $platform->quoteIdentifier($name->getTable()); + } else { + $name = $platform->quoteIdentifier($name); + } + $jColumns[] = $name . $separator . $platform->quoteIdentifierInFragment($jColumn); + } + if (is_string($jKey)) { + $jColumns[] = $platform->quoteIdentifier($jKey); + } elseif ($jColumn !== self::SQL_STAR) { + $jColumns[] = $platform->quoteIdentifier($jColumn); + } + $columns[] = $jColumns; + } + } + + if ($this->quantifier) { + if ($this->quantifier instanceof ExpressionInterface) { + $quantifierParts = $this->processExpression($this->quantifier, $platform, $driver, 'quantifier'); + if ($parameterContainer) { + $parameterContainer->merge($quantifierParts->getParameterContainer()); + } + $quantifier = $quantifierParts->getSql(); + } else { + $quantifier = $this->quantifier; + } + } + + if (!isset($table)) { + return array($columns); + } elseif (isset($quantifier)) { + return array($quantifier, $columns, $table); + } else { + return array($columns, $table); + } + } + + protected function processJoins(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + if (!$this->joins) { + return null; + } + + // process joins + $joinSpecArgArray = array(); + foreach ($this->joins as $j => $join) { + $joinSpecArgArray[$j] = array(); + $joinName = null; + $joinAs = null; + + // type + $joinSpecArgArray[$j][] = strtoupper($join['type']); + + // table name + if (is_array($join['name'])) { + $joinName = current($join['name']); + $joinAs = $platform->quoteIdentifier(key($join['name'])); + } else { + $joinName = $join['name']; + } + if ($joinName instanceof ExpressionInterface) { + $joinName = $joinName->getExpression(); + } elseif ($joinName instanceof TableIdentifier) { + $joinName = $joinName->getTableAndSchema(); + $joinName = ($joinName[1] ? $platform->quoteIdentifier($joinName[1]) . $platform->getIdentifierSeparator() : '') . $platform->quoteIdentifier($joinName[0]); + } else { + if ($joinName instanceof Select) { + $joinName = '(' . $this->processSubSelect($joinName, $platform, $driver, $parameterContainer) . ')'; + } else { + $joinName = $platform->quoteIdentifier($joinName); + } + } + $joinSpecArgArray[$j][] = (isset($joinAs)) ? $joinName . ' AS ' . $joinAs : $joinName; + + // on expression + // note: for Expression objects, pass them to processExpression with a prefix specific to each join (used for named parameters) + $joinSpecArgArray[$j][] = ($join['on'] instanceof ExpressionInterface) + ? $this->processExpression($join['on'], $platform, $driver, $this->processInfo['paramPrefix'] . 'join' . ($j+1) . 'part') + : $platform->quoteIdentifierInFragment($join['on'], array('=', 'AND', 'OR', '(', ')', 'BETWEEN', '<', '>')); // on + if ($joinSpecArgArray[$j][2] instanceof StatementContainerInterface) { + if ($parameterContainer) { + $parameterContainer->merge($joinSpecArgArray[$j][2]->getParameterContainer()); + } + $joinSpecArgArray[$j][2] = $joinSpecArgArray[$j][2]->getSql(); + } + } + + return array($joinSpecArgArray); + } + + protected function processWhere(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + if ($this->where->count() == 0) { + return null; + } + $whereParts = $this->processExpression($this->where, $platform, $driver, $this->processInfo['paramPrefix'] . 'where'); + if ($parameterContainer) { + $parameterContainer->merge($whereParts->getParameterContainer()); + } + return array($whereParts->getSql()); + } + + protected function processGroup(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + if ($this->group === null) { + return null; + } + // process table columns + $groups = array(); + foreach ($this->group as $column) { + $columnSql = ''; + if ($column instanceof Expression) { + $columnParts = $this->processExpression($column, $platform, $driver, $this->processInfo['paramPrefix'] . 'group'); + if ($parameterContainer) { + $parameterContainer->merge($columnParts->getParameterContainer()); + } + $columnSql .= $columnParts->getSql(); + } else { + $columnSql .= $platform->quoteIdentifierInFragment($column); + } + $groups[] = $columnSql; + } + return array($groups); + } + + protected function processHaving(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + if ($this->having->count() == 0) { + return null; + } + $whereParts = $this->processExpression($this->having, $platform, $driver, $this->processInfo['paramPrefix'] . 'having'); + if ($parameterContainer) { + $parameterContainer->merge($whereParts->getParameterContainer()); + } + return array($whereParts->getSql()); + } + + protected function processOrder(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + if (empty($this->order)) { + return null; + } + $orders = array(); + foreach ($this->order as $k => $v) { + if ($v instanceof Expression) { + /** @var $orderParts \Zend\Db\Adapter\StatementContainer */ + $orderParts = $this->processExpression($v, $platform, $driver); + if ($parameterContainer) { + $parameterContainer->merge($orderParts->getParameterContainer()); + } + $orders[] = array($orderParts->getSql()); + continue; + } + if (is_int($k)) { + if (strpos($v, ' ') !== false) { + list($k, $v) = preg_split('# #', $v, 2); + } else { + $k = $v; + $v = self::ORDER_ASCENDING; + } + } + if (strtoupper($v) == self::ORDER_DESCENDING) { + $orders[] = array($platform->quoteIdentifierInFragment($k), self::ORDER_DESCENDING); + } else { + $orders[] = array($platform->quoteIdentifierInFragment($k), self::ORDER_ASCENDING); + } + } + return array($orders); + } + + protected function processLimit(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + if ($this->limit === null) { + return null; + } + + $limit = $this->limit; + + if ($driver) { + $sql = $driver->formatParameterName('limit'); + $parameterContainer->offsetSet('limit', $limit, ParameterContainer::TYPE_INTEGER); + } else { + $sql = $platform->quoteValue($limit); + } + + return array($sql); + } + + protected function processOffset(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + if ($this->offset === null) { + return null; + } + + $offset = $this->offset; + + if ($driver) { + $parameterContainer->offsetSet('offset', $offset, ParameterContainer::TYPE_INTEGER); + return array($driver->formatParameterName('offset')); + } + + return array($platform->quoteValue($offset)); + } + + protected function processCombine(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) + { + if ($this->combine == array()) { + return null; + } + + $type = $this->combine['type']; + if ($this->combine['modifier']) { + $type .= ' ' . $this->combine['modifier']; + } + $type = strtoupper($type); + + if ($driver) { + $sql = $this->processSubSelect($this->combine['select'], $platform, $driver, $parameterContainer); + return array($type, $sql); + } + return array( + $type, + $this->processSubSelect($this->combine['select'], $platform) + ); + } + + /** + * Variable overloading + * + * @param string $name + * @throws Exception\InvalidArgumentException + * @return mixed + */ + public function __get($name) + { + switch (strtolower($name)) { + case 'where': + return $this->where; + case 'having': + return $this->having; + default: + throw new Exception\InvalidArgumentException('Not a valid magic property for this object'); + } + } + + /** + * __clone + * + * Resets the where object each time the Select is cloned. + * + * @return void + */ + public function __clone() + { + $this->where = clone $this->where; + $this->having = clone $this->having; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Sql.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Sql.php new file mode 100644 index 0000000000000000000000000000000000000000..e80c7281aedfbc2ac115d5857a4f73e0b645bf5d --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Sql.php @@ -0,0 +1,145 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql; + +use Zend\Db\Adapter\AdapterInterface; +use Zend\Db\Adapter\Driver\StatementInterface; +use Zend\Db\Adapter\Platform\PlatformInterface; + +class Sql +{ + /** @var AdapterInterface */ + protected $adapter = null; + + /** @var string|array|TableIdentifier */ + protected $table = null; + + /** @var Platform\Platform */ + protected $sqlPlatform = null; + + public function __construct(AdapterInterface $adapter, $table = null, Platform\AbstractPlatform $sqlPlatform = null) + { + $this->adapter = $adapter; + if ($table) { + $this->setTable($table); + } + $this->sqlPlatform = ($sqlPlatform) ?: new Platform\Platform($adapter); + } + + /** + * @return null|\Zend\Db\Adapter\AdapterInterface + */ + public function getAdapter() + { + return $this->adapter; + } + + public function hasTable() + { + return ($this->table != null); + } + + public function setTable($table) + { + if (is_string($table) || is_array($table) || $table instanceof TableIdentifier) { + $this->table = $table; + } else { + throw new Exception\InvalidArgumentException('Table must be a string, array or instance of TableIdentifier.'); + } + return $this; + } + + public function getTable() + { + return $this->table; + } + + public function getSqlPlatform() + { + return $this->sqlPlatform; + } + + public function select($table = null) + { + if ($this->table !== null && $table !== null) { + throw new Exception\InvalidArgumentException(sprintf( + 'This Sql object is intended to work with only the table "%s" provided at construction time.', + $this->table + )); + } + return new Select(($table) ?: $this->table); + } + + public function insert($table = null) + { + if ($this->table !== null && $table !== null) { + throw new Exception\InvalidArgumentException(sprintf( + 'This Sql object is intended to work with only the table "%s" provided at construction time.', + $this->table + )); + } + return new Insert(($table) ?: $this->table); + } + + public function update($table = null) + { + if ($this->table !== null && $table !== null) { + throw new Exception\InvalidArgumentException(sprintf( + 'This Sql object is intended to work with only the table "%s" provided at construction time.', + $this->table + )); + } + return new Update(($table) ?: $this->table); + } + + public function delete($table = null) + { + if ($this->table !== null && $table !== null) { + throw new Exception\InvalidArgumentException(sprintf( + 'This Sql object is intended to work with only the table "%s" provided at construction time.', + $this->table + )); + } + return new Delete(($table) ?: $this->table); + } + + /** + * @param PreparableSqlInterface $sqlObject + * @param StatementInterface|null $statement + * @return StatementInterface + */ + public function prepareStatementForSqlObject(PreparableSqlInterface $sqlObject, StatementInterface $statement = null) + { + $statement = ($statement) ?: $this->adapter->getDriver()->createStatement(); + + if ($this->sqlPlatform) { + $this->sqlPlatform->setSubject($sqlObject); + $this->sqlPlatform->prepareStatement($this->adapter, $statement); + } else { + $sqlObject->prepareStatement($this->adapter, $statement); + } + + return $statement; + } + + public function getSqlStringForSqlObject(SqlInterface $sqlObject, PlatformInterface $platform = null) + { + $platform = ($platform) ?: $this->adapter->getPlatform(); + + if ($this->sqlPlatform) { + $this->sqlPlatform->setSubject($sqlObject); + $sqlString = $this->sqlPlatform->getSqlString($platform); + } else { + $sqlString = $sqlObject->getSqlString($platform); + } + + return $sqlString; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/SqlInterface.php b/vendor/zendframework/zend-db/Zend/Db/Sql/SqlInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..d36419e5d29fc46d96788abb4568f5d1af2aa6d7 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/SqlInterface.php @@ -0,0 +1,17 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql; + +use Zend\Db\Adapter\Platform\PlatformInterface; + +interface SqlInterface +{ + public function getSqlString(PlatformInterface $adapterPlatform = null); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/TableIdentifier.php b/vendor/zendframework/zend-db/Zend/Db/Sql/TableIdentifier.php new file mode 100644 index 0000000000000000000000000000000000000000..4877122819631d42e8ad4a9fd6b3276d456cf384 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/TableIdentifier.php @@ -0,0 +1,81 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql; + +/** + */ +class TableIdentifier +{ + + /** + * @var string + */ + protected $table; + + /** + * @var string + */ + protected $schema; + + /** + * @param string $table + * @param string $schema + */ + public function __construct($table, $schema = null) + { + $this->table = $table; + $this->schema = $schema; + } + + /** + * @param string $table + */ + public function setTable($table) + { + $this->table = $table; + } + + /** + * @return string + */ + public function getTable() + { + return $this->table; + } + + /** + * @return bool + */ + public function hasSchema() + { + return ($this->schema != null); + } + + /** + * @param $schema + */ + public function setSchema($schema) + { + $this->schema = $schema; + } + + /** + * @return null|string + */ + public function getSchema() + { + return $this->schema; + } + + public function getTableAndSchema() + { + return array($this->table, $this->schema); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Update.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Update.php new file mode 100644 index 0000000000000000000000000000000000000000..5808a442be2490e1e9ab4af70629456c654f0d8e --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Update.php @@ -0,0 +1,274 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql; + +use Zend\Db\Adapter\AdapterInterface; +use Zend\Db\Adapter\ParameterContainer; +use Zend\Db\Adapter\Platform\PlatformInterface; +use Zend\Db\Adapter\Platform\Sql92; +use Zend\Db\Adapter\StatementContainerInterface; + +/** + * + * @property Where $where + */ +class Update extends AbstractSql implements SqlInterface, PreparableSqlInterface +{ + /**@#++ + * @const + */ + const SPECIFICATION_UPDATE = 'update'; + const SPECIFICATION_WHERE = 'where'; + + const VALUES_MERGE = 'merge'; + const VALUES_SET = 'set'; + /**@#-**/ + + protected $specifications = array( + self::SPECIFICATION_UPDATE => 'UPDATE %1$s SET %2$s', + self::SPECIFICATION_WHERE => 'WHERE %1$s' + ); + + /** + * @var string|TableIdentifier + */ + protected $table = ''; + + /** + * @var bool + */ + protected $emptyWhereProtection = true; + + /** + * @var array + */ + protected $set = array(); + + /** + * @var string|Where + */ + protected $where = null; + + /** + * Constructor + * + * @param null|string|TableIdentifier $table + */ + public function __construct($table = null) + { + if ($table) { + $this->table($table); + } + $this->where = new Where(); + } + + /** + * Specify table for statement + * + * @param string|TableIdentifier $table + * @return Update + */ + public function table($table) + { + $this->table = $table; + return $this; + } + + /** + * Set key/value pairs to update + * + * @param array $values Associative array of key values + * @param string $flag One of the VALUES_* constants + * @throws Exception\InvalidArgumentException + * @return Update + */ + public function set(array $values, $flag = self::VALUES_SET) + { + if ($values == null) { + throw new Exception\InvalidArgumentException('set() expects an array of values'); + } + + if ($flag == self::VALUES_SET) { + $this->set = array(); + } + + foreach ($values as $k => $v) { + if (!is_string($k)) { + throw new Exception\InvalidArgumentException('set() expects a string for the value key'); + } + $this->set[$k] = $v; + } + + return $this; + } + + /** + * Create where clause + * + * @param Where|\Closure|string|array $predicate + * @param string $combination One of the OP_* constants from Predicate\PredicateSet + * @throws Exception\InvalidArgumentException + * @return Select + */ + public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) + { + if ($predicate instanceof Where) { + $this->where = $predicate; + } else { + $this->where->addPredicates($predicate, $combination); + } + return $this; + } + + public function getRawState($key = null) + { + $rawState = array( + 'emptyWhereProtection' => $this->emptyWhereProtection, + 'table' => $this->table, + 'set' => $this->set, + 'where' => $this->where + ); + return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState; + } + + /** + * Prepare statement + * + * @param AdapterInterface $adapter + * @param StatementContainerInterface $statementContainer + * @return void + */ + public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer) + { + $driver = $adapter->getDriver(); + $platform = $adapter->getPlatform(); + $parameterContainer = $statementContainer->getParameterContainer(); + + if (!$parameterContainer instanceof ParameterContainer) { + $parameterContainer = new ParameterContainer(); + $statementContainer->setParameterContainer($parameterContainer); + } + + $table = $this->table; + $schema = null; + + // create quoted table name to use in update processing + if ($table instanceof TableIdentifier) { + list($table, $schema) = $table->getTableAndSchema(); + } + + $table = $platform->quoteIdentifier($table); + + if ($schema) { + $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table; + } + + $set = $this->set; + if (is_array($set)) { + $setSql = array(); + foreach ($set as $column => $value) { + if ($value instanceof Expression) { + $exprData = $this->processExpression($value, $platform, $driver); + $setSql[] = $platform->quoteIdentifier($column) . ' = ' . $exprData->getSql(); + $parameterContainer->merge($exprData->getParameterContainer()); + } else { + $setSql[] = $platform->quoteIdentifier($column) . ' = ' . $driver->formatParameterName($column); + $parameterContainer->offsetSet($column, $value); + } + } + $set = implode(', ', $setSql); + } + + $sql = sprintf($this->specifications[static::SPECIFICATION_UPDATE], $table, $set); + + // process where + if ($this->where->count() > 0) { + $whereParts = $this->processExpression($this->where, $platform, $driver, 'where'); + $parameterContainer->merge($whereParts->getParameterContainer()); + $sql .= ' ' . sprintf($this->specifications[static::SPECIFICATION_WHERE], $whereParts->getSql()); + } + $statementContainer->setSql($sql); + } + + /** + * Get SQL string for statement + * + * @param null|PlatformInterface $adapterPlatform If null, defaults to Sql92 + * @return string + */ + public function getSqlString(PlatformInterface $adapterPlatform = null) + { + $adapterPlatform = ($adapterPlatform) ?: new Sql92; + $table = $this->table; + $schema = null; + + // create quoted table name to use in update processing + if ($table instanceof TableIdentifier) { + list($table, $schema) = $table->getTableAndSchema(); + } + + $table = $adapterPlatform->quoteIdentifier($table); + + if ($schema) { + $table = $adapterPlatform->quoteIdentifier($schema) . $adapterPlatform->getIdentifierSeparator() . $table; + } + + $set = $this->set; + if (is_array($set)) { + $setSql = array(); + foreach ($set as $column => $value) { + if ($value instanceof Expression) { + $exprData = $this->processExpression($value, $adapterPlatform); + $setSql[] = $adapterPlatform->quoteIdentifier($column) . ' = ' . $exprData->getSql(); + } elseif ($value === null) { + $setSql[] = $adapterPlatform->quoteIdentifier($column) . ' = NULL'; + } else { + $setSql[] = $adapterPlatform->quoteIdentifier($column) . ' = ' . $adapterPlatform->quoteValue($value); + } + } + $set = implode(', ', $setSql); + } + + $sql = sprintf($this->specifications[static::SPECIFICATION_UPDATE], $table, $set); + if ($this->where->count() > 0) { + $whereParts = $this->processExpression($this->where, $adapterPlatform, null, 'where'); + $sql .= ' ' . sprintf($this->specifications[static::SPECIFICATION_WHERE], $whereParts->getSql()); + } + return $sql; + } + + /** + * Variable overloading + * + * Proxies to "where" only + * + * @param string $name + * @return mixed + */ + public function __get($name) + { + switch (strtolower($name)) { + case 'where': + return $this->where; + } + } + + /** + * __clone + * + * Resets the where object each time the Update is cloned. + * + * @return void + */ + public function __clone() + { + $this->where = clone $this->where; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/Sql/Where.php b/vendor/zendframework/zend-db/Zend/Db/Sql/Where.php new file mode 100644 index 0000000000000000000000000000000000000000..23426a93846375c9b254bcd5eee23eec6179e610 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/Sql/Where.php @@ -0,0 +1,15 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\Sql; + +class Where extends Predicate\Predicate +{ + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/AbstractTableGateway.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/AbstractTableGateway.php new file mode 100644 index 0000000000000000000000000000000000000000..c648346078f709ec368a0f6f97ab706482a7c8d1 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/AbstractTableGateway.php @@ -0,0 +1,488 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway; + +use Zend\Db\Adapter\AdapterInterface; +use Zend\Db\ResultSet\ResultSet; +use Zend\Db\ResultSet\ResultSetInterface; +use Zend\Db\Sql\Delete; +use Zend\Db\Sql\Insert; +use Zend\Db\Sql\Select; +use Zend\Db\Sql\Sql; +use Zend\Db\Sql\TableIdentifier; +use Zend\Db\Sql\Update; +use Zend\Db\Sql\Where; + +/** + * + * @property AdapterInterface $adapter + * @property int $lastInsertValue + * @property string $table + */ +abstract class AbstractTableGateway implements TableGatewayInterface +{ + + /** + * @var bool + */ + protected $isInitialized = false; + + /** + * @var AdapterInterface + */ + protected $adapter = null; + + /** + * @var string + */ + protected $table = null; + + /** + * @var array + */ + protected $columns = array(); + + /** + * @var Feature\FeatureSet + */ + protected $featureSet = null; + + /** + * @var ResultSetInterface + */ + protected $resultSetPrototype = null; + + /** + * @var Sql + */ + protected $sql = null; + + /** + * + * @var int + */ + protected $lastInsertValue = null; + + /** + * @return bool + */ + public function isInitialized() + { + return $this->isInitialized; + } + + /** + * Initialize + * + * @throws Exception\RuntimeException + * @return null + */ + public function initialize() + { + if ($this->isInitialized) { + return; + } + + if (!$this->featureSet instanceof Feature\FeatureSet) { + $this->featureSet = new Feature\FeatureSet; + } + + $this->featureSet->setTableGateway($this); + $this->featureSet->apply('preInitialize', array()); + + if (!$this->adapter instanceof AdapterInterface) { + throw new Exception\RuntimeException('This table does not have an Adapter setup'); + } + + if (!is_string($this->table) && !$this->table instanceof TableIdentifier) { + throw new Exception\RuntimeException('This table object does not have a valid table set.'); + } + + if (!$this->resultSetPrototype instanceof ResultSetInterface) { + $this->resultSetPrototype = new ResultSet; + } + + if (!$this->sql instanceof Sql) { + $this->sql = new Sql($this->adapter, $this->table); + } + + $this->featureSet->apply('postInitialize', array()); + + $this->isInitialized = true; + } + + /** + * Get table name + * + * @return string + */ + public function getTable() + { + return $this->table; + } + + /** + * Get adapter + * + * @return AdapterInterface + */ + public function getAdapter() + { + return $this->adapter; + } + + /** + * @return array + */ + public function getColumns() + { + return $this->columns; + } + + /** + * @return Feature\FeatureSet + */ + public function getFeatureSet() + { + return $this->featureSet; + } + + /** + * Get select result prototype + * + * @return ResultSet + */ + public function getResultSetPrototype() + { + return $this->resultSetPrototype; + } + + /** + * @return Sql + */ + public function getSql() + { + return $this->sql; + } + + /** + * Select + * + * @param Where|\Closure|string|array $where + * @return ResultSet + */ + public function select($where = null) + { + if (!$this->isInitialized) { + $this->initialize(); + } + + $select = $this->sql->select(); + + if ($where instanceof \Closure) { + $where($select); + } elseif ($where !== null) { + $select->where($where); + } + + return $this->selectWith($select); + } + + /** + * @param Select $select + * @return null|ResultSetInterface + * @throws \RuntimeException + */ + public function selectWith(Select $select) + { + if (!$this->isInitialized) { + $this->initialize(); + } + return $this->executeSelect($select); + } + + /** + * @param Select $select + * @return ResultSet + * @throws Exception\RuntimeException + */ + protected function executeSelect(Select $select) + { + $selectState = $select->getRawState(); + if ($selectState['table'] != $this->table) { + throw new Exception\RuntimeException('The table name of the provided select object must match that of the table'); + } + + if ($selectState['columns'] == array(Select::SQL_STAR) + && $this->columns !== array()) { + $select->columns($this->columns); + } + + // apply preSelect features + $this->featureSet->apply('preSelect', array($select)); + + // prepare and execute + $statement = $this->sql->prepareStatementForSqlObject($select); + $result = $statement->execute(); + + // build result set + $resultSet = clone $this->resultSetPrototype; + $resultSet->initialize($result); + + // apply postSelect features + $this->featureSet->apply('postSelect', array($statement, $result, $resultSet)); + + return $resultSet; + } + + /** + * Insert + * + * @param array $set + * @return int + */ + public function insert($set) + { + if (!$this->isInitialized) { + $this->initialize(); + } + $insert = $this->sql->insert(); + $insert->values($set); + return $this->executeInsert($insert); + } + + /** + * @param Insert $insert + * @return mixed + */ + public function insertWith(Insert $insert) + { + if (!$this->isInitialized) { + $this->initialize(); + } + return $this->executeInsert($insert); + } + + /** + * @todo add $columns support + * + * @param Insert $insert + * @return mixed + * @throws Exception\RuntimeException + */ + protected function executeInsert(Insert $insert) + { + $insertState = $insert->getRawState(); + if ($insertState['table'] != $this->table) { + throw new Exception\RuntimeException('The table name of the provided Insert object must match that of the table'); + } + + // apply preInsert features + $this->featureSet->apply('preInsert', array($insert)); + + $statement = $this->sql->prepareStatementForSqlObject($insert); + $result = $statement->execute(); + $this->lastInsertValue = $this->adapter->getDriver()->getConnection()->getLastGeneratedValue(); + + // apply postInsert features + $this->featureSet->apply('postInsert', array($statement, $result)); + + return $result->getAffectedRows(); + } + + /** + * Update + * + * @param array $set + * @param string|array|\Closure $where + * @return int + */ + public function update($set, $where = null) + { + if (!$this->isInitialized) { + $this->initialize(); + } + $sql = $this->sql; + $update = $sql->update(); + $update->set($set); + if ($where !== null) { + $update->where($where); + } + return $this->executeUpdate($update); + } + + /** + * @param \Zend\Db\Sql\Update $update + * @return mixed + */ + public function updateWith(Update $update) + { + if (!$this->isInitialized) { + $this->initialize(); + } + return $this->executeUpdate($update); + } + + /** + * @todo add $columns support + * + * @param Update $update + * @return mixed + * @throws Exception\RuntimeException + */ + protected function executeUpdate(Update $update) + { + $updateState = $update->getRawState(); + if ($updateState['table'] != $this->table) { + throw new Exception\RuntimeException('The table name of the provided Update object must match that of the table'); + } + + // apply preUpdate features + $this->featureSet->apply('preUpdate', array($update)); + + $statement = $this->sql->prepareStatementForSqlObject($update); + $result = $statement->execute(); + + // apply postUpdate features + $this->featureSet->apply('postUpdate', array($statement, $result)); + + return $result->getAffectedRows(); + } + + /** + * Delete + * + * @param Where|\Closure|string|array $where + * @return int + */ + public function delete($where) + { + if (!$this->isInitialized) { + $this->initialize(); + } + $delete = $this->sql->delete(); + if ($where instanceof \Closure) { + $where($delete); + } else { + $delete->where($where); + } + return $this->executeDelete($delete); + } + + /** + * @param Delete $delete + * @return mixed + */ + public function deleteWith(Delete $delete) + { + $this->initialize(); + return $this->executeDelete($delete); + } + + /** + * @todo add $columns support + * + * @param Delete $delete + * @return mixed + * @throws Exception\RuntimeException + */ + protected function executeDelete(Delete $delete) + { + $deleteState = $delete->getRawState(); + if ($deleteState['table'] != $this->table) { + throw new Exception\RuntimeException('The table name of the provided Update object must match that of the table'); + } + + // pre delete update + $this->featureSet->apply('preDelete', array($delete)); + + $statement = $this->sql->prepareStatementForSqlObject($delete); + $result = $statement->execute(); + + // apply postDelete features + $this->featureSet->apply('postDelete', array($statement, $result)); + + return $result->getAffectedRows(); + } + + /** + * Get last insert value + * + * @return int + */ + public function getLastInsertValue() + { + return $this->lastInsertValue; + } + + /** + * __get + * + * @param string $property + * @throws Exception\InvalidArgumentException + * @return mixed + */ + public function __get($property) + { + switch (strtolower($property)) { + case 'lastinsertvalue': + return $this->lastInsertValue; + case 'adapter': + return $this->adapter; + case 'table': + return $this->table; + } + if ($this->featureSet->canCallMagicGet($property)) { + return $this->featureSet->callMagicGet($property); + } + throw new Exception\InvalidArgumentException('Invalid magic property access in ' . __CLASS__ . '::__get()'); + } + + /** + * @param string $property + * @param mixed $value + * @return mixed + * @throws Exception\InvalidArgumentException + */ + public function __set($property, $value) + { + if ($this->featureSet->canCallMagicSet($property)) { + return $this->featureSet->callMagicSet($property, $value); + } + throw new Exception\InvalidArgumentException('Invalid magic property access in ' . __CLASS__ . '::__set()'); + } + + /** + * @param $method + * @param $arguments + * @return mixed + * @throws Exception\InvalidArgumentException + */ + public function __call($method, $arguments) + { + if ($this->featureSet->canCallMagicCall($method)) { + return $this->featureSet->callMagicCall($method, $arguments); + } + throw new Exception\InvalidArgumentException('Invalid method (' . $method . ') called, caught by ' . __CLASS__ . '::__call()'); + } + + /** + * __clone + */ + public function __clone() + { + $this->resultSetPrototype = (isset($this->resultSetPrototype)) ? clone $this->resultSetPrototype : null; + $this->sql = clone $this->sql; + if (is_object($this->table)) { + $this->table = clone $this->table; + } + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/Exception/ExceptionInterface.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Exception/ExceptionInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..ecd3085ac6d2e6b1b83c5d7b9b1fb801e6e07dd9 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Exception/ExceptionInterface.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway\Exception; + +use Zend\Db\Exception; + +interface ExceptionInterface extends Exception\ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/Exception/InvalidArgumentException.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Exception/InvalidArgumentException.php new file mode 100644 index 0000000000000000000000000000000000000000..1f967a5947760528ef1df04d08216649041f2a23 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Exception/InvalidArgumentException.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway\Exception; + +use Zend\Db\Exception; + +class InvalidArgumentException extends Exception\InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/Exception/RuntimeException.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Exception/RuntimeException.php new file mode 100644 index 0000000000000000000000000000000000000000..3c79b9f0ff80c8fde0029e9e909e543a52217d25 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Exception/RuntimeException.php @@ -0,0 +1,16 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway\Exception; + +use Zend\Db\Exception; + +class RuntimeException extends Exception\InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/AbstractFeature.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/AbstractFeature.php new file mode 100644 index 0000000000000000000000000000000000000000..e3d4c319aad1229eddd7ca8c87e05fa34db24280 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/AbstractFeature.php @@ -0,0 +1,59 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway\Feature; + +use Zend\Db\TableGateway\AbstractTableGateway; +use Zend\Db\TableGateway\Exception; + +abstract class AbstractFeature extends AbstractTableGateway +{ + + /** + * @var AbstractTableGateway + */ + protected $tableGateway = null; + + protected $sharedData = array(); + + public function getName() + { + return get_class($this); + } + + public function setTableGateway(AbstractTableGateway $tableGateway) + { + $this->tableGateway = $tableGateway; + } + + public function initialize() + { + throw new Exception\RuntimeException('This method is not intended to be called on this object.'); + } + + public function getMagicMethodSpecifications() + { + return array(); + } + + + /* + public function preInitialize(); + public function postInitialize(); + public function preSelect(Select $select); + public function postSelect(StatementInterface $statement, ResultInterface $result, ResultSetInterface $resultSet); + public function preInsert(Insert $insert); + public function postInsert(StatementInterface $statement, ResultInterface $result); + public function preUpdate(Update $update); + public function postUpdate(StatementInterface $statement, ResultInterface $result); + public function preDelete(Delete $delete); + public function postDelete(StatementInterface $statement, ResultInterface $result); + */ + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/EventFeature.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/EventFeature.php new file mode 100644 index 0000000000000000000000000000000000000000..08e3cffbdca144cf29a15dab3fd33a7cae5d70df --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/EventFeature.php @@ -0,0 +1,255 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway\Feature; + +use Zend\Db\Adapter\Driver\ResultInterface; +use Zend\Db\Adapter\Driver\StatementInterface; +use Zend\Db\ResultSet\ResultSetInterface; +use Zend\Db\Sql\Delete; +use Zend\Db\Sql\Insert; +use Zend\Db\Sql\Select; +use Zend\Db\Sql\Update; +use Zend\EventManager\EventManager; +use Zend\EventManager\EventManagerInterface; +use Zend\EventManager\EventsCapableInterface; + +class EventFeature extends AbstractFeature implements EventsCapableInterface +{ + /** + * @var EventManagerInterface + */ + protected $eventManager = null; + + /** + * @var null + */ + protected $event = null; + + /** + * @param EventManagerInterface $eventManager + * @param EventFeature\TableGatewayEvent $tableGatewayEvent + */ + public function __construct( + EventManagerInterface $eventManager = null, + EventFeature\TableGatewayEvent $tableGatewayEvent = null + ) { + $this->eventManager = ($eventManager instanceof EventManagerInterface) + ? $eventManager + : new EventManager; + + $this->eventManager->addIdentifiers(array( + 'Zend\Db\TableGateway\TableGateway', + )); + + $this->event = ($tableGatewayEvent) ?: new EventFeature\TableGatewayEvent(); + } + + /** + * Retrieve composed event manager instance + * + * @return EventManagerInterface + */ + public function getEventManager() + { + return $this->eventManager; + } + + /** + * Retrieve composed event instance + * + * @return EventFeature\TableGatewayEvent + */ + public function getEvent() + { + return $this->event; + } + + /** + * Initialize feature and trigger "preInitialize" event + * + * Ensures that the composed TableGateway has identifiers based on the + * class name, and that the event target is set to the TableGateway + * instance. It then triggers the "preInitialize" event. + * + * @return void + */ + public function preInitialize() + { + if (get_class($this->tableGateway) != 'Zend\Db\TableGateway\TableGateway') { + $this->eventManager->addIdentifiers(get_class($this->tableGateway)); + } + + $this->event->setTarget($this->tableGateway); + $this->event->setName(__FUNCTION__); + $this->eventManager->trigger($this->event); + } + + /** + * Trigger the "postInitialize" event + * + * @return void + */ + public function postInitialize() + { + $this->event->setName(__FUNCTION__); + $this->eventManager->trigger($this->event); + } + + /** + * Trigger the "preSelect" event + * + * Triggers the "preSelect" event mapping the following parameters: + * - $select as "select" + * + * @param Select $select + * @return void + */ + public function preSelect(Select $select) + { + $this->event->setName(__FUNCTION__); + $this->event->setParams(array('select' => $select)); + $this->eventManager->trigger($this->event); + } + + /** + * Trigger the "postSelect" event + * + * Triggers the "postSelect" event mapping the following parameters: + * - $statement as "statement" + * - $result as "result" + * - $resultSet as "result_set" + * + * @param StatementInterface $statement + * @param ResultInterface $result + * @param ResultSetInterface $resultSet + * @return void + */ + public function postSelect(StatementInterface $statement, ResultInterface $result, ResultSetInterface $resultSet) + { + $this->event->setName(__FUNCTION__); + $this->event->setParams(array( + 'statement' => $statement, + 'result' => $result, + 'result_set' => $resultSet + )); + $this->eventManager->trigger($this->event); + } + + /** + * Trigger the "preInsert" event + * + * Triggers the "preInsert" event mapping the following parameters: + * - $insert as "insert" + * + * @param Insert $insert + * @return void + */ + public function preInsert(Insert $insert) + { + $this->event->setName(__FUNCTION__); + $this->event->setParams(array('insert' => $insert)); + $this->eventManager->trigger($this->event); + } + + /** + * Trigger the "postInsert" event + * + * Triggers the "postInsert" event mapping the following parameters: + * - $statement as "statement" + * - $result as "result" + * + * @param StatementInterface $statement + * @param ResultInterface $result + * @return void + */ + public function postInsert(StatementInterface $statement, ResultInterface $result) + { + $this->event->setName(__FUNCTION__); + $this->event->setParams(array( + 'statement' => $statement, + 'result' => $result, + )); + $this->eventManager->trigger($this->event); + } + + /** + * Trigger the "preUpdate" event + * + * Triggers the "preUpdate" event mapping the following parameters: + * - $update as "update" + * + * @param Update $update + * @return void + */ + public function preUpdate(Update $update) + { + $this->event->setName(__FUNCTION__); + $this->event->setParams(array('update' => $update)); + $this->eventManager->trigger($this->event); + } + + /** + * Trigger the "postUpdate" event + * + * Triggers the "postUpdate" event mapping the following parameters: + * - $statement as "statement" + * - $result as "result" + * + * @param StatementInterface $statement + * @param ResultInterface $result + * @return void + */ + public function postUpdate(StatementInterface $statement, ResultInterface $result) + { + $this->event->setName(__FUNCTION__); + $this->event->setParams(array( + 'statement' => $statement, + 'result' => $result, + )); + $this->eventManager->trigger($this->event); + } + + /** + * Trigger the "preDelete" event + * + * Triggers the "preDelete" event mapping the following parameters: + * - $delete as "delete" + * + * @param Delete $delete + * @return void + */ + public function preDelete(Delete $delete) + { + $this->event->setName(__FUNCTION__); + $this->event->setParams(array('delete' => $delete)); + $this->eventManager->trigger($this->event); + } + + /** + * Trigger the "postDelete" event + * + * Triggers the "postDelete" event mapping the following parameters: + * - $statement as "statement" + * - $result as "result" + * + * @param StatementInterface $statement + * @param ResultInterface $result + * @return void + */ + public function postDelete(StatementInterface $statement, ResultInterface $result) + { + $this->event->setName(__FUNCTION__); + $this->event->setParams(array( + 'statement' => $statement, + 'result' => $result, + )); + $this->eventManager->trigger($this->event); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/EventFeature/TableGatewayEvent.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/EventFeature/TableGatewayEvent.php new file mode 100644 index 0000000000000000000000000000000000000000..e6a20f834083fbbcfb4a2d04ac30c161301fa0f8 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/EventFeature/TableGatewayEvent.php @@ -0,0 +1,140 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway\Feature\EventFeature; + +use Zend\Db\TableGateway\AbstractTableGateway; +use Zend\EventManager\EventInterface; + +class TableGatewayEvent implements EventInterface +{ + + /** + * @var AbstractTableGateway + */ + protected $target = null; + + /** + * @var null + */ + protected $name = null; + + /** + * @var array|\ArrayAccess + */ + protected $params = array(); + + /** + * Get event name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Get target/context from which event was triggered + * + * @return null|string|object + */ + public function getTarget() + { + return $this->target; + } + + /** + * Get parameters passed to the event + * + * @return array|\ArrayAccess + */ + public function getParams() + { + return $this->params; + } + + /** + * Get a single parameter by name + * + * @param string $name + * @param mixed $default Default value to return if parameter does not exist + * @return mixed + */ + public function getParam($name, $default = null) + { + return (isset($this->params[$name]) ? $this->params[$name] : $default); + } + + /** + * Set the event name + * + * @param string $name + * @return void + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Set the event target/context + * + * @param null|string|object $target + * @return void + */ + public function setTarget($target) + { + $this->target = $target; + } + + /** + * Set event parameters + * + * @param string $params + * @return void + */ + public function setParams($params) + { + $this->params = $params; + } + + /** + * Set a single parameter by key + * + * @param string $name + * @param mixed $value + * @return void + */ + public function setParam($name, $value) + { + $this->params[$name] = $value; + } + + /** + * Indicate whether or not the parent EventManagerInterface should stop propagating events + * + * @param bool $flag + * @return void + */ + public function stopPropagation($flag = true) + { + return; + } + + /** + * Has this event indicated event propagation should stop? + * + * @return bool + */ + public function propagationIsStopped() + { + return false; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/FeatureSet.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/FeatureSet.php new file mode 100644 index 0000000000000000000000000000000000000000..498db1ad7f59d38e7ae33e3373925fd8bf21c5ba --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/FeatureSet.php @@ -0,0 +1,146 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway\Feature; + +use Zend\Db\TableGateway\AbstractTableGateway; +use Zend\Db\TableGateway\TableGatewayInterface; + +class FeatureSet +{ + const APPLY_HALT = 'halt'; + + protected $tableGateway = null; + + /** + * @var AbstractFeature[] + */ + protected $features = array(); + + /** + * @var array + */ + protected $magicSpecifications = array(); + + public function __construct(array $features = array()) + { + if ($features) { + $this->addFeatures($features); + } + } + + public function setTableGateway(AbstractTableGateway $tableGateway) + { + $this->tableGateway = $tableGateway; + foreach ($this->features as $feature) { + $feature->setTableGateway($this->tableGateway); + } + return $this; + } + + public function getFeatureByClassName($featureClassName) + { + $feature = false; + foreach ($this->features as $potentialFeature) { + if ($potentialFeature instanceof $featureClassName) { + $feature = $potentialFeature; + break; + } + } + return $feature; + } + + public function addFeatures(array $features) + { + foreach ($features as $feature) { + $this->addFeature($feature); + } + return $this; + } + + public function addFeature(AbstractFeature $feature) + { + if ($this->tableGateway instanceof TableGatewayInterface) { + $feature->setTableGateway($this->tableGateway); + } + $this->features[] = $feature; + return $this; + } + + public function apply($method, $args) + { + foreach ($this->features as $feature) { + if (method_exists($feature, $method)) { + $return = call_user_func_array(array($feature, $method), $args); + if ($return === self::APPLY_HALT) { + break; + } + } + } + } + + /** + * @param string $property + * @return bool + */ + public function canCallMagicGet($property) + { + return false; + } + + /** + * @param string $property + * @return mixed + */ + public function callMagicGet($property) + { + $return = null; + return $return; + } + + /** + * @param string $property + * @return bool + */ + public function canCallMagicSet($property) + { + return false; + } + + /** + * @param $property + * @param $value + * @return mixed + */ + public function callMagicSet($property, $value) + { + $return = null; + return $return; + } + + /** + * @param string $method + * @return bool + */ + public function canCallMagicCall($method) + { + return false; + } + + /** + * @param string $method + * @param array $arguments + * @return mixed + */ + public function callMagicCall($method, $arguments) + { + $return = null; + return $return; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/GlobalAdapterFeature.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/GlobalAdapterFeature.php new file mode 100644 index 0000000000000000000000000000000000000000..f1fa78eb32fbc2c79df7e775711713f211a28e9b --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/GlobalAdapterFeature.php @@ -0,0 +1,70 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway\Feature; + +use Zend\Db\Adapter\Adapter; +use Zend\Db\TableGateway\Exception; + +class GlobalAdapterFeature extends AbstractFeature +{ + + /** + * @var Adapter[] + */ + protected static $staticAdapters = array(); + + /** + * Set static adapter + * + * @param Adapter $adapter + */ + public static function setStaticAdapter(Adapter $adapter) + { + $class = get_called_class(); + + static::$staticAdapters[$class] = $adapter; + if ($class === __CLASS__) { + static::$staticAdapters[__CLASS__] = $adapter; + } + } + + /** + * Get static adapter + * + * @throws Exception\RuntimeException + * @return Adapter + */ + public static function getStaticAdapter() + { + $class = get_called_class(); + + // class specific adapter + if (isset(static::$staticAdapters[$class])) { + return static::$staticAdapters[$class]; + } + + // default adapter + if (isset(static::$staticAdapters[__CLASS__])) { + return static::$staticAdapters[__CLASS__]; + } + + throw new Exception\RuntimeException('No database adapter was found in the static registry.'); + } + + /** + * after initialization, retrieve the original adapter as "master" + */ + public function preInitialize() + { + $this->tableGateway->adapter = self::getStaticAdapter(); + } + + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/MasterSlaveFeature.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/MasterSlaveFeature.php new file mode 100644 index 0000000000000000000000000000000000000000..7c12dc8f732671ff56765826944bea07aafdcf8e --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/MasterSlaveFeature.php @@ -0,0 +1,93 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway\Feature; + +use Zend\Db\Adapter\AdapterInterface; +use Zend\Db\Sql\Sql; + +class MasterSlaveFeature extends AbstractFeature +{ + + /** + * @var AdapterInterface + */ + protected $slaveAdapter = null; + + /** + * @var Sql + */ + protected $masterSql = null; + + /** + * @var Sql + */ + protected $slaveSql = null; + + /** + * Constructor + * + * @param AdapterInterface $slaveAdapter + * @param Sql|null $slaveSql + */ + public function __construct(AdapterInterface $slaveAdapter, Sql $slaveSql = null) + { + $this->slaveAdapter = $slaveAdapter; + if ($slaveSql) { + $this->slaveSql = $slaveSql; + } + } + + public function getSlaveAdapter() + { + return $this->slaveAdapter; + } + + /** + * @return Sql + */ + public function getSlaveSql() + { + return $this->slaveSql; + } + + /** + * after initialization, retrieve the original adapter as "master" + */ + public function postInitialize() + { + $this->masterSql = $this->tableGateway->sql; + if ($this->slaveSql == null) { + $this->slaveSql = new Sql( + $this->slaveAdapter, + $this->tableGateway->sql->getTable(), + $this->tableGateway->sql->getSqlPlatform() + ); + } + } + + /** + * preSelect() + * Replace adapter with slave temporarily + */ + public function preSelect() + { + $this->tableGateway->sql = $this->slaveSql; + } + + /** + * postSelect() + * Ensure to return to the master adapter + */ + public function postSelect() + { + $this->tableGateway->sql = $this->masterSql; + } + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/MetadataFeature.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/MetadataFeature.php new file mode 100644 index 0000000000000000000000000000000000000000..b88415888368f98b65bc4eec26c064e41f250848 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/MetadataFeature.php @@ -0,0 +1,88 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway\Feature; + +use Zend\Db\Metadata\Metadata; +use Zend\Db\Metadata\MetadataInterface; +use Zend\Db\TableGateway\Exception; +use Zend\Db\Metadata\Object\TableObject; + +class MetadataFeature extends AbstractFeature +{ + + /** + * @var MetadataInterface + */ + protected $metadata = null; + + /** + * Constructor + * + * @param MetadataInterface $metadata + */ + public function __construct(MetadataInterface $metadata = null) + { + if ($metadata) { + $this->metadata = $metadata; + } + $this->sharedData['metadata'] = array( + 'primaryKey' => null, + 'columns' => array() + ); + } + + public function postInitialize() + { + if ($this->metadata == null) { + $this->metadata = new Metadata($this->tableGateway->adapter); + } + + // localize variable for brevity + $t = $this->tableGateway; + $m = $this->metadata; + + // get column named + $columns = $m->getColumnNames($t->table); + $t->columns = $columns; + + // set locally + $this->sharedData['metadata']['columns'] = $columns; + + // process primary key only if table is a table; there are no PK constraints on views + if (!($m->getTable($t->table) instanceof TableObject)) { + return; + } + + $pkc = null; + + foreach ($m->getConstraints($t->table) as $constraint) { + /** @var $constraint \Zend\Db\Metadata\Object\ConstraintObject */ + if ($constraint->getType() == 'PRIMARY KEY') { + $pkc = $constraint; + break; + } + } + + if ($pkc === null) { + throw new Exception\RuntimeException('A primary key for this column could not be found in the metadata.'); + } + + if (count($pkc->getColumns()) == 1) { + $pkck = $pkc->getColumns(); + $primaryKey = $pkck[0]; + } else { + $primaryKey = $pkc->getColumns(); + } + + $this->sharedData['metadata']['primaryKey'] = $primaryKey; + } + + +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/RowGatewayFeature.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/RowGatewayFeature.php new file mode 100644 index 0000000000000000000000000000000000000000..b3c467ac49988a99de2ff43907a234a8890dc426 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/RowGatewayFeature.php @@ -0,0 +1,68 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway\Feature; + +use Zend\Db\ResultSet\ResultSet; +use Zend\Db\RowGateway\RowGateway; +use Zend\Db\RowGateway\RowGatewayInterface; +use Zend\Db\TableGateway\Exception; + +class RowGatewayFeature extends AbstractFeature +{ + + /** + * @var array + */ + protected $constructorArguments = array(); + + /** + * @param null $primaryKey + */ + public function __construct() + { + $this->constructorArguments = func_get_args(); + } + + public function postInitialize() + { + $args = $this->constructorArguments; + + /** @var $resultSetPrototype ResultSet */ + $resultSetPrototype = $this->tableGateway->resultSetPrototype; + + if (!$this->tableGateway->resultSetPrototype instanceof ResultSet) { + throw new Exception\RuntimeException( + 'This feature ' . __CLASS__ . ' expects the ResultSet to be an instance of Zend\Db\ResultSet\ResultSet' + ); + } + + if (isset($args[0])) { + if (is_string($args[0])) { + $primaryKey = $args[0]; + $rowGatewayPrototype = new RowGateway($primaryKey, $this->tableGateway->table, $this->tableGateway->adapter, $this->tableGateway->sql); + $resultSetPrototype->setArrayObjectPrototype($rowGatewayPrototype); + } elseif ($args[0] instanceof RowGatewayInterface) { + $rowGatewayPrototype = $args[0]; + $resultSetPrototype->setArrayObjectPrototype($rowGatewayPrototype); + } + } else { + // get from metadata feature + $metadata = $this->tableGateway->featureSet->getFeatureByClassName('Zend\Db\TableGateway\Feature\MetadataFeature'); + if ($metadata === false || !isset($metadata->sharedData['metadata'])) { + throw new Exception\RuntimeException( + 'No information was provided to the RowGatewayFeature and/or no MetadataFeature could be consulted to find the primary key necessary for RowGateway object creation.' + ); + } + $primaryKey = $metadata->sharedData['metadata']['primaryKey']; + $rowGatewayPrototype = new RowGateway($primaryKey, $this->tableGateway->table, $this->tableGateway->adapter, $this->tableGateway->sql); + $resultSetPrototype->setArrayObjectPrototype($rowGatewayPrototype); + } + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/SequenceFeature.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/SequenceFeature.php new file mode 100644 index 0000000000000000000000000000000000000000..103f2092b57f06bd14e0303daf5a45276e8d869f --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/Feature/SequenceFeature.php @@ -0,0 +1,128 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway\Feature; + +use Zend\Db\Sql\Insert; +use Zend\Db\Adapter\Driver\ResultInterface; +use Zend\Db\Adapter\Driver\StatementInterface; + +class SequenceFeature extends AbstractFeature +{ + /** + * @var string + */ + protected $primaryKeyField; + + /** + * @var string + */ + protected $sequenceName; + + /** + * @var int + */ + protected $sequenceValue; + + + /** + * @param string $primaryKeyField + * @param string $sequenceName + */ + public function __construct($primaryKeyField, $sequenceName) + { + $this->primaryKeyField = $primaryKeyField; + $this->sequenceName = $sequenceName; + } + + /** + * @param Insert $insert + */ + public function preInsert(Insert $insert) + { + $columns = $insert->getRawState('columns'); + $values = $insert->getRawState('values'); + $key = array_search($this->primaryKeyField, $columns); + if ($key !== false) { + $this->sequenceValue = $values[$key]; + return $insert; + } + + $this->sequenceValue = $this->nextSequenceId(); + if ($this->sequenceValue === null) { + return $insert; + } + + $insert->values(array($this->primaryKeyField => $this->sequenceValue), Insert::VALUES_MERGE); + return $insert; + } + + public function postInsert(StatementInterface $statement, ResultInterface $result) + { + if ($this->sequenceValue !== null) { + $this->tableGateway->lastInsertValue = $this->sequenceValue; + } + } + + /** + * Generate a new value from the specified sequence in the database, and return it. + * @return int + */ + public function nextSequenceId() + { + $platform = $this->tableGateway->adapter->getPlatform(); + $platformName = $platform->getName(); + + switch ($platformName) { + case 'Oracle': + $sql = 'SELECT ' . $platform->quoteIdentifier($this->sequenceName) . '.NEXTVAL as "nextval" FROM dual'; + break; + case 'PostgreSQL': + $sql = 'SELECT NEXTVAL(\'' . $this->sequenceName . '\')'; + break; + default : + return null; + } + + $statement = $this->tableGateway->adapter->createStatement(); + $statement->prepare($sql); + $result = $statement->execute(); + $sequence = $result->current(); + unset($statement, $result); + return $sequence['nextval']; + } + + /** + * Return the most recent value from the specified sequence in the database. + * @return int + */ + public function lastSequenceId() + { + $platform = $this->tableGateway->adapter->getPlatform(); + $platformName = $platform->getName(); + + switch ($platformName) { + case 'Oracle': + $sql = 'SELECT ' . $platform->quoteIdentifier($this->sequenceName) . '.CURRVAL as "currval" FROM dual'; + break; + case 'PostgreSQL': + $sql = 'SELECT CURRVAL(\'' . $this->sequenceName . '\')'; + break; + default : + return null; + } + + $statement = $this->tableGateway->adapter->createStatement(); + $statement->prepare($sql); + $result = $statement->execute(); + $sequence = $result->current(); + unset($statement, $result); + return $sequence['currval']; + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/TableGateway.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/TableGateway.php new file mode 100644 index 0000000000000000000000000000000000000000..e1aaaf326a35b6cf1e0bb5d4978901c1ea3e8941 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/TableGateway.php @@ -0,0 +1,73 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway; + +use Zend\Db\Adapter\AdapterInterface; +use Zend\Db\ResultSet\ResultSet; +use Zend\Db\ResultSet\ResultSetInterface; +use Zend\Db\Sql\Sql; +use Zend\Db\Sql\TableIdentifier; + +class TableGateway extends AbstractTableGateway +{ + + /** + * Constructor + * + * @param string $table + * @param AdapterInterface $adapter + * @param Feature\AbstractFeature|Feature\FeatureSet|Feature\AbstractFeature[] $features + * @param ResultSetInterface $resultSetPrototype + * @param Sql $sql + * @throws Exception\InvalidArgumentException + */ + public function __construct($table, AdapterInterface $adapter, $features = null, ResultSetInterface $resultSetPrototype = null, Sql $sql = null) + { + // table + if (!(is_string($table) || $table instanceof TableIdentifier)) { + throw new Exception\InvalidArgumentException('Table name must be a string or an instance of Zend\Db\Sql\TableIdentifier'); + } + $this->table = $table; + + // adapter + $this->adapter = $adapter; + + // process features + if ($features !== null) { + if ($features instanceof Feature\AbstractFeature) { + $features = array($features); + } + if (is_array($features)) { + $this->featureSet = new Feature\FeatureSet($features); + } elseif ($features instanceof Feature\FeatureSet) { + $this->featureSet = $features; + } else { + throw new Exception\InvalidArgumentException( + 'TableGateway expects $feature to be an instance of an AbstractFeature or a FeatureSet, or an array of AbstractFeatures' + ); + } + } else { + $this->featureSet = new Feature\FeatureSet(); + } + + // result prototype + $this->resultSetPrototype = ($resultSetPrototype) ?: new ResultSet; + + // Sql object (factory for select, insert, update, delete) + $this->sql = ($sql) ?: new Sql($this->adapter, $this->table); + + // check sql object bound to same table + if ($this->sql->getTable() != $this->table) { + throw new Exception\InvalidArgumentException('The table inside the provided Sql object must match the table of this TableGateway'); + } + + $this->initialize(); + } +} diff --git a/vendor/zendframework/zend-db/Zend/Db/TableGateway/TableGatewayInterface.php b/vendor/zendframework/zend-db/Zend/Db/TableGateway/TableGatewayInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..0a77e0f1d7750ca6f4e38d7c9f21358a70d586ad --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/TableGateway/TableGatewayInterface.php @@ -0,0 +1,19 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +namespace Zend\Db\TableGateway; + +interface TableGatewayInterface +{ + public function getTable(); + public function select($where = null); + public function insert($set); + public function update($set, $where = null); + public function delete($where); +} diff --git a/vendor/zendframework/zend-db/Zend/Db/composer.json b/vendor/zendframework/zend-db/Zend/Db/composer.json new file mode 100644 index 0000000000000000000000000000000000000000..c0ffca7dbd77ab655044f6ebda48e2f6976d68a9 --- /dev/null +++ b/vendor/zendframework/zend-db/Zend/Db/composer.json @@ -0,0 +1,34 @@ +{ + "name": "zendframework/zend-db", + "description": " ", + "license": "BSD-3-Clause", + "keywords": [ + "zf2", + "db" + ], + "autoload": { + "psr-0": { + "Zend\\Db\\": "" + } + }, + "target-dir": "Zend/Db", + "require": { + "php": ">=5.3.23" + }, + "require-dev": { + "zendframework/zend-eventmanager": "self.version", + "zendframework/zend-servicemanager": "self.version", + "zendframework/zend-stdlib": "self.version" + }, + "suggest": { + "zendframework/zend-eventmanager": "Zend\\EventManager component", + "zendframework/zend-servicemanager": "Zend\\ServiceManager component", + "zendframework/zend-stdlib": "Zend\\Stdlib component" + }, + "extra": { + "branch-alias": { + "dev-master": "2.3-dev", + "dev-develop": "2.4-dev" + } + } +}