[Ivan Diaz] - Updated vendor

This commit is contained in:
Ivan Diaz 2015-11-18 21:56:43 -03:00
parent 4b66684c0e
commit b3df77988b
133 changed files with 1543 additions and 1181 deletions

63
server/composer.lock generated
View File

@ -8,16 +8,16 @@
"packages": [ "packages": [
{ {
"name": "gabordemooij/redbean", "name": "gabordemooij/redbean",
"version": "v4.2.1", "version": "v4.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/gabordemooij/redbean.git", "url": "https://github.com/gabordemooij/redbean.git",
"reference": "13610146620d7c0a66215dcaf0c8796bb03a04aa" "reference": "f375a1678d137ca1ff806813fac306723f97ec6b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/gabordemooij/redbean/zipball/13610146620d7c0a66215dcaf0c8796bb03a04aa", "url": "https://api.github.com/repos/gabordemooij/redbean/zipball/f375a1678d137ca1ff806813fac306723f97ec6b",
"reference": "13610146620d7c0a66215dcaf0c8796bb03a04aa", "reference": "f375a1678d137ca1ff806813fac306723f97ec6b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -45,7 +45,7 @@
"keywords": [ "keywords": [
"orm" "orm"
], ],
"time": "2015-05-09 12:22:47" "time": "2015-09-11 18:55:25"
}, },
{ {
"name": "slim/slim", "name": "slim/slim",
@ -151,16 +151,16 @@
}, },
{ {
"name": "myclabs/deep-copy", "name": "myclabs/deep-copy",
"version": "1.4.0", "version": "1.5.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/myclabs/DeepCopy.git", "url": "https://github.com/myclabs/DeepCopy.git",
"reference": "d8093b631a31628342d0703764935f8bac2c56b1" "reference": "e3abefcd7f106677fd352cd7c187d6c969aa9ddc"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/d8093b631a31628342d0703764935f8bac2c56b1", "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/e3abefcd7f106677fd352cd7c187d6c969aa9ddc",
"reference": "d8093b631a31628342d0703764935f8bac2c56b1", "reference": "e3abefcd7f106677fd352cd7c187d6c969aa9ddc",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -189,7 +189,7 @@
"object", "object",
"object graph" "object graph"
], ],
"time": "2015-10-05 15:07:09" "time": "2015-11-07 22:20:37"
}, },
{ {
"name": "phpdocumentor/reflection-docblock", "name": "phpdocumentor/reflection-docblock",
@ -302,16 +302,16 @@
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "3.0.1", "version": "3.0.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "c84f05be256cd7c9d2340b26f7995b4afbf8787b" "reference": "f7bb5cddf4ffe113eeb737b05241adb947b43f9d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c84f05be256cd7c9d2340b26f7995b4afbf8787b", "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f7bb5cddf4ffe113eeb737b05241adb947b43f9d",
"reference": "c84f05be256cd7c9d2340b26f7995b4afbf8787b", "reference": "f7bb5cddf4ffe113eeb737b05241adb947b43f9d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -360,7 +360,7 @@
"testing", "testing",
"xunit" "xunit"
], ],
"time": "2015-10-06 15:51:05" "time": "2015-11-12 21:08:20"
}, },
{ {
"name": "phpunit/php-file-iterator", "name": "phpunit/php-file-iterator",
@ -542,16 +542,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "5.0.6", "version": "5.0.9",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "d2656ec378c88e036b3fc14fb4262ee1a25498c9" "reference": "ed084be6b5b912f11c3559e17110f8d8a1e3a8a1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d2656ec378c88e036b3fc14fb4262ee1a25498c9", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ed084be6b5b912f11c3559e17110f8d8a1e3a8a1",
"reference": "d2656ec378c88e036b3fc14fb4262ee1a25498c9", "reference": "ed084be6b5b912f11c3559e17110f8d8a1e3a8a1",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -612,20 +612,20 @@
"testing", "testing",
"xunit" "xunit"
], ],
"time": "2015-10-14 13:51:20" "time": "2015-11-10 21:47:43"
}, },
{ {
"name": "phpunit/phpunit-mock-objects", "name": "phpunit/phpunit-mock-objects",
"version": "3.0.3", "version": "3.0.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
"reference": "382c729a52b7ef682e94c73fd6868f5ee8116ba7" "reference": "b28b029356e65091dfbf8c2bc4ef106ffece509e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/382c729a52b7ef682e94c73fd6868f5ee8116ba7", "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/b28b029356e65091dfbf8c2bc4ef106ffece509e",
"reference": "382c729a52b7ef682e94c73fd6868f5ee8116ba7", "reference": "b28b029356e65091dfbf8c2bc4ef106ffece509e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -668,7 +668,7 @@
"mock", "mock",
"xunit" "xunit"
], ],
"time": "2015-10-18 07:55:54" "time": "2015-11-09 15:37:17"
}, },
{ {
"name": "sebastian/comparator", "name": "sebastian/comparator",
@ -1085,24 +1085,21 @@
}, },
{ {
"name": "symfony/yaml", "name": "symfony/yaml",
"version": "v2.7.5", "version": "v2.7.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/yaml.git", "url": "https://github.com/symfony/yaml.git",
"reference": "31cb2ad0155c95b88ee55fe12bc7ff92232c1770" "reference": "eca9019c88fbe250164affd107bc8057771f3f4d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/31cb2ad0155c95b88ee55fe12bc7ff92232c1770", "url": "https://api.github.com/repos/symfony/yaml/zipball/eca9019c88fbe250164affd107bc8057771f3f4d",
"reference": "31cb2ad0155c95b88ee55fe12bc7ff92232c1770", "reference": "eca9019c88fbe250164affd107bc8057771f3f4d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.3.9" "php": ">=5.3.9"
}, },
"require-dev": {
"symfony/phpunit-bridge": "~2.7"
},
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
@ -1130,7 +1127,7 @@
], ],
"description": "Symfony Yaml Component", "description": "Symfony Yaml Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2015-09-14 14:14:09" "time": "2015-10-11 09:39:48"
} }
], ],
"aliases": [], "aliases": [],

View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer' . '/autoload_real.php'; require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInita2f433ace6603da0dacbae24a9d70062::getLoader(); return ComposerAutoloaderInitc1131bbfb8e9acff5fc8b79d0d7d1f64::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInita2f433ace6603da0dacbae24a9d70062 class ComposerAutoloaderInitc1131bbfb8e9acff5fc8b79d0d7d1f64
{ {
private static $loader; private static $loader;
@ -19,9 +19,9 @@ class ComposerAutoloaderInita2f433ace6603da0dacbae24a9d70062
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInita2f433ace6603da0dacbae24a9d70062', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInitc1131bbfb8e9acff5fc8b79d0d7d1f64', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(); self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInita2f433ace6603da0dacbae24a9d70062', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInitc1131bbfb8e9acff5fc8b79d0d7d1f64', 'loadClassLoader'));
$map = require __DIR__ . '/autoload_namespaces.php'; $map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) { foreach ($map as $namespace => $path) {
@ -44,7 +44,7 @@ class ComposerAutoloaderInita2f433ace6603da0dacbae24a9d70062
} }
} }
function composerRequirea2f433ace6603da0dacbae24a9d70062($file) function composerRequirec1131bbfb8e9acff5fc8b79d0d7d1f64($file)
{ {
require $file; require $file;
} }

View File

@ -48,18 +48,61 @@
] ]
}, },
{ {
"name": "myclabs/deep-copy", "name": "gabordemooij/redbean",
"version": "1.4.0", "version": "v4.3",
"version_normalized": "1.4.0.0", "version_normalized": "4.3.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/myclabs/DeepCopy.git", "url": "https://github.com/gabordemooij/redbean.git",
"reference": "d8093b631a31628342d0703764935f8bac2c56b1" "reference": "f375a1678d137ca1ff806813fac306723f97ec6b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/d8093b631a31628342d0703764935f8bac2c56b1", "url": "https://api.github.com/repos/gabordemooij/redbean/zipball/f375a1678d137ca1ff806813fac306723f97ec6b",
"reference": "d8093b631a31628342d0703764935f8bac2c56b1", "reference": "f375a1678d137ca1ff806813fac306723f97ec6b",
"shasum": ""
},
"require": {
"php": ">=5.3.4"
},
"time": "2015-09-11 18:55:25",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"RedBeanPHP\\": "RedBeanPHP"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"New BSD and GPLv2"
],
"authors": [
{
"name": "Gabor de Mooij",
"email": "gabor@redbeanphp.com",
"homepage": "http://redbeanphp.com"
}
],
"description": "RedBeanPHP ORM",
"homepage": "http://redbeanphp.com/",
"keywords": [
"orm"
]
},
{
"name": "myclabs/deep-copy",
"version": "1.5.0",
"version_normalized": "1.5.0.0",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
"reference": "e3abefcd7f106677fd352cd7c187d6c969aa9ddc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/e3abefcd7f106677fd352cd7c187d6c969aa9ddc",
"reference": "e3abefcd7f106677fd352cd7c187d6c969aa9ddc",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -69,7 +112,7 @@
"doctrine/collections": "1.*", "doctrine/collections": "1.*",
"phpunit/phpunit": "~4.1" "phpunit/phpunit": "~4.1"
}, },
"time": "2015-10-05 15:07:09", "time": "2015-11-07 22:20:37",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {
@ -522,26 +565,23 @@
}, },
{ {
"name": "symfony/yaml", "name": "symfony/yaml",
"version": "v2.7.5", "version": "v2.7.6",
"version_normalized": "2.7.5.0", "version_normalized": "2.7.6.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/yaml.git", "url": "https://github.com/symfony/yaml.git",
"reference": "31cb2ad0155c95b88ee55fe12bc7ff92232c1770" "reference": "eca9019c88fbe250164affd107bc8057771f3f4d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/31cb2ad0155c95b88ee55fe12bc7ff92232c1770", "url": "https://api.github.com/repos/symfony/yaml/zipball/eca9019c88fbe250164affd107bc8057771f3f4d",
"reference": "31cb2ad0155c95b88ee55fe12bc7ff92232c1770", "reference": "eca9019c88fbe250164affd107bc8057771f3f4d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.3.9" "php": ">=5.3.9"
}, },
"require-dev": { "time": "2015-10-11 09:39:48",
"symfony/phpunit-bridge": "~2.7"
},
"time": "2015-09-14 14:14:09",
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
@ -785,17 +825,17 @@
}, },
{ {
"name": "phpunit/phpunit-mock-objects", "name": "phpunit/phpunit-mock-objects",
"version": "3.0.3", "version": "3.0.4",
"version_normalized": "3.0.3.0", "version_normalized": "3.0.4.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
"reference": "382c729a52b7ef682e94c73fd6868f5ee8116ba7" "reference": "b28b029356e65091dfbf8c2bc4ef106ffece509e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/382c729a52b7ef682e94c73fd6868f5ee8116ba7", "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/b28b029356e65091dfbf8c2bc4ef106ffece509e",
"reference": "382c729a52b7ef682e94c73fd6868f5ee8116ba7", "reference": "b28b029356e65091dfbf8c2bc4ef106ffece509e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -810,7 +850,7 @@
"suggest": { "suggest": {
"ext-soap": "*" "ext-soap": "*"
}, },
"time": "2015-10-18 07:55:54", "time": "2015-11-09 15:37:17",
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
@ -986,17 +1026,17 @@
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "3.0.1", "version": "3.0.2",
"version_normalized": "3.0.1.0", "version_normalized": "3.0.2.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "c84f05be256cd7c9d2340b26f7995b4afbf8787b" "reference": "f7bb5cddf4ffe113eeb737b05241adb947b43f9d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c84f05be256cd7c9d2340b26f7995b4afbf8787b", "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f7bb5cddf4ffe113eeb737b05241adb947b43f9d",
"reference": "c84f05be256cd7c9d2340b26f7995b4afbf8787b", "reference": "f7bb5cddf4ffe113eeb737b05241adb947b43f9d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1016,7 +1056,7 @@
"ext-xdebug": ">=2.2.1", "ext-xdebug": ">=2.2.1",
"ext-xmlwriter": "*" "ext-xmlwriter": "*"
}, },
"time": "2015-10-06 15:51:05", "time": "2015-11-12 21:08:20",
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
@ -1050,17 +1090,17 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "5.0.6", "version": "5.0.9",
"version_normalized": "5.0.6.0", "version_normalized": "5.0.9.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "d2656ec378c88e036b3fc14fb4262ee1a25498c9" "reference": "ed084be6b5b912f11c3559e17110f8d8a1e3a8a1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d2656ec378c88e036b3fc14fb4262ee1a25498c9", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ed084be6b5b912f11c3559e17110f8d8a1e3a8a1",
"reference": "d2656ec378c88e036b3fc14fb4262ee1a25498c9", "reference": "ed084be6b5b912f11c3559e17110f8d8a1e3a8a1",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1089,7 +1129,7 @@
"suggest": { "suggest": {
"phpunit/php-invoker": "~1.1" "phpunit/php-invoker": "~1.1"
}, },
"time": "2015-10-14 13:51:20", "time": "2015-11-10 21:47:43",
"bin": [ "bin": [
"phpunit" "phpunit"
], ],
@ -1123,48 +1163,5 @@
"testing", "testing",
"xunit" "xunit"
] ]
},
{
"name": "gabordemooij/redbean",
"version": "v4.2.1",
"version_normalized": "4.2.1.0",
"source": {
"type": "git",
"url": "https://github.com/gabordemooij/redbean.git",
"reference": "13610146620d7c0a66215dcaf0c8796bb03a04aa"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/gabordemooij/redbean/zipball/13610146620d7c0a66215dcaf0c8796bb03a04aa",
"reference": "13610146620d7c0a66215dcaf0c8796bb03a04aa",
"shasum": ""
},
"require": {
"php": ">=5.3.4"
},
"time": "2015-05-09 12:22:47",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"RedBeanPHP\\": "RedBeanPHP"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"New BSD and GPLv2"
],
"authors": [
{
"name": "Gabor de Mooij",
"email": "gabor@redbeanphp.com",
"homepage": "http://redbeanphp.com"
}
],
"description": "RedBeanPHP ORM",
"homepage": "http://redbeanphp.com/",
"keywords": [
"orm"
]
} }
] ]

View File

@ -9,6 +9,22 @@ RedBeanPHP is an easy to use ORM tool for PHP.
* No configuration, just fire and forget * No configuration, just fire and forget
* No complicated package tools, no autoloaders, just ONE file * No complicated package tools, no autoloaders, just ONE file
Installation via Composer
-------------------------
Just open your composer.json file and add the package name ```(e.g. "gabordemooij/redbean": "dev-master")``` in your require list.
```json
{
"require": {
"gabordemooij/redbean": "dev-master"
}
}
```
If you not using composer then [try it.](http://redbeanphp.com/install)
Quick Example Quick Example
------------- -------------

View File

@ -20,7 +20,7 @@ namespace RedBeanPHP;
interface Adapter interface Adapter
{ {
/** /**
* Returns the latest SQL statement * Returns the latest SQL statement.
* *
* @return string * @return string
*/ */
@ -32,9 +32,11 @@ interface Adapter
* observers to notify about the SQL execution; this to prevent * observers to notify about the SQL execution; this to prevent
* infinite recursion when using observers. * infinite recursion when using observers.
* *
* @param string $sql SQL * @param string $sql string containing SQL code for database
* @param array $bindings values * @param array $bindings array of values to bind to parameters in query string
* @param boolean $noevent no event firing * @param boolean $noevent no event firing
*
* @return void
*/ */
public function exec( $sql, $bindings = array(), $noevent = FALSE ); public function exec( $sql, $bindings = array(), $noevent = FALSE );
@ -44,8 +46,8 @@ interface Adapter
* The values array can be used to bind values to the place holders in the * The values array can be used to bind values to the place holders in the
* SQL query. * SQL query.
* *
* @param string $sql SQL * @param string $sql string containing SQL code for database
* @param array $bindings values * @param array $bindings array of values to bind to parameters in query string
* *
* @return array * @return array
*/ */
@ -57,8 +59,8 @@ interface Adapter
* The values array can be used to bind values to the place holders in the * The values array can be used to bind values to the place holders in the
* SQL query. * SQL query.
* *
* @param string $sql SQL * @param string $sql string containing SQL code for database
* @param array $bindings values to bind * @param array $bindings array of values to bind to parameters in query string
* *
* @return array * @return array
*/ */
@ -70,8 +72,8 @@ interface Adapter
* The values array can be used to bind values to the place holders in the * The values array can be used to bind values to the place holders in the
* SQL query. * SQL query.
* *
* @param string $sql SQL * @param string $sql string containing SQL code for database
* @param array $bindings values to bind * @param array $bindings array of values to bind to parameters in query string
* *
* @return array * @return array
*/ */
@ -83,8 +85,8 @@ interface Adapter
* The values array can be used to bind values to the place holders in the * The values array can be used to bind values to the place holders in the
* SQL query. * SQL query.
* *
* @param string $sql SQL * @param string $sql string containing SQL code for database
* @param array $bindings values to bind * @param array $bindings array of values to bind to parameters in query string
* *
* @return string * @return string
*/ */
@ -98,8 +100,8 @@ interface Adapter
* The values array can be used to bind values to the place holders in the * The values array can be used to bind values to the place holders in the
* SQL query. * SQL query.
* *
* @param string $sql SQL * @param string $sql string containing SQL code for database
* @param array $bindings values to bind * @param array $bindings array of values to bind to parameters in query string
* *
* @return array * @return array
*/ */
@ -109,7 +111,7 @@ interface Adapter
* Executes the SQL query specified in $sql and indexes * Executes the SQL query specified in $sql and indexes
* the row by the first column. * the row by the first column.
* *
* @param string $sql SQL * @param string $sql Sstring containing SQL code for databaseQL
* @param array $bindings values to bind * @param array $bindings values to bind
* *
* @return array * @return array
@ -134,8 +136,8 @@ interface Adapter
/** /**
* Returns a database agnostic Cursor object. * Returns a database agnostic Cursor object.
* *
* @param string $sql SQL * @param string $sql string containing SQL code for database
* @param array $bindings bindings * @param array $bindings array of values to bind to parameters in query string
* *
* @return Cursor * @return Cursor
*/ */
@ -147,7 +149,7 @@ interface Adapter
* adapter. RedBean will only access the adapter and never to talk * adapter. RedBean will only access the adapter and never to talk
* directly to the driver though. * directly to the driver though.
* *
* @return object * @return mixed
*/ */
public function getDatabase(); public function getDatabase();

View File

@ -2,15 +2,10 @@
namespace RedBeanPHP; namespace RedBeanPHP;
use RedBeanPHP\Observable as Observable;
use RedBeanPHP\OODB as OODB;
use RedBeanPHP\Adapter\DBAdapter as DBAdapter; use RedBeanPHP\Adapter\DBAdapter as DBAdapter;
use RedBeanPHP\QueryWriter as QueryWriter; use RedBeanPHP\QueryWriter as QueryWriter;
use RedBeanPHP\OODBBean as OODBBean;
use RedBeanPHP\RedException as RedException; use RedBeanPHP\RedException as RedException;
use RedBeanPHP\RedException\Security as Security;
use RedBeanPHP\RedException\SQL as SQLException; use RedBeanPHP\RedException\SQL as SQLException;
use RedBeanPHP\ToolBox as ToolBox;
/** /**
* Association Manager. * Association Manager.
@ -43,13 +38,11 @@ class AssociationManager extends Observable
protected $writer; protected $writer;
/** /**
* Handles\Exceptions. Suppresses exceptions caused by missing structures. * Handles exceptions. Suppresses exceptions caused by missing structures.
* *
* @param\Exception $exception * @param Exception $exception exception to handle
* *
* @return void * @return void
*
* @throws\Exception
*/ */
private function handleException( \Exception $exception ) private function handleException( \Exception $exception )
{ {
@ -74,9 +67,6 @@ class AssociationManager extends Observable
* @param array $bindings bindings for query * @param array $bindings bindings for query
* *
* @return array * @return array
*
* @throws Security
* @throws SQL
*/ */
private function relatedRows( $bean, $type, $sql = '', $bindings = array() ) private function relatedRows( $bean, $type, $sql = '', $bindings = array() )
{ {
@ -100,8 +90,6 @@ class AssociationManager extends Observable
* @param OODBBean $bean2 second bean * @param OODBBean $bean2 second bean
* @param OODBBean $bean base bean (association record) * @param OODBBean $bean base bean (association record)
* *
* @throws\Exception|SQL
*
* @return mixed * @return mixed
*/ */
protected function associateBeans( OODBBean $bean1, OODBBean $bean2, OODBBean $bean ) protected function associateBeans( OODBBean $bean1, OODBBean $bean2, OODBBean $bean )
@ -214,8 +202,6 @@ class AssociationManager extends Observable
* @param array $bindings bindings for your SQL string * @param array $bindings bindings for your SQL string
* *
* @return integer * @return integer
*
* @throws Security
*/ */
public function relatedCount( $bean, $type, $sql = NULL, $bindings = array() ) public function relatedCount( $bean, $type, $sql = NULL, $bindings = array() )
{ {
@ -249,9 +235,9 @@ class AssociationManager extends Observable
* set to boolean TRUE this method will remove the beans without their consent, * set to boolean TRUE this method will remove the beans without their consent,
* bypassing FUSE. This can be used to improve performance. * bypassing FUSE. This can be used to improve performance.
* *
* @param OODBBean $bean1 first bean * @param OODBBean $bean1 first bean in target association
* @param OODBBean $bean2 second bean * @param OODBBean $bean2 second bean in target association
* @param boolean $fast If TRUE, removes the entries by query without FUSE * @param boolean $fast if TRUE, removes the entries by query without FUSE
* *
* @return void * @return void
*/ */
@ -332,7 +318,6 @@ class AssociationManager extends Observable
* @param string $type the type of beans you want * @param string $type the type of beans you want
* @param string $sql SQL snippet for extra filtering * @param string $sql SQL snippet for extra filtering
* @param array $bindings values to be inserted in SQL slots * @param array $bindings values to be inserted in SQL slots
* @param boolean $glue whether the SQL should be prefixed with WHERE
* *
* @return array * @return array
*/ */

View File

@ -28,7 +28,7 @@ interface BeanHelper
* as such the bean is a proxy for OODB. This allows beans to implement * as such the bean is a proxy for OODB. This allows beans to implement
* their magic getters and setters and return lists. * their magic getters and setters and return lists.
* *
* @return ToolBox $toolbox toolbox * @return ToolBox
*/ */
public function getToolbox(); public function getToolbox();
@ -46,9 +46,9 @@ interface BeanHelper
* Given a certain bean this method will * Given a certain bean this method will
* return the corresponding model. * return the corresponding model.
* *
* @param OODBBean $bean * @param OODBBean $bean bean to obtain the corresponding model of
* *
* @return object * @return SimpleModel|CustomModel
*/ */
public function getModelForBean( OODBBean $bean ); public function getModelForBean( OODBBean $bean );
} }

View File

@ -50,7 +50,7 @@ class SimpleFacadeBeanHelper implements BeanHelper
* Sets the factory function to create the model when using FUSE * Sets the factory function to create the model when using FUSE
* to connect a bean to a model. * to connect a bean to a model.
* *
* @param closure $factory * @param closure $factory factory function
* *
* @return void * @return void
*/ */

View File

@ -21,7 +21,7 @@ interface Driver
/** /**
* Runs a query and fetches results as a multi dimensional array. * Runs a query and fetches results as a multi dimensional array.
* *
* @param string $sql SQL to be executed * @param string $sql SQL query to execute
* @param array $bindings list of values to bind to SQL snippet * @param array $bindings list of values to bind to SQL snippet
* *
* @return array * @return array
@ -31,7 +31,7 @@ interface Driver
/** /**
* Runs a query and fetches results as a column. * Runs a query and fetches results as a column.
* *
* @param string $sql SQL Code to execute * @param string $sql SQL query to execute
* @param array $bindings list of values to bind to SQL snippet * @param array $bindings list of values to bind to SQL snippet
* *
* @return array * @return array
@ -41,7 +41,7 @@ interface Driver
/** /**
* Runs a query and returns results as a single cell. * Runs a query and returns results as a single cell.
* *
* @param string $sql SQL to execute * @param string $sql SQL query to execute
* @param array $bindings list of values to bind to SQL snippet * @param array $bindings list of values to bind to SQL snippet
* *
* @return mixed * @return mixed
@ -52,7 +52,7 @@ interface Driver
* Runs a query and returns results as an associative array * Runs a query and returns results as an associative array
* indexed by the first column. * indexed by the first column.
* *
* @param string $sql SQL to execute * @param string $sql SQL query to execute
* @param array $bindings list of values to bind to SQL snippet * @param array $bindings list of values to bind to SQL snippet
* *
* @return mixed * @return mixed
@ -63,7 +63,7 @@ interface Driver
* Runs a query and returns a flat array containing the values of * Runs a query and returns a flat array containing the values of
* one row. * one row.
* *
* @param string $sql SQL to execute * @param string $sql SQL query to execute
* @param array $bindings list of values to bind to SQL snippet * @param array $bindings list of values to bind to SQL snippet
* *
* @return array * @return array
@ -80,7 +80,7 @@ interface Driver
* array(":key"=>123) will bind the integer 123 to the key :key in the * array(":key"=>123) will bind the integer 123 to the key :key in the
* SQL. This method has no return value. * SQL. This method has no return value.
* *
* @param string $sql SQL Code to execute * @param string $sql SQL query to execute
* @param array $bindings list of values to bind to SQL snippet * @param array $bindings list of values to bind to SQL snippet
* *
* @return array Affected Rows * @return array Affected Rows
@ -106,8 +106,8 @@ interface Driver
/** /**
* Returns a cursor-like object from the database. * Returns a cursor-like object from the database.
* *
* @param string $sql SQL code to execute * @param string $sql SQL query to execute
* @param array $bindings Bindings * @param array $bindings list of values to bind to SQL snippet
* *
* @return mixed * @return mixed
*/ */
@ -120,11 +120,12 @@ interface Driver
* passes on to the screen for inspection. * passes on to the screen for inspection.
* This method has no return value. * This method has no return value.
* *
* @param boolean $trueFalse turn on/off * @param boolean $tf TRUE = debug mode ON
* @param Logger $customLogger
* *
* @return void * @return void
*/ */
public function setDebugMode( $tf ); public function setDebugMode( $tf, $customLogger );
/** /**
* Starts a transaction. * Starts a transaction.

View File

@ -130,9 +130,9 @@ class RPDO implements Driver
* *
* @param string $sql the SQL string to be send to database server * @param string $sql the SQL string to be send to database server
* @param array $bindings the values that need to get bound to the query slots * @param array $bindings the values that need to get bound to the query slots
* @param array $options
* *
* @return void * @return mixed
*
* @throws SQL * @throws SQL
*/ */
protected function runQuery( $sql, $bindings, $options = array() ) protected function runQuery( $sql, $bindings, $options = array() )
@ -184,6 +184,8 @@ class RPDO implements Driver
* MySQL < 5.5 does not support proper 4 byte unicode but they * MySQL < 5.5 does not support proper 4 byte unicode but they
* seem to have added it with version 5.5 under a different label: utf8mb4. * seem to have added it with version 5.5 under a different label: utf8mb4.
* We try to select the best possible charset based on your version data. * We try to select the best possible charset based on your version data.
*
* @return void
*/ */
protected function setEncoding() protected function setEncoding()
{ {
@ -209,6 +211,7 @@ class RPDO implements Driver
* @param string $user optional, usename to sign in * @param string $user optional, usename to sign in
* @param string $pass optional, password for connection login * @param string $pass optional, password for connection login
* *
* @return void
*/ */
public function __construct( $dsn, $user = NULL, $pass = NULL ) public function __construct( $dsn, $user = NULL, $pass = NULL )
{ {
@ -286,8 +289,6 @@ class RPDO implements Driver
* UTF8 for the database and PDO-ERRMODE-EXCEPTION as well as * UTF8 for the database and PDO-ERRMODE-EXCEPTION as well as
* PDO-FETCH-ASSOC. * PDO-FETCH-ASSOC.
* *
* @throws\PDOException
*
* @return void * @return void
*/ */
public function connect() public function connect()
@ -531,7 +532,7 @@ class RPDO implements Driver
/** /**
* Returns the version number of the database. * Returns the version number of the database.
* *
* @return mixed $version version number of the database * @return mixed
*/ */
public function getDatabaseVersion() public function getDatabaseVersion()
{ {
@ -551,7 +552,7 @@ class RPDO implements Driver
} }
/** /**
* Closes database connection by destructing\PDO. * Closes database connection by destructing PDO.
* *
* @return void * @return void
*/ */
@ -562,7 +563,7 @@ class RPDO implements Driver
} }
/** /**
* Returns TRUE if the current\PDO instance is connected. * Returns TRUE if the current PDO instance is connected.
* *
* @return boolean * @return boolean
*/ */

View File

@ -278,11 +278,15 @@ class DuplicationManager
* *
* This method allows two array formats: * This method allows two array formats:
* *
* <code>
* array( TABLE1, TABLE2 ... ) * array( TABLE1, TABLE2 ... )
* </code>
* *
* or * or
* *
* <code>
* array( TABLE1 => array( COLUMN1, COLUMN2 ... ) ... ) * array( TABLE1 => array( COLUMN1, COLUMN2 ... ) ... )
* </code>
* *
* @param array $tables a table cache array * @param array $tables a table cache array
* *
@ -335,6 +339,8 @@ class DuplicationManager
* the default behavior. * the default behavior.
* *
* @param array $filters list of tables to be filtered * @param array $filters list of tables to be filtered
*
* @return void
*/ */
public function setFilters( $filters ) public function setFilters( $filters )
{ {

View File

@ -2,34 +2,28 @@
namespace RedBeanPHP; namespace RedBeanPHP;
use RedBeanPHP\ToolBox as ToolBox;
use RedBeanPHP\OODB as OODB;
use RedBeanPHP\QueryWriter as QueryWriter; use RedBeanPHP\QueryWriter as QueryWriter;
use RedBeanPHP\Adapter\DBAdapter as DBAdapter; use RedBeanPHP\Adapter\DBAdapter as DBAdapter;
use RedBeanPHP\AssociationManager as AssociationManager;
use RedBeanPHP\TagManager as TagManager;
use RedBeanPHP\DuplicationManager as DuplicationManager;
use RedBeanPHP\LabelMaker as LabelMaker;
use RedBeanPHP\Finder as Finder;
use RedBeanPHP\RedException\SQL as SQLException; use RedBeanPHP\RedException\SQL as SQLException;
use RedBeanPHP\RedException\Security as Security;
use RedBeanPHP\Logger as Logger; use RedBeanPHP\Logger as Logger;
use RedBeanPHP\Logger\RDefault as RDefault; use RedBeanPHP\Logger\RDefault as RDefault;
use RedBeanPHP\Logger\RDefault\Debug as Debug; use RedBeanPHP\Logger\RDefault\Debug as Debug;
use RedBeanPHP\OODBBean as OODBBean;
use RedBeanPHP\SimpleModel as SimpleModel;
use RedBeanPHP\SimpleModelHelper as SimpleModelHelper;
use RedBeanPHP\Adapter as Adapter; use RedBeanPHP\Adapter as Adapter;
use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter; use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter;
use RedBeanPHP\RedException as RedException; use RedBeanPHP\RedException as RedException;
use RedBeanPHP\BeanHelper\SimpleFacadeBeanHelper as SimpleFacadeBeanHelper; use RedBeanPHP\BeanHelper\SimpleFacadeBeanHelper as SimpleFacadeBeanHelper;
use RedBeanPHP\Driver\RPDO as RPDO; use RedBeanPHP\Driver\RPDO as RPDO;
use RedBeanPHP\Util\MultiLoader as MultiLoader;
use RedBeanPHP\Util\Transaction as Transaction;
use RedBeanPHP\Util\Dump as Dump;
use RedBeanPHP\Util\DispenseHelper as DispenseHelper;
use RedBeanPHP\Util\ArrayTool as ArrayTool;
/** /**
* RedBean Facade * RedBean Facade
* *
* Version Information * Version Information
* RedBean Version @version 4.2 * RedBean Version @version 4.3
* *
* This class hides the object landscape of * This class hides the object landscape of
* RedBeanPHP behind a single letter class providing * RedBeanPHP behind a single letter class providing
@ -49,7 +43,7 @@ class Facade
/** /**
* RedBeanPHP version constant. * RedBeanPHP version constant.
*/ */
const C_REDBEANPHP_VERSION = '4.2'; const C_REDBEANPHP_VERSION = '4.3';
/** /**
* @var ToolBox * @var ToolBox
@ -130,8 +124,6 @@ class Facade
* Internal Query function, executes the desired query. Used by * Internal Query function, executes the desired query. Used by
* all facade query functions. This keeps things DRY. * all facade query functions. This keeps things DRY.
* *
* @throws SQL
*
* @param string $method desired query method (i.e. 'cell', 'col', 'exec' etc..) * @param string $method desired query method (i.e. 'cell', 'col', 'exec' etc..)
* @param string $sql the sql you want to execute * @param string $sql the sql you want to execute
* @param array $bindings array of values to be bound to query statement * @param array $bindings array of values to be bound to query statement
@ -231,13 +223,16 @@ class Facade
} }
/** /**
* Starts a transaction within a closure (or other valid callback). * Wraps a transaction around a closure or string callback.
* If an\Exception is thrown inside, the operation is automatically rolled back. * If an Exception is thrown inside, the operation is automatically rolled back.
* If no\Exception happens, it commits automatically. * If no Exception happens, it commits automatically.
* It also supports (simulated) nested transactions (that is useful when * It also supports (simulated) nested transactions (that is useful when
* you have many methods that needs transactions but are unaware of * you have many methods that needs transactions but are unaware of
* each other). * each other).
* ex: *
* Example:
*
* <code>
* $from = 1; * $from = 1;
* $to = 2; * $to = 2;
* $amount = 300; * $amount = 300;
@ -246,47 +241,20 @@ class Facade
* { * {
* $accountFrom = R::load('account', $from); * $accountFrom = R::load('account', $from);
* $accountTo = R::load('account', $to); * $accountTo = R::load('account', $to);
*
* $accountFrom->money -= $amount; * $accountFrom->money -= $amount;
* $accountTo->money += $amount; * $accountTo->money += $amount;
*
* R::store($accountFrom); * R::store($accountFrom);
* R::store($accountTo); * R::store($accountTo);
* }); * });
* </code>
* *
* @param callable $callback Closure (or other callable) with the transaction logic * @param callable $callback Closure (or other callable) with the transaction logic
* *
* @throws Security
*
* @return mixed * @return mixed
*
*/ */
public static function transaction( $callback ) public static function transaction( $callback )
{ {
if ( !is_callable( $callback ) ) { return Transaction::transaction( self::$adapter, $callback );
throw new RedException( 'R::transaction needs a valid callback.' );
}
static $depth = 0;
$result = null;
try {
if ( $depth == 0 ) {
self::begin();
}
$depth++;
$result = call_user_func( $callback ); //maintain 5.2 compatibility
$depth--;
if ( $depth == 0 ) {
self::commit();
}
} catch (\Exception $exception ) {
$depth--;
if ( $depth == 0 ) {
self::rollback();
}
throw $exception;
}
return $result;
} }
/** /**
@ -295,8 +263,10 @@ class Facade
* *
* Usage: * Usage:
* *
* <code>
* R::addDatabase( 'database-1', 'sqlite:/tmp/db1.txt' ); * R::addDatabase( 'database-1', 'sqlite:/tmp/db1.txt' );
* R::selectDatabase( 'database-1' ); //to select database again * R::selectDatabase( 'database-1' ); //to select database again
* </code>
* *
* This method allows you to dynamically add (and select) new databases * This method allows you to dynamically add (and select) new databases
* to the facade. Adding a database with the same key will cause an exception. * to the facade. Adding a database with the same key will cause an exception.
@ -334,7 +304,10 @@ class Facade
); );
$wkey = trim( strtolower( $dbType ) ); $wkey = trim( strtolower( $dbType ) );
if ( !isset( $writers[$wkey] ) ) trigger_error( 'Unsupported DSN: '.$wkey ); if ( !isset( $writers[$wkey] ) ) {
$wkey = preg_replace( '/\W/', '' , $wkey );
throw new RedException( 'Unsupported database ('.$wkey.').' );
}
$writerClass = '\\RedBeanPHP\\QueryWriter\\'.$writers[$wkey]; $writerClass = '\\RedBeanPHP\\QueryWriter\\'.$writers[$wkey];
$writer = new $writerClass( $adapter ); $writer = new $writerClass( $adapter );
$redbean = new OODB( $writer, $frozen ); $redbean = new OODB( $writer, $frozen );
@ -362,6 +335,10 @@ class Facade
return FALSE; return FALSE;
} }
if ( !isset( self::$toolboxes[$key] ) ) {
throw new RedException( 'Database not found in registry. Add database using R::addDatabase().' );
}
self::configureFacadeWithToolbox( self::$toolboxes[$key] ); self::configureFacadeWithToolbox( self::$toolboxes[$key] );
self::$currentDB = $key; self::$currentDB = $key;
@ -379,9 +356,8 @@ class Facade
* @param boolean $tf debug mode (true or false) * @param boolean $tf debug mode (true or false)
* @param integer $mode (0 = to STDOUT, 1 = to ARRAY) * @param integer $mode (0 = to STDOUT, 1 = to ARRAY)
* *
* @throws Security
*
* @return RDefault * @return RDefault
* @throws RedException
*/ */
public static function debug( $tf = TRUE, $mode = 0 ) public static function debug( $tf = TRUE, $mode = 0 )
{ {
@ -450,8 +426,6 @@ class Facade
* @param OODBBean|SimpleModel $bean bean to store * @param OODBBean|SimpleModel $bean bean to store
* *
* @return integer|string * @return integer|string
*
* @throws Security
*/ */
public static function store( $bean ) public static function store( $bean )
{ {
@ -480,28 +454,16 @@ class Facade
* for loading a one-to-one relation. * for loading a one-to-one relation.
* *
* Usage: * Usage:
* list($author, $bio) = R::load('author, bio', $id); * list( $author, $bio ) = R::loadMulti( 'author, bio', $id );
* *
* @param string|array $types * @param string|array $types the set of types to load at once
* @param mixed $id * @param mixed $id the common ID
* *
* @return OODBBean * @return OODBBean
*/ */
public static function loadMulti( $types, $id ) public static function loadMulti( $types, $id )
{ {
if ( is_string( $types ) ) { return MultiLoader::load( self::$redbean, $types, $id );
$types = explode( ',', $types );
}
if ( !is_array( $types ) ) {
return array();
}
foreach ( $types as $k => $typeItem ) {
$types[$k] = self::$redbean->load( $typeItem, $id );
}
return $types;
} }
/** /**
@ -524,8 +486,6 @@ class Facade
* @param string $type type of bean you want to load * @param string $type type of bean you want to load
* @param integer $id ID of the bean you want to load * @param integer $id ID of the bean you want to load
* *
* @throws SQL
*
* @return OODBBean * @return OODBBean
*/ */
public static function load( $type, $id ) public static function load( $type, $id )
@ -543,7 +503,7 @@ class Facade
* and THEN trash it. * and THEN trash it.
* *
* @param string|OODBBean|SimpleModel $bean bean you want to remove from database * @param string|OODBBean|SimpleModel $bean bean you want to remove from database
* @param integer $id (optional) * @param integer $id ID if the bean to trash (optional, type-id variant only)
* *
* @return void * @return void
*/ */
@ -562,38 +522,10 @@ class Facade
* @param boolean $alwaysReturnArray if TRUE always returns the result as an array * @param boolean $alwaysReturnArray if TRUE always returns the result as an array
* *
* @return array|OODBBean * @return array|OODBBean
*
* @throws Security
*/ */
public static function dispense( $typeOrBeanArray, $num = 1, $alwaysReturnArray = FALSE ) public static function dispense( $typeOrBeanArray, $num = 1, $alwaysReturnArray = FALSE )
{ {
if ( is_array($typeOrBeanArray) ) { return DispenseHelper::dispense( self::$redbean, $typeOrBeanArray, $num, $alwaysReturnArray );
if ( !isset( $typeOrBeanArray['_type'] ) ) {
$list = array();
foreach( $typeOrBeanArray as $beanArray ) if ( !( is_array( $beanArray ) && isset( $beanArray['_type'] ) ) ) throw new RedException( 'Invalid Array Bean' );
foreach( $typeOrBeanArray as $beanArray ) $list[] = self::dispense( $beanArray );
return $list;
}
$import = $typeOrBeanArray;
$type = $import['_type'];
unset( $import['_type'] );
} else {
$type = $typeOrBeanArray;
}
if ( !preg_match( '/^[a-z0-9]+$/', $type ) ) {
throw new RedException( 'Invalid type: ' . $type );
}
$beanOrBeans = self::$redbean->dispense( $type, $num, $alwaysReturnArray );
if ( isset( $import ) ) {
$beanOrBeans->import( $import );
}
return $beanOrBeans;
} }
/** /**
@ -603,14 +535,18 @@ class Facade
* *
* Usage: * Usage:
* *
* <code>
* list( $book, $page, $text ) = R::dispenseAll( 'book,page,text' ); * list( $book, $page, $text ) = R::dispenseAll( 'book,page,text' );
* </code>
* *
* This will dispense a book, a page and a text. This way you can * This will dispense a book, a page and a text. This way you can
* quickly dispense beans of various types in just one line of code. * quickly dispense beans of various types in just one line of code.
* *
* Usage: * Usage:
* *
* <code>
* list($book, $pages) = R::dispenseAll('book,page*100'); * list($book, $pages) = R::dispenseAll('book,page*100');
* </code>
* *
* This returns an array with a book bean and then another array * This returns an array with a book bean and then another array
* containing 100 page beans. * containing 100 page beans.
@ -622,21 +558,7 @@ class Facade
*/ */
public static function dispenseAll( $order, $onlyArrays = FALSE ) public static function dispenseAll( $order, $onlyArrays = FALSE )
{ {
return DispenseHelper::dispenseAll( self::$redbean, $order, $onlyArrays );
$list = array();
foreach( explode( ',', $order ) as $order ) {
if ( strpos( $order, '*' ) !== false ) {
list( $type, $amount ) = explode( '*', $order );
} else {
$type = $order;
$amount = 1;
}
$list[] = self::dispense( $type, $amount, $onlyArrays );
}
return $list;
} }
/** /**
@ -661,9 +583,9 @@ class Facade
* array parameter; you can either use the question mark notation * array parameter; you can either use the question mark notation
* or the slot-notation (:keyname). * or the slot-notation (:keyname).
* *
* @param string $type type the type of bean you are looking for * @param string $type the type of bean you are looking for
* @param string $sql sql SQL query to find the desired bean, starting right after WHERE clause * @param string $sql SQL query to find the desired bean, starting right after WHERE clause
* @param array $bindings values array of values to be bound to parameters in query * @param array $bindings array of values to be bound to parameters in query
* *
* @return array * @return array
*/ */
@ -681,9 +603,9 @@ class Facade
* *
* Your SQL does not have to start with a valid WHERE-clause condition. * Your SQL does not have to start with a valid WHERE-clause condition.
* *
* @param string $type type the type of bean you are looking for * @param string $type the type of bean you are looking for
* @param string $sql sql SQL query to find the desired bean, starting right after WHERE clause * @param string $sql SQL query to find the desired bean, starting right after WHERE clause
* @param array $bindings values array of values to be bound to parameters in query * @param array $bindings array of values to be bound to parameters in query
* *
* @return array * @return array
*/ */
@ -696,9 +618,9 @@ class Facade
* @see Facade::find * @see Facade::find
* The variation also exports the beans (i.e. it returns arrays). * The variation also exports the beans (i.e. it returns arrays).
* *
* @param string $type type the type of bean you are looking for * @param string $type the type of bean you are looking for
* @param string $sql sql SQL query to find the desired bean, starting right after WHERE clause * @param string $sql SQL query to find the desired bean, starting right after WHERE clause
* @param array $bindings values array of values to be bound to parameters in query * @param array $bindings array of values to be bound to parameters in query
* *
* @return array * @return array
*/ */
@ -711,9 +633,9 @@ class Facade
* @see Facade::find * @see Facade::find
* This variation returns the first bean only. * This variation returns the first bean only.
* *
* @param string $type type the type of bean you are looking for * @param string $type the type of bean you are looking for
* @param string $sql sql SQL query to find the desired bean, starting right after WHERE clause * @param string $sql SQL query to find the desired bean, starting right after WHERE clause
* @param array $bindings values array of values to be bound to parameters in query * @param array $bindings array of values to be bound to parameters in query
* *
* @return OODBBean * @return OODBBean
*/ */
@ -726,9 +648,9 @@ class Facade
* @see Facade::find * @see Facade::find
* This variation returns the last bean only. * This variation returns the last bean only.
* *
* @param string $type type the type of bean you are looking for * @param string $type the type of bean you are looking for
* @param string $sql sql SQL query to find the desired bean, starting right after WHERE clause * @param string $sql SQL query to find the desired bean, starting right after WHERE clause
* @param array $bindings values array of values to be bound to parameters in query * @param array $bindings array of values to be bound to parameters in query
* *
* @return OODBBean * @return OODBBean
*/ */
@ -741,9 +663,9 @@ class Facade
* Finds a bean collection. * Finds a bean collection.
* Use this for large datasets. * Use this for large datasets.
* *
* @param string $type type the type of bean you are looking for * @param string $type the type of bean you are looking for
* @param string $sql sql SQL query to find the desired bean, starting right after WHERE clause * @param string $sql SQL query to find the desired bean, starting right after WHERE clause
* @param array $bindings values array of values to be bound to parameters in query * @param array $bindings array of values to be bound to parameters in query
* *
* @return BeanCollection * @return BeanCollection
*/ */
@ -762,7 +684,7 @@ class Facade
* @param array|string $types a list of bean types to find * @param array|string $types a list of bean types to find
* @param string|array $sqlOrArr SQL query string or result set array * @param string|array $sqlOrArr SQL query string or result set array
* @param array $bindings SQL bindings * @param array $bindings SQL bindings
* @param array $remappings An array of remapping arrays containing closures * @param array $remappings an array of remapping arrays containing closures
* *
* @return array * @return array
*/ */
@ -812,8 +734,8 @@ class Facade
* Convenience function to execute Queries directly. * Convenience function to execute Queries directly.
* Executes SQL. * Executes SQL.
* *
* @param string $sql sql SQL query to execute * @param string $sql SQL query to execute
* @param array $bindings values a list of values to be bound to query parameters * @param array $bindings a list of values to be bound to query parameters
* *
* @return integer * @return integer
*/ */
@ -826,8 +748,8 @@ class Facade
* Convenience function to execute Queries directly. * Convenience function to execute Queries directly.
* Executes SQL. * Executes SQL.
* *
* @param string $sql sql SQL query to execute * @param string $sql SQL query to execute
* @param array $bindings values a list of values to be bound to query parameters * @param array $bindings a list of values to be bound to query parameters
* *
* @return array * @return array
*/ */
@ -840,8 +762,8 @@ class Facade
* Convenience function to execute Queries directly. * Convenience function to execute Queries directly.
* Executes SQL. * Executes SQL.
* *
* @param string $sql sql SQL query to execute * @param string $sql SQL query to execute
* @param array $bindings values a list of values to be bound to query parameters * @param array $bindings a list of values to be bound to query parameters
* *
* @return string * @return string
*/ */
@ -854,8 +776,8 @@ class Facade
* Convenience function to execute Queries directly. * Convenience function to execute Queries directly.
* Executes SQL. * Executes SQL.
* *
* @param string $sql sql SQL query to execute * @param string $sql SQL query to execute
* @param array $bindings values a list of values to be bound to query parameters * @param array $bindings a list of values to be bound to query parameters
* *
* @return array * @return array
*/ */
@ -868,8 +790,8 @@ class Facade
* Convenience function to execute Queries directly. * Convenience function to execute Queries directly.
* Executes SQL. * Executes SQL.
* *
* @param string $sql sql SQL query to execute * @param string $sql SQL query to execute
* @param array $bindings values a list of values to be bound to query parameters * @param array $bindings a list of values to be bound to query parameters
* *
* @return array * @return array
*/ */
@ -887,8 +809,8 @@ class Facade
* selected in the query, both key and value of the array will have the * selected in the query, both key and value of the array will have the
* value of this field for each row. * value of this field for each row.
* *
* @param string $sql sql SQL query to execute * @param string $sql SQL query to execute
* @param array $bindings values a list of values to be bound to query parameters * @param array $bindings a list of values to be bound to query parameters
* *
* @return array * @return array
*/ */
@ -903,8 +825,8 @@ class Facade
* Results will be returned as an associative array indexed by the first * Results will be returned as an associative array indexed by the first
* column in the select. * column in the select.
* *
* @param string $sql sql SQL query to execute * @param string $sql SQL query to execute
* @param array $bindings values a list of values to be bound to query parameters * @param array $bindings a list of values to be bound to query parameters
* *
* @return array * @return array
*/ */
@ -960,9 +882,9 @@ class Facade
* Makes a deep copy of a bean. This method makes a deep copy * Makes a deep copy of a bean. This method makes a deep copy
* of the bean.The copy will have the following: * of the bean.The copy will have the following:
* *
* - All beans in own-lists will be duplicated as well * * All beans in own-lists will be duplicated as well
* - All references to shared beans will be copied but not the shared beans themselves * * All references to shared beans will be copied but not the shared beans themselves
* - All references to parent objects (_id fields) will be copied but not the parents themselves * * All references to parent objects (_id fields) will be copied but not the parents themselves
* *
* In most cases this is the desired scenario for copying beans. * In most cases this is the desired scenario for copying beans.
* This function uses a trail-array to prevent infinite recursion, if a recursive bean is found * This function uses a trail-array to prevent infinite recursion, if a recursive bean is found
@ -989,9 +911,10 @@ class Facade
* Exports a collection of beans. Handy for XML/JSON exports with a * Exports a collection of beans. Handy for XML/JSON exports with a
* Javascript framework like Dojo or ExtJS. * Javascript framework like Dojo or ExtJS.
* What will be exported: * What will be exported:
* - contents of the bean *
* - all own bean lists (recursively) * * contents of the bean
* - all shared beans (not THEIR own lists) * * all own bean lists (recursively)
* * all shared beans (not THEIR own lists)
* *
* @param array|OODBBean $beans beans to be exported * @param array|OODBBean $beans beans to be exported
* @param boolean $parents whether you want parent beans to be exported * @param boolean $parents whether you want parent beans to be exported
@ -1009,9 +932,9 @@ class Facade
* This will determine the case style for the keys of exported beans (see exportAll). * This will determine the case style for the keys of exported beans (see exportAll).
* The following options are accepted: * The following options are accepted:
* *
* 'default' RedBeanPHP by default enforces Snake Case (i.e. book_id is_valid ) * * 'default' RedBeanPHP by default enforces Snake Case (i.e. book_id is_valid )
* 'camel' Camel Case (i.e. bookId isValid ) * * 'camel' Camel Case (i.e. bookId isValid )
* 'dolphin' Dolphin Case (i.e. bookID isValid ) Like CamelCase but ID is written all uppercase * * 'dolphin' Dolphin Case (i.e. bookID isValid ) Like CamelCase but ID is written all uppercase
* *
* @warning RedBeanPHP transforms camelCase to snake_case using a slightly different * @warning RedBeanPHP transforms camelCase to snake_case using a slightly different
* algorithm, it also converts isACL to is_acl (not is_a_c_l) and bookID to book_id. * algorithm, it also converts isACL to is_acl (not is_a_c_l) and bookID to book_id.
@ -1090,8 +1013,8 @@ class Facade
* be associated with the bean. * be associated with the bean.
* You may also pass an array instead of a string. * You may also pass an array instead of a string.
* *
* @param OODBBean $bean bean * @param OODBBean $bean bean to tag
* @param mixed $tagList tags * @param mixed $tagList tags to attach to the specified bean
* *
* @return string * @return string
*/ */
@ -1107,7 +1030,7 @@ class Facade
* be associated with the bean. * be associated with the bean.
* You may also pass an array instead of a string. * You may also pass an array instead of a string.
* *
* @param OODBBean $bean bean * @param OODBBean $bean bean to tag
* @param array $tagList list of tags to add to bean * @param array $tagList list of tags to add to bean
* *
* @return void * @return void
@ -1123,8 +1046,8 @@ class Facade
* *
* @param string $beanType type of bean you are looking for * @param string $beanType type of bean you are looking for
* @param array $tagList list of tags to match * @param array $tagList list of tags to match
* @param string $sql additional SQL * @param string $sql additional SQL query snippet
* @param array $bindings bindings * @param array $bindings a list of values to bind to the query parameters
* *
* @return array * @return array
*/ */
@ -1139,8 +1062,8 @@ class Facade
* *
* @param string $beanType type of bean you are looking for * @param string $beanType type of bean you are looking for
* @param array $tagList list of tags to match * @param array $tagList list of tags to match
* @param string $sql additional SQL * @param string $sql additional SQL query snippet
* @param array $bindings bindings * @param array $bindings a list of values to bind to the query parameters
* *
* @return array * @return array
*/ */
@ -1171,8 +1094,6 @@ class Facade
* @param array $bindings parameters to bind to SQL * @param array $bindings parameters to bind to SQL
* *
* @return integer * @return integer
*
* @throws SQL
*/ */
public static function count( $type, $addSQL = '', $bindings = array() ) public static function count( $type, $addSQL = '', $bindings = array() )
{ {
@ -1184,36 +1105,26 @@ class Facade
* Adapter and you want it on-the-fly? Use this method to hot-swap your facade with a new * Adapter and you want it on-the-fly? Use this method to hot-swap your facade with a new
* toolbox. * toolbox.
* *
* @param ToolBox $tb toolbox * @param ToolBox $tb toolbox to configure facade with
* *
* @return ToolBox * @return ToolBox
*/ */
public static function configureFacadeWithToolbox( ToolBox $tb ) public static function configureFacadeWithToolbox( ToolBox $tb )
{ {
$oldTools = self::$toolbox; $oldTools = self::$toolbox;
self::$toolbox = $tb; self::$toolbox = $tb;
self::$writer = self::$toolbox->getWriter(); self::$writer = self::$toolbox->getWriter();
self::$adapter = self::$toolbox->getDatabaseAdapter(); self::$adapter = self::$toolbox->getDatabaseAdapter();
self::$redbean = self::$toolbox->getRedBean(); self::$redbean = self::$toolbox->getRedBean();
self::$finder = new Finder( self::$toolbox ); self::$finder = new Finder( self::$toolbox );
self::$associationManager = new AssociationManager( self::$toolbox ); self::$associationManager = new AssociationManager( self::$toolbox );
self::$redbean->setAssociationManager( self::$associationManager ); self::$redbean->setAssociationManager( self::$associationManager );
self::$labelMaker = new LabelMaker( self::$toolbox ); self::$labelMaker = new LabelMaker( self::$toolbox );
$helper = new SimpleModelHelper(); $helper = new SimpleModelHelper();
$helper->attachEventListeners( self::$redbean ); $helper->attachEventListeners( self::$redbean );
self::$redbean->setBeanHelper( new SimpleFacadeBeanHelper ); self::$redbean->setBeanHelper( new SimpleFacadeBeanHelper );
self::$duplicationManager = new DuplicationManager( self::$toolbox ); self::$duplicationManager = new DuplicationManager( self::$toolbox );
self::$tagManager = new TagManager( self::$toolbox ); self::$tagManager = new TagManager( self::$toolbox );
return $oldTools; return $oldTools;
} }
@ -1226,9 +1137,7 @@ class Facade
public static function begin() public static function begin()
{ {
if ( !self::$redbean->isFrozen() ) return FALSE; if ( !self::$redbean->isFrozen() ) return FALSE;
self::$adapter->startTransaction(); self::$adapter->startTransaction();
return TRUE; return TRUE;
} }
@ -1241,9 +1150,7 @@ class Facade
public static function commit() public static function commit()
{ {
if ( !self::$redbean->isFrozen() ) return FALSE; if ( !self::$redbean->isFrozen() ) return FALSE;
self::$adapter->commit(); self::$adapter->commit();
return TRUE; return TRUE;
} }
@ -1256,9 +1163,7 @@ class Facade
public static function rollback() public static function rollback()
{ {
if ( !self::$redbean->isFrozen() ) return FALSE; if ( !self::$redbean->isFrozen() ) return FALSE;
self::$adapter->rollback(); self::$adapter->rollback();
return TRUE; return TRUE;
} }
@ -1286,8 +1191,7 @@ class Facade
*/ */
public static function genSlots( $array, $template = NULL ) public static function genSlots( $array, $template = NULL )
{ {
$str = count( $array ) ? implode( ',', array_fill( 0, count( $array ), '?' ) ) : ''; return ArrayTool::genSlots( $array, $template );
return ( is_null( $template ) || $str === '' ) ? $str : sprintf( $template, $str );
} }
/** /**
@ -1299,11 +1203,7 @@ class Facade
*/ */
public static function flat( $array, $result = array() ) public static function flat( $array, $result = array() )
{ {
foreach( $array as $value ) { return ArrayTool::flat( $array, $result );
if ( is_array( $value ) ) $result = self::flat( $value, $result );
else $result[] = $value;
}
return $result;
} }
/** /**
@ -1338,7 +1238,6 @@ class Facade
foreach ( $beans as $bean ) { foreach ( $beans as $bean ) {
$ids[] = self::store( $bean ); $ids[] = self::store( $bean );
} }
return $ids; return $ids;
} }
@ -1378,7 +1277,6 @@ class Facade
self::getWriter()->setUseCache( $yesNo ); self::getWriter()->setUseCache( $yesNo );
} }
/** /**
* A label is a bean with only an id, type and name property. * A label is a bean with only an id, type and name property.
* This function will dispense beans for all entries in the array. The * This function will dispense beans for all entries in the array. The
@ -1402,7 +1300,9 @@ class Facade
* *
* To obtain (and add if necessary) an ENUM value: * To obtain (and add if necessary) an ENUM value:
* *
* <code>
* $tea->flavour = R::enum( 'flavour:apple' ); * $tea->flavour = R::enum( 'flavour:apple' );
* </code>
* *
* Returns a bean of type 'flavour' with name = apple. * Returns a bean of type 'flavour' with name = apple.
* This will add a bean with property name (set to APPLE) to the database * This will add a bean with property name (set to APPLE) to the database
@ -1410,11 +1310,15 @@ class Facade
* *
* To obtain all flavours: * To obtain all flavours:
* *
* <code>
* R::enum('flavour'); * R::enum('flavour');
* </code>
* *
* To get a list of all flavour names: * To get a list of all flavour names:
* *
* <code>
* R::gatherLabels( R::enum( 'flavour' ) ); * R::gatherLabels( R::enum( 'flavour' ) );
* </code>
* *
* @param string $enum either type or type-value * @param string $enum either type or type-value
* *
@ -1481,7 +1385,6 @@ class Facade
public static function isoDateTime( $time = NULL ) public static function isoDateTime( $time = NULL )
{ {
if ( !$time ) $time = time(); if ( !$time ) $time = time();
return @date( 'Y-m-d H:i:s', $time ); return @date( 'Y-m-d H:i:s', $time );
} }
@ -1489,7 +1392,7 @@ class Facade
* Optional accessor for neat code. * Optional accessor for neat code.
* Sets the database adapter you want to use. * Sets the database adapter you want to use.
* *
* @param Adapter $adapter * @param Adapter $adapter Database Adapter for facade to use
* *
* @return void * @return void
*/ */
@ -1502,7 +1405,7 @@ class Facade
* Optional accessor for neat code. * Optional accessor for neat code.
* Sets the database adapter you want to use. * Sets the database adapter you want to use.
* *
* @param QueryWriter $writer * @param QueryWriter $writer Query Writer instance for facade to use
* *
* @return void * @return void
*/ */
@ -1515,7 +1418,7 @@ class Facade
* Optional accessor for neat code. * Optional accessor for neat code.
* Sets the database adapter you want to use. * Sets the database adapter you want to use.
* *
* @param OODB $redbean * @param OODB $redbean Object Database for facade to use
*/ */
public static function setRedBean( OODB $redbean ) public static function setRedBean( OODB $redbean )
{ {
@ -1586,21 +1489,16 @@ class Facade
* *
* Returns the components in the following order: * Returns the components in the following order:
* *
* 0 - OODB instance (getRedBean()) * # OODB instance (getRedBean())
* 1 - Database Adapter * # Database Adapter
* 2 - Query Writer * # Query Writer
* 3 - Toolbox itself * # Toolbox itself
* *
* @return array * @return array
*/ */
public static function getExtractedToolbox() public static function getExtractedToolbox()
{ {
return array( return array( self::$redbean, self::$adapter, self::$writer, self::$toolbox );
self::$redbean,
self::$adapter,
self::$writer,
self::$toolbox
);
} }
/** /**
@ -1630,9 +1528,7 @@ class Facade
public static function beansToArray( $beans ) public static function beansToArray( $beans )
{ {
$list = array(); $list = array();
foreach( $beans as $bean ) { foreach( $beans as $bean ) $list[] = $bean->export();
$list[] = $bean->export();
}
return $list; return $list;
} }
@ -1641,24 +1537,26 @@ class Facade
* What to do if a FUSE model method does not exist? * What to do if a FUSE model method does not exist?
* You can set the following options: * You can set the following options:
* *
* OODBBean::C_ERR_IGNORE (default), ignores the call, returns NULL * * OODBBean::C_ERR_IGNORE (default), ignores the call, returns NULL
* OODBBean::C_ERR_LOG, logs the incident using error_log * * OODBBean::C_ERR_LOG, logs the incident using error_log
* OODBBean::C_ERR_NOTICE, triggers a E_USER_NOTICE * * OODBBean::C_ERR_NOTICE, triggers a E_USER_NOTICE
* OODBBean::C_ERR_WARN, triggers a E_USER_WARNING * * OODBBean::C_ERR_WARN, triggers a E_USER_WARNING
* OODBBean::C_ERR_EXCEPTION, throws an exception * * OODBBean::C_ERR_EXCEPTION, throws an exception
* OODBBean::C_ERR_FUNC, allows you to specify a custom handler (function) * * OODBBean::C_ERR_FUNC, allows you to specify a custom handler (function)
* OODBBean::C_ERR_FATAL, triggers a E_USER_ERROR * * OODBBean::C_ERR_FATAL, triggers a E_USER_ERROR
* *
* <code>
* Custom handler method signature: handler( array ( * Custom handler method signature: handler( array (
* 'message' => string * 'message' => string
* 'bean' => OODBBean * 'bean' => OODBBean
* 'method' => string * 'method' => string
* ) ) * ) )
* </code>
* *
* This method returns the old mode and handler as an array. * This method returns the old mode and handler as an array.
* *
* @param integer $mode mode * @param integer $mode mode, determines how to handle errors
* @param callable|NULL $func custom handler * @param callable|NULL $func custom handler (if applicable)
* *
* @return array * @return array
*/ */
@ -1676,29 +1574,10 @@ class Facade
* @param OODBBean|array $data either a bean or an array of beans * @param OODBBean|array $data either a bean or an array of beans
* *
* @return array * @return array
*
*/ */
public static function dump( $data ) public static function dump( $data )
{ {
$array = array(); return Dump::dump( $data );
if ( $data instanceof OODBBean ) {
$str = strval( $data );
if (strlen($str) > 35) {
$beanStr = substr( $str, 0, 35 ).'... ';
} else {
$beanStr = $str;
}
return $beanStr;
}
if ( is_array( $data ) ) {
foreach( $data as $key => $item ) {
$array[$key] = self::dump( $item );
}
}
return $array;
} }
/** /**
@ -1710,16 +1589,19 @@ class Facade
* *
* Example: * Example:
* *
* <code>
* R::bindFunc( 'read', 'location.point', 'asText' ); * R::bindFunc( 'read', 'location.point', 'asText' );
* R::bindFunc( 'write', 'location.point', 'GeomFromText' ); * R::bindFunc( 'write', 'location.point', 'GeomFromText' );
* </code>
* *
* Passing NULL as the function will reset (clear) the function * Passing NULL as the function will reset (clear) the function
* for this column/mode. * for this column/mode.
* *
* @param string $mode (read or write) * @param string $mode mode for function: i.e. read or write
* @param string $field * @param string $field field (table.column) to bind function to
* @param string $function * @param string $function SQL function to bind to specified column
* *
* @return void
*/ */
public static function bindFunc( $mode, $field, $function ) public static function bindFunc( $mode, $field, $function )
{ {
@ -1729,7 +1611,7 @@ class Facade
/** /**
* Sets global aliases. * Sets global aliases.
* *
* @param array $list * @param array $list list of global aliases
* *
* @return void * @return void
*/ */
@ -1865,14 +1747,20 @@ class Facade
* *
* Usage: * Usage:
* *
* <code>
* R::ext( 'makeTea', function() { ... } ); * R::ext( 'makeTea', function() { ... } );
* </code>
* *
* Now you can use your makeTea plugin like this: * Now you can use your makeTea plugin like this:
* *
* <code>
* R::makeTea(); * R::makeTea();
* </code>
* *
* @param string $pluginName name of the method to call the plugin * @param string $pluginName name of the method to call the plugin
* @param callable $callable a PHP callable * @param callable $callable a PHP callable
*
* @return void
*/ */
public static function ext( $pluginName, $callable ) public static function ext( $pluginName, $callable )
{ {

View File

@ -2,10 +2,6 @@
namespace RedBeanPHP; namespace RedBeanPHP;
use RedBeanPHP\ToolBox as ToolBox;
use RedBeanPHP\OODB as OODB;
use RedBeanPHP\RedException\Security as Security;
use RedBeanPHP\OODBBean as OODBBean;
/** /**
* RedBeanPHP Finder. * RedBeanPHP Finder.
@ -59,8 +55,6 @@ class Finder
* @param array $bindings values array of values to be bound to parameters in query * @param array $bindings values array of values to be bound to parameters in query
* *
* @return array * @return array
*
* @throws Security
*/ */
public function find( $type, $sql = NULL, $bindings = array() ) public function find( $type, $sql = NULL, $bindings = array() )
{ {
@ -75,8 +69,12 @@ class Finder
/** /**
* Like find() but also exports the beans as an array. * Like find() but also exports the beans as an array.
* This method will perform a find-operation. For every bean
* in the result collection this method will call the export() method.
* This method returns an array containing the array representations
* of every bean in the result set.
* *
* @see Finder::findAndExport * @see Finder::find
* *
* @param string $type type the type of bean you are looking for * @param string $type type the type of bean you are looking for
* @param string $sql sql SQL query to find the desired bean, starting right after WHERE clause * @param string $sql sql SQL query to find the desired bean, starting right after WHERE clause
@ -97,6 +95,7 @@ class Finder
/** /**
* Like find() but returns just one bean instead of an array of beans. * Like find() but returns just one bean instead of an array of beans.
* This method will return only the first bean of the array. * This method will return only the first bean of the array.
* If no beans are found, this method will return NULL.
* *
* @see Finder::find * @see Finder::find
* *
@ -122,6 +121,7 @@ class Finder
/** /**
* Like find() but returns the last bean of the result array. * Like find() but returns the last bean of the result array.
* Opposite of Finder::findLast(). * Opposite of Finder::findLast().
* If no beans are found, this method will return NULL.
* *
* @see Finder::find * @see Finder::find
* *
@ -252,9 +252,11 @@ class Finder
* *
* Example: * Example:
* *
* <code>
* $stuff = $finder->findMulti('movie,review', ' * $stuff = $finder->findMulti('movie,review', '
* SELECT movie.*, review.* FROM movie * SELECT movie.*, review.* FROM movie
* LEFT JOIN review ON review.movie_id = movie.id'); * LEFT JOIN review ON review.movie_id = movie.id');
* </code>
* *
* After this operation, $stuff will contain an entry 'movie' containing all * After this operation, $stuff will contain an entry 'movie' containing all
* movies and an entry named 'review' containing all reviews (all beans). * movies and an entry named 'review' containing all reviews (all beans).
@ -267,18 +269,21 @@ class Finder
* The remapping argument (optional) should contain an array of arrays. * The remapping argument (optional) should contain an array of arrays.
* Each array in the remapping array should contain the following entries: * Each array in the remapping array should contain the following entries:
* *
* <code>
* array( * array(
* 'a' => TYPE A * 'a' => TYPE A
* 'b' => TYPE B * 'b' => TYPE B
* 'matcher' => MATCHING FUNCTION ACCEPTING A, B and ALL BEANS * 'matcher' => MATCHING FUNCTION ACCEPTING A, B and ALL BEANS
* 'do' => OPERATION FUNCTION ACCEPTING A, B, ALL BEANS, ALL REMAPPINGS * 'do' => OPERATION FUNCTION ACCEPTING A, B, ALL BEANS, ALL REMAPPINGS
* ) * )
* </code>
* *
* Using this mechanism you can build your own 'preloader' with tiny function * Using this mechanism you can build your own 'preloader' with tiny function
* snippets (and those can be re-used and shared online of course). * snippets (and those can be re-used and shared online of course).
* *
* Example: * Example:
* *
* <code>
* array( * array(
* 'a' => 'movie' //define A as movie * 'a' => 'movie' //define A as movie
* 'b' => 'review' //define B as review * 'b' => 'review' //define B as review
@ -290,6 +295,7 @@ class Finder
* $a->clearHistory(); //optional, act 'as if these beans have been loaded through ownReviewList'. * $a->clearHistory(); //optional, act 'as if these beans have been loaded through ownReviewList'.
* } * }
* ) * )
* </code>
* *
* The Query Template parameter is optional as well but can be used to * The Query Template parameter is optional as well but can be used to
* set a different SQL template (sprintf-style) for processing the original query. * set a different SQL template (sprintf-style) for processing the original query.

View File

@ -19,7 +19,9 @@
* *
* Usage: * Usage:
* *
* <code>
* R::find( 'paint', ' color_id = ? ', [ EID('color:yellow') ] ); * R::find( 'paint', ' color_id = ? ', [ EID('color:yellow') ] );
* </code>
* *
* If a function called EID() already exists you'll have to write this * If a function called EID() already exists you'll have to write this
* wrapper yourself ;) * wrapper yourself ;)

View File

@ -45,7 +45,9 @@ class LabelMaker
* values of the array will be assigned to the name property of each * values of the array will be assigned to the name property of each
* individual bean. * individual bean.
* *
* <code>
* $people = R::dispenseLabels( 'person', [ 'Santa', 'Claus' ] ); * $people = R::dispenseLabels( 'person', [ 'Santa', 'Claus' ] );
* </code>
* *
* @param string $type type of beans you would like to have * @param string $type type of beans you would like to have
* @param array $labels list of labels, names for each bean * @param array $labels list of labels, names for each bean
@ -72,9 +74,11 @@ class LabelMaker
* *
* Usage: * Usage:
* *
* <code>
* $o1->name = 'hamburger'; * $o1->name = 'hamburger';
* $o2->name = 'pizza'; * $o2->name = 'pizza';
* implode( ',', R::gatherLabels( [ $o1, $o2 ] ) ); //hamburger,pizza * implode( ',', R::gatherLabels( [ $o1, $o2 ] ) ); //hamburger,pizza
* </code>
* *
* Note that the return value is an array of strings, not beans. * Note that the return value is an array of strings, not beans.
* *
@ -99,22 +103,30 @@ class LabelMaker
* Fetches an ENUM from the database and creates it if necessary. * Fetches an ENUM from the database and creates it if necessary.
* An ENUM has the following format: * An ENUM has the following format:
* *
* <code>
* ENUM:VALUE * ENUM:VALUE
* </code>
* *
* If you pass 'ENUM' only, this method will return an array of its * If you pass 'ENUM' only, this method will return an array of its
* values: * values:
* *
* <code>
* implode( ',', R::gatherLabels( R::enum( 'flavour' ) ) ) //'BANANA,MOCCA' * implode( ',', R::gatherLabels( R::enum( 'flavour' ) ) ) //'BANANA,MOCCA'
* </code>
* *
* If you pass 'ENUM:VALUE' this method will return the specified enum bean * If you pass 'ENUM:VALUE' this method will return the specified enum bean
* and create it in the database if it does not exist yet: * and create it in the database if it does not exist yet:
* *
* <code>
* $bananaFlavour = R::enum( 'flavour:banana' ); * $bananaFlavour = R::enum( 'flavour:banana' );
* $bananaFlavour->name; * $bananaFlavour->name;
* </code>
* *
* So you can use this method to set an ENUM value in a bean: * So you can use this method to set an ENUM value in a bean:
* *
* <code>
* $shake->flavour = R::enum( 'flavour:banana' ); * $shake->flavour = R::enum( 'flavour:banana' );
* </code>
* *
* the property flavour now contains the enum bean, a parent bean. * the property flavour now contains the enum bean, a parent bean.
* In the database, flavour_id will point to the flavour record with name 'banana'. * In the database, flavour_id will point to the flavour record with name 'banana'.
@ -135,6 +147,21 @@ class LabelMaker
$value = preg_replace( '/\W+/', '_', strtoupper( trim( $value ) ) ); $value = preg_replace( '/\W+/', '_', strtoupper( trim( $value ) ) );
} }
/**
* We use simply find here, we could use inspect() in fluid mode etc,
* but this would be useless. At first sight it looks clean, you could even
* bake this into find(), however, find not only has to deal with the primary
* search type, people can also include references in the SQL part, so avoiding
* find failures does not matter, this is still the quickest way making use
* of existing functionality.
*
* @note There seems to be a bug in XDebug v2.3.2 causing suppressed
* exceptions like these to surface anyway, to prevent this use:
*
* "xdebug.default_enable = 0"
*
* Also see Github Issue #464
*/
$values = $oodb->find( $type ); $values = $oodb->find( $type );
if ( $value === FALSE ) { if ( $value === FALSE ) {

View File

@ -18,9 +18,8 @@ namespace RedBeanPHP;
*/ */
interface Logger interface Logger
{ {
/** /**
* A logger (for\PDO or OCI driver) needs to implement the log method. * A logger (for PDO or OCI driver) needs to implement the log method.
* The log method will receive logging data. Note that the number of parameters is 0, this means * The log method will receive logging data. Note that the number of parameters is 0, this means
* all parameters are optional and the number may vary. This way the logger can be used in a very * all parameters are optional and the number may vary. This way the logger can be used in a very
* flexible way. Sometimes the logger is used to log a simple error message and in other * flexible way. Sometimes the logger is used to log a simple error message and in other
@ -28,6 +27,7 @@ interface Logger
* The log method should be able to accept all kinds of parameters and data by using * The log method should be able to accept all kinds of parameters and data by using
* functions like func_num_args/func_get_args. * functions like func_num_args/func_get_args.
* *
* @param string $message, ...
* @return void * @return void
*/ */
public function log(); public function log();

View File

@ -4,7 +4,6 @@ namespace RedBeanPHP\Logger;
use RedBeanPHP\Logger as Logger; use RedBeanPHP\Logger as Logger;
use RedBeanPHP\RedException as RedException; use RedBeanPHP\RedException as RedException;
use RedBeanPHP\RedException\Security as Security;
/** /**
* Logger. Provides a basic logging function for RedBeanPHP. * Logger. Provides a basic logging function for RedBeanPHP.
@ -66,7 +65,7 @@ class RDefault implements Logger
} }
} }
if ( $this->mode === self::C_LOGGER_ECHO ) echo "<br>\n"; if ( $this->mode === self::C_LOGGER_ECHO ) echo "<br>" . PHP_EOL;
} }
} }
@ -97,8 +96,8 @@ class RDefault implements Logger
* Selects a logging mode. * Selects a logging mode.
* There are several options available. * There are several options available.
* *
* C_LOGGER_ARRAY - log silently, stores entries in internal log array only * * C_LOGGER_ARRAY - log silently, stores entries in internal log array only
* C_LOGGER_ECHO - also forward log messages directly to STDOUT * * C_LOGGER_ECHO - also forward log messages directly to STDOUT
* *
* @param integer $mode mode of operation for logging object * @param integer $mode mode of operation for logging object
* *

View File

@ -5,7 +5,6 @@ namespace RedBeanPHP\Logger\RDefault;
use RedBeanPHP\Logger as Logger; use RedBeanPHP\Logger as Logger;
use RedBeanPHP\Logger\RDefault as RDefault; use RedBeanPHP\Logger\RDefault as RDefault;
use RedBeanPHP\RedException as RedException; use RedBeanPHP\RedException as RedException;
use RedBeanPHP\RedException\Security as Security;
/** /**
* Debug logger. * Debug logger.
@ -57,7 +56,7 @@ class Debug extends RDefault implements Logger
* Fills in a value of a binding and truncates the * Fills in a value of a binding and truncates the
* resulting string if necessary. * resulting string if necessary.
* *
* @param mixed $value * @param mixed $value bound value
* *
* @return string * @return string
*/ */
@ -89,7 +88,7 @@ class Debug extends RDefault implements Logger
protected function output( $str ) protected function output( $str )
{ {
$this->logs[] = $str; $this->logs[] = $str;
if ( !$this->mode ) echo $str .'<br />'; if ( !$this->mode ) echo $str ,'<br />';
} }
/** /**

View File

@ -2,16 +2,9 @@
namespace RedBeanPHP; namespace RedBeanPHP;
use RedBeanPHP\OODBBean as OODBBean;
use RedBeanPHP\Observable as Observable;
use RedBeanPHP\Adapter\DBAdapter as DBAdapter; use RedBeanPHP\Adapter\DBAdapter as DBAdapter;
use RedBeanPHP\BeanHelper\FacadeBeanHelper as FacadeBeanHelper;
use RedBeanPHP\AssociationManager as AssociationManager;
use RedBeanPHP\QueryWriter as QueryWriter; use RedBeanPHP\QueryWriter as QueryWriter;
use RedBeanPHP\RedException\Security as Security;
use RedBeanPHP\SimpleModel as SimpleModel;
use RedBeanPHP\BeanHelper as BeanHelper; use RedBeanPHP\BeanHelper as BeanHelper;
use RedBeanPHP\RedException\SQL as SQL;
use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter; use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter;
use RedBeanPHP\Repository as Repository; use RedBeanPHP\Repository as Repository;
use RedBeanPHP\Repository\Fluid as FluidRepo; use RedBeanPHP\Repository\Fluid as FluidRepo;
@ -46,7 +39,6 @@ class OODB extends Observable
*/ */
protected $chillList = array(); protected $chillList = array();
/** /**
* @var array * @var array
*/ */
@ -92,6 +84,24 @@ class OODB extends Observable
*/ */
protected $fluidRepository = NULL; protected $fluidRepository = NULL;
/**
* @var boolean
*/
protected static $autoClearHistoryAfterStore = FALSE;
/**
* If set to TRUE, this method will call clearHistory every time
* the bean gets stored.
*
* @param boolean $autoClear auto clear option
*
* @return void
*/
public static function autoClearHistoryAfterStore( $autoClear = TRUE )
{
self::$autoClearHistoryAfterStore = (boolean) $autoClear;
}
/** /**
* Unboxes a bean from a FUSE model if needed and checks whether the bean is * Unboxes a bean from a FUSE model if needed and checks whether the bean is
* an instance of OODBBean. * an instance of OODBBean.
@ -99,8 +109,6 @@ class OODB extends Observable
* @param OODBBean $bean bean you wish to unbox * @param OODBBean $bean bean you wish to unbox
* *
* @return OODBBean * @return OODBBean
*
* @throws Security
*/ */
protected function unboxIfNeeded( $bean ) protected function unboxIfNeeded( $bean )
{ {
@ -259,8 +267,6 @@ class OODB extends Observable
* @param OODBBean $bean the bean that needs to be checked * @param OODBBean $bean the bean that needs to be checked
* *
* @return void * @return void
*
* @throws Security $exception
*/ */
public function check( OODBBean $bean ) public function check( OODBBean $bean )
{ {
@ -273,10 +279,12 @@ class OODB extends Observable
* *
* Conditions need to take form: * Conditions need to take form:
* *
* <code>
* array( * array(
* 'PROPERTY' => array( POSSIBLE VALUES... 'John', 'Steve' ) * 'PROPERTY' => array( POSSIBLE VALUES... 'John', 'Steve' )
* 'PROPERTY' => array( POSSIBLE VALUES... ) * 'PROPERTY' => array( POSSIBLE VALUES... )
* ); * );
* </code>
* *
* All conditions are glued together using the AND-operator, while all value lists * All conditions are glued together using the AND-operator, while all value lists
* are glued using IN-operators thus acting as OR-conditions. * are glued using IN-operators thus acting as OR-conditions.
@ -287,11 +295,9 @@ class OODB extends Observable
* @param string $type type of beans you are looking for * @param string $type type of beans you are looking for
* @param array $conditions list of conditions * @param array $conditions list of conditions
* @param string $addSQL SQL to be used in query * @param string $addSQL SQL to be used in query
* @param array $bindings whether you prefer to use a WHERE clause or not (TRUE = not) * @param array $bindings a list of values to bind to query parameters
* *
* @return array * @return array
*
* @throws SQL
*/ */
public function find( $type, $conditions = array(), $sql = NULL, $bindings = array() ) public function find( $type, $conditions = array(), $sql = NULL, $bindings = array() )
{ {
@ -303,11 +309,9 @@ class OODB extends Observable
* *
* @param string $type type of beans you are looking for * @param string $type type of beans you are looking for
* @param string $addSQL SQL to be used in query * @param string $addSQL SQL to be used in query
* @param array $bindings whether you prefer to use a WHERE clause or not (TRUE = not) * @param array $bindings a list of values to bind to query parameters
* *
* @return array * @return array
*
* @throws SQL
*/ */
public function findCollection( $type, $sql = NULL, $bindings = array() ) public function findCollection( $type, $sql = NULL, $bindings = array() )
{ {
@ -348,13 +352,15 @@ class OODB extends Observable
* @param OODBBean|SimpleModel $bean bean to store * @param OODBBean|SimpleModel $bean bean to store
* *
* @return integer|string * @return integer|string
*
* @throws Security
*/ */
public function store( $bean ) public function store( $bean )
{ {
$bean = $this->unboxIfNeeded( $bean ); $bean = $this->unboxIfNeeded( $bean );
return $this->repository->store( $bean ); $id = $this->repository->store( $bean );
if ( self::$autoClearHistoryAfterStore ) {
$bean->clearHistory();
}
return $id;
} }
/** /**
@ -377,10 +383,7 @@ class OODB extends Observable
* @param string $type type of bean you want to load * @param string $type type of bean you want to load
* @param integer $id ID of the bean you want to load * @param integer $id ID of the bean you want to load
* *
* @throws SQL
*
* @return OODBBean * @return OODBBean
*
*/ */
public function load( $type, $id ) public function load( $type, $id )
{ {
@ -395,8 +398,6 @@ class OODB extends Observable
* @param OODBBean|SimpleModel $bean bean you want to remove from database * @param OODBBean|SimpleModel $bean bean you want to remove from database
* *
* @return void * @return void
*
* @throws Security
*/ */
public function trash( $bean ) public function trash( $bean )
{ {
@ -449,8 +450,6 @@ class OODB extends Observable
* @param array $bindings parameters to bind to SQL * @param array $bindings parameters to bind to SQL
* *
* @return integer * @return integer
*
* @throws SQL
*/ */
public function count( $type, $addSQL = '', $bindings = array() ) public function count( $type, $addSQL = '', $bindings = array() )
{ {
@ -463,8 +462,6 @@ class OODB extends Observable
* @param string $type type of bean you wish to delete all instances of * @param string $type type of bean you wish to delete all instances of
* *
* @return boolean * @return boolean
*
* @throws SQL
*/ */
public function wipe( $type ) public function wipe( $type )
{ {
@ -477,8 +474,6 @@ class OODB extends Observable
* storage and more. * storage and more.
* *
* @return AssociationManager * @return AssociationManager
*
* @throws Security
*/ */
public function getAssociationManager() public function getAssociationManager()
{ {
@ -521,9 +516,11 @@ class OODB extends Observable
* MySQL spatial columns, because they need to be processed first using * MySQL spatial columns, because they need to be processed first using
* the asText/GeomFromText functions. * the asText/GeomFromText functions.
* *
* @param string $mode (read or write) * @param string $mode mode to set function for, i.e. read or write
* @param string $field * @param string $field field (table.column) to bind SQL function to
* @param string $function * @param string $function SQL function to bind to field
*
* @return void
*/ */
public function bindFunc( $mode, $field, $function ) public function bindFunc( $mode, $field, $function )
{ {

View File

@ -4,9 +4,7 @@ namespace RedBeanPHP;
use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter; use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter;
use RedBeanPHP\BeanHelper as BeanHelper; use RedBeanPHP\BeanHelper as BeanHelper;
use RedBeanPHP\RedException\Security as Security;
use RedBeanPHP\RedException as RedException; use RedBeanPHP\RedException as RedException;
use RedBeanPHP\OODBBean as OODBBean;
/** /**
* OODBBean (Object Oriented DataBase Bean). * OODBBean (Object Oriented DataBase Bean).
@ -58,84 +56,6 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
*/ */
protected static $autoResolve = FALSE; protected static $autoResolve = FALSE;
/**
* Sets the error mode for FUSE.
* What to do if a FUSE model method does not exist?
* You can set the following options:
*
* OODBBean::C_ERR_IGNORE (default), ignores the call, returns NULL
* OODBBean::C_ERR_LOG, logs the incident using error_log
* OODBBean::C_ERR_NOTICE, triggers a E_USER_NOTICE
* OODBBean::C_ERR_WARN, triggers a E_USER_WARNING
* OODBBean::C_ERR_EXCEPTION, throws an exception
* OODBBean::C_ERR_FUNC, allows you to specify a custom handler (function)
* OODBBean::C_ERR_FATAL, triggers a E_USER_ERROR
*
* Custom handler method signature: handler( array (
* 'message' => string
* 'bean' => OODBBean
* 'method' => string
* ) )
*
* This method returns the old mode and handler as an array.
*
* @param integer $mode mode
* @param callable|NULL $func custom handler
*
* @return array
*/
public static function setErrorHandlingFUSE($mode, $func = NULL) {
if (
$mode !== self::C_ERR_IGNORE
&& $mode !== self::C_ERR_LOG
&& $mode !== self::C_ERR_NOTICE
&& $mode !== self::C_ERR_WARN
&& $mode !== self::C_ERR_EXCEPTION
&& $mode !== self::C_ERR_FUNC
&& $mode !== self::C_ERR_FATAL
) throw new \Exception( 'Invalid error mode selected' );
if ( $mode === self::C_ERR_FUNC && !is_callable( $func ) ) {
throw new \Exception( 'Invalid error handler' );
}
$old = array( self::$errorHandlingFUSE, self::$errorHandler );
self::$errorHandlingFUSE = $mode;
if ( is_callable( $func ) ) {
self::$errorHandler = $func;
} else {
self::$errorHandler = NULL;
}
return $old;
}
/**
* Sets aliases.
*
* @param array $list
*
* @return void
*/
public static function aliases( $list )
{
self::$aliases = $list;
}
/**
* Enables or disables auto-resolving fetch types.
* Auto-resolving aliased parent beans is convenient but can
* be slower and can create infinite recursion if you
* used aliases to break cyclic relations in your domain.
*
* @param boolean $automatic TRUE to enable automatic resolving aliased parents
*
* @return void
*/
public static function setAutoResolve( $automatic = TRUE )
{
self::$autoResolve = (boolean) $automatic;
}
/** /**
* This is where the real properties of the bean live. They are stored and retrieved * This is where the real properties of the bean live. They are stored and retrieved
* by the magic getter and setter (__get and __set). * by the magic getter and setter (__get and __set).
@ -195,6 +115,86 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
*/ */
protected $all = FALSE; protected $all = FALSE;
/**
* Sets the error mode for FUSE.
* What to do if a FUSE model method does not exist?
* You can set the following options:
*
* * OODBBean::C_ERR_IGNORE (default), ignores the call, returns NULL
* * OODBBean::C_ERR_LOG, logs the incident using error_log
* * OODBBean::C_ERR_NOTICE, triggers a E_USER_NOTICE
* * OODBBean::C_ERR_WARN, triggers a E_USER_WARNING
* * OODBBean::C_ERR_EXCEPTION, throws an exception
* * OODBBean::C_ERR_FUNC, allows you to specify a custom handler (function)
* * OODBBean::C_ERR_FATAL, triggers a E_USER_ERROR
*
* <code>
* Custom handler method signature: handler( array (
* 'message' => string
* 'bean' => OODBBean
* 'method' => string
* ) )
* </code>
*
* This method returns the old mode and handler as an array.
*
* @param integer $mode error handling mode
* @param callable|NULL $func custom handler
*
* @return array
*/
public static function setErrorHandlingFUSE($mode, $func = NULL) {
if (
$mode !== self::C_ERR_IGNORE
&& $mode !== self::C_ERR_LOG
&& $mode !== self::C_ERR_NOTICE
&& $mode !== self::C_ERR_WARN
&& $mode !== self::C_ERR_EXCEPTION
&& $mode !== self::C_ERR_FUNC
&& $mode !== self::C_ERR_FATAL
) throw new \Exception( 'Invalid error mode selected' );
if ( $mode === self::C_ERR_FUNC && !is_callable( $func ) ) {
throw new \Exception( 'Invalid error handler' );
}
$old = array( self::$errorHandlingFUSE, self::$errorHandler );
self::$errorHandlingFUSE = $mode;
if ( is_callable( $func ) ) {
self::$errorHandler = $func;
} else {
self::$errorHandler = NULL;
}
return $old;
}
/**
* Sets global aliases.
*
* @param array $list list of global aliases to use
*
* @return void
*/
public static function aliases( $list )
{
self::$aliases = $list;
}
/**
* Enables or disables auto-resolving fetch types.
* Auto-resolving aliased parent beans is convenient but can
* be slower and can create infinite recursion if you
* used aliases to break cyclic relations in your domain.
*
* @param boolean $automatic TRUE to enable automatic resolving aliased parents
*
* @return void
*/
public static function setAutoResolve( $automatic = TRUE )
{
self::$autoResolve = (boolean) $automatic;
}
/** /**
* Sets a meta property for all beans. This is a quicker way to set * Sets a meta property for all beans. This is a quicker way to set
* the meta properties for a collection of beans because this method * the meta properties for a collection of beans because this method
@ -232,7 +232,7 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* *
* @param string $type the source type for the join * @param string $type the source type for the join
* *
* @return string $joinSql * @return string
*/ */
private function parseJoin( $type ) private function parseJoin( $type )
{ {
@ -380,7 +380,7 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* nested beans (bean lists: ownBean, sharedBean) without the need to * nested beans (bean lists: ownBean, sharedBean) without the need to
* rely on static calls to the facade (or make this class dep. on OODB). * rely on static calls to the facade (or make this class dep. on OODB).
* *
* @param BeanHelper $helper * @param BeanHelper $helper helper to use for this bean
* *
* @return void * @return void
*/ */
@ -390,7 +390,7 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
} }
/** /**
* Returns an\ArrayIterator so you can treat the bean like * Returns an ArrayIterator so you can treat the bean like
* an array with the properties container as its contents. * an array with the properties container as its contents.
* This method is meant for PHP and allows you to access beans as if * This method is meant for PHP and allows you to access beans as if
* they were arrays, i.e. using array notation: * they were arrays, i.e. using array notation:
@ -399,7 +399,7 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* *
* Note that not all PHP functions work with the array interface. * Note that not all PHP functions work with the array interface.
* *
* @return \ArrayIterator * @return ArrayIterator
*/ */
public function getIterator() public function getIterator()
{ {
@ -636,7 +636,9 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* issue the following command: $book->ownPage * issue the following command: $book->ownPage
* However, to order these pages by number use: * However, to order these pages by number use:
* *
* <code>
* $book->with(' ORDER BY `number` ASC ')->ownPage * $book->with(' ORDER BY `number` ASC ')->ownPage
* </code>
* *
* the additional SQL snippet will be merged into the final * the additional SQL snippet will be merged into the final
* query. * query.
@ -682,8 +684,10 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* *
* Usage: * Usage:
* *
* <code>
* $bean->with( ' LIMIT 3 ' )->ownPage; //Just 3 * $bean->with( ' LIMIT 3 ' )->ownPage; //Just 3
* $bean->all()->ownPage; //Reload all pages * $bean->all()->ownPage; //Reload all pages
* </code>
* *
* @return self * @return self
*/ */
@ -713,16 +717,22 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* case, so to the project has a teacher_id pointing to a person, and a student_id * case, so to the project has a teacher_id pointing to a person, and a student_id
* also pointing to a person. Given a project, we obtain the teacher like this: * also pointing to a person. Given a project, we obtain the teacher like this:
* *
* <code>
* $project->fetchAs('person')->teacher; * $project->fetchAs('person')->teacher;
* </code>
* *
* Now, if we want all projects of a teacher we cant say: * Now, if we want all projects of a teacher we cant say:
* *
* <code>
* $teacher->ownProject * $teacher->ownProject
* </code>
* *
* because the $teacher is a bean of type 'person' and no project has been * because the $teacher is a bean of type 'person' and no project has been
* assigned to a person. Instead we use the alias() method like this: * assigned to a person. Instead we use the alias() method like this:
* *
* <code>
* $teacher->alias('teacher')->ownProject * $teacher->alias('teacher')->ownProject
* </code>
* *
* now we get the projects associated with the person bean aliased as * now we get the projects associated with the person bean aliased as
* a teacher. * a teacher.
@ -770,12 +780,13 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* Turns a camelcase property name into an underscored property name. * Turns a camelcase property name into an underscored property name.
* *
* Examples: * Examples:
* oneACLRoute -> one_acl_route *
* camelCase -> camel_case * * oneACLRoute -> one_acl_route
* * camelCase -> camel_case
* *
* Also caches the result to improve performance. * Also caches the result to improve performance.
* *
* @param string $property * @param string $property property to un-beautify
* *
* @return string * @return string
*/ */
@ -911,7 +922,6 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
return $this->properties[$property]; return $this->properties[$property];
} }
list( $redbean, , , $toolbox ) = $this->beanHelper->getExtractedToolbox(); list( $redbean, , , $toolbox ) = $this->beanHelper->getExtractedToolbox();
if ( isset( $this->$fieldLink ) ) { if ( isset( $this->$fieldLink ) ) {
@ -989,8 +999,6 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* @param mixed $value the value you want to assign * @param mixed $value the value you want to assign
* *
* @return void * @return void
*
* @throws Security
*/ */
public function __set( $property, $value ) public function __set( $property, $value )
{ {
@ -1101,12 +1109,14 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* *
* Example: * Example:
* *
* <code>
* $bean->setMeta( 'flush-cache', TRUE ); * $bean->setMeta( 'flush-cache', TRUE );
* </code>
* *
* RedBeanPHP also stores meta data in beans, this meta data uses * RedBeanPHP also stores meta data in beans, this meta data uses
* keys prefixed with 'sys.' (system). * keys prefixed with 'sys.' (system).
* *
* @param string $path path * @param string $path path to property in meta data
* @param mixed $default default value * @param mixed $default default value
* *
* @return mixed * @return mixed
@ -1122,7 +1132,7 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* This is a short-cut method that can be used instead * This is a short-cut method that can be used instead
* of combining a get/unset. * of combining a get/unset.
* *
* @param string $path path * @param string $path path to property in meta data
* @param mixed $default default value * @param mixed $default default value
* *
* @return mixed * @return mixed
@ -1161,7 +1171,7 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* This is a convenience method to enable you to * This is a convenience method to enable you to
* exchange meta information easily. * exchange meta information easily.
* *
* @param OODBBean $bean * @param OODBBean $bean bean to copy meta data of
* *
* @return OODBBean * @return OODBBean
*/ */
@ -1338,7 +1348,7 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* For polymorphic bean relations. * For polymorphic bean relations.
* Same as fetchAs but uses a column instead of a direct value. * Same as fetchAs but uses a column instead of a direct value.
* *
* @param string $column * @param string $field field name to use for mapping
* *
* @return OODBBean * @return OODBBean
*/ */
@ -1355,9 +1365,11 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* Can be used together with with, withCondition, alias and fetchAs. * Can be used together with with, withCondition, alias and fetchAs.
* *
* @param string $property property * @param string $property property
* @param closure $function function * @param callable $function function
* @param integer $maxDepth maximum depth for traversal
* *
* @return OODBBean * @return OODBBean
* @throws RedException
*/ */
public function traverse( $property, $function, $maxDepth = NULL ) public function traverse( $property, $function, $maxDepth = NULL )
{ {
@ -1382,7 +1394,7 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
if ( !is_array( $beans ) ) $beans = array( $beans ); if ( !is_array( $beans ) ) $beans = array( $beans );
foreach( $beans as $bean ) { foreach( $beans as $bean ) {
/** @var OODBBean $bean */
$function( $bean ); $function( $bean );
$bean->fetchType = $oldFetchType; $bean->fetchType = $oldFetchType;
@ -1397,7 +1409,7 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
} }
/** /**
* Implementation of\Countable interface. Makes it possible to use * Implementation of Countable interface. Makes it possible to use
* count() function on a bean. * count() function on a bean.
* *
* @return integer * @return integer
@ -1564,11 +1576,15 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* *
* Usage: * Usage:
* *
* <code>
* $album->link('track', array('number'=>1))->song = $song; * $album->link('track', array('number'=>1))->song = $song;
* </code>
* *
* or: * or:
* *
* <code>
* $album->link($trackBean)->song = $song; * $album->link($trackBean)->song = $song;
* </code>
* *
* What this method does is adding the link bean to the own-list, in this case * What this method does is adding the link bean to the own-list, in this case
* ownTrack. If the first argument is a string and the second is an array or * ownTrack. If the first argument is a string and the second is an array or
@ -1609,6 +1625,19 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
return $bean; return $bean;
} }
/**
* Returns a bean of the given type with the same ID of as
* the current one. This only happens in a one-to-one relation.
* This is as far as support for 1-1 goes in RedBeanPHP. This
* method will only return a reference to the bean, changing it
* and storing the bean will not update the related one-bean.
*
* @return OODBBean
*/
public function one( $type ) {
return $this->beanHelper->getToolBox()->getRedBean()->load( $type, $this->id );
}
/** /**
* Returns the same bean freshly loaded from the database. * Returns the same bean freshly loaded from the database.
* *
@ -1708,7 +1737,7 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
$count = 0; $count = 0;
if ( $this->getID() ) { if ( $this->getID() ) {
$count = $redbean->getAssociationManager()->relatedCount( $this, $type, $this->withSql, $this->withParams, TRUE ); $count = $redbean->getAssociationManager()->relatedCount( $this, $type, $this->withSql, $this->withParams );
} }
$this->clearModifiers(); $this->clearModifiers();
@ -1727,7 +1756,9 @@ class OODBBean implements\IteratorAggregate,\ArrayAccess,\Countable
* *
* Example: * Example:
* *
* <code>
* $quest->aggr( 'xownQuestTarget', 'target', 'quest' ); * $quest->aggr( 'xownQuestTarget', 'target', 'quest' );
* </code>
* *
* Loads (in batch) and returns references to all * Loads (in batch) and returns references to all
* quest beans residing in the $questTarget->target properties * quest beans residing in the $questTarget->target properties

View File

@ -1 +0,0 @@
This folder will get mounted in the phar.

View File

@ -90,9 +90,9 @@ interface QueryWriter
* *
* The GLUE type determines the prefix: * The GLUE type determines the prefix:
* *
* - NONE prefixes with WHERE * * NONE prefixes with WHERE
* - WHERE prefixes with WHERE and replaces AND if snippets starts with AND * * WHERE prefixes with WHERE and replaces AND if snippets starts with AND
* - AND prefixes with AND * * AND prefixes with AND
* *
* This method will never replace WHERE with AND since a snippet should never * This method will never replace WHERE with AND since a snippet should never
* begin with WHERE in the first place. OR is not supported. * begin with WHERE in the first place. OR is not supported.
@ -350,7 +350,7 @@ interface QueryWriter
* This method will add a UNIQUE constraint index to a table on columns $columns. * This method will add a UNIQUE constraint index to a table on columns $columns.
* This methods accepts a type and infers the corresponding table name. * This methods accepts a type and infers the corresponding table name.
* *
* @param string $type type * @param string $type target bean type
* @param array $columnsPartOfIndex columns to include in index * @param array $columnsPartOfIndex columns to include in index
* *
* @return void * @return void
@ -364,8 +364,8 @@ interface QueryWriter
* a one of the constants defined in this class and then check whether it is in the list * a one of the constants defined in this class and then check whether it is in the list
* of standard states provided. * of standard states provided.
* *
* @param string $state sql state * @param string $state SQL state to consider
* @param array $list list * @param array $list list of standardized SQL state constants to check against
* *
* @return boolean * @return boolean
*/ */
@ -439,11 +439,15 @@ interface QueryWriter
* Renames an association. For instance if you would like to refer to * Renames an association. For instance if you would like to refer to
* album_song as: track you can specify this by calling this method like: * album_song as: track you can specify this by calling this method like:
* *
* <code>
* renameAssociation('album_song','track') * renameAssociation('album_song','track')
* </code>
* *
* This allows: * This allows:
* *
* <code>
* $album->sharedSong * $album->sharedSong
* </code>
* *
* to add/retrieve beans from track instead of album_song. * to add/retrieve beans from track instead of album_song.
* Also works for exportAll(). * Also works for exportAll().
@ -451,8 +455,8 @@ interface QueryWriter
* This method also accepts a single associative array as * This method also accepts a single associative array as
* its first argument. * its first argument.
* *
* @param string|array $fromType * @param string|array $fromType original type name, or array
* @param string $toType (optional) * @param string $toType new type name (only if 1st argument is string)
* *
* @return void * @return void
*/ */

View File

@ -123,7 +123,7 @@ abstract class AQueryWriter
* Globally available service method for RedBeanPHP. * Globally available service method for RedBeanPHP.
* Converts a camel cased string to a snake cased string. * Converts a camel cased string to a snake cased string.
* *
* @param string $camel a camelCased string * @param string $camel camelCased string to converty to snake case
* *
* @return string * @return string
*/ */
@ -172,6 +172,7 @@ abstract class AQueryWriter
* This is a lowlevel method to set the SQL filter array. * This is a lowlevel method to set the SQL filter array.
* The format of this array is: * The format of this array is:
* *
* <code>
* array( * array(
* '<MODE, i.e. 'r' for read, 'w' for write>' => array( * '<MODE, i.e. 'r' for read, 'w' for write>' => array(
* '<TABLE NAME>' => array( * '<TABLE NAME>' => array(
@ -179,22 +180,27 @@ abstract class AQueryWriter
* ) * )
* ) * )
* ) * )
* </code>
* *
* Example: * Example:
* *
* <code>
* array( * array(
* QueryWriter::C_SQLFILTER_READ => array( * QueryWriter::C_SQLFILTER_READ => array(
* 'book' => array( * 'book' => array(
* 'title' => ' LOWER(book.title) ' * 'title' => ' LOWER(book.title) '
* ) * )
* ) * )
* </code>
* *
* Note that you can use constants instead of magical chars * Note that you can use constants instead of magical chars
* as keys for the uppermost array. * as keys for the uppermost array.
* This is a lowlevel method. For a more friendly method * This is a lowlevel method. For a more friendly method
* please take a look at the facade: R::bindFunc(). * please take a look at the facade: R::bindFunc().
* *
* @param array * @param array list of filters to set
*
* @return void
*/ */
public static function setSQLFilters( $sqlFilters, $safeMode = false ) public static function setSQLFilters( $sqlFilters, $safeMode = false )
{ {
@ -284,7 +290,7 @@ abstract class AQueryWriter
* improve caching efficiency (issue #400). * improve caching efficiency (issue #400).
* *
* @param string $cacheTag cache tag (secondary key) * @param string $cacheTag cache tag (secondary key)
* @param string $key key * @param string $key key to store values under
* @param array $values content to be stored * @param array $values content to be stored
* *
* @return void * @return void
@ -303,15 +309,17 @@ abstract class AQueryWriter
/** /**
* Creates an SQL snippet from a list of conditions of format: * Creates an SQL snippet from a list of conditions of format:
* *
* <code>
* array( * array(
* key => array( * key => array(
* value1, value2, value3 .... * value1, value2, value3 ....
* ) * )
* ) * )
* </code>
* *
* @param array $conditions list of conditions * @param array $conditions list of conditions
* @param array $bindings parameter bindings for SQL snippet * @param array $bindings parameter bindings for SQL snippet
* @param string $addSql SQL snippet * @param string $addSql additional SQL snippet to append to result
* *
* @return string * @return string
*/ */
@ -434,6 +442,7 @@ abstract class AQueryWriter
* A foreign key map describes the foreign keys in a table. * A foreign key map describes the foreign keys in a table.
* A FKM always has the same structure: * A FKM always has the same structure:
* *
* <code>
* array( * array(
* 'name' => <name of the foreign key> * 'name' => <name of the foreign key>
* 'from' => <name of the column on the source table> * 'from' => <name of the column on the source table>
@ -442,6 +451,7 @@ abstract class AQueryWriter
* 'on_update' => <update rule: 'SET NULL','CASCADE' or 'RESTRICT'> * 'on_update' => <update rule: 'SET NULL','CASCADE' or 'RESTRICT'>
* 'on_delete' => <delete rule: 'SET NULL','CASCADE' or 'RESTRICT'> * 'on_delete' => <delete rule: 'SET NULL','CASCADE' or 'RESTRICT'>
* ) * )
* </code>
* *
* @note the keys in the result array are FKDLs, i.e. descriptive unique * @note the keys in the result array are FKDLs, i.e. descriptive unique
* keys per source table. Also see: AQueryWriter::makeFKLabel for details. * keys per source table. Also see: AQueryWriter::makeFKLabel for details.
@ -648,8 +658,6 @@ abstract class AQueryWriter
* @param string $table table string * @param string $table table string
* *
* @return string * @return string
*
* @throws Security
*/ */
protected function check( $struct ) protected function check( $struct )
{ {
@ -712,7 +720,7 @@ abstract class AQueryWriter
*/ */
public function glueLimitOne( $sql = '') public function glueLimitOne( $sql = '')
{ {
return ( strpos( $sql, 'LIMIT' ) === FALSE ) ? ( $sql . ' LIMIT 1 ' ) : $sql; return ( strpos( strtoupper( $sql ), 'LIMIT' ) === FALSE ) ? ( $sql . ' LIMIT 1 ' ) : $sql;
} }
/** /**
@ -832,7 +840,6 @@ abstract class AQueryWriter
$rows = $this->adapter->get( $sql, $bindings ); $rows = $this->adapter->get( $sql, $bindings );
if ( $this->flagUseCache && $key ) { if ( $this->flagUseCache && $key ) {
$this->putResultInCache( $type, $key, $rows ); $this->putResultInCache( $type, $key, $rows );
} }
@ -1107,6 +1114,8 @@ abstract class AQueryWriter
* use a result row cache. * use a result row cache.
* *
* @param boolean * @param boolean
*
* @return void
*/ */
public function setUseCache( $yesNo ) public function setUseCache( $yesNo )
{ {

View File

@ -52,13 +52,13 @@ class CUBRID extends AQueryWriter implements QueryWriter
* later on. * later on.
* This methods accepts a type and infers the corresponding table name. * This methods accepts a type and infers the corresponding table name.
* *
*
* @param string $type type that will have a foreign key field * @param string $type type that will have a foreign key field
* @param string $targetType points to this type * @param string $targetType points to this type
* @param string $field field that contains the foreign key value * @param string $property field that contains the foreign key value
* @param string $targetField field where the fk points to * @param string $targetProperty field where the fk points to
* @param bool $isDep
* *
* @return void * @return bool
*/ */
protected function buildFK( $type, $targetType, $property, $targetProperty, $isDep = FALSE ) protected function buildFK( $type, $targetType, $property, $targetProperty, $isDep = FALSE )
{ {
@ -137,7 +137,7 @@ class CUBRID extends AQueryWriter implements QueryWriter
* This method returns the datatype to be used for primary key IDS and * This method returns the datatype to be used for primary key IDS and
* foreign keys. Returns one if the data type constants. * foreign keys. Returns one if the data type constants.
* *
* @return integer $const data type to be used for IDS. * @return integer
*/ */
public function getTypeForID() public function getTypeForID()
{ {

View File

@ -39,6 +39,7 @@ class MySQL extends AQueryWriter implements QueryWriter
const C_DATATYPE_SPECIAL_POINT = 90; const C_DATATYPE_SPECIAL_POINT = 90;
const C_DATATYPE_SPECIAL_LINESTRING = 91; const C_DATATYPE_SPECIAL_LINESTRING = 91;
const C_DATATYPE_SPECIAL_POLYGON = 92; const C_DATATYPE_SPECIAL_POLYGON = 92;
const C_DATATYPE_SPECIAL_MONEY = 93;
const C_DATATYPE_SPECIFIED = 99; const C_DATATYPE_SPECIFIED = 99;
@ -57,6 +58,7 @@ class MySQL extends AQueryWriter implements QueryWriter
*/ */
protected function getKeyMapForType( $type ) protected function getKeyMapForType( $type )
{ {
$databaseName = $this->adapter->getCell('SELECT DATABASE()');
$table = $this->esc( $type, TRUE ); $table = $this->esc( $type, TRUE );
$keys = $this->adapter->get(' $keys = $this->adapter->get('
SELECT SELECT
@ -68,17 +70,15 @@ class MySQL extends AQueryWriter implements QueryWriter
information_schema.referential_constraints.delete_rule AS `on_delete` information_schema.referential_constraints.delete_rule AS `on_delete`
FROM information_schema.key_column_usage FROM information_schema.key_column_usage
INNER JOIN information_schema.referential_constraints INNER JOIN information_schema.referential_constraints
ON ( ON information_schema.referential_constraints.constraint_name = information_schema.key_column_usage.constraint_name
information_schema.referential_constraints.constraint_name = information_schema.key_column_usage.constraint_name
AND information_schema.referential_constraints.constraint_schema = information_schema.key_column_usage.constraint_schema
AND information_schema.referential_constraints.constraint_catalog = information_schema.key_column_usage.constraint_catalog
)
WHERE WHERE
information_schema.key_column_usage.table_schema IN ( SELECT DATABASE() ) information_schema.key_column_usage.table_schema = :database
AND information_schema.key_column_usage.table_name = ? AND information_schema.referential_constraints.constraint_schema = :database
AND information_schema.key_column_usage.constraint_schema = :database
AND information_schema.key_column_usage.table_name = :table
AND information_schema.key_column_usage.constraint_name != \'PRIMARY\' AND information_schema.key_column_usage.constraint_name != \'PRIMARY\'
AND information_schema.key_column_usage.referenced_table_name IS NOT NULL AND information_schema.key_column_usage.referenced_table_name IS NOT NULL
', array($table)); ', array( ':database' => $databaseName, ':table' => $table ) );
$keyInfoList = array(); $keyInfoList = array();
foreach ( $keys as $k ) { foreach ( $keys as $k ) {
$label = $this->makeFKLabel( $k['from'], $k['table'], $k['to'] ); $label = $this->makeFKLabel( $k['from'], $k['table'], $k['to'] );
@ -114,6 +114,7 @@ class MySQL extends AQueryWriter implements QueryWriter
MySQL::C_DATATYPE_SPECIAL_POINT => ' POINT ', MySQL::C_DATATYPE_SPECIAL_POINT => ' POINT ',
MySQL::C_DATATYPE_SPECIAL_LINESTRING => ' LINESTRING ', MySQL::C_DATATYPE_SPECIAL_LINESTRING => ' LINESTRING ',
MySQL::C_DATATYPE_SPECIAL_POLYGON => ' POLYGON ', MySQL::C_DATATYPE_SPECIAL_POLYGON => ' POLYGON ',
MySQL::C_DATATYPE_SPECIAL_MONEY => ' DECIMAL(10,2) '
); );
$this->sqltype_typeno = array(); $this->sqltype_typeno = array();
@ -131,7 +132,7 @@ class MySQL extends AQueryWriter implements QueryWriter
* This method returns the datatype to be used for primary key IDS and * This method returns the datatype to be used for primary key IDS and
* foreign keys. Returns one if the data type constants. * foreign keys. Returns one if the data type constants.
* *
* @return integer $const data type to be used for IDS. * @return integer
*/ */
public function getTypeForID() public function getTypeForID()
{ {
@ -185,6 +186,9 @@ class MySQL extends AQueryWriter implements QueryWriter
if ( $value === INF ) return MySQL::C_DATATYPE_TEXT7; if ( $value === INF ) return MySQL::C_DATATYPE_TEXT7;
if ( $flagSpecial ) { if ( $flagSpecial ) {
if ( preg_match( '/^-?\d+\.\d{2}$/', $value ) ) {
return MySQL::C_DATATYPE_SPECIAL_MONEY;
}
if ( preg_match( '/^\d{4}\-\d\d-\d\d$/', $value ) ) { if ( preg_match( '/^\d{4}\-\d\d-\d\d$/', $value ) ) {
return MySQL::C_DATATYPE_SPECIAL_DATE; return MySQL::C_DATATYPE_SPECIAL_DATE;
} }
@ -297,6 +301,7 @@ class MySQL extends AQueryWriter implements QueryWriter
/** /**
* @see QueryWriter::addFK * @see QueryWriter::addFK
* @return bool
*/ */
public function addFK( $type, $targetType, $property, $targetProperty, $isDependent = FALSE ) public function addFK( $type, $targetType, $property, $targetProperty, $isDependent = FALSE )
{ {
@ -329,6 +334,7 @@ class MySQL extends AQueryWriter implements QueryWriter
} catch ( SQLException $e ) { } catch ( SQLException $e ) {
// Failure of fk-constraints is not a problem // Failure of fk-constraints is not a problem
} }
return true;
} }
/** /**

View File

@ -37,6 +37,7 @@ class PostgreSQL extends AQueryWriter implements QueryWriter
const C_DATATYPE_SPECIAL_CIRCLE = 92; const C_DATATYPE_SPECIAL_CIRCLE = 92;
const C_DATATYPE_SPECIAL_MONEY = 93; const C_DATATYPE_SPECIAL_MONEY = 93;
const C_DATATYPE_SPECIAL_POLYGON = 94; const C_DATATYPE_SPECIAL_POLYGON = 94;
const C_DATATYPE_SPECIAL_MONEY2 = 95; //Numbers only money, i.e. fixed point numeric
const C_DATATYPE_SPECIFIED = 99; const C_DATATYPE_SPECIFIED = 99;
/** /**
@ -136,6 +137,7 @@ class PostgreSQL extends AQueryWriter implements QueryWriter
self::C_DATATYPE_SPECIAL_LSEG => ' lseg ', self::C_DATATYPE_SPECIAL_LSEG => ' lseg ',
self::C_DATATYPE_SPECIAL_CIRCLE => ' circle ', self::C_DATATYPE_SPECIAL_CIRCLE => ' circle ',
self::C_DATATYPE_SPECIAL_MONEY => ' money ', self::C_DATATYPE_SPECIAL_MONEY => ' money ',
self::C_DATATYPE_SPECIAL_MONEY2 => ' numeric(10,2) ',
self::C_DATATYPE_SPECIAL_POLYGON => ' polygon ', self::C_DATATYPE_SPECIAL_POLYGON => ' polygon ',
); );
@ -152,7 +154,7 @@ class PostgreSQL extends AQueryWriter implements QueryWriter
* This method returns the datatype to be used for primary key IDS and * This method returns the datatype to be used for primary key IDS and
* foreign keys. Returns one if the data type constants. * foreign keys. Returns one if the data type constants.
* *
* @return integer $const data type to be used for IDS. * @return integer
*/ */
public function getTypeForID() public function getTypeForID()
{ {
@ -184,7 +186,7 @@ class PostgreSQL extends AQueryWriter implements QueryWriter
{ {
$table = $this->esc( $table, TRUE ); $table = $this->esc( $table, TRUE );
$columnsRaw = $this->adapter->get( "SELECT column_name, data_type FROM information_schema.columns WHERE table_name='$table'" ); $columnsRaw = $this->adapter->get( "SELECT column_name, data_type FROM information_schema.columns WHERE table_name='$table' AND table_schema = ANY( current_schemas( FALSE ) )" );
$columns = array(); $columns = array();
foreach ( $columnsRaw as $r ) { foreach ( $columnsRaw as $r ) {
@ -231,6 +233,10 @@ class PostgreSQL extends AQueryWriter implements QueryWriter
if ( preg_match( '/^\-?(\$|€|¥|£)[\d,\.]+$/', $value ) ) { if ( preg_match( '/^\-?(\$|€|¥|£)[\d,\.]+$/', $value ) ) {
return PostgreSQL::C_DATATYPE_SPECIAL_MONEY; return PostgreSQL::C_DATATYPE_SPECIAL_MONEY;
} }
if ( preg_match( '/^-?\d+\.\d{2}$/', $value ) ) {
return PostgreSQL::C_DATATYPE_SPECIAL_MONEY2;
}
} }
if ( is_float( $value ) ) return self::C_DATATYPE_DOUBLE; if ( is_float( $value ) ) return self::C_DATATYPE_DOUBLE;

View File

@ -55,7 +55,7 @@ class SQLiteT extends AQueryWriter implements QueryWriter
* *
* @param string $type type you want to get info of * @param string $type type you want to get info of
* *
* @return array $info * @return array
*/ */
protected function getTable( $type ) protected function getTable( $type )
{ {
@ -83,6 +83,8 @@ class SQLiteT extends AQueryWriter implements QueryWriter
* then store it with putTable()... * then store it with putTable()...
* *
* @param array $tableMap information array * @param array $tableMap information array
*
* @return void
*/ */
protected function putTable( $tableMap ) protected function putTable( $tableMap )
{ {
@ -131,11 +133,11 @@ class SQLiteT extends AQueryWriter implements QueryWriter
} }
/** /**
* Returns the indexes for type $type. * Returns the an array describing the indexes for type $type.
* *
* @param string $type * @param string $type type to describe indexes of
* *
* @return array $indexInfo index information * @return array
*/ */
protected function getIndexes( $type ) protected function getIndexes( $type )
{ {
@ -153,7 +155,9 @@ class SQLiteT extends AQueryWriter implements QueryWriter
} }
/** /**
* Adds a foreign key to a type * Adds a foreign key to a type.
* Note: cant put this in try-catch because that can hide the fact
* that database has been damaged.
* *
* @param string $type type you want to modify table of * @param string $type type you want to modify table of
* @param string $targetType target type * @param string $targetType target type
@ -161,10 +165,7 @@ class SQLiteT extends AQueryWriter implements QueryWriter
* @param string $targetField field where the fk needs to point to * @param string $targetField field where the fk needs to point to
* @param integer $buildopt 0 = NO ACTION, 1 = ON DELETE CASCADE * @param integer $buildopt 0 = NO ACTION, 1 = ON DELETE CASCADE
* *
* @return boolean $didIt * @return boolean
*
* @note: cant put this in try-catch because that can hide the fact
* that database has been damaged.
*/ */
protected function buildFK( $type, $targetType, $property, $targetProperty, $constraint = FALSE ) protected function buildFK( $type, $targetType, $property, $targetProperty, $constraint = FALSE )
{ {

View File

@ -16,4 +16,6 @@ namespace RedBeanPHP;
* @license BSD/GPLv2 * @license BSD/GPLv2
* *
*/ */
class R extends Facade {} class R extends Facade
{
}

View File

@ -27,7 +27,7 @@ class SQL extends RedException
/** /**
* Returns an ANSI-92 compliant SQL state. * Returns an ANSI-92 compliant SQL state.
* *
* @return string $state ANSI state code * @return string
*/ */
public function getSQLState() public function getSQLState()
{ {
@ -50,7 +50,7 @@ class SQL extends RedException
/** /**
* To String prints both code and SQL state. * To String prints both code and SQL state.
* *
* @return string $message prints this exception instance as a string * @return string
*/ */
public function __toString() public function __toString()
{ {

View File

@ -2,17 +2,11 @@
namespace RedBeanPHP; namespace RedBeanPHP;
use RedBeanPHP\OODBBean as OODBBean;
use RedBeanPHP\Observable as Observable;
use RedBeanPHP\Adapter\DBAdapter as DBAdapter; use RedBeanPHP\Adapter\DBAdapter as DBAdapter;
use RedBeanPHP\BeanHelper\FacadeBeanHelper as FacadeBeanHelper;
use RedBeanPHP\QueryWriter as QueryWriter; use RedBeanPHP\QueryWriter as QueryWriter;
use RedBeanPHP\RedException\Security as Security;
use RedBeanPHP\SimpleModel as SimpleModel;
use RedBeanPHP\BeanHelper as BeanHelper; use RedBeanPHP\BeanHelper as BeanHelper;
use RedBeanPHP\RedException\SQL as SQLException; use RedBeanPHP\RedException\SQL as SQLException;
use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter; use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter;
use RedBeanPHP\OODB as OODB;
use RedBeanPHP\Cursor as Cursor; use RedBeanPHP\Cursor as Cursor;
use RedBeanPHP\Cursor\NullCursor as NullCursor; use RedBeanPHP\Cursor\NullCursor as NullCursor;
@ -55,7 +49,7 @@ abstract class Repository
/** /**
* Stores a bean and its lists in one run. * Stores a bean and its lists in one run.
* *
* @param OODBBean $bean * @param OODBBean $bean bean to process
* *
* @return void * @return void
*/ */
@ -140,8 +134,6 @@ abstract class Repository
* @param array $sharedAdditions list with shared additions * @param array $sharedAdditions list with shared additions
* *
* @return void * @return void
*
* @throws Security
*/ */
protected function processSharedAdditions( $bean, $sharedAdditions ) protected function processSharedAdditions( $bean, $sharedAdditions )
{ {
@ -161,8 +153,8 @@ abstract class Repository
* checks if there have been any modification to this bean, in that case * checks if there have been any modification to this bean, in that case
* the bean is stored once again, otherwise the bean will be left untouched. * the bean is stored once again, otherwise the bean will be left untouched.
* *
* @param OODBBean $bean the bean * @param OODBBean $bean bean tor process
* @param array $ownresidue list * @param array $ownresidue list to process
* *
* @return void * @return void
*/ */
@ -184,14 +176,13 @@ abstract class Repository
* If not, the connection between the bean and the owner bean will be broken by * If not, the connection between the bean and the owner bean will be broken by
* setting the ID to NULL. * setting the ID to NULL.
* *
* @param OODBBean $bean the bean * @param OODBBean $bean bean to process
* @param array $ownTrashcan list * @param array $ownTrashcan list to process
* *
* @return void * @return void
*/ */
protected function processTrashcan( $bean, $ownTrashcan ) protected function processTrashcan( $bean, $ownTrashcan )
{ {
foreach ( $ownTrashcan as $trash ) { foreach ( $ownTrashcan as $trash ) {
$myFieldLink = $bean->getMeta( 'type' ) . '_id'; $myFieldLink = $bean->getMeta( 'type' ) . '_id';
@ -210,8 +201,8 @@ abstract class Repository
/** /**
* Unassociates the list items in the trashcan. * Unassociates the list items in the trashcan.
* *
* @param OODBBean $bean bean * @param OODBBean $bean bean to process
* @param array $sharedTrashcan list * @param array $sharedTrashcan list to process
* *
* @return void * @return void
*/ */
@ -225,8 +216,8 @@ abstract class Repository
/** /**
* Stores all the beans in the residue group. * Stores all the beans in the residue group.
* *
* @param OODBBean $bean bean * @param OODBBean $bean bean to process
* @param array $sharedresidue list * @param array $sharedresidue list to process
* *
* @return void * @return void
*/ */
@ -259,15 +250,16 @@ abstract class Repository
return $processLists; return $processLists;
} }
/** /**
* Converts an embedded bean to an ID, removed the bean property and * Converts an embedded bean to an ID, removed the bean property and
* stores the bean in the embedded beans array. * stores the bean in the embedded beans array.
* *
* @param array $embeddedBeans destination array for embedded bean * @param array $embeddedBeans destination array for embedded bean
* @param OODBBean $bean target bean * @param OODBBean $bean target bean to process
* @param string $property property that contains the embedded bean * @param string $property property that contains the embedded bean
* @param OODBBean $value embedded bean itself * @param OODBBean $value embedded bean itself
*
* @return void
*/ */
protected function processEmbeddedBean( &$embeddedBeans, $bean, $property, OODBBean $value ) protected function processEmbeddedBean( &$embeddedBeans, $bean, $property, OODBBean $value )
{ {
@ -279,11 +271,13 @@ abstract class Repository
unset( $bean->$property ); unset( $bean->$property );
} }
/** /**
* Constructor, requires a query writer. * Constructor, requires a query writer.
* Creates a new instance of the bean respository class.
* *
* @param QueryWriter $writer writer * @param QueryWriter $writer the Query Writer to use for this repository
*
* @return void
*/ */
public function __construct( OODB $oodb, QueryWriter $writer ) public function __construct( OODB $oodb, QueryWriter $writer )
{ {
@ -299,8 +293,6 @@ abstract class Repository
* @param OODBBean $bean the bean that needs to be checked * @param OODBBean $bean the bean that needs to be checked
* *
* @return void * @return void
*
* @throws Security $exception
*/ */
public function check( OODBBean $bean ) public function check( OODBBean $bean )
{ {
@ -339,10 +331,12 @@ abstract class Repository
* *
* Conditions need to take form: * Conditions need to take form:
* *
* <code>
* array( * array(
* 'PROPERTY' => array( POSSIBLE VALUES... 'John', 'Steve' ) * 'PROPERTY' => array( POSSIBLE VALUES... 'John', 'Steve' )
* 'PROPERTY' => array( POSSIBLE VALUES... ) * 'PROPERTY' => array( POSSIBLE VALUES... )
* ); * );
* </code>
* *
* All conditions are glued together using the AND-operator, while all value lists * All conditions are glued together using the AND-operator, while all value lists
* are glued using IN-operators thus acting as OR-conditions. * are glued using IN-operators thus acting as OR-conditions.
@ -356,7 +350,6 @@ abstract class Repository
* @param array $bindings whether you prefer to use a WHERE clause or not (TRUE = not) * @param array $bindings whether you prefer to use a WHERE clause or not (TRUE = not)
* *
* @return array * @return array
*
*/ */
public function find( $type, $conditions = array(), $sql = NULL, $bindings = array() ) public function find( $type, $conditions = array(), $sql = NULL, $bindings = array() )
{ {
@ -512,8 +505,6 @@ abstract class Repository
* @param array $bindings parameters to bind to SQL * @param array $bindings parameters to bind to SQL
* *
* @return integer * @return integer
*
* @throws SQLException
*/ */
public function count( $type, $addSQL = '', $bindings = array() ) public function count( $type, $addSQL = '', $bindings = array() )
{ {
@ -543,8 +534,6 @@ abstract class Repository
* @param OODBBean|SimpleModel $bean bean you want to remove from database * @param OODBBean|SimpleModel $bean bean you want to remove from database
* *
* @return void * @return void
*
* @throws SQLException
*/ */
public function trash( $bean ) public function trash( $bean )
{ {
@ -591,8 +580,6 @@ abstract class Repository
* @param string $type type of bean you wish to delete all instances of * @param string $type type of bean you wish to delete all instances of
* *
* @return boolean * @return boolean
*
* @throws SQLException
*/ */
public function wipe( $type ) public function wipe( $type )
{ {

View File

@ -3,16 +3,10 @@
namespace RedBeanPHP\Repository; namespace RedBeanPHP\Repository;
use RedBeanPHP\OODBBean as OODBBean; use RedBeanPHP\OODBBean as OODBBean;
use RedBeanPHP\Observable as Observable;
use RedBeanPHP\Adapter\DBAdapter as DBAdapter;
use RedBeanPHP\BeanHelper\FacadeBeanHelper as FacadeBeanHelper;
use RedBeanPHP\QueryWriter as QueryWriter; use RedBeanPHP\QueryWriter as QueryWriter;
use RedBeanPHP\RedException as RedException; use RedBeanPHP\RedException as RedException;
use RedBeanPHP\RedException\Security as Security;
use RedBeanPHP\SimpleModel as SimpleModel;
use RedBeanPHP\BeanHelper as BeanHelper; use RedBeanPHP\BeanHelper as BeanHelper;
use RedBeanPHP\RedException\SQL as SQLException; use RedBeanPHP\RedException\SQL as SQLException;
use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter;
use RedBeanPHP\Repository as Repository; use RedBeanPHP\Repository as Repository;
/** /**
@ -41,8 +35,6 @@ class Fluid extends Repository
* @param string $cast cast identifier * @param string $cast cast identifier
* *
* @return integer * @return integer
*
* @throws Security
*/ */
private function getTypeFromCast( $cast ) private function getTypeFromCast( $cast )
{ {
@ -149,12 +141,15 @@ class Fluid extends Repository
* adds a foreign key. Also adds a constraint in case the type is * adds a foreign key. Also adds a constraint in case the type is
* in the dependent list. * in the dependent list.
* *
* @param OODBBean $bean bean * Note that this method raises a custom exception if the bean
* is not an instance of OODBBean. Therefore it does not use
* a type hint. This allows the user to take action in case
* invalid objects are passed in the list.
*
* @param OODBBean $bean bean to process
* @param array $ownAdditions list of addition beans in own-list * @param array $ownAdditions list of addition beans in own-list
* *
* @return void * @return void
*
* @throws Security
*/ */
protected function processAdditions( $bean, $ownAdditions ) protected function processAdditions( $bean, $ownAdditions )
{ {
@ -217,13 +212,11 @@ class Fluid extends Repository
} }
/** /**
* Handles\Exceptions. Suppresses exceptions caused by missing structures. * Handles exceptions. Suppresses exceptions caused by missing structures.
* *
* @param\Exception $exception exception * @param Exception $exception exception
* *
* @return void * @return void
*
* @throws\Exception
*/ */
protected function handleException( \Exception $exception ) protected function handleException( \Exception $exception )
{ {
@ -286,10 +279,7 @@ class Fluid extends Repository
* @param string $type type of bean you want to load * @param string $type type of bean you want to load
* @param integer $id ID of the bean you want to load * @param integer $id ID of the bean you want to load
* *
* @throws SQL
*
* @return OODBBean * @return OODBBean
*
*/ */
public function load( $type, $id ) public function load( $type, $id )
{ {

View File

@ -3,16 +3,10 @@
namespace RedBeanPHP\Repository; namespace RedBeanPHP\Repository;
use RedBeanPHP\OODBBean as OODBBean; use RedBeanPHP\OODBBean as OODBBean;
use RedBeanPHP\Observable as Observable;
use RedBeanPHP\Adapter\DBAdapter as DBAdapter;
use RedBeanPHP\BeanHelper\FacadeBeanHelper as FacadeBeanHelper;
use RedBeanPHP\QueryWriter as QueryWriter; use RedBeanPHP\QueryWriter as QueryWriter;
use RedBeanPHP\RedException as RedException; use RedBeanPHP\RedException as RedException;
use RedBeanPHP\RedException\Security as Security;
use RedBeanPHP\SimpleModel as SimpleModel;
use RedBeanPHP\BeanHelper as BeanHelper; use RedBeanPHP\BeanHelper as BeanHelper;
use RedBeanPHP\RedException\SQL as SQLException; use RedBeanPHP\RedException\SQL as SQLException;
use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter;
use RedBeanPHP\Repository as Repository; use RedBeanPHP\Repository as Repository;
/** /**
@ -36,12 +30,11 @@ use RedBeanPHP\Repository as Repository;
class Frozen extends Repository class Frozen extends Repository
{ {
/** /**
* Handles\Exceptions. Suppresses exceptions caused by missing structures. * Handles exceptions. Suppresses exceptions caused by missing structures.
* *
* @param \Exception $exception exception * @param \Exception $exception exception to handle
* *
* @return void * @return void
*
* @throws \Exception * @throws \Exception
*/ */
protected function handleException( \Exception $exception ) protected function handleException( \Exception $exception )
@ -85,12 +78,16 @@ class Frozen extends Repository
* adds a foreign key. Also adds a constraint in case the type is * adds a foreign key. Also adds a constraint in case the type is
* in the dependent list. * in the dependent list.
* *
* @param OODBBean $bean bean * Note that this method raises a custom exception if the bean
* is not an instance of OODBBean. Therefore it does not use
* a type hint. This allows the user to take action in case
* invalid objects are passed in the list.
*
* @param OODBBean $bean bean to process
* @param array $ownAdditions list of addition beans in own-list * @param array $ownAdditions list of addition beans in own-list
* *
* @return void * @return void
* * @throws RedException
* @throws Security
*/ */
protected function processAdditions( $bean, $ownAdditions ) protected function processAdditions( $bean, $ownAdditions )
{ {
@ -124,7 +121,7 @@ class Frozen extends Repository
* configuration for you. * configuration for you.
* *
* @param string $type type of bean you want to dispense * @param string $type type of bean you want to dispense
* @param string $number number of beans you would like to get * @param int $number number of beans you would like to get
* @param boolean $alwaysReturnArray if TRUE always returns the result as an array * @param boolean $alwaysReturnArray if TRUE always returns the result as an array
* *
* @return OODBBean * @return OODBBean
@ -134,6 +131,7 @@ class Frozen extends Repository
$OODBBEAN = defined( 'REDBEAN_OODBBEAN_CLASS' ) ? REDBEAN_OODBBEAN_CLASS : '\RedBeanPHP\OODBBean'; $OODBBEAN = defined( 'REDBEAN_OODBBEAN_CLASS' ) ? REDBEAN_OODBBEAN_CLASS : '\RedBeanPHP\OODBBean';
$beans = array(); $beans = array();
for ( $i = 0; $i < $number; $i++ ) { for ( $i = 0; $i < $number; $i++ ) {
/** @var \RedBeanPHP\OODBBean $bean */
$bean = new $OODBBEAN; $bean = new $OODBBEAN;
$bean->initializeForDispense( $type, $this->oodb->getBeanHelper() ); $bean->initializeForDispense( $type, $this->oodb->getBeanHelper() );
$this->oodb->signal( 'dispense', $bean ); $this->oodb->signal( 'dispense', $bean );
@ -163,10 +161,8 @@ class Frozen extends Repository
* @param string $type type of bean you want to load * @param string $type type of bean you want to load
* @param integer $id ID of the bean you want to load * @param integer $id ID of the bean you want to load
* *
* @throws SQL
*
* @return OODBBean * @return OODBBean
* * @throws SQLException
*/ */
public function load( $type, $id ) public function load( $type, $id )
{ {

View File

@ -32,7 +32,7 @@ class SimpleModel
* Used by FUSE: the ModelHelper class to connect a bean to a model. * Used by FUSE: the ModelHelper class to connect a bean to a model.
* This method loads a bean in the model. * This method loads a bean in the model.
* *
* @param OODBBean $bean bean * @param OODBBean $bean bean to load
* *
* @return void * @return void
*/ */
@ -48,7 +48,7 @@ class SimpleModel
* @note this method returns a value, not a reference! * @note this method returns a value, not a reference!
* To obtain a reference unbox the bean first! * To obtain a reference unbox the bean first!
* *
* @param string $prop property * @param string $prop property to get
* *
* @return mixed * @return mixed
*/ */
@ -61,8 +61,8 @@ class SimpleModel
* Magic Setter. * Magic Setter.
* Sets the value directly as a bean property. * Sets the value directly as a bean property.
* *
* @param string $prop property * @param string $prop property to set value of
* @param mixed $value value * @param mixed $value value to set
* *
* @return void * @return void
*/ */

View File

@ -38,7 +38,7 @@ class SimpleModelHelper implements Observer
* that belongs to the CRUD bean and this model will take over control from * that belongs to the CRUD bean and this model will take over control from
* there. * there.
* *
* @param Observable $observable * @param Observable $observable object to observe
* *
* @return void * @return void
*/ */

View File

@ -65,7 +65,7 @@ class TagManager
* Finds a tag bean by it's title. * Finds a tag bean by it's title.
* Internal method. * Internal method.
* *
* @param string $title title * @param string $title title to search for
* *
* @return OODBBean * @return OODBBean
*/ */
@ -87,7 +87,7 @@ class TagManager
* The tag manager offers an easy way to quickly implement basic tagging * The tag manager offers an easy way to quickly implement basic tagging
* functionality. * functionality.
* *
* @param ToolBox $toolbox * @param ToolBox $toolbox toolbox object
*/ */
public function __construct( ToolBox $toolbox ) public function __construct( ToolBox $toolbox )
{ {

View File

@ -51,11 +51,9 @@ class ToolBox
* the adapter, the query writer and the core functionality of RedBeanPHP in * the adapter, the query writer and the core functionality of RedBeanPHP in
* OODB. * OODB.
* *
* @param OODB $oodb Object Database * @param OODB $oodb Object Database, OODB
* @param DBAdapter $adapter Adapter * @param DBAdapter $adapter Database Adapter
* @param QueryWriter $writer Writer * @param QueryWriter $writer Query Writer
*
* @return ToolBox
*/ */
public function __construct( OODB $oodb, Adapter $adapter, QueryWriter $writer ) public function __construct( OODB $oodb, Adapter $adapter, QueryWriter $writer )
{ {

View File

@ -59,6 +59,13 @@ require( REDBEANPHP_MAIN_DIR . 'DuplicationManager.php' );
require( REDBEANPHP_MAIN_DIR . 'Plugin.php' ); require( REDBEANPHP_MAIN_DIR . 'Plugin.php' );
require( REDBEANPHP_MAIN_DIR . 'Functions.php' ); require( REDBEANPHP_MAIN_DIR . 'Functions.php' );
/* Facade Utilities */
require( REDBEANPHP_MAIN_DIR . 'Util/ArrayTool.php' );
require( REDBEANPHP_MAIN_DIR . 'Util/DispenseHelper.php' );
require( REDBEANPHP_MAIN_DIR . 'Util/Dump.php' );
require( REDBEANPHP_MAIN_DIR . 'Util/MultiLoader.php' );
require( REDBEANPHP_MAIN_DIR . 'Util/Transaction.php' );
//Allow users to mount the plugin folder. //Allow users to mount the plugin folder.
if ( defined( 'REDBEANPHP_PLUGINS' ) ) { if ( defined( 'REDBEANPHP_PLUGINS' ) ) {
Phar::mount( 'RedBeanPHP/Plugin', REDBEANPHP_PLUGINS ); Phar::mount( 'RedBeanPHP/Plugin', REDBEANPHP_PLUGINS );

View File

@ -40,7 +40,7 @@ if ($mode !== 'onlyphar') {
function addFile($file) { function addFile($file) {
global $code; global $code;
echo 'Added '. $file . ' to package... '.PHP_EOL; echo 'Added ', $file , ' to package... ',PHP_EOL;
$raw = file_get_contents($file); $raw = file_get_contents($file);
$raw = preg_replace('/namespace\s+([a-zA-Z0-9\\\;]+);/m', 'namespace $1 {', $raw); $raw = preg_replace('/namespace\s+([a-zA-Z0-9\\\;]+);/m', 'namespace $1 {', $raw);
$raw .= '}'; $raw .= '}';
@ -85,6 +85,11 @@ if ($mode !== 'onlyphar') {
addFile( DIR . 'LabelMaker.php' ); addFile( DIR . 'LabelMaker.php' );
addFile( DIR . 'Facade.php' ); addFile( DIR . 'Facade.php' );
addFile( DIR . 'DuplicationManager.php' ); addFile( DIR . 'DuplicationManager.php' );
addFile( DIR . 'Util/ArrayTool.php' );
addFile( DIR . 'Util/DispenseHelper.php' );
addFile( DIR . 'Util/Dump.php' );
addFile( DIR . 'Util/MultiLoader.php' );
addFile( DIR . 'Util/Transaction.php' );
addFile( DIR . 'Plugin.php' ); addFile( DIR . 'Plugin.php' );
$func = file_get_contents(DIR . 'Functions.php'); $func = file_get_contents(DIR . 'Functions.php');
@ -106,16 +111,16 @@ if ($mode !== 'onlyphar') {
$code = '<?php'.str_replace('<?php', '', $code); $code = '<?php'.str_replace('<?php', '', $code);
echo 'Okay, seems we have all the code.. now writing file: rb.php' .PHP_EOL; echo 'Okay, seems we have all the code.. now writing file: rb.php' ,PHP_EOL;
$b = file_put_contents('rb.php', $code); $b = file_put_contents('rb.php', $code);
echo 'Written: '.$b.' bytes.'.PHP_EOL; echo 'Written: ',$b,' bytes.',PHP_EOL;
if ($b > 0) { if ($b > 0) {
echo 'Done!' .PHP_EOL; echo 'Done!' ,PHP_EOL;
} else { } else {
echo 'Hm, something seems to have gone wrong... '.PHP_EOL; echo 'Hm, something seems to have gone wrong... ',PHP_EOL;
} }
} }

View File

@ -19,6 +19,11 @@ use RedBeanPHP\Facade as R;
*/ */
abstract class RedUNIT abstract class RedUNIT
{ {
/**
* @var integer
*/
protected $round;
/** /**
* @var string * @var string
*/ */
@ -86,4 +91,34 @@ abstract class RedUNIT
{ {
$this->currentlyActiveDriverID = $driver; $this->currentlyActiveDriverID = $driver;
} }
/**
* Sets the round number.
*
* @param integer $roundNumber round
*/
public function setRound( $roundNumber )
{
$this->round = (int) $roundNumber;
}
/**
* Returns the current round number
*
* @return integer
*/
public function getRound()
{
return $this->round;
}
/**
* Returns TRUE if the current round is the first round.
*
* @return boolean
*/
public function isFirstRound()
{
return ( $this->round === 0 );
}
} }

View File

@ -252,7 +252,8 @@ class Aliasing extends Base
list( $teacher, $student ) = R::dispense( 'person', 2 ) ; list( $teacher, $student ) = R::dispense( 'person', 2 ) ;
$teacher->name = 'jimmy' ; $teacher->name = 'jimmy' ;
$student->name = 'jacko' ; $student->name = 'jacko' ;
R::store( $teacher, $student ) ; R::store( $teacher ) ;
R::store( $student ) ;
$client = R::dispense( 'client' ) ; $client = R::dispense( 'client' ) ;
$client->firm = 'bean AG' ; $client->firm = 'bean AG' ;

View File

@ -264,7 +264,6 @@ class Arrays extends Base
asrt( isset( $book['sharedTagList'] ), TRUE ); asrt( isset( $book['sharedTagList'] ), TRUE );
asrt( isset( $book['sharedTag'] ), TRUE ); asrt( isset( $book['sharedTag'] ), TRUE );
$book['sharedTag'][] = R::dispense( 'tag' ); $book['sharedTag'][] = R::dispense( 'tag' );
R::store( $book ); R::store( $book );

View File

@ -170,6 +170,14 @@ class Association extends Base
R::storeAll( array( $author, $bio ) ); R::storeAll( array( $author, $bio ) );
$x = $author->one( 'bio' );
$y = $bio->one('author');
asrt( $x->name, $bio->name );
asrt( $y->name, $author->name );
asrt( $x->id, $bio->id );
asrt( $y->id, $author->id );
$id2 = $author->id; $id2 = $author->id;
list( $a, $b ) = R::loadMulti( 'author,bio', $id1 ); list( $a, $b ) = R::loadMulti( 'author,bio', $id1 );
@ -310,7 +318,6 @@ class Association extends Base
asrt( count( $wines[2]->sharedOlive ), 0 ); asrt( count( $wines[2]->sharedOlive ), 0 );
} }
public function testErrorHandling() public function testErrorHandling()
{ {
R::nuke(); R::nuke();
@ -345,7 +352,6 @@ class Association extends Base
fail(); fail();
} }
} }
} }

View File

@ -72,4 +72,3 @@ class Boxing extends Base
} }
} }

View File

@ -99,7 +99,6 @@ class Chill extends Base
} }
asrt(R::count('person_role'), 2); asrt(R::count('person_role'), 2);
R::nuke(); R::nuke();
$link = R::getRedBean()->dispense('person_role'); $link = R::getRedBean()->dispense('person_role');
$person = R::dispense( 'person' ); $person = R::dispense( 'person' );

View File

@ -38,4 +38,3 @@ class Close extends Base
} }
} }

View File

@ -50,7 +50,6 @@ class Count extends Base
} }
} }
/** /**
* Test count and wipe. * Test count and wipe.
* *

View File

@ -461,7 +461,7 @@ class Cross extends Base
$text->content = 'CHANGED'; $text->content = 'CHANGED';
} }
foreach( $texts as $text ) { foreach( $texts as $text ) {
asrt( $text->content, 'CHANGED', TRUE ); asrt( $text->content, 'CHANGED' );
} }
} }
@ -504,7 +504,7 @@ class Cross extends Base
$text->content = 'CHANGED'; $text->content = 'CHANGED';
} }
foreach( $texts as $text ) { foreach( $texts as $text ) {
asrt( $text->content, 'CHANGED', TRUE ); asrt( $text->content, 'CHANGED' );
} }
} }

View File

@ -391,4 +391,3 @@ class TroubleDapter extends DBAdapter
} }
} }

View File

@ -70,7 +70,6 @@ class Dispense extends Base
asrt( isset( $bean["abc"] ), TRUE ); asrt( isset( $bean["abc"] ), TRUE );
} }
/** /**
* Tests the facade-only dispenseAll method. * Tests the facade-only dispenseAll method.
* *

View File

@ -424,7 +424,7 @@ class Dup extends Base
* }}' * }}'
*/ */
$d->setTables( $cache, 1 ); $d->setTables( $cache );
ob_start(); ob_start();

View File

@ -663,6 +663,10 @@ class Finding extends Base {
$logger->clear(); $logger->clear();
$found = R::findOne( 'book', ' title = ? LIMIT 1', array( 'b' ) ); $found = R::findOne( 'book', ' title = ? LIMIT 1', array( 'b' ) );
asrt( count( $logger->grep('LIMIT 1') ), 1 ); asrt( count( $logger->grep('LIMIT 1') ), 1 );
$logger->clear();
$found = R::findOne( 'book', ' title = ? limit 1', array( 'b' ) );
asrt( count( $logger->grep('LIMIT 1') ), 0 );
asrt( count( $logger->grep('limit 1') ), 1 );
asrt( ( $found instanceof \RedBeanPHP\OODBBean ), TRUE ); asrt( ( $found instanceof \RedBeanPHP\OODBBean ), TRUE );
$found = R::findOne( 'book', ' title = ? LIMIT 2', array( 'b' ) ); $found = R::findOne( 'book', ' title = ? LIMIT 2', array( 'b' ) );
asrt( count( $logger->grep('LIMIT 2') ), 1 ); asrt( count( $logger->grep('LIMIT 2') ), 1 );

View File

@ -9,7 +9,6 @@ use RedBeanPHP\OODBBean as OODBBean;
use RedBeanPHP\Adapter as Adapter; use RedBeanPHP\Adapter as Adapter;
use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter; use RedBeanPHP\QueryWriter\AQueryWriter as AQueryWriter;
/** /**
* Foreignkeys * Foreignkeys
* *

View File

@ -6,7 +6,6 @@ use RedUNIT\Base as Base;
use RedBeanPHP\Facade as R; use RedBeanPHP\Facade as R;
use RedBeanPHP\OODBBean as OODBBean; use RedBeanPHP\OODBBean as OODBBean;
/** /**
* Joins * Joins
* *

View File

@ -48,7 +48,6 @@ class Keywords extends Base
'distinct', 'like' 'distinct', 'like'
); );
foreach ( $keywords as $k ) { foreach ( $keywords as $k ) {
R::nuke(); R::nuke();
@ -76,6 +75,5 @@ class Keywords extends Base
pass(); pass();
} }
} }
} }

View File

@ -28,6 +28,37 @@ use RedBeanPHP\Driver\RPDO as RPDO;
*/ */
class Misc extends Base class Misc extends Base
{ {
/**
* Test whether we can set the 'auto clear'
* option in OODB.
*
* @return void
*/
public function testAutoClearHistory()
{
testpack( 'Auto clear history' );
$book = R::dispense( 'book' );
$book->pages = 100;
$book->title = 'book';
R::store( $book );
$book = R::findOne( 'book' );
asrt( $book->hasChanged( 'title' ), FALSE );
$book->title = 'yes';
R::store( $book );
asrt( $book->hasChanged( 'title' ), TRUE );
OODB::autoClearHistoryAfterStore( TRUE );
$book = R::findOne( 'book' );
asrt( $book->hasChanged( 'title' ), FALSE );
$book->title = 'yes2';
R::store( $book );
asrt( $book->hasChanged( 'title' ), FALSE );
OODB::autoClearHistoryAfterStore( FALSE );
$book = R::findOne( 'book' );
asrt( $book->hasChanged( 'title' ), FALSE );
$book->title = 'yes';
R::store( $book );
asrt( $book->hasChanged( 'title' ), TRUE );
}
/** /**
* Tests the R::inspect() method on the Facade. * Tests the R::inspect() method on the Facade.
@ -584,7 +615,6 @@ class Misc extends Base
asrt( R::count( 'flavour' ), 4 ); asrt( R::count( 'flavour' ), 4 );
} }
/** /**
* Test trashAll(). * Test trashAll().
*/ */

View File

@ -981,12 +981,10 @@ class Relations extends Base
// Get books for topic // Get books for topic
asrt( $topic3->countShared('book'), 2 ); asrt( $topic3->countShared('book'), 2 );
$t3 = R::load( 'topic', $topic3->id ); $t3 = R::load( 'topic', $topic3->id );
asrt( count( $t3->sharedBook ), 2 ); asrt( count( $t3->sharedBook ), 2 );
// Nuke an own-array, replace entire array at once without getting first // Nuke an own-array, replace entire array at once without getting first
$page2->id = 0; $page2->id = 0;
$page2->title = 'yet another page 2'; $page2->title = 'yet another page 2';
@ -1420,7 +1418,6 @@ class Relations extends Base
$v2->name = 'Ville 2'; $v2->name = 'Ville 2';
$v3->name = 'Ville 3'; $v3->name = 'Ville 3';
$v1->link( 'armyVillage' )->army = $a3; $v1->link( 'armyVillage' )->army = $a3;
$v2->link( 'army_village' )->army = $a2; $v2->link( 'army_village' )->army = $a2;
$v3->link( 'armyVillage' )->army = $a1; $v3->link( 'armyVillage' )->army = $a1;

View File

@ -149,7 +149,6 @@ class Traverse extends Base
asrt( implode( ',', $path ), 'e,f,h' ); asrt( implode( ',', $path ), 'e,f,h' );
$path = array(); $path = array();
$pageA->traverse( 'ownPageList', function( $page ) use ( &$path ) { $pageA->traverse( 'ownPageList', function( $page ) use ( &$path ) {
$path[] = $page->title; $path[] = $page->title;
@ -226,7 +225,6 @@ class Traverse extends Base
} ); } );
asrt( implode( ',', $cats ), 'SF,Fantasy' ); asrt( implode( ',', $cats ), 'SF,Fantasy' );
$catList = array(); $catList = array();
$fantasy->alias( 'genre' ) $fantasy->alias( 'genre' )
->with( ' ORDER BY gname ASC ' ) ->with( ' ORDER BY gname ASC ' )

View File

@ -176,7 +176,6 @@ class Update extends Base
$account = R::load( 'user', $id ); $account = R::load( 'user', $id );
asrt( count( $account->alias( 'seller' )->ownTransaction ), 10 ); asrt( count( $account->alias( 'seller' )->ownTransaction ), 10 );
$account->alias( 'seller' )->ownTransaction = array(); $account->alias( 'seller' )->ownTransaction = array();
$id = R::store( $account ); $id = R::store( $account );

View File

@ -91,7 +91,6 @@ class Via extends Base
$book->via('garbage')->item = 'test'; $book->via('garbage')->item = 'test';
asrt( count( $book->sharedPageList ), 1 ); asrt( count( $book->sharedPageList ), 1 );
//yet another //yet another
$book = R::dispense('leaflet'); $book = R::dispense('leaflet');
$book->title = 'leaflet'; $book->title = 'leaflet';
@ -189,7 +188,6 @@ class Via extends Base
R::storeAll(array( $p1, $p2 )); R::storeAll(array( $p1, $p2 ));
$project = R::load('project', $x1->id); $project = R::load('project', $x1->id);
$designers = $project $designers = $project
@ -201,7 +199,6 @@ class Via extends Base
asrt(count($designers), 1); asrt(count($designers), 1);
asrt($anna->name, 'Anna'); asrt($anna->name, 'Anna');
$coders = $project $coders = $project
->withCondition(' participant.arole = ? ', array( 'coder' ) ) ->withCondition(' participant.arole = ? ', array( 'coder' ) )
->via( 'participant' ) ->via( 'participant' )

View File

@ -107,7 +107,6 @@ class With extends Base
} }
/** /**
* Test all(). * Test all().
* *
@ -466,7 +465,6 @@ class With extends Base
$book->ownPage[] = R::dispense( 'page' ); $book->ownPage[] = R::dispense( 'page' );
asrt( count( $book->ownPageList ), 4 ); asrt( count( $book->ownPageList ), 4 );
//Do not reload an own list if told to not reload using noLoad() //Do not reload an own list if told to not reload using noLoad()
$book->noLoad()->with(' LIMIT 1 ')->ownPage; //dont reload! $book->noLoad()->with(' LIMIT 1 ')->ownPage; //dont reload!
asrt( count( $book->xownPage ), 0); //dont reload! asrt( count( $book->xownPage ), 0); //dont reload!
@ -529,7 +527,6 @@ class With extends Base
$book->sharedTag = R::dispense( 'tag', 16 ); $book->sharedTag = R::dispense( 'tag', 16 );
asrt( count( $book->sharedTag ), 16 ); asrt( count( $book->sharedTag ), 16 );
//Do not reload a sharedTag list if told to not reload using noLoad() //Do not reload a sharedTag list if told to not reload using noLoad()
$book->noLoad()->with(' LIMIT 1 ')->sharedTag; //dont reload! $book->noLoad()->with(' LIMIT 1 ')->sharedTag; //dont reload!
asrt( count( $book->sharedTag ), 0); //dont reload! asrt( count( $book->sharedTag ), 0); //dont reload!

View File

@ -118,7 +118,6 @@ class Debug extends Blackhole
$this->testDebug(':a,?', array(':a'=>20, 30), '20,30'); $this->testDebug(':a,?', array(':a'=>20, 30), '20,30');
$this->testDebug(':a,?', array(30, ':a'=>20), '20,30'); $this->testDebug(':a,?', array(30, ':a'=>20), '20,30');
$this->testDebug('?,?', array('test',20), '\'test\',20'); $this->testDebug('?,?', array('test',20), '\'test\',20');
$this->testDebug('?', array( NULL ), 'NULL'); $this->testDebug('?', array( NULL ), 'NULL');
$this->testDebug('title = ?', array( NULL ), 'title = NULL'); $this->testDebug('title = ?', array( NULL ), 'title = NULL');

View File

@ -69,4 +69,3 @@ class Fusebox extends Blackhole
} }
} }

View File

@ -256,7 +256,6 @@ class Misc extends Blackhole
$bean->name = 'a'; $bean->name = 'a';
try { try {
R::transaction( function () use ( $bean ) { R::transaction( function () use ( $bean ) {
R::store( $bean ); R::store( $bean );
@ -336,7 +335,6 @@ class Misc extends Blackhole
testpack( 'Misc Tests' ); testpack( 'Misc Tests' );
R::debug( 1 ); R::debug( 1 );
flush(); flush();

View File

@ -13,7 +13,7 @@ use RedBeanPHP\BeanHelper\SimpleFacadeBeanHelper as SimpleFacadeBeanHelper;
use RedBeanPHP\Repository as Repository; use RedBeanPHP\Repository as Repository;
use RedBeanPHP\Repository\Fluid as FluidRepo; use RedBeanPHP\Repository\Fluid as FluidRepo;
use RedBeanPHP\Repository\Frozen as FrozenRepo; use RedBeanPHP\Repository\Frozen as FrozenRepo;
use RedBeanPHP\RedException as RedException;
/** /**
* Toolbox * Toolbox
@ -29,6 +29,22 @@ use RedBeanPHP\Repository\Frozen as FrozenRepo;
*/ */
class Toolbox extends Blackhole { class Toolbox extends Blackhole {
/**
* Github issue #458, selectDatabase causes PHP notice undefined index
* if database key not found.
*
* @return void
*/
public function testInvalidDB()
{
try {
R::selectDatabase( 'idontexist' );
fail();
} catch ( RedException $exception ) {
pass();
}
}
/** /**
* Test whether we can obtain a toolbox properly. * Test whether we can obtain a toolbox properly.
* *

View File

@ -107,8 +107,8 @@ class Setget extends \RedUNIT\CUBRID
asrt( setget( "NULL" ), "NULL" ); asrt( setget( "NULL" ), "NULL" );
asrt( setget( "NULL" ), "NULL" ); asrt( setget( "NULL" ), "NULL" );
asrt( setget( "0123", 1 ), "0123" ); asrt( setget( "0123" ), "0123" );
asrt( setget( "0000123", 1 ), "0000123" ); asrt( setget( "0000123" ), "0000123" );
asrt( setget( NULL ), NULL ); asrt( setget( NULL ), NULL );

View File

@ -47,7 +47,6 @@ class Writer extends \RedUNIT\CUBRID
asrt( $writer->code( $cols['special'], FALSE ), CUBRID::C_DATATYPE_SPECIFIED ); asrt( $writer->code( $cols['special'], FALSE ), CUBRID::C_DATATYPE_SPECIFIED );
} }
} }

View File

@ -276,7 +276,6 @@ class Foreignkeys extends Mysql
//Now add non-dep key //Now add non-dep key
R::nuke(); R::nuke();
$sql = ' $sql = '
CREATE TABLE book ( CREATE TABLE book (
id INT( 11 ) UNSIGNED NULL AUTO_INCREMENT, id INT( 11 ) UNSIGNED NULL AUTO_INCREMENT,
@ -363,7 +362,6 @@ class Foreignkeys extends Mysql
$writer->addIndex('song', 'index1', 'album_id'); $writer->addIndex('song', 'index1', 'album_id');
$indexes = R::getAll( 'SHOW INDEX FROM song' ); $indexes = R::getAll( 'SHOW INDEX FROM song' );
asrt( count( $indexes ), 2 ); asrt( count( $indexes ), 2 );
@ -379,7 +377,6 @@ class Foreignkeys extends Mysql
asrt( count( $indexes ), 3 ); asrt( count( $indexes ), 3 );
//Dont fail, just dont //Dont fail, just dont
try { try {
$writer->addIndex('song', 'index3', 'nonexistant'); $writer->addIndex('song', 'index3', 'nonexistant');

View File

@ -55,6 +55,3 @@ class Issue411 extends Mysql
} }
} }

View File

@ -145,6 +145,3 @@ class Mix extends Mysql
} }
} }

View File

@ -48,6 +48,11 @@ class Setget extends Mysql
asrt( setget( "1.0" ), "1" ); asrt( setget( "1.0" ), "1" );
asrt( setget( 1.0 ), "1" ); asrt( setget( 1.0 ), "1" );
asrt( setget( "3.20" ), "3.20" );
asrt( setget( "13.20" ), "13.20" );
asrt( setget( "134.20" ), "134.20" );
asrt( setget( 3.21 ), '3.21' );
asrt( setget( "0.12345678" ), "0.12345678" ); asrt( setget( "0.12345678" ), "0.12345678" );
asrt( setget( 0.12345678 ), "0.12345678" ); asrt( setget( 0.12345678 ), "0.12345678" );
@ -133,8 +138,8 @@ class Setget extends Mysql
asrt( setget( "NULL" ), "NULL" ); asrt( setget( "NULL" ), "NULL" );
asrt( setget( "NULL" ), "NULL" ); asrt( setget( "NULL" ), "NULL" );
asrt( setget( "0123", 1 ), "0123" ); asrt( setget( "0123" ), "0123" );
asrt( setget( "0000123", 1 ), "0000123" ); asrt( setget( "0000123" ), "0000123" );
asrt( setget( NULL ), NULL ); asrt( setget( NULL ), NULL );

View File

@ -179,6 +179,10 @@ class Writer extends \RedUNIT\Mysql
asrt( $writer->scanType( "2001-10-10 10:00:00" ), MySQL::C_DATATYPE_TEXT7 ); asrt( $writer->scanType( "2001-10-10 10:00:00" ), MySQL::C_DATATYPE_TEXT7 );
asrt( $writer->scanType( "1.23", TRUE ), MySQL::C_DATATYPE_SPECIAL_MONEY );
asrt( $writer->scanType( "12.23", TRUE ), MySQL::C_DATATYPE_SPECIAL_MONEY );
asrt( $writer->scanType( "124.23", TRUE ), MySQL::C_DATATYPE_SPECIAL_MONEY );
asrt( $writer->scanType( str_repeat( "lorem ipsum", 100 ) ), MySQL::C_DATATYPE_TEXT16 ); asrt( $writer->scanType( str_repeat( "lorem ipsum", 100 ) ), MySQL::C_DATATYPE_TEXT16 );
$writer->widenColumn( "testtable", "c1", MySQL::C_DATATYPE_UINT32 ); $writer->widenColumn( "testtable", "c1", MySQL::C_DATATYPE_UINT32 );
@ -544,6 +548,37 @@ class Writer extends \RedUNIT\Mysql
asrt( $cols['date'], 'date' ); asrt( $cols['date'], 'date' );
} }
/**
* Test money types.
*
* @return void
*/
public function testTypesMon()
{
$bean = R::dispense( 'bean' );
$bean->amount = '22.99';
R::store( $bean );
$cols = R::getColumns( 'bean' );
asrt( $cols['amount'], 'decimal(10,2)' );
R::nuke();
$bean = R::dispense( 'bean' );
$bean->amount = '-22.99';
R::store( $bean );
$cols = R::getColumns( 'bean' );
asrt( $cols['amount'], 'decimal(10,2)' );
}
/** /**
* Date-time * Date-time
* *

View File

@ -35,6 +35,11 @@ class Setget extends Postgres
asrt( setget( "-0.25" ), "-0.25" ); asrt( setget( "-0.25" ), "-0.25" );
asrt( setget( -0.25 ), "-0.25" ); asrt( setget( -0.25 ), "-0.25" );
asrt( setget( "3.20" ), "3.20" );
asrt( setget( "13.20" ), "13.20" );
asrt( setget( "134.20" ), "134.20" );
asrt( setget( 3.21 ), '3.21' );
asrt( setget( "0.12345678" ), "0.12345678" ); asrt( setget( "0.12345678" ), "0.12345678" );
asrt( setget( 0.12345678 ), "0.12345678" ); asrt( setget( 0.12345678 ), "0.12345678" );

View File

@ -171,7 +171,6 @@ class Uuid extends Postgres
$id = R::store( $mansion ); $id = R::store( $mansion );
//exit; //exit;
asrt( is_string( $id ), TRUE ); asrt( is_string( $id ), TRUE );
asrt( strlen( $id ), 36 ); asrt( strlen( $id ), 36 );
$haunted = R::load( 'mansion', $id ); $haunted = R::load( 'mansion', $id );

View File

@ -500,6 +500,36 @@ class Writer extends Postgres
asrt( $bean->circle, '<(9.2,1.2),7.9>' ); asrt( $bean->circle, '<(9.2,1.2),7.9>' );
} }
/**
* Test money types.
*
* @return void
*/
public function testTypesMon()
{
$bean = R::dispense( 'bean' );
$bean->amount = '22.99';
R::store( $bean );
$cols = R::getColumns( 'bean' );
asrt( $cols['amount'], 'numeric' );
R::nuke();
$bean = R::dispense( 'bean' );
$bean->amount = '-22.99';
R::store( $bean );
$cols = R::getColumns( 'bean' );
asrt( $cols['amount'], 'numeric' );
}
/** /**
* Test money data type. * Test money data type.
* *

View File

@ -9,7 +9,6 @@ require 'RedUNIT.php';
require 'RedUNIT/Base.php'; require 'RedUNIT/Base.php';
require 'RedUNIT/Base/Performance.php'; require 'RedUNIT/Base/Performance.php';
error_reporting( E_ALL ); error_reporting( E_ALL );
//Load configuration file //Load configuration file
@ -19,7 +18,6 @@ if ( file_exists( 'config/test.ini' ) ) {
die( 'Cant find configuration file.' ); die( 'Cant find configuration file.' );
} }
//Configure the databases //Configure the databases
if ( isset( $ini['mysql'] ) ) { if ( isset( $ini['mysql'] ) ) {
$dsn = "mysql:host={$ini['mysql']['host']};dbname={$ini['mysql']['schema']}"; $dsn = "mysql:host={$ini['mysql']['host']};dbname={$ini['mysql']['schema']}";
@ -52,8 +50,6 @@ $test = new \RedUNIT\Base\Performance();
$drivers = $test->getTargetDrivers(); $drivers = $test->getTargetDrivers();
foreach ( $drivers as $driver ) { foreach ( $drivers as $driver ) {
if ( !isset( $ini[$driver] ) ) continue; if ( !isset( $ini[$driver] ) ) continue;

View File

@ -2,7 +2,6 @@
chdir( '..' ); chdir( '..' );
$xdebugSupported = (function_exists('xdebug_start_code_coverage')); $xdebugSupported = (function_exists('xdebug_start_code_coverage'));
if ($xdebugSupported) xdebug_start_code_coverage( XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE ); if ($xdebugSupported) xdebug_start_code_coverage( XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE );
@ -26,7 +25,6 @@ echo '*** RedUNIT ***'.PHP_EOL;
echo 'Welcome to RedUNIT Unit testing framework for RedBeanPHP.'.PHP_EOL; echo 'Welcome to RedUNIT Unit testing framework for RedBeanPHP.'.PHP_EOL;
echo PHP_EOL; echo PHP_EOL;
/** /**
* Define some globals. * Define some globals.
*/ */
@ -44,7 +42,6 @@ require_once( 'RedUNIT/Mysql.php' );
require_once( 'RedUNIT/Postgres.php' ); require_once( 'RedUNIT/Postgres.php' );
require_once( 'RedUNIT/Sqlite.php' ); require_once( 'RedUNIT/Sqlite.php' );
require_once( 'RedUNIT/Pretest.php' ); require_once( 'RedUNIT/Pretest.php' );
$extraTestsFromHook = array(); $extraTestsFromHook = array();
@ -91,7 +88,6 @@ function activate_driver( $d )
R::selectDatabase( $d ); R::selectDatabase( $d );
} }
$arguments = $_SERVER['argc']; $arguments = $_SERVER['argc'];
$mode = 'all'; $mode = 'all';
@ -198,8 +194,6 @@ $suffix = array(
'Base/Close' 'Base/Close'
); );
// Default (mode == all) // Default (mode == all)
if ( $mode == 'all' ) { if ( $mode == 'all' ) {
$packList = $allPacks; $packList = $allPacks;
@ -237,6 +231,9 @@ foreach ( $packList as $testPack ) {
maintestpack( str_replace( '_', ' ', get_class( $test ) ) ); maintestpack( str_replace( '_', ' ', get_class( $test ) ) );
$round = 0;
$test->setRound( $round );
if ( $drivers && is_array( $drivers ) ) { if ( $drivers && is_array( $drivers ) ) {
foreach ( $drivers as $driver ) { foreach ( $drivers as $driver ) {
if ( !isset( $ini[$driver] ) ) continue; if ( !isset( $ini[$driver] ) ) continue;
@ -267,6 +264,7 @@ foreach ( $packList as $testPack ) {
} }
echo PHP_EOL; echo PHP_EOL;
$test->setRound( ++$round );
} }
} else { } else {
@ -276,7 +274,6 @@ foreach ( $packList as $testPack ) {
} }
} }
if (!$xdebugSupported) { if (!$xdebugSupported) {
echo 'Done. No report - XDEBUG not installed.'; echo 'Done. No report - XDEBUG not installed.';
exit(0); exit(0);

View File

@ -409,7 +409,6 @@ class Model_PageWidget extends RedBean_SimpleModel {
} }
} }
/** /**
* Mock class to test proper model name * Mock class to test proper model name
* beautificattion for link table beans in FUSE. * beautificattion for link table beans in FUSE.
@ -484,7 +483,6 @@ class Model_Feed extends \RedbeanPHP\SimpleModel {
} }
} }
/** /**
* UUID QueryWriter for MySQL for testing purposes. * UUID QueryWriter for MySQL for testing purposes.
*/ */
@ -664,10 +662,8 @@ class DiagnosticModel extends \RedBeanPHP\SimpleModel
return $this->logs[$logIndex]['data'][$property]; return $this->logs[$logIndex]['data'][$property];
} }
} }
class Model_Probe extends DiagnosticModel {}; class Model_Probe extends DiagnosticModel {};
define('REDBEAN_OODBBEAN_CLASS', '\DiagnosticBean'); define('REDBEAN_OODBBEAN_CLASS', '\DiagnosticBean');

View File

@ -400,7 +400,6 @@ function getIndexes( $tableNoQ )
return array(); return array();
} }
function are_cols_in_unique( $type, $properties ) function are_cols_in_unique( $type, $properties )
{ {
sort( $properties ); sort( $properties );
@ -414,7 +413,6 @@ function are_cols_in_unique( $type, $properties )
return FALSE; return FALSE;
} }
function get_uniques_for_type( $type ) function get_uniques_for_type( $type )
{ {
$list = array(); $list = array();

View File

@ -5,6 +5,8 @@ namespace DeepCopy;
use DeepCopy\Exception\CloneException; use DeepCopy\Exception\CloneException;
use DeepCopy\Filter\Filter; use DeepCopy\Filter\Filter;
use DeepCopy\Matcher\Matcher; use DeepCopy\Matcher\Matcher;
use DeepCopy\TypeFilter\TypeFilter;
use DeepCopy\TypeMatcher\TypeMatcher;
use ReflectionProperty; use ReflectionProperty;
use DeepCopy\Reflection\ReflectionHelper; use DeepCopy\Reflection\ReflectionHelper;
@ -24,6 +26,12 @@ class DeepCopy
*/ */
private $filters = []; private $filters = [];
/**
* Type Filters to apply.
* @var array
*/
private $typeFilters = [];
private $skipUncloneable = false; private $skipUncloneable = false;
/** /**
@ -39,8 +47,8 @@ class DeepCopy
/** /**
* Perform a deep copy of the object. * Perform a deep copy of the object.
* @param object $object * @param mixed $object
* @return object * @return mixed
*/ */
public function copy($object) public function copy($object)
{ {
@ -57,8 +65,22 @@ class DeepCopy
]; ];
} }
public function addTypeFilter(TypeFilter $filter, TypeMatcher $matcher)
{
$this->typeFilters[] = [
'matcher' => $matcher,
'filter' => $filter,
];
}
private function recursiveCopy($var) private function recursiveCopy($var)
{ {
// Matches Type Filter
if ($filter = $this->getFirstMatchedTypeFilter($this->typeFilters, $var)) {
return $filter->apply($var);
}
// Resource // Resource
if (is_resource($var)) { if (is_resource($var)) {
return $var; return $var;
@ -159,4 +181,43 @@ class DeepCopy
// Copy the property // Copy the property
$property->setValue($object, $this->recursiveCopy($propertyValue)); $property->setValue($object, $this->recursiveCopy($propertyValue));
} }
/**
* Returns first filter that matches variable, NULL if no such filter found.
* @param array $filterRecords Associative array with 2 members: 'filter' with value of type {@see TypeFilter} and
* 'matcher' with value of type {@see TypeMatcher}
* @param mixed $var
* @return TypeFilter|null
*/
private function getFirstMatchedTypeFilter(array $filterRecords, $var)
{
$matched = $this->first(
$filterRecords,
function (array $record) use ($var) {
/* @var TypeMatcher $matcher */
$matcher = $record['matcher'];
return $matcher->matches($var);
}
);
return isset($matched) ? $matched['filter'] : null;
}
/**
* Returns first element that matches predicate, NULL if no such element found.
* @param array $elements
* @param callable $predicate Predicate arguments are: element.
* @return mixed|null
*/
private function first(array $elements, callable $predicate)
{
foreach ($elements as $element) {
if (call_user_func($predicate, $element)) {
return $element;
}
}
return null;
}
} }

View File

@ -6,6 +6,9 @@ use ReflectionProperty;
/** /**
* Match a property by its type * Match a property by its type
*
* @deprecated It is recommended to use {@see DeepCopy\TypeFilter\TypeFilter} instead, as it applies on all occurrences
* of given type in copied context (eg. array elements), not just on object properties.
*/ */
class PropertyTypeMatcher implements Matcher class PropertyTypeMatcher implements Matcher
{ {

View File

@ -2,6 +2,12 @@
All notable changes of the PHP_CodeCoverage 3.0 release series are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. All notable changes of the PHP_CodeCoverage 3.0 release series are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [3.0.2] - 2015-11-12
### Changed
* It is now optional that `@deprecated` code is ignored
## [3.0.1] - 2015-10-06 ## [3.0.1] - 2015-10-06
### Fixed ### Fixed
@ -19,6 +25,7 @@ All notable changes of the PHP_CodeCoverage 3.0 release series are documented in
* The blacklist functionality has been removed * The blacklist functionality has been removed
* PHP_CodeCoverage is no longer supported on PHP 5.3, PHP 5.4, and PHP 5.5 * PHP_CodeCoverage is no longer supported on PHP 5.3, PHP 5.4, and PHP 5.5
[3.0.2]: https://github.com/sebastianbergmann/php-code-coverage/compare/3.0.1...3.0.2
[3.0.1]: https://github.com/sebastianbergmann/php-code-coverage/compare/3.0.0...3.0.1 [3.0.1]: https://github.com/sebastianbergmann/php-code-coverage/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/sebastianbergmann/php-code-coverage/compare/2.2...3.0.0 [3.0.0]: https://github.com/sebastianbergmann/php-code-coverage/compare/2.2...3.0.0

View File

@ -57,6 +57,11 @@ class PHP_CodeCoverage
*/ */
private $processUncoveredFilesFromWhitelist = false; private $processUncoveredFilesFromWhitelist = false;
/**
* @var bool
*/
private $ignoreDeprecatedCode = false;
/** /**
* @var mixed * @var mixed
*/ */
@ -486,6 +491,23 @@ class PHP_CodeCoverage
$this->disableIgnoredLines = $flag; $this->disableIgnoredLines = $flag;
} }
/**
* @param bool $flag
* @throws PHP_CodeCoverage_InvalidArgumentException
* @since Method available since Release 3.0.2
*/
public function setIgnoreDeprecatedCode($flag)
{
if (!is_bool($flag)) {
throw PHP_CodeCoverage_InvalidArgumentException::create(
1,
'boolean'
);
}
$this->ignoreDeprecatedCode = $flag;
}
/** /**
* Applies the @covers annotation filtering. * Applies the @covers annotation filtering.
* *
@ -732,7 +754,7 @@ class PHP_CodeCoverage
$this->ignoredLines[$filename][] = $token->getLine(); $this->ignoredLines[$filename][] = $token->getLine();
if (strpos($docblock, '@codeCoverageIgnore') || strpos($docblock, '@deprecated')) { if (strpos($docblock, '@codeCoverageIgnore') || ($this->ignoreDeprecatedCode && strpos($docblock, '@deprecated'))) {
$endLine = $token->getEndLine(); $endLine = $token->getEndLine();
for ($i = $token->getLine(); $i <= $endLine; $i++) { for ($i = $token->getLine(); $i <= $endLine; $i++) {

View File

@ -58,7 +58,7 @@ abstract class PHP_CodeCoverage_Report_HTML_Renderer
*/ */
public function __construct($templatePath, $generator, $date, $lowUpperBound, $highLowerBound) public function __construct($templatePath, $generator, $date, $lowUpperBound, $highLowerBound)
{ {
$version = new SebastianBergmann\Version('3.0.1', dirname(dirname(dirname(dirname(__DIR__))))); $version = new SebastianBergmann\Version('3.0.2', dirname(dirname(dirname(dirname(__DIR__)))));
$this->templatePath = $templatePath; $this->templatePath = $templatePath;
$this->generator = $generator; $this->generator = $generator;

View File

@ -238,6 +238,28 @@ class PHP_CodeCoverageTest extends PHP_CodeCoverage_TestCase
$this->coverage->setMapTestClassNameToCoveredClassName(null); $this->coverage->setMapTestClassNameToCoveredClassName(null);
} }
/**
* @covers PHP_CodeCoverage::setIgnoreDeprecatedCode
*/
public function testSetIgnoreDeprecatedCode()
{
$this->coverage->setIgnoreDeprecatedCode(true);
$this->assertAttributeEquals(
true,
'ignoreDeprecatedCode',
$this->coverage
);
}
/**
* @covers PHP_CodeCoverage::setIgnoreDeprecatedCode
* @expectedException PHP_CodeCoverage_Exception
*/
public function testSetIgnoreDeprecatedCodeThrowsExceptionForInvalidArgument()
{
$this->coverage->setIgnoreDeprecatedCode(null);
}
/** /**
* @covers PHP_CodeCoverage::clear * @covers PHP_CodeCoverage::clear
*/ */

View File

@ -100,13 +100,7 @@ class PHPUnit_Framework_MockObject_InvocationMocker implements PHPUnit_Framework
{ {
$exception = null; $exception = null;
$hasReturnValue = false; $hasReturnValue = false;
if (strtolower($invocation->methodName) == '__tostring') {
$hasReturnValue = true;
$returnValue = '';
} else {
$returnValue = null; $returnValue = null;
}
foreach ($this->matchers as $match) { foreach ($this->matchers as $match) {
try { try {
@ -129,6 +123,8 @@ class PHPUnit_Framework_MockObject_InvocationMocker implements PHPUnit_Framework
if ($hasReturnValue) { if ($hasReturnValue) {
return $returnValue; return $returnValue;
} elseif (strtolower($invocation->methodName) == '__tostring') {
return '';
} }
return $invocation->generateReturnValue(); return $invocation->generateReturnValue();

View File

@ -841,4 +841,12 @@ class Framework_MockObjectTest extends PHPUnit_Framework_TestCase
$this->assertInternalType('string', (string) $mock); $this->assertInternalType('string', (string) $mock);
} }
public function testStringableClassCanBeMocked()
{
$mock = $this->getMock('StringableClass');
$mock->method('__toString')->willReturn('foo');
$this->assertSame('foo', (string) $mock);
}
} }

View File

@ -61,7 +61,6 @@ Please use the most specific issue tracker to search for existing tickets and to
* [Code Coverage](https://github.com/sebastianbergmann/php-code-coverage/issues) * [Code Coverage](https://github.com/sebastianbergmann/php-code-coverage/issues)
* [Stub and Mock Objects](https://github.com/sebastianbergmann/phpunit-mock-objects/issues) * [Stub and Mock Objects](https://github.com/sebastianbergmann/phpunit-mock-objects/issues)
* [DbUnit](https://github.com/sebastianbergmann/dbunit/issues) * [DbUnit](https://github.com/sebastianbergmann/dbunit/issues)
* [PHPUnit_Selenium](https://github.com/sebastianbergmann/phpunit-selenium/issues)
* [Documentation](https://github.com/sebastianbergmann/phpunit-documentation/issues) * [Documentation](https://github.com/sebastianbergmann/phpunit-documentation/issues)
* [Website](https://github.com/sebastianbergmann/phpunit-website/issues) * [Website](https://github.com/sebastianbergmann/phpunit-website/issues)

View File

@ -2,6 +2,36 @@
All notable changes of the PHPUnit 4.8 release series are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. All notable changes of the PHPUnit 4.8 release series are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [4.8.17] - 2015-11-10
### Fixed
* Fixed [#1935](https://github.com/sebastianbergmann/phpunit/issues/1935): `PHP_CodeCoverage_Exception` not handled properly
* Fixed [#1948](https://github.com/sebastianbergmann/phpunit/issues/1948): Unable to use PHAR due to unsupported signature error
### Changed
* DbUnit >= 2.0.2 is now bundled in the PHAR distribution
## [4.8.16] - 2015-10-23
### Added
* Implemented [#1925](https://github.com/sebastianbergmann/phpunit/issues/1925): Provide a library-only PHAR
## [4.8.15] - 2015-10-22
### Fixed
* The backup of global state is now properly restored when changes to global state are disallowed
* The `__PHPUNIT_PHAR__` constant is now properly set when the PHPUnit PHAR is used as a library
## [4.8.14] - 2015-10-17
### Fixed
* Fixed [#1892](https://github.com/sebastianbergmann/phpunit/issues/1892): `--coverage-text` does not honor color settings
## [4.8.13] - 2015-10-14 ## [4.8.13] - 2015-10-14
### Added ### Added
@ -101,6 +131,10 @@ New PHAR release due to updated dependencies
* Made the argument check of `assertContains()` and `assertNotContains()` more strict to prevent undefined behavior such as [#1808](https://github.com/sebastianbergmann/phpunit/issues/1808) * Made the argument check of `assertContains()` and `assertNotContains()` more strict to prevent undefined behavior such as [#1808](https://github.com/sebastianbergmann/phpunit/issues/1808)
* Changed the name of the default group from `__nogroup__` to `default` * Changed the name of the default group from `__nogroup__` to `default`
[4.8.17]: https://github.com/sebastianbergmann/phpunit/compare/4.8.16...4.8.17
[4.8.16]: https://github.com/sebastianbergmann/phpunit/compare/4.8.15...4.8.16
[4.8.15]: https://github.com/sebastianbergmann/phpunit/compare/4.8.14...4.8.15
[4.8.14]: https://github.com/sebastianbergmann/phpunit/compare/4.8.13...4.8.14
[4.8.13]: https://github.com/sebastianbergmann/phpunit/compare/4.8.12...4.8.13 [4.8.13]: https://github.com/sebastianbergmann/phpunit/compare/4.8.12...4.8.13
[4.8.12]: https://github.com/sebastianbergmann/phpunit/compare/4.8.11...4.8.12 [4.8.12]: https://github.com/sebastianbergmann/phpunit/compare/4.8.11...4.8.12
[4.8.11]: https://github.com/sebastianbergmann/phpunit/compare/4.8.10...4.8.11 [4.8.11]: https://github.com/sebastianbergmann/phpunit/compare/4.8.10...4.8.11

View File

@ -2,6 +2,35 @@
All notable changes of the PHPUnit 5.0 release series are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. All notable changes of the PHPUnit 5.0 release series are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [5.0.9] - 2015-11-10
### Added
* Merged [#1909](https://github.com/sebastianbergmann/phpunit/issues/1909): Added `flowId` parameter to each TeamCity message (for parallel tests)
### Fixed
* Fixed [#1935](https://github.com/sebastianbergmann/phpunit/issues/1935): `PHP_CodeCoverage_Exception` not handled properly
* Fixed [#1944](https://github.com/sebastianbergmann/phpunit/issues/1944): Exceptions are not handled correctly on PHP 7 when an exception is expected
* Fixed [#1948](https://github.com/sebastianbergmann/phpunit/issues/1948): Unable to use PHAR due to unsupported signature error
### Removed
* Removed leftover references to PHPUnit_Selenium
## [5.0.8] - 2015-10-23
### Added
* Implemented [#1925](https://github.com/sebastianbergmann/phpunit/issues/1925): Provide a library-only PHAR
## [5.0.7] - 2015-10-22
### Fixed
* The backup of global state is now properly restored when changes to global state are disallowed
* The `__PHPUNIT_PHAR__` constant is now properly set when the PHPUnit PHAR is used as a library
## [5.0.6] - 2015-10-14 ## [5.0.6] - 2015-10-14
### Added ### Added
@ -78,6 +107,9 @@ All notable changes of the PHPUnit 5.0 release series are documented in this fil
* The PHPUnit_Selenium component can no longer be configured using the `<selenium/browser>` element of PHPUnit's configuration file * The PHPUnit_Selenium component can no longer be configured using the `<selenium/browser>` element of PHPUnit's configuration file
* PHPUnit is no longer supported on PHP 5.3, PHP 5.4, and PHP 5.5 * PHPUnit is no longer supported on PHP 5.3, PHP 5.4, and PHP 5.5
[5.0.9]: https://github.com/sebastianbergmann/phpunit/compare/5.0.8...5.0.9
[5.0.8]: https://github.com/sebastianbergmann/phpunit/compare/5.0.7...5.0.8
[5.0.7]: https://github.com/sebastianbergmann/phpunit/compare/5.0.6...5.0.7
[5.0.6]: https://github.com/sebastianbergmann/phpunit/compare/5.0.5...5.0.6 [5.0.6]: https://github.com/sebastianbergmann/phpunit/compare/5.0.5...5.0.6
[5.0.5]: https://github.com/sebastianbergmann/phpunit/compare/5.0.4...5.0.5 [5.0.5]: https://github.com/sebastianbergmann/phpunit/compare/5.0.4...5.0.5
[5.0.4]: https://github.com/sebastianbergmann/phpunit/compare/5.0.3...5.0.4 [5.0.4]: https://github.com/sebastianbergmann/phpunit/compare/5.0.3...5.0.4

View File

@ -42,6 +42,12 @@
<arg value="${basedir}/phpunit --version | awk 'BEGIN { ORS = &quot;&quot;; } {print $2}'" /> <arg value="${basedir}/phpunit --version | awk 'BEGIN { ORS = &quot;&quot;; } {print $2}'" />
</exec> </exec>
<exec executable="gpg" failonerror="true">
<arg value="--armor" />
<arg value="--detach-sign" />
<arg path="${basedir}/build/phpunit-library-${version}.phar" />
</exec>
<exec executable="gpg" failonerror="true"> <exec executable="gpg" failonerror="true">
<arg value="--armor" /> <arg value="--armor" />
<arg value="--detach-sign" /> <arg value="--detach-sign" />
@ -253,15 +259,31 @@
<arg value="${version}" /> <arg value="${version}" />
</exec> </exec>
<exec executable="phpab"> <exec executable="${basedir}/build/bin/phpab">
<arg value="--all" />
<arg value="--static" />
<arg value="--once" />
<arg value="--phar" />
<arg value="--hash" />
<arg value="SHA-1" />
<arg value="--output" />
<arg path="${basedir}/build/phpunit-library-${_version}.phar" />
<arg value="--template" />
<arg path="${basedir}/build/library-phar-autoload.php.in" />
<arg path="${basedir}/build/phar" />
</exec>
<exec executable="${basedir}/build/bin/phpab">
<arg value="--all" /> <arg value="--all" />
<arg value="--nolower" /> <arg value="--nolower" />
<arg value="--static" /> <arg value="--static" />
<arg value="--phar" /> <arg value="--phar" />
<arg value="--hash" />
<arg value="SHA-1" />
<arg value="--output" /> <arg value="--output" />
<arg path="${basedir}/build/phpunit-${_version}.phar" /> <arg path="${basedir}/build/phpunit-${_version}.phar" />
<arg value="--template" /> <arg value="--template" />
<arg path="${basedir}/build/phar-autoload.php.in" /> <arg path="${basedir}/build/binary-phar-autoload.php.in" />
<arg path="${basedir}/build/phar" /> <arg path="${basedir}/build/phar" />
</exec> </exec>

View File

@ -215,7 +215,6 @@
<xs:attribute name="timeoutForSmallTests" type="xs:integer" default="1"/> <xs:attribute name="timeoutForSmallTests" type="xs:integer" default="1"/>
<xs:attribute name="timeoutForMediumTests" type="xs:integer" default="10"/> <xs:attribute name="timeoutForMediumTests" type="xs:integer" default="10"/>
<xs:attribute name="timeoutForLargeTests" type="xs:integer" default="60"/> <xs:attribute name="timeoutForLargeTests" type="xs:integer" default="60"/>
<xs:attribute name="strict" type="xs:boolean" default="false"/>
<xs:attribute name="testSuiteLoaderClass" type="xs:string" default="PHPUnit_Runner_StandardTestSuiteLoader"/> <xs:attribute name="testSuiteLoaderClass" type="xs:string" default="PHPUnit_Runner_StandardTestSuiteLoader"/>
<xs:attribute name="testSuiteLoaderFile" type="xs:anyURI"/> <xs:attribute name="testSuiteLoaderFile" type="xs:anyURI"/>
<xs:attribute name="verbose" type="xs:boolean" default="false"/> <xs:attribute name="verbose" type="xs:boolean" default="false"/>

View File

@ -54,9 +54,9 @@ class PHPUnit_Framework_Constraint_Exception extends PHPUnit_Framework_Constrain
{ {
if ($other !== null) { if ($other !== null) {
$message = ''; $message = '';
if ($other instanceof Exception) { if ($other instanceof Exception || $other instanceof Throwable) {
$message = '. Message was: "' . $other->getMessage() . '" at' $message = '. Message was: "' . $other->getMessage() . '" at'
. "\n" . $other->getTraceAsString(); . "\n" . PHPUnit_Util_Filter::getFilteredStacktrace($other);
} }
return sprintf( return sprintf(

View File

@ -629,7 +629,6 @@ abstract class PHPUnit_Framework_TestCase extends PHPUnit_Framework_Assert imple
if ($this->runTestInSeparateProcess === true && if ($this->runTestInSeparateProcess === true &&
$this->inIsolation !== true && $this->inIsolation !== true &&
!$this instanceof PHPUnit_Extensions_SeleniumTestCase &&
!$this instanceof PHPUnit_Extensions_PhptTestCase) { !$this instanceof PHPUnit_Extensions_PhptTestCase) {
$class = new ReflectionClass($this); $class = new ReflectionClass($this);
@ -1352,7 +1351,7 @@ abstract class PHPUnit_Framework_TestCase extends PHPUnit_Framework_Assert imple
} }
/** /**
* Returns a mock object for the specified class. * Returns a mock with disabled constructor object for the specified class.
* *
* @param string $originalClassName * @param string $originalClassName
* *
@ -2103,10 +2102,14 @@ abstract class PHPUnit_Framework_TestCase extends PHPUnit_Framework_Assert imple
$backupGlobals = $this->backupGlobals === null || $this->backupGlobals === true; $backupGlobals = $this->backupGlobals === null || $this->backupGlobals === true;
if ($this->beStrictAboutChangesToGlobalState) { if ($this->beStrictAboutChangesToGlobalState) {
try {
$this->compareGlobalStateSnapshots( $this->compareGlobalStateSnapshots(
$this->snapshot, $this->snapshot,
$this->createGlobalStateSnapshot($backupGlobals) $this->createGlobalStateSnapshot($backupGlobals)
); );
} catch (PHPUnit_Framework_RiskyTestError $rte) {
// Intentionally left empty
}
} }
$restorer = new Restorer; $restorer = new Restorer;
@ -2120,6 +2123,10 @@ abstract class PHPUnit_Framework_TestCase extends PHPUnit_Framework_Assert imple
} }
$this->snapshot = null; $this->snapshot = null;
if (isset($rte)) {
throw $rte;
}
} }
/** /**

View File

@ -574,7 +574,6 @@ class PHPUnit_Framework_TestResult implements Countable
} }
$collectCodeCoverage = $this->codeCoverage !== null && $collectCodeCoverage = $this->codeCoverage !== null &&
!$test instanceof PHPUnit_Extensions_SeleniumTestCase &&
!$test instanceof PHPUnit_Framework_Warning; !$test instanceof PHPUnit_Framework_Warning;
if ($collectCodeCoverage) { if ($collectCodeCoverage) {

View File

@ -30,7 +30,7 @@ class PHPUnit_Runner_Version
} }
if (self::$version === null) { if (self::$version === null) {
$version = new SebastianBergmann\Version('5.0.6', dirname(dirname(__DIR__))); $version = new SebastianBergmann\Version('5.0.9', dirname(dirname(__DIR__)));
self::$version = $version->getVersion(); self::$version = $version->getVersion();
} }
@ -44,7 +44,7 @@ class PHPUnit_Runner_Version
*/ */
public static function series() public static function series()
{ {
return join('.', array_slice(explode('.', self::id()), 0, 2)); return implode('.', array_slice(explode('.', self::id()), 0, 2));
} }
/** /**

View File

@ -437,11 +437,17 @@ class PHPUnit_TextUI_TestRunner extends PHPUnit_Runner_BaseTestRunner
"\nGenerating code coverage report in Clover XML format ..." "\nGenerating code coverage report in Clover XML format ..."
); );
try {
$writer = new PHP_CodeCoverage_Report_Clover; $writer = new PHP_CodeCoverage_Report_Clover;
$writer->process($codeCoverage, $arguments['coverageClover']); $writer->process($codeCoverage, $arguments['coverageClover']);
$this->printer->write(" done\n"); $this->printer->write(" done\n");
unset($writer); unset($writer);
} catch (PHP_CodeCoverage_Exception $e) {
$this->printer->write(
" failed\n" . $e->getMessage() . "\n"
);
}
} }
if (isset($arguments['coverageCrap4J'])) { if (isset($arguments['coverageCrap4J'])) {
@ -449,11 +455,17 @@ class PHPUnit_TextUI_TestRunner extends PHPUnit_Runner_BaseTestRunner
"\nGenerating Crap4J report XML file ..." "\nGenerating Crap4J report XML file ..."
); );
try {
$writer = new PHP_CodeCoverage_Report_Crap4j($arguments['crap4jThreshold']); $writer = new PHP_CodeCoverage_Report_Crap4j($arguments['crap4jThreshold']);
$writer->process($codeCoverage, $arguments['coverageCrap4J']); $writer->process($codeCoverage, $arguments['coverageCrap4J']);
$this->printer->write(" done\n"); $this->printer->write(" done\n");
unset($writer); unset($writer);
} catch (PHP_CodeCoverage_Exception $e) {
$this->printer->write(
" failed\n" . $e->getMessage() . "\n"
);
}
} }
if (isset($arguments['coverageHtml'])) { if (isset($arguments['coverageHtml'])) {
@ -461,11 +473,12 @@ class PHPUnit_TextUI_TestRunner extends PHPUnit_Runner_BaseTestRunner
"\nGenerating code coverage report in HTML format ..." "\nGenerating code coverage report in HTML format ..."
); );
try {
$writer = new PHP_CodeCoverage_Report_HTML( $writer = new PHP_CodeCoverage_Report_HTML(
$arguments['reportLowUpperBound'], $arguments['reportLowUpperBound'],
$arguments['reportHighLowerBound'], $arguments['reportHighLowerBound'],
sprintf( sprintf(
' and <a href="http://phpunit.de/">PHPUnit %s</a>', ' and <a href="https://phpunit.de/">PHPUnit %s</a>',
PHPUnit_Runner_Version::id() PHPUnit_Runner_Version::id()
) )
); );
@ -474,6 +487,11 @@ class PHPUnit_TextUI_TestRunner extends PHPUnit_Runner_BaseTestRunner
$this->printer->write(" done\n"); $this->printer->write(" done\n");
unset($writer); unset($writer);
} catch (PHP_CodeCoverage_Exception $e) {
$this->printer->write(
" failed\n" . $e->getMessage() . "\n"
);
}
} }
if (isset($arguments['coveragePHP'])) { if (isset($arguments['coveragePHP'])) {
@ -481,11 +499,17 @@ class PHPUnit_TextUI_TestRunner extends PHPUnit_Runner_BaseTestRunner
"\nGenerating code coverage report in PHP format ..." "\nGenerating code coverage report in PHP format ..."
); );
try {
$writer = new PHP_CodeCoverage_Report_PHP; $writer = new PHP_CodeCoverage_Report_PHP;
$writer->process($codeCoverage, $arguments['coveragePHP']); $writer->process($codeCoverage, $arguments['coveragePHP']);
$this->printer->write(" done\n"); $this->printer->write(" done\n");
unset($writer); unset($writer);
} catch (PHP_CodeCoverage_Exception $e) {
$this->printer->write(
" failed\n" . $e->getMessage() . "\n"
);
}
} }
if (isset($arguments['coverageText'])) { if (isset($arguments['coverageText'])) {
@ -514,11 +538,17 @@ class PHPUnit_TextUI_TestRunner extends PHPUnit_Runner_BaseTestRunner
"\nGenerating code coverage report in PHPUnit XML format ..." "\nGenerating code coverage report in PHPUnit XML format ..."
); );
try {
$writer = new PHP_CodeCoverage_Report_XML; $writer = new PHP_CodeCoverage_Report_XML;
$writer->process($codeCoverage, $arguments['coverageXml']); $writer->process($codeCoverage, $arguments['coverageXml']);
$this->printer->write(" done\n"); $this->printer->write(" done\n");
unset($writer); unset($writer);
} catch (PHP_CodeCoverage_Exception $e) {
$this->printer->write(
" failed\n" . $e->getMessage() . "\n"
);
}
} }
} }

View File

@ -27,7 +27,6 @@ class PHPUnit_Util_Blacklist
'PHPUnit_Framework_TestCase' => 2, 'PHPUnit_Framework_TestCase' => 2,
'PHPUnit_Extensions_Database_TestCase' => 2, 'PHPUnit_Extensions_Database_TestCase' => 2,
'PHPUnit_Framework_MockObject_Generator' => 2, 'PHPUnit_Framework_MockObject_Generator' => 2,
'PHPUnit_Extensions_SeleniumTestCase' => 2,
'Text_Template' => 1, 'Text_Template' => 1,
'Symfony\Component\Yaml\Yaml' => 1, 'Symfony\Component\Yaml\Yaml' => 1,
'SebastianBergmann\Diff\Diff' => 1, 'SebastianBergmann\Diff\Diff' => 1,

View File

@ -23,7 +23,7 @@ class PHPUnit_Util_Filter
* *
* @return string * @return string
*/ */
public static function getFilteredStacktrace(Exception $e, $asString = true) public static function getFilteredStacktrace($e, $asString = true)
{ {
$prefix = false; $prefix = false;
$script = realpath($GLOBALS['_SERVER']['SCRIPT_NAME']); $script = realpath($GLOBALS['_SERVER']['SCRIPT_NAME']);

View File

@ -28,6 +28,11 @@ class PHPUnit_Util_Log_TeamCity extends PHPUnit_TextUI_ResultPrinter
*/ */
private $startedTestName; private $startedTestName;
/**
* @var string
*/
private $flowId;
/** /**
* @param string $progress * @param string $progress
*/ */
@ -166,6 +171,12 @@ class PHPUnit_Util_Log_TeamCity extends PHPUnit_TextUI_ResultPrinter
*/ */
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
{ {
if (stripos(ini_get('disable_functions'), 'getmypid') === false) {
$this->flowId = getmypid();
} else {
$this->flowId = false;
}
if (!$this->isSummaryTestCountPrinted) { if (!$this->isSummaryTestCountPrinted) {
$this->isSummaryTestCountPrinted = true; $this->isSummaryTestCountPrinted = true;
@ -272,6 +283,10 @@ class PHPUnit_Util_Log_TeamCity extends PHPUnit_TextUI_ResultPrinter
{ {
$this->write("\n##teamcity[$eventName"); $this->write("\n##teamcity[$eventName");
if ($this->flowId) {
$params['flowId'] = $this->flowId;
}
foreach ($params as $key => $value) { foreach ($params as $key => $value) {
$escapedValue = self::escapeValue($value); $escapedValue = self::escapeValue($value);
$this->write(" $key='$escapedValue'"); $this->write(" $key='$escapedValue'");

Some files were not shown because too many files have changed in this diff Show More