Upgraded to Symfony 2.1-beta2

This commit is contained in:
Polonkai Gergely
2012-07-15 14:56:31 +02:00
parent c1232c9792
commit bb7aee6fee
455 changed files with 21001 additions and 18480 deletions

4
vendor/autoload.php vendored
View File

@@ -5,8 +5,6 @@ if (!class_exists('Composer\\Autoload\\ClassLoader', false)) {
require __DIR__ . '/composer' . '/ClassLoader.php';
}
require __DIR__ . '/swiftmailer/swiftmailer/lib/swift_required.php';
return call_user_func(function() {
$loader = new \Composer\Autoload\ClassLoader();
$composerDir = __DIR__ . '/composer';
@@ -23,5 +21,7 @@ return call_user_func(function() {
$loader->register();
require __DIR__ . '/swiftmailer/swiftmailer/lib/swift_required.php';
return $loader;
});

View File

@@ -102,7 +102,7 @@ class ClassLoader
/**
* Turns on searching the include path for class files.
*
* @param Boolean $useIncludePath
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
@@ -113,7 +113,7 @@ class ClassLoader
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return Boolean
* @return bool
*/
public function getUseIncludePath()
{
@@ -123,7 +123,7 @@ class ClassLoader
/**
* Registers this instance as an autoloader.
*
* @param Boolean $prepend Whether to prepend the autoloader or not
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
@@ -141,8 +141,8 @@ class ClassLoader
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return Boolean|null True, if loaded
* @param string $class The name of the class
* @return bool|null True, if loaded
*/
public function loadClass($class)
{

View File

@@ -3,7 +3,7 @@
"name": "jms/metadata",
"version": "1.1.1",
"version_normalized": "1.1.1.0",
"time": "2011-12-31 21:32:49",
"time": "2011-12-30 10:32:49",
"source": {
"type": "git",
"url": "https://github.com/schmittjoh/metadata",
@@ -47,7 +47,7 @@
"name": "jms/cg",
"version": "1.0.0",
"version_normalized": "1.0.0.0",
"time": "2011-12-31 20:40:52",
"time": "2011-12-30 09:40:52",
"source": {
"type": "git",
"url": "git://github.com/schmittjoh/cg-library.git",
@@ -89,7 +89,7 @@
"version": "1.0.0",
"version_normalized": "1.0.0.0",
"target-dir": "JMS/AopBundle",
"time": "2011-12-31 20:50:26",
"time": "2011-12-30 09:50:26",
"source": {
"type": "git",
"url": "https://github.com/schmittjoh/JMSAopBundle",
@@ -133,7 +133,7 @@
"version": "1.1.0",
"version_normalized": "1.1.0.0",
"target-dir": "JMS/SecurityExtraBundle",
"time": "2012-01-01 00:38:12",
"time": "2011-12-30 13:38:12",
"source": {
"type": "git",
"url": "https://github.com/schmittjoh/JMSSecurityExtraBundle",
@@ -178,7 +178,7 @@
"version": "1.0.1",
"version_normalized": "1.0.1.0",
"target-dir": "JMS/DiExtraBundle",
"time": "2012-02-26 16:01:54",
"time": "2012-02-25 05:01:54",
"source": {
"type": "git",
"url": "https://github.com/schmittjoh/JMSDiExtraBundle",
@@ -221,7 +221,7 @@
"name": "doctrine/common",
"version": "2.2.2",
"version_normalized": "2.2.2.0",
"time": "2012-04-11 01:46:44",
"time": "2012-04-08 03:46:44",
"source": {
"type": "git",
"url": "https://github.com/doctrine/common",
@@ -287,7 +287,7 @@
"name": "monolog/monolog",
"version": "1.1.0",
"version_normalized": "1.1.0.0",
"time": "2012-04-21 12:27:40",
"time": "2012-04-18 14:27:40",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/monolog.git",
@@ -337,7 +337,7 @@
"name": "twig/extensions",
"version": "dev-master",
"version_normalized": "9999999-dev",
"time": "2012-05-19 19:28:19",
"time": "2012-05-16 21:28:19",
"source": {
"type": "git",
"url": "https://github.com/fabpot/Twig-extensions",
@@ -378,70 +378,11 @@
}
}
},
{
"name": "symfony/monolog-bundle",
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Symfony/Bundle/MonologBundle",
"time": "2012-06-13 05:14:37",
"source": {
"type": "git",
"url": "https://github.com/symfony/MonologBundle",
"reference": "0b5046d3d1ef93cd59ceabfa37de2665f5118c7f"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/MonologBundle/zipball/0b5046d3d1ef93cd59ceabfa37de2665f5118c7f",
"reference": "0b5046d3d1ef93cd59ceabfa37de2665f5118c7f",
"shasum": ""
},
"require": {
"php": ">=5.3.2",
"monolog/monolog": "1.*",
"symfony/monolog-bridge": "2.1.*",
"symfony/dependency-injection": "2.1.*",
"symfony/config": "2.1.*"
},
"require-dev": {
"symfony/yaml": "2.1.*"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
}
},
"installation-source": "source",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": null,
"role": null
},
{
"name": "Symfony Community",
"email": null,
"homepage": "http://symfony.com/contributors",
"role": null
}
],
"description": "Symfony MonologBundle",
"homepage": "http://symfony.com",
"autoload": {
"psr-0": {
"Symfony\\Bundle\\MonologBundle": ""
}
}
},
{
"name": "kriswallsmith/assetic",
"version": "dev-master",
"version_normalized": "9999999-dev",
"time": "2012-06-10 23:41:54",
"time": "2012-06-08 01:41:54",
"source": {
"type": "git",
"url": "http://github.com/kriswallsmith/assetic.git",
@@ -497,132 +438,221 @@
}
},
{
"name": "doctrine/orm",
"version": "2.2.x-dev",
"version_normalized": "2.2.9999999.9999999-dev",
"time": "2012-05-26 01:13:46",
"name": "sensio/generator-bundle",
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Sensio/Bundle/GeneratorBundle",
"time": "2012-06-15 18:40:45",
"source": {
"type": "git",
"url": "git://github.com/doctrine/doctrine2.git",
"reference": "5f66c65c9a8d984899903b54215d0249a45b92d6"
"url": "https://github.com/sensio/SensioGeneratorBundle",
"reference": "43ed45c48db18e4a0e48aec0c098f42e56e22d36"
},
"dist": {
"type": "zip",
"url": "https://github.com/doctrine/doctrine2/zipball/5f66c65c9a8d984899903b54215d0249a45b92d6",
"reference": "5f66c65c9a8d984899903b54215d0249a45b92d6",
"url": "https://github.com/sensio/SensioGeneratorBundle/zipball/43ed45c48db18e4a0e48aec0c098f42e56e22d36",
"reference": "43ed45c48db18e4a0e48aec0c098f42e56e22d36",
"shasum": ""
},
"require": {
"php": ">=5.3.2",
"ext-pdo": "*",
"doctrine/common": "2.2.*",
"doctrine/dbal": "2.2.*"
"symfony/framework-bundle": "2.1.*"
},
"require-dev": {
"symfony/doctrine-bridge": "2.1.*",
"doctrine/orm": ">=2.1,<2.4-dev",
"twig/twig": ">=1.8,<2.0-dev"
},
"suggest": {
"doctrine/doctrine-bundle": "to generate entities and their crud controller"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
}
},
"type": "library",
"installation-source": "source",
"license": [
"LGPL"
"MIT"
],
"authors": [
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com",
"homepage": "http://www.jwage.com/",
"role": null
},
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com",
"homepage": null,
"role": null
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org",
"homepage": null,
"role": null
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de",
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": null,
"role": null
}
],
"description": "Object-Relational-Mapper for PHP",
"homepage": "http://www.doctrine-project.org",
"keywords": [
"database",
"orm"
],
"description": "This bundle generates code for you",
"autoload": {
"psr-0": {
"Doctrine\\ORM": "lib/"
"Sensio\\Bundle\\GeneratorBundle": ""
}
}
},
{
"name": "doctrine/dbal",
"version": "2.2.x-dev",
"version_normalized": "2.2.9999999.9999999-dev",
"time": "2012-05-25 20:08:36",
"name": "symfony/assetic-bundle",
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Symfony/Bundle/AsseticBundle",
"time": "2012-06-16 23:29:31",
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal",
"reference": "8cc129aa64a8de6447056bce20f0a274fe2a340b"
"url": "https://github.com/symfony/AsseticBundle",
"reference": "8fe7b898b08103c1d6fce64c3e279a7afd61adfc"
},
"dist": {
"type": "zip",
"url": "https://github.com/doctrine/dbal/zipball/8cc129aa64a8de6447056bce20f0a274fe2a340b",
"reference": "8cc129aa64a8de6447056bce20f0a274fe2a340b",
"url": "https://github.com/symfony/AsseticBundle/zipball/8fe7b898b08103c1d6fce64c3e279a7afd61adfc",
"reference": "8fe7b898b08103c1d6fce64c3e279a7afd61adfc",
"shasum": ""
},
"require": {
"php": ">=5.3.0",
"symfony/framework-bundle": "2.1.*",
"kriswallsmith/assetic": "1.1.*"
},
"suggest": {
"symfony/twig-bundle": "2.1.*"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
}
},
"installation-source": "source",
"license": [
"MIT"
],
"authors": [
{
"name": "Kris Wallsmith",
"email": "kris.wallsmith@gmail.com",
"homepage": "http://kriswallsmith.net/",
"role": null
}
],
"description": "Integrates Assetic into Symfony2",
"homepage": "https://github.com/symfony/AsseticBundle",
"keywords": [
"assets",
"compression",
"minification"
],
"autoload": {
"psr-0": {
"Symfony\\Bundle\\AsseticBundle": ""
}
}
},
{
"name": "symfony/monolog-bundle",
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Symfony/Bundle/MonologBundle",
"time": "2012-06-28 15:48:07",
"source": {
"type": "git",
"url": "https://github.com/symfony/MonologBundle",
"reference": "7fe7f711bb04b86ad7f45a9e11a7f8cbaf9bc1a5"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/MonologBundle/zipball/7fe7f711bb04b86ad7f45a9e11a7f8cbaf9bc1a5",
"reference": "7fe7f711bb04b86ad7f45a9e11a7f8cbaf9bc1a5",
"shasum": ""
},
"require": {
"php": ">=5.3.2",
"doctrine/common": ">=2.2.0,<=2.2.99"
"monolog/monolog": "1.*",
"symfony/monolog-bridge": "2.1.*",
"symfony/dependency-injection": "2.1.*",
"symfony/config": "2.1.*"
},
"require-dev": {
"symfony/yaml": "2.1.*",
"symfony/config": "2.1.*"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
}
},
"type": "library",
"installation-source": "source",
"license": [
"LGPL"
"MIT"
],
"authors": [
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com",
"homepage": "http://www.jwage.com/",
"role": null
},
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com",
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": null,
"role": null
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org",
"homepage": null,
"name": "Symfony Community",
"email": null,
"homepage": "http://symfony.com/contributors",
"role": null
},
}
],
"description": "Symfony MonologBundle",
"homepage": "http://symfony.com",
"autoload": {
"psr-0": {
"Symfony\\Bundle\\MonologBundle": ""
}
}
},
{
"name": "sensio/framework-extra-bundle",
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Sensio/Bundle/FrameworkExtraBundle",
"time": "2012-06-29 05:03:39",
"source": {
"type": "git",
"url": "https://github.com/sensio/SensioFrameworkExtraBundle",
"reference": "4f54e5d5fb3b54fb107892684018f3704934c48d"
},
"dist": {
"type": "zip",
"url": "https://github.com/sensio/SensioFrameworkExtraBundle/zipball/4f54e5d5fb3b54fb107892684018f3704934c48d",
"reference": "4f54e5d5fb3b54fb107892684018f3704934c48d",
"shasum": ""
},
"require": {
"doctrine/common": ">=2.1,<2.4-dev",
"symfony/framework-bundle": "2.1.*"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
}
},
"installation-source": "source",
"license": [
"MIT"
],
"authors": [
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de",
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": null,
"role": null
}
],
"description": "Database Abstraction Layer",
"homepage": "http://www.doctrine-project.org",
"description": "This bundle provides a way to configure your controllers with annotations",
"keywords": [
"database",
"persistence",
"dbal",
"queryobject"
"annotations",
"controllers"
],
"autoload": {
"psr-0": {
"Doctrine\\DBAL": "lib/"
"Sensio\\Bundle\\FrameworkExtraBundle": ""
}
}
},
@@ -630,16 +660,16 @@
"name": "twig/twig",
"version": "dev-master",
"version_normalized": "9999999-dev",
"time": "2012-06-16 08:52:23",
"time": "2012-07-03 15:33:25",
"source": {
"type": "git",
"url": "git://github.com/fabpot/Twig.git",
"reference": "4679ad51c5390648b7ea4c8f0ecd2c0c344145ba"
"reference": "26eb0a2653eade50dffdd31b11ca454232dea8cf"
},
"dist": {
"type": "zip",
"url": "https://github.com/fabpot/Twig/zipball/4679ad51c5390648b7ea4c8f0ecd2c0c344145ba",
"reference": "4679ad51c5390648b7ea4c8f0ecd2c0c344145ba",
"url": "https://github.com/fabpot/Twig/zipball/26eb0a2653eade50dffdd31b11ca454232dea8cf",
"reference": "26eb0a2653eade50dffdd31b11ca454232dea8cf",
"shasum": ""
},
"require": {
@@ -648,7 +678,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.8-dev"
"dev-master": "1.9-dev"
}
},
"installation-source": "source",
@@ -685,16 +715,16 @@
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Doctrine/Bundle/DoctrineBundle",
"time": "2012-06-18 06:36:07",
"time": "2012-07-03 10:42:17",
"source": {
"type": "git",
"url": "git://github.com/doctrine/DoctrineBundle.git",
"reference": "94951737d6c692500d6b13bb92871935568a4ba5"
"reference": "c9ea46d1f0c48bb88bb87b44214fe44e03c0c692"
},
"dist": {
"type": "zip",
"url": "https://github.com/doctrine/DoctrineBundle/zipball/94951737d6c692500d6b13bb92871935568a4ba5",
"reference": "94951737d6c692500d6b13bb92871935568a4ba5",
"url": "https://github.com/doctrine/DoctrineBundle/zipball/c9ea46d1f0c48bb88bb87b44214fe44e03c0c692",
"reference": "c9ea46d1f0c48bb88bb87b44214fe44e03c0c692",
"shasum": ""
},
"require": {
@@ -755,191 +785,37 @@
}
}
},
{
"name": "sensio/generator-bundle",
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Sensio/Bundle/GeneratorBundle",
"time": "2012-06-18 16:40:45",
"source": {
"type": "git",
"url": "https://github.com/sensio/SensioGeneratorBundle",
"reference": "43ed45c48db18e4a0e48aec0c098f42e56e22d36"
},
"dist": {
"type": "zip",
"url": "https://github.com/sensio/SensioGeneratorBundle/zipball/43ed45c48db18e4a0e48aec0c098f42e56e22d36",
"reference": "43ed45c48db18e4a0e48aec0c098f42e56e22d36",
"shasum": ""
},
"require": {
"symfony/framework-bundle": "2.1.*"
},
"require-dev": {
"symfony/doctrine-bridge": "2.1.*",
"doctrine/orm": ">=2.1,<2.4-dev",
"twig/twig": ">=1.8,<2.0-dev"
},
"suggest": {
"doctrine/doctrine-bundle": "to generate entities and their crud controller"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
}
},
"installation-source": "source",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": null,
"role": null
}
],
"description": "This bundle generates code for you",
"autoload": {
"psr-0": {
"Sensio\\Bundle\\GeneratorBundle": ""
}
}
},
{
"name": "sensio/framework-extra-bundle",
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Sensio/Bundle/FrameworkExtraBundle",
"time": "2012-06-18 10:41:18",
"source": {
"type": "git",
"url": "https://github.com/sensio/SensioFrameworkExtraBundle",
"reference": "62e41b85947034b0f1dfe31bb8e76920e1488571"
},
"dist": {
"type": "zip",
"url": "https://github.com/sensio/SensioFrameworkExtraBundle/zipball/62e41b85947034b0f1dfe31bb8e76920e1488571",
"reference": "62e41b85947034b0f1dfe31bb8e76920e1488571",
"shasum": ""
},
"require": {
"doctrine/common": ">=2.1,<2.4-dev",
"symfony/framework-bundle": "2.1.*"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
}
},
"installation-source": "source",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": null,
"role": null
}
],
"description": "This bundle provides a way to configure your controllers with annotations",
"keywords": [
"annotations",
"controllers"
],
"autoload": {
"psr-0": {
"Sensio\\Bundle\\FrameworkExtraBundle": ""
}
}
},
{
"name": "symfony/assetic-bundle",
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Symfony/Bundle/AsseticBundle",
"time": "2012-06-19 21:29:31",
"source": {
"type": "git",
"url": "https://github.com/symfony/AsseticBundle",
"reference": "8fe7b898b08103c1d6fce64c3e279a7afd61adfc"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/AsseticBundle/zipball/8fe7b898b08103c1d6fce64c3e279a7afd61adfc",
"reference": "8fe7b898b08103c1d6fce64c3e279a7afd61adfc",
"shasum": ""
},
"require": {
"php": ">=5.3.0",
"symfony/framework-bundle": "2.1.*",
"kriswallsmith/assetic": "1.1.*"
},
"suggest": {
"symfony/twig-bundle": "2.1.*"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
}
},
"installation-source": "source",
"license": [
"MIT"
],
"authors": [
{
"name": "Kris Wallsmith",
"email": "kris.wallsmith@gmail.com",
"homepage": "http://kriswallsmith.net/",
"role": null
}
],
"description": "Integrates Assetic into Symfony2",
"homepage": "https://github.com/symfony/AsseticBundle",
"keywords": [
"assets",
"compression",
"minification"
],
"autoload": {
"psr-0": {
"Symfony\\Bundle\\AsseticBundle": ""
}
}
},
{
"name": "symfony/swiftmailer-bundle",
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Symfony/Bundle/SwiftmailerBundle",
"time": "2012-06-18 20:25:44",
"time": "2012-07-04 15:33:34",
"source": {
"type": "git",
"url": "https://github.com/symfony/SwiftmailerBundle",
"reference": "d05c9c514a631ee688c53c4cc5505da757bd50d3"
"reference": "e1d413ce27fd1696bdc82ad9525f1b874664530e"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/SwiftmailerBundle/zipball/d05c9c514a631ee688c53c4cc5505da757bd50d3",
"reference": "d05c9c514a631ee688c53c4cc5505da757bd50d3",
"url": "https://github.com/symfony/SwiftmailerBundle/zipball/e1d413ce27fd1696bdc82ad9525f1b874664530e",
"reference": "e1d413ce27fd1696bdc82ad9525f1b874664530e",
"shasum": ""
},
"require": {
"php": ">=5.3.2",
"symfony/swiftmailer-bridge": "self.version",
"swiftmailer/swiftmailer": ">=4.1.8,<4.2-dev"
"symfony/swiftmailer-bridge": "2.1.*",
"swiftmailer/swiftmailer": ">=4.2.0,<4.3-dev"
},
"require-dev": {
"symfony/dependency-injection": "2.1.*",
"symfony/http-kernel": "2.1.*",
"symfony/config": "2.1.*"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
"dev-master": "2.1-dev"
}
},
"installation-source": "source",
@@ -969,19 +845,84 @@
}
},
{
"name": "swiftmailer/swiftmailer",
"version": "dev-master",
"version_normalized": "9999999-dev",
"time": "2012-06-20 14:46:20",
"name": "doctrine/orm",
"version": "2.2.x-dev",
"version_normalized": "2.2.9999999.9999999-dev",
"time": "2012-07-07 07:48:00",
"source": {
"type": "git",
"url": "git://github.com/swiftmailer/swiftmailer.git",
"reference": "d57ffdeed664d6061cef0047e1f5d3fc3ee3fb99"
"url": "git://github.com/doctrine/doctrine2.git",
"reference": "5d2a3bcb3b467f41ee58575764f3ba84937f76e4"
},
"dist": {
"type": "zip",
"url": "https://github.com/swiftmailer/swiftmailer/zipball/d57ffdeed664d6061cef0047e1f5d3fc3ee3fb99",
"reference": "d57ffdeed664d6061cef0047e1f5d3fc3ee3fb99",
"url": "https://github.com/doctrine/doctrine2/zipball/5d2a3bcb3b467f41ee58575764f3ba84937f76e4",
"reference": "5d2a3bcb3b467f41ee58575764f3ba84937f76e4",
"shasum": ""
},
"require": {
"php": ">=5.3.2",
"ext-pdo": "*",
"doctrine/common": "2.2.*",
"doctrine/dbal": "2.2.*"
},
"type": "library",
"installation-source": "source",
"license": [
"LGPL"
],
"authors": [
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com",
"homepage": "http://www.jwage.com/",
"role": null
},
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com",
"homepage": null,
"role": null
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org",
"homepage": null,
"role": null
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de",
"homepage": null,
"role": null
}
],
"description": "Object-Relational-Mapper for PHP",
"homepage": "http://www.doctrine-project.org",
"keywords": [
"database",
"orm"
],
"autoload": {
"psr-0": {
"Doctrine\\ORM": "lib/"
}
}
},
{
"name": "swiftmailer/swiftmailer",
"version": "dev-master",
"version_normalized": "9999999-dev",
"time": "2012-07-08 09:21:00",
"source": {
"type": "git",
"url": "git://github.com/swiftmailer/swiftmailer.git",
"reference": "f51b5f33c83b48faea75f1285f99a2e8f1c66f75"
},
"dist": {
"type": "zip",
"url": "https://github.com/swiftmailer/swiftmailer/zipball/f51b5f33c83b48faea75f1285f99a2e8f1c66f75",
"reference": "f51b5f33c83b48faea75f1285f99a2e8f1c66f75",
"shasum": ""
},
"require": {
@@ -990,7 +931,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.1-dev"
"dev-master": "4.2-dev"
}
},
"installation-source": "source",
@@ -1024,19 +965,84 @@
}
},
{
"name": "symfony/symfony",
"version": "dev-master",
"version_normalized": "9999999-dev",
"time": "2012-06-21 09:42:20",
"name": "doctrine/dbal",
"version": "2.2.x-dev",
"version_normalized": "2.2.9999999.9999999-dev",
"time": "2012-07-08 18:30:35",
"source": {
"type": "git",
"url": "git://github.com/symfony/symfony.git",
"reference": "v2.1.0-BETA1"
"url": "https://github.com/doctrine/dbal",
"reference": "b961a3fce6bf220f1dca47d7d747b9074bea4730"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/symfony/zipball/v2.1.0-BETA1",
"reference": "v2.1.0-BETA1",
"url": "https://github.com/doctrine/dbal/zipball/b961a3fce6bf220f1dca47d7d747b9074bea4730",
"reference": "b961a3fce6bf220f1dca47d7d747b9074bea4730",
"shasum": ""
},
"require": {
"php": ">=5.3.2",
"doctrine/common": ">=2.2.0,<=2.2.99"
},
"type": "library",
"installation-source": "source",
"license": [
"LGPL"
],
"authors": [
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com",
"homepage": "http://www.jwage.com/",
"role": null
},
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com",
"homepage": null,
"role": null
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org",
"homepage": null,
"role": null
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de",
"homepage": null,
"role": null
}
],
"description": "Database Abstraction Layer",
"homepage": "http://www.doctrine-project.org",
"keywords": [
"database",
"persistence",
"dbal",
"queryobject"
],
"autoload": {
"psr-0": {
"Doctrine\\DBAL": "lib/"
}
}
},
{
"name": "symfony/symfony",
"version": "dev-master",
"version_normalized": "9999999-dev",
"time": "2012-07-09 05:52:38",
"source": {
"type": "git",
"url": "git://github.com/symfony/symfony.git",
"reference": "v2.1.0-BETA2"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/symfony/zipball/v2.1.0-BETA2",
"reference": "v2.1.0-BETA2",
"shasum": ""
},
"require": {
@@ -1129,16 +1135,16 @@
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Sensio/Bundle/DistributionBundle",
"time": "2012-06-21 15:12:48",
"time": "2012-07-08 08:02:21",
"source": {
"type": "git",
"url": "https://github.com/sensio/SensioDistributionBundle",
"reference": "a360ad61fe34206a7295c1ef00b5455b2b2e1071"
"reference": "9a7dbd867fd5061e4bfd660a175aa66122f53d25"
},
"dist": {
"type": "zip",
"url": "https://github.com/sensio/SensioDistributionBundle/zipball/a360ad61fe34206a7295c1ef00b5455b2b2e1071",
"reference": "a360ad61fe34206a7295c1ef00b5455b2b2e1071",
"url": "https://github.com/sensio/SensioDistributionBundle/zipball/9a7dbd867fd5061e4bfd660a175aa66122f53d25",
"reference": "9a7dbd867fd5061e4bfd660a175aa66122f53d25",
"shasum": ""
},
"require": {

View File

@@ -280,7 +280,7 @@ class SQLServerPlatform extends AbstractPlatform
$columnSql = array();
if ($diff->newName !== false) {
$queryParts[] = 'RENAME TO ' . $diff->newName;
$queryParts[] = "sp_RENAME '" . $diff->name . "', '" . $diff->newName . "'";
}
foreach ($diff->addedColumns AS $fieldName => $column) {

View File

@@ -61,10 +61,10 @@ class SQLParserUtils
} else {
$name = "";
// TODO: Something faster/better to match this than regex?
for ($j = $i; ($j < $stmtLen && preg_match('(([:a-zA-Z0-9_]{1}))', $statement[$j])); $j++) {
for ($j = $i + 1; ($j < $stmtLen && preg_match('(([a-zA-Z0-9_]{1}))', $statement[$j])); $j++) {
$name .= $statement[$j];
}
$paramMap[$name][] = $i; // named parameters can be duplicated!
$paramMap[$i] = $name; // named parameters can be duplicated!
$i = $j;
}
++$count;
@@ -139,34 +139,28 @@ class SQLParserUtils
$queryOffset= 0;
$typesOrd = array();
$paramsOrd = array();
foreach ($paramPos as $needle => $needlePos) {
$paramLen = strlen($needle);
$token = substr($needle,0,1);
$needle = substr($needle,1);
$value = $params[$needle];
foreach ($paramPos as $pos => $paramName) {
$paramLen = strlen($paramName) + 1;
$value = $params[$paramName];
if (!isset($arrayPositions[$needle])) {
foreach ($needlePos as $pos) {
$pos += $queryOffset;
$queryOffset -= ($paramLen - 1);
$paramsOrd[] = $value;
$typesOrd[] = $types[$needle];
$query = substr($query, 0, $pos) . '?' . substr($query, ($pos + $paramLen));
}
if (!isset($arrayPositions[$paramName])) {
$pos += $queryOffset;
$queryOffset -= ($paramLen - 1);
$paramsOrd[] = $value;
$typesOrd[] = $types[$paramName];
$query = substr($query, 0, $pos) . '?' . substr($query, ($pos + $paramLen));
} else {
$len = count($value);
$expandStr = implode(", ", array_fill(0, $len, "?"));
foreach ($needlePos as $pos) {
foreach ($value as $val) {
$paramsOrd[] = $val;
$typesOrd[] = $types[$needle] - Connection::ARRAY_PARAM_OFFSET;
}
$pos += $queryOffset;
$queryOffset += (strlen($expandStr) - $paramLen);
$query = substr($query, 0, $pos) . $expandStr . substr($query, ($pos + $paramLen));
foreach ($value as $val) {
$paramsOrd[] = $val;
$typesOrd[] = $types[$paramName] - Connection::ARRAY_PARAM_OFFSET;
}
$pos += $queryOffset;
$queryOffset += (strlen($expandStr) - $paramLen);
$query = substr($query, 0, $pos) . $expandStr . substr($query, ($pos + $paramLen));
}
}

View File

@@ -77,6 +77,14 @@ class Index extends AbstractAsset implements Constraint
return $this->_columns;
}
/**
* @return array
*/
public function getUnquotedColumns()
{
return array_map(array($this, 'trimQuotes'), $this->getColumns());
}
/**
* Is the index neither unique nor primary key?
*
@@ -108,11 +116,11 @@ class Index extends AbstractAsset implements Constraint
* @param int $pos
* @return bool
*/
public function hasColumnAtPosition($columnName, $pos=0)
public function hasColumnAtPosition($columnName, $pos = 0)
{
$columnName = strtolower($columnName);
$indexColumns = \array_map('strtolower', $this->getColumns());
return \array_search($columnName, $indexColumns) === $pos;
$columnName = $this->trimQuotes(strtolower($columnName));
$indexColumns = array_map('strtolower', $this->getUnquotedColumns());
return array_search($columnName, $indexColumns) === $pos;
}
/**
@@ -125,7 +133,7 @@ class Index extends AbstractAsset implements Constraint
{
$sameColumns = true;
for ($i = 0; $i < count($this->_columns); $i++) {
if (!isset($columnNames[$i]) || strtolower($this->_columns[$i]) != strtolower($columnNames[$i])) {
if (!isset($columnNames[$i]) || $this->trimQuotes(strtolower($this->_columns[$i])) != $this->trimQuotes(strtolower($columnNames[$i]))) {
$sameColumns = false;
}
}
@@ -185,4 +193,4 @@ class Index extends AbstractAsset implements Constraint
}
return false;
}
}
}

View File

@@ -27,6 +27,9 @@ use Doctrine\DBAL\DriverManager;
*/
class CreateDatabaseDoctrineCommand extends DoctrineCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
$this
@@ -47,6 +50,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$connection = $this->getDoctrineConnection($input->getOption('connection'));

View File

@@ -24,6 +24,11 @@ use Doctrine\ORM\Tools\EntityGenerator;
*/
abstract class DoctrineCommand extends ContainerAwareCommand
{
/**
* get a doctrine entity generator
*
* @return EntityGenerator
*/
protected function getEntityGenerator()
{
$entityGenerator = new EntityGenerator();
@@ -37,6 +42,12 @@ abstract class DoctrineCommand extends ContainerAwareCommand
return $entityGenerator;
}
/**
* Get a doctrine entity manager by symfony name.
*
* @param string $name
* @return \Doctrine\ORM\EntityManager
*/
protected function getEntityManager($name)
{
return $this->getContainer()->get('doctrine')->getManager($name);
@@ -46,7 +57,7 @@ abstract class DoctrineCommand extends ContainerAwareCommand
* Get a doctrine dbal connection by symfony name.
*
* @param string $name
* @return Doctrine\DBAL\Connection
* @return \Doctrine\DBAL\Connection
*/
protected function getDoctrineConnection($name)
{

View File

@@ -26,6 +26,9 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class DropDatabaseDoctrineCommand extends DoctrineCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
$this
@@ -52,6 +55,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$connection = $this->getDoctrineConnection($input->getOption('connection'));

View File

@@ -29,6 +29,9 @@ use Doctrine\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory;
*/
class GenerateEntitiesDoctrineCommand extends DoctrineCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
$this
@@ -79,6 +82,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$manager = new DisconnectedMetadataFactory($this->getContainer()->get('doctrine'));

View File

@@ -31,6 +31,9 @@ use Doctrine\ORM\Tools\Console\MetadataFilter;
*/
class ImportMappingDoctrineCommand extends DoctrineCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
$this
@@ -65,6 +68,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));

View File

@@ -27,6 +27,9 @@ use Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand;
*/
class ClearMetadataCacheDoctrineCommand extends MetadataCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
parent::configure();
@@ -49,6 +52,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));

View File

@@ -27,6 +27,9 @@ use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand;
*/
class ClearQueryCacheDoctrineCommand extends QueryCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
parent::configure();
@@ -49,6 +52,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));

View File

@@ -27,6 +27,9 @@ use Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand;
*/
class ClearResultCacheDoctrineCommand extends ResultCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
parent::configure();
@@ -45,25 +48,13 @@ You can also optionally specify the <comment>--em</comment> option to specify
which entity manager to clear the cache for:
<info>php app/console doctrine:cache:clear-result --em=default</info>
If you don't want to clear all result cache you can specify some additional
options to control what cache is deleted:
<info>php app/console doctrine:cache:clear-result --id=cache_key</info>
Or you can specify a <comment>--regex</comment> to delete cache entries that
match it:
<info>php app/console doctrine:cache:clear-result --regex="user_(.*)"</info>
You can also specify a <comment>--prefix</comment> or
<comment>--suffix</comment> to delete cache entries for:
<info>php app/console doctrine:cache:clear-result --prefix="user_" --suffix="_frontend"</info>
EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));

View File

@@ -31,6 +31,9 @@ use Doctrine\ORM\Tools\Export\Driver\YamlExporter;
*/
class ConvertMappingDoctrineCommand extends ConvertMappingCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
parent::configure();
@@ -46,6 +49,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
@@ -53,9 +59,15 @@ EOT
return parent::execute($input, $output);
}
/**
* @param string $toType
* @param string $destPath
*
* @return \Doctrine\ORM\Tools\Export\Driver\AbstractExporter
*/
protected function getExporter($toType, $destPath)
{
/** @var $exporter \Doctrine\ORM\Tools\Export\Driver\AbstractExporter */
$exporter = parent::getExporter($toType, $destPath);
if ($exporter instanceof XmlExporter) {
$exporter->setExtension('.orm.xml');

View File

@@ -29,6 +29,9 @@ use Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand;
*/
class CreateSchemaDoctrineCommand extends CreateCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
parent::configure();
@@ -54,6 +57,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));

View File

@@ -13,7 +13,7 @@
*/
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
use Symfony\Component\Console\Application;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
@@ -33,12 +33,19 @@ abstract class DoctrineCommandHelper
*/
static public function setApplicationEntityManager(Application $application, $emName)
{
/** @var $em \Doctrine\ORM\EntityManager */
$em = $application->getKernel()->getContainer()->get('doctrine')->getManager($emName);
$helperSet = $application->getHelperSet();
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
$helperSet->set(new EntityManagerHelper($em), 'em');
}
/**
* Convenience method to push the helper sets of a given connection into the application.
*
* @param Application $application
* @param string $connName
*/
static public function setApplicationConnection(Application $application, $connName)
{
$connection = $application->getKernel()->getContainer()->get('doctrine')->getConnection($connName);

View File

@@ -28,6 +28,9 @@ use Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand;
*/
class DropSchemaDoctrineCommand extends DropCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
parent::configure();
@@ -54,6 +57,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));

View File

@@ -28,6 +28,9 @@ use Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand;
*/
class EnsureProductionSettingsDoctrineCommand extends EnsureProductionSettingsCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
parent::configure();
@@ -49,6 +52,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));

View File

@@ -27,6 +27,9 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class InfoDoctrineCommand extends InfoCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
$this
@@ -48,6 +51,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));

View File

@@ -28,6 +28,9 @@ use Doctrine\ORM\Tools\Console\Command\RunDqlCommand;
*/
class RunDqlDoctrineCommand extends RunDqlCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
parent::configure();
@@ -54,6 +57,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));

View File

@@ -28,6 +28,9 @@ use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand;
*/
class RunSqlDoctrineCommand extends RunSqlCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
parent::configure();
@@ -44,6 +47,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationConnection($this->getApplication(), $input->getOption('connection'));

View File

@@ -29,6 +29,9 @@ use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand;
*/
class UpdateSchemaDoctrineCommand extends UpdateCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
parent::configure();
@@ -58,6 +61,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));

View File

@@ -28,6 +28,9 @@ use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand as DoctrineValidate
*/
class ValidateSchemaCommand extends DoctrineValidateSchemaCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
parent::configure();
@@ -50,6 +53,9 @@ EOT
);
}
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));

View File

@@ -69,6 +69,9 @@ class ConnectionFactory
return $connection;
}
/**
* initialize the types
*/
private function initializeTypes()
{
foreach ($this->typesConfig as $type => $typeConfig) {

View File

@@ -35,6 +35,7 @@ class ProfilerController extends ContainerAware
*/
public function explainAction($token, $connectionName, $query)
{
/** @var $profiler \Symfony\Component\HttpKernel\Profiler\Profiler */
$profiler = $this->container->get('profiler');
$profiler->disable();

View File

@@ -41,9 +41,7 @@ class Configuration implements ConfigurationInterface
}
/**
* Generates the configuration tree builder.
*
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
@@ -56,6 +54,11 @@ class Configuration implements ConfigurationInterface
return $treeBuilder;
}
/**
* Add DBAL section to configuration tree
*
* @param ArrayNodeDefinition $node
*/
private function addDbalSection(ArrayNodeDefinition $node)
{
$node
@@ -105,6 +108,11 @@ class Configuration implements ConfigurationInterface
;
}
/**
* Return the dbal connections node
*
* @return ArrayNodeDefinition
*/
private function getDbalConnectionsNode()
{
$treeBuilder = new TreeBuilder();
@@ -157,7 +165,7 @@ class Configuration implements ConfigurationInterface
*
* These keys are available for slave configurations too.
*
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node
* @param ArrayNodeDefinition $node
*/
private function configureDbalDriverNode(ArrayNodeDefinition $node)
{
@@ -202,6 +210,11 @@ class Configuration implements ConfigurationInterface
;
}
/**
* Add the ORM section to configuration tree
*
* @param ArrayNodeDefinition $node
*/
private function addOrmSection(ArrayNodeDefinition $node)
{
$node
@@ -246,6 +259,11 @@ class Configuration implements ConfigurationInterface
;
}
/**
* Return ORM target entity resolver node
*
* @return \Symfony\Component\Config\Definition\Builder\NodeDefinition
*/
private function getOrmTargetEntityResolverNode()
{
$treeBuilder = new TreeBuilder();
@@ -261,6 +279,11 @@ class Configuration implements ConfigurationInterface
return $node;
}
/**
* Return ORM entity manager node
*
* @return ArrayNodeDefinition
*/
private function getOrmEntityManagersNode()
{
$treeBuilder = new TreeBuilder();
@@ -362,6 +385,13 @@ class Configuration implements ConfigurationInterface
return $node;
}
/**
* Return a ORM cache driver node for an given entity manager
*
* @param string $name
*
* @return ArrayNodeDefinition
*/
private function getOrmCacheDriverNode($name)
{
$treeBuilder = new TreeBuilder();

View File

@@ -32,6 +32,9 @@ use Symfony\Component\Config\FileLocator;
*/
class DoctrineExtension extends AbstractDoctrineExtension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = $this->getConfiguration($configs, $container);
@@ -377,6 +380,9 @@ class DoctrineExtension extends AbstractDoctrineExtension
$ormConfigDef->addMethodCall('setEntityNamespaces', array($this->aliasMap));
}
/**
* {@inheritDoc}
*/
protected function getObjectManagerElementName($name)
{
return 'doctrine.orm.'.$name;
@@ -387,11 +393,17 @@ class DoctrineExtension extends AbstractDoctrineExtension
return 'Entity';
}
/**
* {@inheritDoc}
*/
protected function getMappingResourceConfigDirectory()
{
return 'Resources/config/doctrine';
}
/**
* {@inheritDoc}
*/
protected function getMappingResourceExtension()
{
return 'orm';
@@ -411,9 +423,7 @@ class DoctrineExtension extends AbstractDoctrineExtension
}
/**
* Returns the base path for the XSD files.
*
* @return string The XSD base path
* {@inheritDoc}
*/
public function getXsdValidationBasePath()
{
@@ -421,15 +431,16 @@ class DoctrineExtension extends AbstractDoctrineExtension
}
/**
* Returns the namespace to be used for this extension (XML namespace).
*
* @return string The XML namespace
* {@inheritDoc}
*/
public function getNamespace()
{
return 'http://symfony.com/schema/dic/doctrine';
}
/**
* {@inheritDoc}
*/
public function getConfiguration(array $config, ContainerBuilder $container)
{
return new Configuration($container->getParameter('kernel.debug'));

View File

@@ -36,6 +36,9 @@ class DoctrineBundle extends Bundle
{
private $autoloader;
/**
* {@inheritDoc}
*/
public function build(ContainerBuilder $container)
{
parent::build($container);
@@ -48,6 +51,9 @@ class DoctrineBundle extends Bundle
$container->addCompilerPass(new DoctrineValidationPass('orm'));
}
/**
* {@inheritDoc}
*/
public function boot()
{
// Register an autoloader for proxies to avoid issues when unserializing them
@@ -66,9 +72,11 @@ class DoctrineBundle extends Bundle
if (!is_file($file) && $container->getParameter('kernel.debug')) {
$originalClassName = ClassUtils::getRealClass($class);
/** @var $registry Registry */
$registry = $container->get('doctrine');
// Tries to auto-generate the proxy file
/** @var $em \Doctrine\ORM\EntityManager */
foreach ($registry->getManagers() as $em) {
if ($em->getConfiguration()->getAutoGenerateProxyClasses()) {
@@ -94,6 +102,9 @@ class DoctrineBundle extends Bundle
}
}
/**
* {@inheritDoc}
*/
public function shutdown()
{
if (null !== $this->autoloader) {
@@ -102,6 +113,9 @@ class DoctrineBundle extends Bundle
}
}
/**
* {@inheritDoc}
*/
public function registerCommands(Application $application)
{
// Use the default logic when the ORM is available.

View File

@@ -45,6 +45,13 @@ class ManagerConfigurator
$this->enableFilters($entityManager);
}
/**
* Enable filters for an given entity manager
*
* @param EntityManager $entityManager
*
* @return null
*/
private function enableFilters(EntityManager $entityManager)
{
if (empty($this->enabledFilters)) {

View File

@@ -23,31 +23,51 @@ class ClassMetadataCollection
private $namespace;
private $metadata;
/**
* Constructor
*
* @param array $metadata
*/
public function __construct(array $metadata)
{
$this->metadata = $metadata;
}
/**
* @return array
*/
public function getMetadata()
{
return $this->metadata;
}
/**
* @param string $path
*/
public function setPath($path)
{
$this->path = $path;
}
/**
* @return string
*/
public function getPath()
{
return $this->path;
}
/**
* @param string $namespace
*/
public function setNamespace($namespace)
{
$this->namespace = $namespace;
}
/**
* @return string
*/
public function getNamespace()
{
return $this->namespace;

View File

@@ -19,6 +19,9 @@ namespace Doctrine\Bundle\DoctrineBundle\Mapping;
*/
class DisconnectedMetadataFactory extends MetadataFactory
{
/**
* @return string
*/
protected function getClassMetadataFactoryClass()
{
return 'Doctrine\\ORM\\Tools\\DisconnectedClassMetadataFactory';

View File

@@ -44,6 +44,7 @@ class MetadataFactory
* @param BundleInterface $bundle A BundleInterface instance
*
* @return ClassMetadataCollection A ClassMetadataCollection instance
* @throws \RuntimeException When bundle does not contain mapped entities
*/
public function getBundleMetadata(BundleInterface $bundle)
{
@@ -68,6 +69,7 @@ class MetadataFactory
* @param string $path The path where the class is stored (if known)
*
* @return ClassMetadataCollection A ClassMetadataCollection instance
* @throws MappingException When class is not valid entity or mapped superclass
*/
public function getClassMetadata($class, $path = null)
{
@@ -88,6 +90,7 @@ class MetadataFactory
* @param string $path The path where the class is stored (if known)
*
* @return ClassMetadataCollection A ClassMetadataCollection instance
* @throws \RuntimeException When namespace not contain mapped entities
*/
public function getNamespaceMetadata($namespace, $path = null)
{
@@ -105,8 +108,9 @@ class MetadataFactory
* Find and configure path and namespace for the metadata collection.
*
* @param ClassMetadataCollection $metadata
* @param string|null $path
* @return void
* @param string|null $path
*
* @throws \RuntimeException When unable to determine the path
*/
public function findNamespaceAndPathForMetadata(ClassMetadataCollection $metadata, $path = null)
{
@@ -122,11 +126,21 @@ class MetadataFactory
$metadata->setNamespace(isset($r) ? $r->getNamespaceName() : $all[0]->name);
}
/**
* Get a base path for a class
*
* @param string $name class name
* @param string $namespace class namespace
* @param string $path class path
*
* @return string
* @throws \RuntimeException When base path not found
*/
private function getBasePathForClass($name, $namespace, $path)
{
$namespace = str_replace('\\', '/', $namespace);
$search = str_replace('\\', '/', $path);
$destination = str_replace('/'.$namespace, '', $search, $c);
$destination = str_replace('/' . $namespace, '', $search, $c);
if ($c != 1) {
throw new \RuntimeException(sprintf('Can\'t find base path for "%s" (path: "%s", destination: "%s").', $name, $path, $destination));
@@ -135,6 +149,11 @@ class MetadataFactory
return $destination;
}
/**
* @param string $namespace
*
* @return ClassMetadataCollection
*/
private function getMetadataForNamespace($namespace)
{
$metadata = array();
@@ -147,6 +166,11 @@ class MetadataFactory
return new ClassMetadataCollection($metadata);
}
/**
* @param string $entity
*
* @return ClassMetadataCollection
*/
private function getMetadataForClass($entity)
{
foreach ($this->getAllMetadata() as $metadata) {
@@ -158,11 +182,15 @@ class MetadataFactory
return new ClassMetadataCollection(array());
}
/**
* @return array
*/
private function getAllMetadata()
{
$metadata = array();
foreach ($this->registry->getManagers() as $em) {
$class = $this->getClassMetadataFactoryClass();
/** @var $cmf \Doctrine\ORM\Mapping\ClassMetadataFactory */
$cmf = new $class();
$cmf->setEntityManager($em);
foreach ($cmf->getAllMetadata() as $m) {
@@ -173,6 +201,9 @@ class MetadataFactory
return $metadata;
}
/**
* @return string
*/
protected function getClassMetadataFactoryClass()
{
return 'Doctrine\\ORM\\Mapping\\ClassMetadataFactory';

View File

@@ -27,6 +27,15 @@ use Doctrine\ORM\EntityManager;
*/
class Registry extends ManagerRegistry implements RegistryInterface
{
/**
* Construct.
*
* @param ContainerInterface $container
* @param array $connections
* @param array $entityManagers
* @param string $defaultConnection
* @param string $defaultEntityManager
*/
public function __construct(ContainerInterface $container, array $connections, array $entityManagers, $defaultConnection, $defaultEntityManager)
{
$this->setContainer($container);

View File

@@ -150,7 +150,7 @@ certain classes, but those are for very advanced use-cases only.
Caching Drivers
~~~~~~~~~~~~~~~
For the caching drivers you can specify the values "array", "apc", "memcache"
For the caching drivers you can specify the values "array", "apc", "memcache", "memcached"
or "xcache".
The following example shows an overview of the caching configurations:

View File

@@ -37,6 +37,7 @@
"psr-0": { "Doctrine\\Bundle\\DoctrineBundle": "" }
},
"target-dir": "Doctrine/Bundle/DoctrineBundle",
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"

View File

@@ -124,8 +124,15 @@ class EntityRepository implements ObjectRepository
return null;
}
if ($lockMode !== LockMode::NONE) {
$this->_em->lock($entity, $lockMode, $lockVersion);
switch ($lockMode) {
case LockMode::OPTIMISTIC:
$this->_em->lock($entity, $lockMode, $lockVersion);
break;
case LockMode::PESSIMISTIC_READ:
case LockMode::PESSIMISTIC_WRITE:
$persister = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName);
$persister->refresh($sortedId, $entity, $lockMode);
break;
}
return $entity; // Hit!

View File

@@ -364,7 +364,19 @@ class BasicEntityPersister
$targetMapping = $this->_em->getClassMetadata($this->_class->associationMappings[$idField]['targetEntity']);
$where[] = $this->_class->associationMappings[$idField]['joinColumns'][0]['name'];
$params[] = $id[$idField];
$types[] = $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type'];
switch (true) {
case (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])):
$types[] = $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type'];
break;
case (isset($targetMapping->associationMappings[$targetMapping->identifier[0]])):
$types[] = $targetMapping->associationMappings[$targetMapping->identifier[0]]['type'];
break;
default:
throw ORMException::unrecognizedField($targetMapping->identifier[0]);
}
} else {
$where[] = $this->_class->getQuotedColumnName($idField, $this->_platform);
$params[] = $id[$idField];
@@ -690,9 +702,9 @@ class BasicEntityPersister
* column or field names to values.
* @param object $entity The entity to refresh.
*/
public function refresh(array $id, $entity)
public function refresh(array $id, $entity, $lockMode = 0)
{
$sql = $this->_getSelectEntitiesSQL($id);
$sql = $this->_getSelectEntitiesSQL($id, null, $lockMode);
list($params, $types) = $this->expandParameters($id);
$stmt = $this->_conn->executeQuery($sql, $params, $types);

View File

@@ -184,7 +184,19 @@ class ProxyFactory
$file = str_replace($placeholders, $replacements, $file);
file_put_contents($fileName, $file, LOCK_EX);
$parentDirectory = dirname($fileName);
if ( ! is_dir($parentDirectory)) {
if (false === @mkdir($parentDirectory, 0775, true)) {
throw ProxyException::proxyDirectoryNotWritable();
}
} else if ( ! is_writable($parentDirectory)) {
throw ProxyException::proxyDirectoryNotWritable();
}
$tmpFileName = $fileName . '.' . uniqid("", true);
file_put_contents($tmpFileName, $file);
rename($tmpFileName, $fileName);
}
/**

View File

@@ -136,6 +136,23 @@ public function <methodName>(<methodTypeHint>$<variableName>)
<spaces>return $this;
}';
/**
* @var string
*/
private static $_removeMethodTemplate =
'/**
* <description>
*
* @param <variableType$<variableName>
*/
public function <methodName>(<methodTypeHint>$<variableName>)
{
<spaces>$this-><fieldName>->removeElement($<variableName>);
}';
/**
* @var string
*/
private static $_lifecycleCallbackMethodTemplate =
'/**
* @<name>
@@ -672,6 +689,9 @@ public function <methodName>()
if ($code = $this->_generateEntityStubMethod($metadata, 'add', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
$methods[] = $code;
}
if ($code = $this->_generateEntityStubMethod($metadata, 'remove', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
$methods[] = $code;
}
if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], 'Doctrine\Common\Collections\Collection')) {
$methods[] = $code;
}
@@ -756,12 +776,9 @@ public function <methodName>()
private function _generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
{
if ($type == "add") {
$addMethod = explode("\\", $typeHint);
$addMethod = end($addMethod);
$methodName = $type . $addMethod;
} else {
$methodName = $type . Inflector::classify($fieldName);
$methodName = $type . Inflector::classify($fieldName);
if (in_array($type, array("add", "remove")) && substr($methodName, -1) == "s") {
$methodName = substr($methodName, 0, -1);
}
if ($this->_hasMethod($methodName, $metadata)) {

View File

@@ -1118,6 +1118,10 @@ class UnitOfWork implements PropertyChangedListener
if (isset($this->entityIdentifiers[$oid])) {
$this->addToIdentityMap($entity);
}
if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this);
}
}
/**
@@ -1296,10 +1300,6 @@ class UnitOfWork implements PropertyChangedListener
$this->identityMap[$className][$idHash] = $entity;
if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this);
}
return true;
}
@@ -1649,7 +1649,7 @@ class UnitOfWork implements PropertyChangedListener
$oid = spl_object_hash($entity);
if (isset($visited[$oid])) {
return; // Prevent infinite recursion
return $visited[$oid]; // Prevent infinite recursion
}
$visited[$oid] = $entity; // mark visited
@@ -2356,11 +2356,12 @@ class UnitOfWork implements PropertyChangedListener
}
} else {
$entity = $this->newInstance($class);
$oid = spl_object_hash($entity);
$oid = spl_object_hash($entity);
$this->entityIdentifiers[$oid] = $id;
$this->entityStates[$oid] = self::STATE_MANAGED;
$this->entityIdentifiers[$oid] = $id;
$this->entityStates[$oid] = self::STATE_MANAGED;
$this->originalEntityData[$oid] = $data;
$this->identityMap[$class->rootEntityName][$idHash] = $entity;
if ($entity instanceof NotifyPropertyChanged) {
@@ -2790,6 +2791,10 @@ class UnitOfWork implements PropertyChangedListener
$this->originalEntityData[$oid] = $data;
$this->addToIdentityMap($entity);
if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this);
}
}
/**

View File

@@ -70,6 +70,27 @@ class ScriptHandler
static::executeCommand($event, $appDir, 'assets:install '.$symlink.escapeshellarg($webDir));
}
public static function installRequirementsFile($event)
{
$options = self::getOptions($event);
$appDir = $options['symfony-app-dir'];
if (!is_dir($appDir)) {
echo 'The symfony-app-dir ('.$appDir.') specified in composer.json was not found in '.getcwd().', can not install the requirements file.'.PHP_EOL;
return;
}
copy(__DIR__.'/../Resources/skeleton/app/SymfonyRequirements.php', $appDir.'/SymfonyRequirements.php');
copy(__DIR__.'/../Resources/skeleton/app/check.php', $appDir.'/check.php');
$webDir = $options['symfony-web-dir'];
if (is_file($webDir.'/config.php')) {
copy(__DIR__.'/../Resources/skeleton/web/config.php', $webDir.'/config.php');
}
}
public static function doBuildBootstrap($appDir)
{
$file = $appDir.'/bootstrap.php.cache';
@@ -81,16 +102,13 @@ class ScriptHandler
'Symfony\\Component\\DependencyInjection\\ContainerAwareInterface',
// Cannot be included because annotations will parse the big compiled class file
//'Symfony\\Component\\DependencyInjection\\ContainerAware',
'Symfony\\Component\\DependencyInjection\\ContainerInterface',
'Symfony\\Component\\DependencyInjection\\Container',
'Symfony\\Component\\HttpKernel\\HttpKernelInterface',
'Symfony\\Component\\HttpKernel\\KernelInterface',
'Symfony\\Component\\HttpKernel\\Kernel',
'Symfony\\Component\\ClassLoader\\ClassCollectionLoader',
'Symfony\\Component\\ClassLoader\\ApcClassLoader',
'Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface',
'Symfony\\Component\\HttpKernel\\Bundle\\Bundle',
'Symfony\\Component\\Config\\ConfigCache',
'Symfony\\Bundle\\FrameworkBundle\\HttpKernel',
// cannot be included as commands are discovered based on the path to this class via Reflection
//'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle',
), dirname($file), basename($file, '.php.cache'), false, false, '.php.cache');
@@ -107,25 +125,23 @@ namespace { return \$loader; }
protected static function executeCommand($event, $appDir, $cmd)
{
$phpFinder = new PhpExecutableFinder;
$php = escapeshellarg($phpFinder->find());
$php = escapeshellarg(self::getPhp());
$console = escapeshellarg($appDir.'/console');
if ($event->getIO()->isDecorated()) {
$console.= ' --ansi';
}
$process = new Process($php.' '.$console.' '.$cmd);
$process = new Process($php.' '.$console.' '.$cmd, null, null, null, 300);
$process->run(function ($type, $buffer) { echo $buffer; });
}
protected static function executeBuildBootstrap($appDir)
{
$phpFinder = new PhpExecutableFinder;
$php = escapeshellarg($phpFinder->find());
$php = escapeshellarg(self::getPhp());
$cmd = escapeshellarg(__DIR__.'/../Resources/bin/build_bootstrap.php');
$appDir = escapeshellarg($appDir);
$process = new Process($php.' '.$cmd.' '.$appDir);
$process = new Process($php.' '.$cmd.' '.$appDir, null, null, null, 300);
$process->run(function ($type, $buffer) { echo $buffer; });
}
@@ -141,4 +157,14 @@ namespace { return \$loader; }
return $options;
}
protected static function getPhp()
{
$phpFinder = new PhpExecutableFinder;
if (!$phpPath = $phpFinder->find()) {
throw new \RuntimeException('The php executable could not be found, add it to your PATH environment variable and try again');
}
return $phpPath;
}
}

View File

@@ -0,0 +1,91 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sensio\Bundle\DistributionBundle\Diff;
/**
* Computes a Diff between files (line by line).
*
* Implements the Longest common subsequence problem algorithm.
*
* @see http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Diff
{
private $diff;
public function __construct($str1, $str2)
{
$lines1 = explode("\n", $str1);
$lines2 = explode("\n", $str2);
$this->diff = $this->computeDiff($this->computeLcs($lines1, $lines2), $lines1, $lines2, count($lines1) - 1, count($lines2) - 1);
}
public function getDiff()
{
$diff = array();
for ($i = 0, $max = count($this->diff); $i < $max; $i++) {
if ('' != $this->diff[$i][0]) {
$diff[] = array('@', sprintf(' Line %s', $this->diff[$i][2]));
do {
$diff[] = $this->diff[$i++];
} while ('' != $this->diff[$i][0]);
}
}
return $diff;
}
public function computeDiff(array $c, array $lines1, array $lines2, $i, $j)
{
$diff = array();
if ($i > -1 && $j > -1 && $lines1[$i] == $lines2[$j]) {
$diff = array_merge($diff, $this->computeDiff($c, $lines1, $lines2, $i - 1, $j - 1));
$diff[] = array('', $lines1[$i], $i, $j);
} else {
if ($j > -1 && ($i == -1 || $c[$i][$j - 1] >= $c[$i - 1][$j])) {
$diff = array_merge($diff, $this->computeDiff($c, $lines1, $lines2, $i, $j - 1));
$diff[] = array('+', $lines2[$j], $i, $j);
} elseif ($i > -1 && ($j == -1 || $c[$i][$j - 1] < $c[$i - 1][$j])) {
$diff = array_merge($diff, $this->computeDiff($c, $lines1, $lines2, $i - 1, $j));
$diff[] = array('-', $lines1[$i], $i, $j);
}
}
return $diff;
}
private function computeLcs(array $lines1, array $lines2)
{
for ($i = -1, $len1 = count($lines1); $i < $len1; $i++) {
for ($j = -1, $len2 = count($lines2); $j < $len2; $j++) {
$c[$i][$j] = 0;
}
}
for ($i = 0; $i < $len1; $i++) {
for ($j = 0; $j < $len2; $j++) {
if ($lines1[$i] == $lines2[$j]) {
$c[$i][$j] = $c[$i - 1][$j - 1] + 1;
} else {
$c[$i][$j] = max($c[$i][$j - 1], $c[$i - 1][$j]);
}
}
}
return $c;
}
}

View File

@@ -16,7 +16,7 @@ $argv = $_SERVER['argv'];
if (isset($argv[1])) {
$appDir = $argv[1];
} else {
if (!$appDir = realpath(__DIR__.'/../../../../../../../app')) {
if (!$appDir = realpath(__DIR__.'/../../../../../../../../app')) {
exit('Looks like you don\'t have a standard layout.');
}
}

View File

@@ -56,7 +56,6 @@ h2 {
padding: 2px 4px;
display: inline-block;
text-transform: uppercase;
}
p {
@@ -135,3 +134,15 @@ ul li {
font-size: 10px;
margin-right: 20px;
}
.ok {
color: #fff;
font-family: "Lucida Sans Unicode", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
background-color: #6d6;
padding: 10px;
margin-bottom: 20px;
}
.ko {
background-color: #d66;
}

View File

@@ -0,0 +1,597 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Represents a single PHP requirement, e.g. an installed extension.
* It can be a mandatory requirement or an optional recommendation.
* There is a special subclass, named PhpIniRequirement, to check a php.ini configuration.
*
* This file must be compatible with PHP 5.2+.
*
* ************** CAUTION **************
*
* DO NOT EDIT THIS FILE AS IT WILL BE OVERRIDEN BY COMPOSER
*
* If you want to change this file, edit the one in the
* SensioDistributionBundle instead.
*
* ************** CAUTION **************
*
* @author Tobias Schultze <http://tobion.de>
*/
class Requirement
{
private $fulfilled;
private $testMessage;
private $helpText;
private $helpHtml;
private $optional;
/**
* Constructor that initializes the requirement.
*
* @param Boolean $fulfilled Whether the requirement is fulfilled
* @param string $testMessage The message for testing the requirement
* @param string $helpHtml The help text formatted in HTML for resolving the problem
* @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
* @param Boolean $optional Whether this is only an optional recommendation not a mandatory requirement
*/
public function __construct($fulfilled, $testMessage, $helpHtml, $helpText = null, $optional = false)
{
$this->fulfilled = (Boolean) $fulfilled;
$this->testMessage = (string) $testMessage;
$this->helpHtml = (string) $helpHtml;
$this->helpText = null === $helpText ? strip_tags($this->helpHtml) : (string) $helpText;
$this->optional = (Boolean) $optional;
}
/**
* Returns whether the requirement is fulfilled.
*
* @return Boolean true if fulfilled, otherwise false
*/
public function isFulfilled()
{
return $this->fulfilled;
}
/**
* Returns the message for testing the requirement.
*
* @return string The test message
*/
public function getTestMessage()
{
return $this->testMessage;
}
/**
* Returns the help text for resolving the problem
*
* @return string The help text
*/
public function getHelpText()
{
return $this->helpText;
}
/**
* Returns the help text formatted in HTML.
*
* @return string The HTML help
*/
public function getHelpHtml()
{
return $this->helpHtml;
}
/**
* Returns whether this is only an optional recommendation and not a mandatory requirement.
*
* @return Boolean true if optional, false if mandatory
*/
public function isOptional()
{
return $this->optional;
}
}
/**
* Represents a PHP requirement in form of a php.ini configuration.
*
* @author Tobias Schultze <http://tobion.de>
*/
class PhpIniRequirement extends Requirement
{
/**
* Constructor that initializes the requirement.
*
* @param string $cfgName The configuration name used for ini_get()
* @param Boolean|callback $evaluation Either a Boolean indicating whether the configuration should evaluate to true or false,
or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement
* @param Boolean $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false.
This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin.
Example: You require a config to be true but PHP later removes this config and defaults it to true internally.
* @param string $testMessage The message for testing the requirement (when null and $evaluation is a Boolean a default message is derived)
* @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a Boolean a default help is derived)
* @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
* @param Boolean $optional Whether this is only an optional recommendation not a mandatory requirement
*/
public function __construct($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null, $optional = false)
{
$cfgValue = ini_get($cfgName);
if (is_callable($evaluation)) {
if (null === $testMessage || null === $helpHtml) {
throw new InvalidArgumentException('You must provide the parameters testMessage and helpHtml for a callback evaluation.');
}
$fulfilled = call_user_func($evaluation, $cfgValue);
} else {
if (null === $testMessage) {
$testMessage = sprintf('%s %s be %s in php.ini',
$cfgName,
$optional ? 'should' : 'must',
$evaluation ? 'enabled' : 'disabled'
);
}
if (null === $helpHtml) {
$helpHtml = sprintf('Set <strong>%s</strong> to <strong>%s</strong> in php.ini<a href="#phpini">*</a>.',
$cfgName,
$evaluation ? 'on' : 'off'
);
}
$fulfilled = $evaluation == $cfgValue;
}
parent::__construct($fulfilled || ($approveCfgAbsence && false === $cfgValue), $testMessage, $helpHtml, $helpText, $optional);
}
}
/**
* A RequirementCollection represents a set of Requirement instances.
*
* Users of PHP 5.2 should be able to run the requirements checks.
* This is why the class must be compatible with PHP 5.2
* (e.g. not using namespaces and closures).
*
* @author Tobias Schultze <http://tobion.de>
*/
class RequirementCollection implements IteratorAggregate
{
private $requirements = array();
/**
* Gets the current RequirementCollection as an Iterator.
*
* @return Traversable A Traversable interface
*/
public function getIterator()
{
return new ArrayIterator($this->requirements);
}
/**
* Adds a Requirement.
*
* @param Requirement $requirement A Requirement instance
*/
public function add(Requirement $requirement)
{
$this->requirements[] = $requirement;
}
/**
* Adds a mandatory requirement.
*
* @param Boolean $fulfilled Whether the requirement is fulfilled
* @param string $testMessage The message for testing the requirement
* @param string $helpHtml The help text formatted in HTML for resolving the problem
* @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
*/
public function addRequirement($fulfilled, $testMessage, $helpHtml, $helpText = null)
{
$this->add(new Requirement($fulfilled, $testMessage, $helpHtml, $helpText, false));
}
/**
* Adds an optional recommendation.
*
* @param Boolean $fulfilled Whether the recommendation is fulfilled
* @param string $testMessage The message for testing the recommendation
* @param string $helpHtml The help text formatted in HTML for resolving the problem
* @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
*/
public function addRecommendation($fulfilled, $testMessage, $helpHtml, $helpText = null)
{
$this->add(new Requirement($fulfilled, $testMessage, $helpHtml, $helpText, true));
}
/**
* Adds a mandatory requirement in form of a php.ini configuration.
*
* @param string $cfgName The configuration name used for ini_get()
* @param Boolean|callback $evaluation Either a Boolean indicating whether the configuration should evaluate to true or false,
or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement
* @param Boolean $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false.
This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin.
Example: You require a config to be true but PHP later removes this config and defaults it to true internally.
* @param string $testMessage The message for testing the requirement (when null and $evaluation is a Boolean a default message is derived)
* @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a Boolean a default help is derived)
* @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
*/
public function addPhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null)
{
$this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, false));
}
/**
* Adds an optional recommendation in form of a php.ini configuration.
*
* @param string $cfgName The configuration name used for ini_get()
* @param Boolean|callback $evaluation Either a Boolean indicating whether the configuration should evaluate to true or false,
or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement
* @param Boolean $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false.
This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin.
Example: You require a config to be true but PHP later removes this config and defaults it to true internally.
* @param string $testMessage The message for testing the requirement (when null and $evaluation is a Boolean a default message is derived)
* @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a Boolean a default help is derived)
* @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
*/
public function addPhpIniRecommendation($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null)
{
$this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, true));
}
/**
* Adds a requirement collection to the current set of requirements.
*
* @param RequirementCollection $collection A RequirementCollection instance
*/
public function addCollection(RequirementCollection $collection)
{
$this->requirements = array_merge($this->requirements, $collection->all());
}
/**
* Returns both requirements and recommendations.
*
* @return array Array of Requirement instances
*/
public function all()
{
return $this->requirements;
}
/**
* Returns all mandatory requirements.
*
* @return array Array of Requirement instances
*/
public function getRequirements()
{
$array = array();
foreach ($this->requirements as $req) {
if (!$req->isOptional()) {
$array[] = $req;
}
}
return $array;
}
/**
* Returns the mandatory requirements that were not met.
*
* @return array Array of Requirement instances
*/
public function getFailedRequirements()
{
$array = array();
foreach ($this->requirements as $req) {
if (!$req->isFulfilled() && !$req->isOptional()) {
$array[] = $req;
}
}
return $array;
}
/**
* Returns all optional recommmendations.
*
* @return array Array of Requirement instances
*/
public function getRecommendations()
{
$array = array();
foreach ($this->requirements as $req) {
if ($req->isOptional()) {
$array[] = $req;
}
}
return $array;
}
/**
* Returns the recommendations that were not met.
*
* @return array Array of Requirement instances
*/
public function getFailedRecommendations()
{
$array = array();
foreach ($this->requirements as $req) {
if (!$req->isFulfilled() && $req->isOptional()) {
$array[] = $req;
}
}
return $array;
}
/**
* Returns whether a php.ini configuration is not correct.
*
* @return Boolean php.ini configuration problem?
*/
public function hasPhpIniConfigIssue()
{
foreach ($this->requirements as $req) {
if (!$req->isFulfilled() && $req instanceof PhpIniRequirement) {
return true;
}
}
return false;
}
/**
* Returns the PHP configuration file (php.ini) path.
*
* @return string|false php.ini file path
*/
public function getPhpIniConfigPath()
{
return get_cfg_var('cfg_file_path');
}
}
/**
* This class specifies all requirements and optional recommendations that
* are necessary to run the Symfony Standard Edition.
*
* @author Tobias Schultze <http://tobion.de>
*/
class SymfonyRequirements extends RequirementCollection
{
const REQUIRED_PHP_VERSION = '5.3.3';
/**
* Constructor that initializes the requirements.
*/
public function __construct()
{
/* mandatory requirements follow */
$installedPhpVersion = phpversion();
$this->addRequirement(
version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>='),
sprintf('PHP version must be at least %s (%s installed)', self::REQUIRED_PHP_VERSION, $installedPhpVersion),
sprintf('You are running PHP version "<strong>%s</strong>", but Symfony needs at least PHP "<strong>%s</strong>" to run.
Before using Symfony, upgrade your PHP installation, preferably to the latest version.',
$installedPhpVersion, self::REQUIRED_PHP_VERSION),
sprintf('Install PHP %s or newer (installed version is %s)', self::REQUIRED_PHP_VERSION, $installedPhpVersion)
);
$this->addRequirement(
is_dir(__DIR__.'/../vendor/composer'),
'Vendor libraries must be installed',
'Vendor libraries are missing. Install composer following instructions from <a href="http://getcomposer.org/">http://getcomposer.org/</a>. ' .
'Then run "<strong>php composer.phar install</strong>" to install them.'
);
$this->addRequirement(
file_get_contents(__FILE__) == file_get_contents(__DIR__.'/../vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/skeleton/app/SymfonyRequirements.php'),
'Outdated requirements file',
'Your requirements file is outdated. Run composer install and re-check your configuration.'
);
$baseDir = basename(__DIR__);
$this->addRequirement(
is_writable(__DIR__.'/cache'),
"$baseDir/cache/ directory must be writable",
"Change the permissions of the \"<strong>$baseDir/cache/</strong>\" directory so that the web server can write into it."
);
$this->addRequirement(
is_writable(__DIR__.'/logs'),
"$baseDir/logs/ directory must be writable",
"Change the permissions of the \"<strong>$baseDir/logs/</strong>\" directory so that the web server can write into it."
);
$this->addPhpIniRequirement(
'date.timezone', true, false,
'date.timezone setting must be set',
'Set the "<strong>date.timezone</strong>" setting in php.ini<a href="#phpini">*</a> (like Europe/Paris).'
);
if (version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>=')) {
$this->addRequirement(
(in_array(date_default_timezone_get(), DateTimeZone::listIdentifiers())),
sprintf('Default timezone is deprecated (%s)', date_default_timezone_get()),
'Fix your <strong>php.ini</strong> file (list of deprecated timezones http://us.php.net/manual/en/timezones.others.php).'
);
}
$this->addRequirement(
function_exists('json_encode'),
'json_encode() must be available',
'Install and enable the <strong>JSON</strong> extension.'
);
$this->addRequirement(
function_exists('session_start'),
'session_start() must be available',
'Install and enable the <strong>session</strong> extension.'
);
$this->addRequirement(
function_exists('ctype_alpha'),
'ctype_alpha() must be available',
'Install and enable the <strong>ctype</strong> extension.'
);
$this->addRequirement(
function_exists('token_get_all'),
'token_get_all() must be available',
'Install and enable the <strong>Tokenizer</strong> extension.'
);
$this->addRequirement(
function_exists('simplexml_import_dom'),
'simplexml_import_dom() must be available',
'Install and enable the <strong>SimpleXML</strong> extension.'
);
$this->addRequirement(
!(function_exists('apc_store') && ini_get('apc.enabled')) || version_compare(phpversion('apc'), '3.0.17', '>='),
'APC version must be at least 3.0.17',
'Upgrade your <strong>APC</strong> extension (3.0.17+)'
);
$this->addPhpIniRequirement('detect_unicode', false);
$this->addPhpIniRequirement(
'suhosin.executor.include.whitelist',
create_function('$cfgValue', 'return false !== stripos($cfgValue, "phar");'),
true,
'suhosin.executor.include.whitelist must be configured correctly in php.ini',
'Add "<strong>phar</strong>" to <strong>suhosin.executor.include.whitelist</strong> in php.ini<a href="#phpini">*</a>.'
);
$pcreVersion = defined('PCRE_VERSION') ? (float) PCRE_VERSION : null;
$this->addRequirement(
null !== $pcreVersion && $pcreVersion > 8.0,
sprintf('PCRE extension must be available and at least 8.0 (%s installed)', $pcreVersion ? $pcreVersion : 'not'),
'Upgrade your <strong>PCRE</strong> extension (8.0+)'
);
/* optional recommendations follow */
$this->addRecommendation(
version_compare($installedPhpVersion, '5.3.8', '>='),
sprintf('Annotations might not work properly due to the PHP bug #55156 before PHP 5.3.8 (%s installed)', $installedPhpVersion),
'Install PHP 5.3.8 or newer if your project uses annotations'
);
$this->addRecommendation(
class_exists('DomDocument'),
'PHP-XML module should be installed',
'Install and enable the <strong>PHP-XML</strong> module.'
);
$this->addRecommendation(
function_exists('mb_strlen'),
'mb_strlen() should be available',
'Install and enable the <strong>mbstring</strong> extension.'
);
$this->addRecommendation(
function_exists('iconv'),
'iconv() should be available',
'Install and enable the <strong>iconv</strong> extension.'
);
$this->addRecommendation(
function_exists('utf8_decode'),
'utf8_decode() should be available',
'Install and enable the <strong>XML</strong> extension.'
);
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->addRecommendation(
function_exists('posix_isatty'),
'posix_isatty() should be available',
'Install and enable the <strong>php_posix</strong> extension (used to colorize the CLI output).'
);
}
$this->addRecommendation(
class_exists('Locale'),
'intl extension should be available',
'Install and enable the <strong>intl</strong> extension (used for validators).'
);
if (class_exists('Locale')) {
if (defined('INTL_ICU_VERSION')) {
$version = INTL_ICU_VERSION;
} else {
$reflector = new ReflectionExtension('intl');
ob_start();
$reflector->info();
$output = strip_tags(ob_get_clean());
preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches);
$version = $matches[1];
}
$this->addRecommendation(
version_compare($version, '4.0', '>='),
'intl ICU version should be at least 4+',
'Upgrade your <strong>intl</strong> extension with a newer ICU version (4+).'
);
}
$accelerator =
(function_exists('apc_store') && ini_get('apc.enabled'))
||
function_exists('eaccelerator_put') && ini_get('eaccelerator.enable')
||
function_exists('xcache_set')
;
$this->addRecommendation(
$accelerator,
'a PHP accelerator should be installed',
'Install and enable a <strong>PHP accelerator</strong> like APC (highly recommended).'
);
$this->addPhpIniRecommendation('short_open_tag', false);
$this->addPhpIniRecommendation('magic_quotes_gpc', false, true);
$this->addPhpIniRecommendation('register_globals', false, true);
$this->addPhpIniRecommendation('session.auto_start', false);
$this->addRecommendation(
class_exists('PDO'),
'PDO should be installed',
'Install <strong>PDO</strong> (mandatory for Doctrine).'
);
if (class_exists('PDO')) {
$drivers = PDO::getAvailableDrivers();
$this->addRecommendation(
count($drivers),
sprintf('PDO should have some drivers installed (currently available: %s)', count($drivers) ? implode(', ', $drivers) : 'none'),
'Install <strong>PDO drivers</strong> (mandatory for Doctrine).'
);
}
}
}

View File

@@ -0,0 +1,55 @@
<?php
require_once dirname(__FILE__).'/SymfonyRequirements.php';
$symfonyRequirements = new SymfonyRequirements();
$iniPath = $symfonyRequirements->getPhpIniConfigPath();
echo "********************************\n";
echo "* *\n";
echo "* Symfony requirements check *\n";
echo "* *\n";
echo "********************************\n\n";
echo $iniPath ? sprintf("* Configuration file used by PHP: %s\n\n", $iniPath) : "* WARNING: No configuration file (php.ini) used by PHP!\n\n";
echo "** ATTENTION **\n";
echo "* The PHP CLI can use a different php.ini file\n";
echo "* than the one used with your web server.\n";
if ('\\' == DIRECTORY_SEPARATOR) {
echo "* (especially on the Windows platform)\n";
}
echo "* To be on the safe side, please also launch the requirements check\n";
echo "* from your web server using the web/config.php script.\n";
echo_title('Mandatory requirements');
foreach ($symfonyRequirements->getRequirements() as $req) {
echo_requirement($req);
}
echo_title('Optional recommendations');
foreach ($symfonyRequirements->getRecommendations() as $req) {
echo_requirement($req);
}
/**
* Prints a Requirement instance
*/
function echo_requirement(Requirement $requirement)
{
$result = $requirement->isFulfilled() ? 'OK' : ($requirement->isOptional() ? 'WARNING' : 'ERROR');
echo ' ' . str_pad($result, 9);
echo $requirement->getTestMessage() . "\n";
if (!$requirement->isFulfilled()) {
echo sprintf(" %s\n\n", $requirement->getHelpText());
}
}
function echo_title($title)
{
echo "\n** $title **\n\n";
}

View File

@@ -0,0 +1,98 @@
<?php
if (!isset($_SERVER['HTTP_HOST'])) {
exit('This script cannot be run from the CLI. Run it from a browser.');
}
if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
))) {
header('HTTP/1.0 403 Forbidden');
exit('This script is only accessible from localhost.');
}
require_once dirname(__FILE__).'/../app/SymfonyRequirements.php';
$symfonyRequirements = new SymfonyRequirements();
$majorProblems = $symfonyRequirements->getFailedRequirements();
$minorProblems = $symfonyRequirements->getFailedRecommendations();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="bundles/sensiodistribution/webconfigurator/css/install.css" media="all" />
<title>Symfony Configuration</title>
</head>
<body>
<div id="symfony-wrapper">
<div id="symfony-content">
<div class="symfony-blocks-install">
<div class="symfony-block-logo">
<img src="bundles/sensiodistribution/webconfigurator/images/logo-big.gif" alt="Symfony logo" />
</div>
<div class="symfony-block-content">
<h1>Welcome!</h1>
<p>Welcome to your new Symfony project.</p>
<p>
This script will guide you through the basic configuration of your project.
You can also do the same by editing the <strong>app/config/parameters.yml</strong> file directly.
</p>
<?php if (count($majorProblems)): ?>
<h2 class="ko">Major problems</h2>
<p>Major problems have been detected and <strong>must</strong> be fixed before continuing:</p>
<ol>
<?php foreach ($majorProblems as $problem): ?>
<li><?php echo $problem->getHelpHtml() ?></li>
<?php endforeach; ?>
</ol>
<?php endif; ?>
<?php if (count($minorProblems)): ?>
<h2>Recommendations</h2>
<p>
<?php if (count($majorProblems)): ?>Additionally, to<?php else: ?>To<?php endif; ?> enhance your Symfony experience,
its recommended that you fix the following:
</p>
<ol>
<?php foreach ($minorProblems as $problem): ?>
<li><?php echo $problem->getHelpHtml() ?></li>
<?php endforeach; ?>
</ol>
<?php endif; ?>
<?php if ($symfonyRequirements->hasPhpIniConfigIssue()): ?>
<p id="phpini">*
<?php if ($symfonyRequirements->getPhpIniConfigPath()): ?>
Changes to the <strong>php.ini</strong> file must be done in "<strong><?php echo $symfonyRequirements->getPhpIniConfigPath() ?></strong>".
<?php else: ?>
To change settings, create a "<strong>php.ini</strong>".
<?php endif; ?>
</p>
<?php endif; ?>
<?php if (!count($majorProblems) && !count($minorProblems)): ?>
<p class="ok">Your configuration looks good to run Symfony.</p>
<?php endif; ?>
<ul class="symfony-install-continue">
<?php if (!count($majorProblems)): ?>
<li><a href="app_dev.php/_configurator/">Configure your Symfony Application online</a></li>
<li><a href="app_dev.php/">Bypass configuration and go to the Welcome page</a></li>
<?php endif; ?>
<?php if (count($majorProblems) || count($minorProblems)): ?>
<li><a href="config.php">Re-check configuration</a></li>
<?php endif; ?>
</ul>
</div>
</div>
</div>
<div class="version">Symfony Standard Edition</div>
</div>
</body>
</html>

View File

@@ -1,15 +1,15 @@
{% extends "form_div_layout.html.twig" %}
{% block field_rows %}
{% block form_rows %}
<div class="symfony-form-errors">
{{ form_errors(form) }}
</div>
{% for child in form.children %}
{% for child in form %}
{{ form_row(child) }}
{% endfor %}
{% endblock field_rows %}
{% endblock %}
{% block field_row %}
{% block form_row %}
<div class="symfony-form-row">
{{ form_label(form) }}
<div class="symfony-form-field">
@@ -21,7 +21,10 @@
</div>
{% endblock %}
{% block field_label %}
{% block form_label %}
{% if label is empty %}
{% set label = name|humanize %}
{% endif %}
<label for="{{ id }}">
{{ label|trans }}
{% if required %}

View File

@@ -0,0 +1,59 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sensio\Bundle\DistributionBundle\Upgrade;
use Sensio\Bundle\DistributionBundle\Diff\Diff;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Upgrade class.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Upgrade
{
public function outputConsoleDiff(OutputInterface $output, $file1, $file2)
{
if (is_file($file1)) {
$file1 = realpath($file1);
$str1 = file_get_contents($file1);
} else {
$str1 = '';
}
if (!is_file($file2)) {
throw new \RuntimeException(sprintf('The skeleton file "%s" does not exist.', $file2));
}
$file2 = realpath($file2);
$str2 = file_get_contents($file2);
$diff = new Diff($str1, $str2);
$output->writeln(sprintf('--- %s', $file1));
$output->writeln(sprintf('+++ %s', $file2));
foreach ($diff->getDiff() as $line) {
if ('+' == $line[0]) {
$format = '<fg=green>+%s</>';
} elseif ('-' == $line[0]) {
$format = '<fg=red>-%s</>';
} elseif ('@' == $line[0]) {
$format = '<fg=cyan>@%s</>';
} else {
$format = ' %s';
}
$output->writeln(sprintf($format, $line[1]));
}
$output->writeln('');
}
}

View File

@@ -3,20 +3,22 @@
namespace Sensio\Bundle\FrameworkExtraBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\NodeInterface;
/**
* FrameworkExtraBundle configuration structure.
*
* @author Henrik Bjornskov <hb@peytz.dk>
*/
class Configuration
class Configuration implements ConfigurationInterface
{
/**
* Generates the configuration tree.
*
* @return Symfony\Component\Config\Definition\NodeInterface
* @return NodeInterface
*/
public function getConfigTree()
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('sensio_framework_extra', 'array');
@@ -50,6 +52,6 @@ class Configuration
->end()
;
return $treeBuilder->buildTree();
return $treeBuilder;
}
}

View File

@@ -7,7 +7,6 @@ use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Definition\Processor;
/*
* This file is part of the Symfony framework.
@@ -21,19 +20,16 @@ use Symfony\Component\Config\Definition\Processor;
/**
* SensioFrameworkExtraExtension.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Fabien Potencier <fabien@symfony.com>
*/
class SensioFrameworkExtraExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$processor = new Processor();
$configuration = new Configuration();
$config = $processor->process($configuration->getConfigTree(), $configs);
$loader->load('services.xml');
$annotationsToLoad = array();

View File

@@ -57,11 +57,12 @@ class DoctrineParamConverter implements ParamConverterInterface
protected function find($class, Request $request, $options)
{
if (!$request->attributes->has('id')) {
$key = isset($options['id']) ? $options['id'] : 'id';
if (!$request->attributes->has($key)) {
return false;
}
return $this->registry->getRepository($class, $options['entity_manager'])->find($request->attributes->get('id'));
return $this->registry->getRepository($class, $options['entity_manager'])->find($request->attributes->get($key));
}
protected function findOneBy($class, Request $request, $options)

View File

@@ -63,6 +63,17 @@ be configured with the ``entity_manager`` option::
{
}
If the placeholder has not the same name as the primary key, pass the ``id``
option::
/**
* @Route("/blog/{post_id}")
* @ParamConverter("post", class="SensioBlogBundle:Post", options={"id" = "post_id"})
*/
public function showAction(Post $post)
{
}
Creating a Converter
--------------------

View File

@@ -1 +1 @@
Swift-4.1.9
Swift-4.2.1

View File

@@ -23,7 +23,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "4.1-dev"
"dev-master": "4.2-dev"
}
}
}

View File

@@ -455,7 +455,7 @@ ID headers contain identifiers for the entity (or the message). The most
notable ID header is the Message-ID header on the message itself.
An ID that exists inside an ID header looks more-or-less less like an email
address. For example, ``<![CDATA[<1234955437.499becad62ec2@example.org>]]>``.
address. For example, ``<1234955437.499becad62ec2@example.org>``.
The part to the left of the @ sign is usually unique, based on the current time
and some random factor. The part on the right is usually a domain name.

View File

@@ -1,18 +1,34 @@
Including Swift Mailer (Autoloading)
====================================
Swift Mailer uses an autoloader so the only file you need to include is the
``lib/swift_required.php`` file.
If you are using Composer, Swift Mailer will be automatically autoloaded.
To use Swift Mailer's autoloader:
If not, you can use the built-in autoloader by requiring the
``swift_required.php`` file::
* Put Swift Mailer somewhere accessible to your PHP scripts (this does not
need to be in the web root).
require_once '/path/to/swift-mailer/lib/swift_required.php';
* Include, or require the ``lib/swift_required.php`` file.
/* rest of code goes here */
* Follow the remainder of the documentation for using the available
components.
If you want to override the default Swift Mailer configuration, call the
``init()`` method on the ``Swift`` class and pass it a valid PHP callable (a
PHP function name, a PHP 5.3 anonymous function, ...)::
require_once '/path/to/swift-mailer/lib/swift_required.php';
function swiftmailer_configurator() {
// configure Swift Mailer
Swift_DependencyContainer::getInstance()->...
Swift_Preferences::getInstance()->...
}
Swift::init('swiftmailer_configurator');
/* rest of code goes here */
The advantage of using the ``init()`` method is that your code will be
executed only if you use Swift Mailer in your script.
.. note::
@@ -25,6 +41,16 @@ To use Swift Mailer's autoloader:
.. code-block:: php
require_once '/path/to/swift-mailer/lib/swift_required.php';
require_once '/path/to/swift-mailer/lib/swift_init.php';
/* rest of code goes here */
For PHP versions starting with 5.3 it is recommended using the native quoted
printable encoder. It uses PHPs native ``quoted_printable_encode()``-function
to achieve much better performance::
Swift::init(function () {
Swift_DependencyContainer::getInstance()
->register('mime.qpcontentencoder')
->asAliasOf('mime.nativeqpcontentencoder');
});

View File

@@ -13,3 +13,4 @@ Swiftmailer
headers
sending
plugins
japanese

View File

@@ -0,0 +1,22 @@
Using Swift Mailer for Japanese Emails
======================================
To send emails in Japanese, you need to tweak the default configuration.
After requiring the Swift Mailer autoloader (by including the
``swift_required.php`` file), call the ``Swift::init()`` method with the
following code::
require_once '/path/to/swift-mailer/lib/swift_required.php';
Swift::init(function () {
Swift_DependencyContainer::getInstance()
->register('mime.qpheaderencoder')
->asAliasOf('mime.base64headerencoder');
Swift_Preferences::getInstance()->setCharset('iso-2022-jp');
});
/* rest of code goes here */
That's all!

View File

@@ -134,7 +134,7 @@ need to make use of a small subset of them. Usually you'll use
``setBody()``.
Calling methods is simple. You just call them like functions, but using the
object operator "``<![CDATA[->]]>``" to do so. If you've created
object operator "``->``" to do so. If you've created
a message object and called it ``$message`` then you'd set a
subject on it like so:
@@ -147,8 +147,8 @@ subject on it like so:
All MIME entities (including a message) have a ``toString()``
method that you can call if you want to take a look at what is going to be
sent. For example, if you ``<![CDATA[echo
$message->toString();]]>`` you would see something like this:
sent. For example, if you ``echo
$message->toString();`` you would see something like this:
.. code-block:: bash

View File

@@ -10,60 +10,72 @@
/**
* General utility class in Swift Mailer, not to be instantiated.
*
*
* @package Swift
*
*
* @author Chris Corbyn
*/
abstract class Swift
{
static $initialized = false;
static $initPath;
/** Swift Mailer Version number generated during dist release process */
const VERSION = '@SWIFT_VERSION_NUMBER@';
/**
* Internal autoloader for spl_autoload_register().
*
* @param string $class
*/
public static function autoload($class)
{
//Don't interfere with other autoloaders
if (0 !== strpos($class, 'Swift_'))
public static $initialized = false;
public static $inits = array();
/** Swift Mailer Version number generated during dist release process */
const VERSION = '@SWIFT_VERSION_NUMBER@';
/**
* Registers an initializer callable that will be called the first time
* a SwiftMailer class is autoloaded.
*
* This enables you to tweak the default configuration in a lazy way.
*
* @param mixed $callable A valid PHP callable that will be called when autoloading the first Swift class
*/
public static function init($callable)
{
return;
self::$inits[] = $callable;
}
$path = dirname(__FILE__).'/'.str_replace('_', '/', $class).'.php';
if (!file_exists($path))
/**
* Internal autoloader for spl_autoload_register().
*
* @param string $class
*/
public static function autoload($class)
{
return;
//Don't interfere with other autoloaders
if (0 !== strpos($class, 'Swift_')) {
return;
}
$path = dirname(__FILE__).'/'.str_replace('_', '/', $class).'.php';
if (!file_exists($path)) {
return;
}
require $path;
if (self::$inits && !self::$initialized) {
self::$initialized = true;
foreach (self::$inits as $init) {
call_user_func($init);
}
}
}
if (self::$initPath && !self::$initialized)
/**
* Configure autoloading using Swift Mailer.
*
* This is designed to play nicely with other autoloaders.
*
* @param mixed $callable A valid PHP callable that will be called when autoloading the first Swift class
*/
public static function registerAutoload($callable = null)
{
self::$initialized = true;
require self::$initPath;
if (null !== $callable) {
self::$inits[] = $callable;
}
spl_autoload_register(array('Swift', 'autoload'));
}
require $path;
}
/**
* Configure autoloading using Swift Mailer.
*
* This is designed to play nicely with other autoloaders.
*
* @param string $initPath The init script to load when autoloading the first Swift class
*/
public static function registerAutoload($initPath = null)
{
self::$initPath = $initPath;
spl_autoload_register(array('Swift', 'autoload'));
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Attachment class for attaching files to a {@link Swift_Mime_Message}.
* @package Swift
@@ -17,56 +16,51 @@
*/
class Swift_Attachment extends Swift_Mime_Attachment
{
/**
* Create a new Attachment.
* Details may be optionally provided to the constructor.
* @param string|Swift_OutputByteStream $data
* @param string $filename
* @param string $contentType
*/
public function __construct($data = null, $filename = null,
$contentType = null)
{
call_user_func_array(
array($this, 'Swift_Mime_Attachment::__construct'),
Swift_DependencyContainer::getInstance()
->createDependenciesFor('mime.attachment')
);
$this->setBody($data);
$this->setFilename($filename);
if ($contentType)
/**
* Create a new Attachment.
* Details may be optionally provided to the constructor.
* @param string|Swift_OutputByteStream $data
* @param string $filename
* @param string $contentType
*/
public function __construct($data = null, $filename = null, $contentType = null)
{
$this->setContentType($contentType);
call_user_func_array(
array($this, 'Swift_Mime_Attachment::__construct'),
Swift_DependencyContainer::getInstance()
->createDependenciesFor('mime.attachment')
);
$this->setBody($data);
$this->setFilename($filename);
if ($contentType) {
$this->setContentType($contentType);
}
}
/**
* Create a new Attachment.
* @param string|Swift_OutputByteStream $data
* @param string $filename
* @param string $contentType
* @return Swift_Mime_Attachment
*/
public static function newInstance($data = null, $filename = null, $contentType = null)
{
return new self($data, $filename, $contentType);
}
/**
* Create a new Attachment from a filesystem path.
* @param string $path
* @param string $contentType optional
* @return Swift_Mime_Attachment
*/
public static function fromPath($path, $contentType = null)
{
return self::newInstance()->setFile(
new Swift_ByteStream_FileByteStream($path),
$contentType
);
}
}
/**
* Create a new Attachment.
* @param string|Swift_OutputByteStream $data
* @param string $filename
* @param string $contentType
* @return Swift_Mime_Attachment
*/
public static function newInstance($data = null, $filename = null,
$contentType = null)
{
return new self($data, $filename, $contentType);
}
/**
* Create a new Attachment from a filesystem path.
* @param string $path
* @param string $contentType optional
* @return Swift_Mime_Attachment
*/
public static function fromPath($path, $contentType = null)
{
return self::newInstance()->setFile(
new Swift_ByteStream_FileByteStream($path),
$contentType
);
}
}

View File

@@ -8,168 +8,157 @@
* file that was distributed with this source code.
*/
/**
* Provides the base functionality for an InputStream supporting filters.
* @package Swift
* @subpackage ByteStream
* @author Chris Corbyn
*/
abstract class Swift_ByteStream_AbstractFilterableInputStream
implements Swift_InputByteStream, Swift_Filterable
abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_InputByteStream, Swift_Filterable
{
/** Write sequence */
protected $_sequence = 0;
/** StreamFilters */
private $_filters = array();
/** A buffer for writing */
private $_writeBuffer = '';
/** Bound streams */
private $_mirrors = array();
/**
* Commit the given bytes to the storage medium immediately.
* @param string $bytes
* @access protected
*/
abstract protected function _commit($bytes);
/**
* Flush any buffers/content with immediate effect.
* @access protected
*/
abstract protected function _flush();
/**
* Add a StreamFilter to this InputByteStream.
* @param Swift_StreamFilter $filter
* @param string $key
*/
public function addFilter(Swift_StreamFilter $filter, $key)
{
$this->_filters[$key] = $filter;
}
/**
* Remove an already present StreamFilter based on its $key.
* @param string $key
*/
public function removeFilter($key)
{
unset($this->_filters[$key]);
}
/**
* Writes $bytes to the end of the stream.
* @param string $bytes
* @throws Swift_IoException
*/
public function write($bytes)
{
$this->_writeBuffer .= $bytes;
foreach ($this->_filters as $filter)
/** Write sequence */
protected $_sequence = 0;
/** StreamFilters */
private $_filters = array();
/** A buffer for writing */
private $_writeBuffer = '';
/** Bound streams */
private $_mirrors = array();
/**
* Commit the given bytes to the storage medium immediately.
* @param string $bytes
* @access protected
*/
abstract protected function _commit($bytes);
/**
* Flush any buffers/content with immediate effect.
* @access protected
*/
abstract protected function _flush();
/**
* Add a StreamFilter to this InputByteStream.
* @param Swift_StreamFilter $filter
* @param string $key
*/
public function addFilter(Swift_StreamFilter $filter, $key)
{
if ($filter->shouldBuffer($this->_writeBuffer))
{
return;
}
$this->_filters[$key] = $filter;
}
$this->_doWrite($this->_writeBuffer);
return ++$this->_sequence;
}
/**
* For any bytes that are currently buffered inside the stream, force them
* off the buffer.
*
* @throws Swift_IoException
*/
public function commit()
{
$this->_doWrite($this->_writeBuffer);
}
/**
* Attach $is to this stream.
* The stream acts as an observer, receiving all data that is written.
* All {@link write()} and {@link flushBuffers()} operations will be mirrored.
*
* @param Swift_InputByteStream $is
*/
public function bind(Swift_InputByteStream $is)
{
$this->_mirrors[] = $is;
}
/**
* Remove an already bound stream.
* If $is is not bound, no errors will be raised.
* If the stream currently has any buffered data it will be written to $is
* before unbinding occurs.
*
* @param Swift_InputByteStream $is
*/
public function unbind(Swift_InputByteStream $is)
{
foreach ($this->_mirrors as $k => $stream)
/**
* Remove an already present StreamFilter based on its $key.
* @param string $key
*/
public function removeFilter($key)
{
if ($is === $stream)
{
if ($this->_writeBuffer !== '')
{
$stream->write($this->_filter($this->_writeBuffer));
unset($this->_filters[$key]);
}
/**
* Writes $bytes to the end of the stream.
* @param string $bytes
* @throws Swift_IoException
*/
public function write($bytes)
{
$this->_writeBuffer .= $bytes;
foreach ($this->_filters as $filter) {
if ($filter->shouldBuffer($this->_writeBuffer)) {
return;
}
}
unset($this->_mirrors[$k]);
}
$this->_doWrite($this->_writeBuffer);
return ++$this->_sequence;
}
}
/**
* Flush the contents of the stream (empty it) and set the internal pointer
* to the beginning.
* @throws Swift_IoException
*/
public function flushBuffers()
{
if ($this->_writeBuffer !== '')
/**
* For any bytes that are currently buffered inside the stream, force them
* off the buffer.
*
* @throws Swift_IoException
*/
public function commit()
{
$this->_doWrite($this->_writeBuffer);
$this->_doWrite($this->_writeBuffer);
}
$this->_flush();
foreach ($this->_mirrors as $stream)
/**
* Attach $is to this stream.
* The stream acts as an observer, receiving all data that is written.
* All {@link write()} and {@link flushBuffers()} operations will be mirrored.
*
* @param Swift_InputByteStream $is
*/
public function bind(Swift_InputByteStream $is)
{
$stream->flushBuffers();
$this->_mirrors[] = $is;
}
}
// -- Private methods
/** Run $bytes through all filters */
private function _filter($bytes)
{
foreach ($this->_filters as $filter)
/**
* Remove an already bound stream.
* If $is is not bound, no errors will be raised.
* If the stream currently has any buffered data it will be written to $is
* before unbinding occurs.
*
* @param Swift_InputByteStream $is
*/
public function unbind(Swift_InputByteStream $is)
{
$bytes = $filter->filter($bytes);
foreach ($this->_mirrors as $k => $stream) {
if ($is === $stream) {
if ($this->_writeBuffer !== '') {
$stream->write($this->_filter($this->_writeBuffer));
}
unset($this->_mirrors[$k]);
}
}
}
return $bytes;
}
/** Just write the bytes to the stream */
private function _doWrite($bytes)
{
$this->_commit($this->_filter($bytes));
foreach ($this->_mirrors as $stream)
/**
* Flush the contents of the stream (empty it) and set the internal pointer
* to the beginning.
* @throws Swift_IoException
*/
public function flushBuffers()
{
$stream->write($bytes);
if ($this->_writeBuffer !== '') {
$this->_doWrite($this->_writeBuffer);
}
$this->_flush();
foreach ($this->_mirrors as $stream) {
$stream->flushBuffers();
}
}
// -- Private methods
/** Run $bytes through all filters */
private function _filter($bytes)
{
foreach ($this->_filters as $filter) {
$bytes = $filter->filter($bytes);
}
return $bytes;
}
/** Just write the bytes to the stream */
private function _doWrite($bytes)
{
$this->_commit($this->_filter($bytes));
foreach ($this->_mirrors as $stream) {
$stream->write($bytes);
}
$this->_writeBuffer = '';
}
$this->_writeBuffer = '';
}
}

View File

@@ -8,181 +8,163 @@
* file that was distributed with this source code.
*/
/**
* Allows reading and writing of bytes to and from an array.
* @package Swift
* @subpackage ByteStream
* @author Chris Corbyn
*/
class Swift_ByteStream_ArrayByteStream
implements Swift_InputByteStream, Swift_OutputByteStream
class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_OutputByteStream
{
/**
* The internal stack of bytes.
* @var string[]
* @access private
*/
private $_array = array();
/**
* The internal stack of bytes.
* @var string[]
* @access private
*/
private $_array = array();
/**
* The size of the stack
* @var int
* @access private
*/
private $_arraySize = 0;
/**
* The size of the stack
* @var int
* @access private
*/
private $_arraySize = 0;
/**
* The internal pointer offset.
* @var int
* @access private
*/
private $_offset = 0;
/**
* The internal pointer offset.
* @var int
* @access private
*/
private $_offset = 0;
/** Bound streams */
private $_mirrors = array();
/**
* Create a new ArrayByteStream.
* If $stack is given the stream will be populated with the bytes it contains.
* @param mixed $stack of bytes in string or array form, optional
*/
public function __construct($stack = null)
{
if (is_array($stack))
{
$this->_array = $stack;
$this->_arraySize = count($stack);
}
elseif (is_string($stack))
{
$this->write($stack);
}
else
{
$this->_array = array();
}
}
/** Bound streams */
private $_mirrors = array();
/**
* Reads $length bytes from the stream into a string and moves the pointer
* through the stream by $length. If less bytes exist than are requested the
* remaining bytes are given instead. If no bytes are remaining at all, boolean
* false is returned.
* @param int $length
* @return string
*/
public function read($length)
{
if ($this->_offset == $this->_arraySize)
/**
* Create a new ArrayByteStream.
* If $stack is given the stream will be populated with the bytes it contains.
* @param mixed $stack of bytes in string or array form, optional
*/
public function __construct($stack = null)
{
return false;
if (is_array($stack)) {
$this->_array = $stack;
$this->_arraySize = count($stack);
} elseif (is_string($stack)) {
$this->write($stack);
} else {
$this->_array = array();
}
}
// Don't use array slice
$end = $length + $this->_offset;
$end = $this->_arraySize<$end
?$this->_arraySize
:$end;
$ret = '';
for (; $this->_offset < $end; ++$this->_offset)
/**
* Reads $length bytes from the stream into a string and moves the pointer
* through the stream by $length. If less bytes exist than are requested the
* remaining bytes are given instead. If no bytes are remaining at all, boolean
* false is returned.
* @param int $length
* @return string
*/
public function read($length)
{
$ret .= $this->_array[$this->_offset];
}
return $ret;
}
if ($this->_offset == $this->_arraySize) {
return false;
}
/**
* Writes $bytes to the end of the stream.
* @param string $bytes
*/
public function write($bytes)
{
$to_add = str_split($bytes);
foreach ($to_add as $value)
{
$this->_array[] = $value;
}
$this->_arraySize = count($this->_array);
foreach ($this->_mirrors as $stream)
{
$stream->write($bytes);
}
}
/**
* Not used.
*/
public function commit()
{
}
/**
* Attach $is to this stream.
* The stream acts as an observer, receiving all data that is written.
* All {@link write()} and {@link flushBuffers()} operations will be mirrored.
*
* @param Swift_InputByteStream $is
*/
public function bind(Swift_InputByteStream $is)
{
$this->_mirrors[] = $is;
}
/**
* Remove an already bound stream.
* If $is is not bound, no errors will be raised.
* If the stream currently has any buffered data it will be written to $is
* before unbinding occurs.
*
* @param Swift_InputByteStream $is
*/
public function unbind(Swift_InputByteStream $is)
{
foreach ($this->_mirrors as $k => $stream)
{
if ($is === $stream)
{
unset($this->_mirrors[$k]);
}
}
}
// Don't use array slice
$end = $length + $this->_offset;
$end = $this->_arraySize<$end
?$this->_arraySize
:$end;
$ret = '';
for (; $this->_offset < $end; ++$this->_offset) {
$ret .= $this->_array[$this->_offset];
}
/**
* Move the internal read pointer to $byteOffset in the stream.
* @param int $byteOffset
* @return boolean
*/
public function setReadPointer($byteOffset)
{
if ($byteOffset > $this->_arraySize)
{
$byteOffset = $this->_arraySize;
}
elseif ($byteOffset < 0)
{
$byteOffset = 0;
return $ret;
}
$this->_offset = $byteOffset;
}
/**
* Flush the contents of the stream (empty it) and set the internal pointer
* to the beginning.
*/
public function flushBuffers()
{
$this->_offset = 0;
$this->_array = array();
$this->_arraySize = 0;
foreach ($this->_mirrors as $stream)
/**
* Writes $bytes to the end of the stream.
* @param string $bytes
*/
public function write($bytes)
{
$stream->flushBuffers();
}
}
$to_add = str_split($bytes);
foreach ($to_add as $value) {
$this->_array[] = $value;
}
$this->_arraySize = count($this->_array);
foreach ($this->_mirrors as $stream) {
$stream->write($bytes);
}
}
/**
* Not used.
*/
public function commit()
{
}
/**
* Attach $is to this stream.
* The stream acts as an observer, receiving all data that is written.
* All {@link write()} and {@link flushBuffers()} operations will be mirrored.
*
* @param Swift_InputByteStream $is
*/
public function bind(Swift_InputByteStream $is)
{
$this->_mirrors[] = $is;
}
/**
* Remove an already bound stream.
* If $is is not bound, no errors will be raised.
* If the stream currently has any buffered data it will be written to $is
* before unbinding occurs.
*
* @param Swift_InputByteStream $is
*/
public function unbind(Swift_InputByteStream $is)
{
foreach ($this->_mirrors as $k => $stream) {
if ($is === $stream) {
unset($this->_mirrors[$k]);
}
}
}
/**
* Move the internal read pointer to $byteOffset in the stream.
* @param int $byteOffset
* @return boolean
*/
public function setReadPointer($byteOffset)
{
if ($byteOffset > $this->_arraySize) {
$byteOffset = $this->_arraySize;
} elseif ($byteOffset < 0) {
$byteOffset = 0;
}
$this->_offset = $byteOffset;
}
/**
* Flush the contents of the stream (empty it) and set the internal pointer
* to the beginning.
*/
public function flushBuffers()
{
$this->_offset = 0;
$this->_array = array();
$this->_arraySize = 0;
foreach ($this->_mirrors as $stream) {
$stream->flushBuffers();
}
}
}

View File

@@ -8,227 +8,205 @@
* file that was distributed with this source code.
*/
/**
* Allows reading and writing of bytes to and from a file.
* @package Swift
* @subpackage ByteStream
* @author Chris Corbyn
*/
class Swift_ByteStream_FileByteStream
extends Swift_ByteStream_AbstractFilterableInputStream
implements Swift_FileStream
class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterableInputStream implements Swift_FileStream
{
/** The internal pointer offset */
private $_offset = 0;
/** The path to the file */
private $_path;
/** The mode this file is opened in for writing */
private $_mode;
/** A lazy-loaded resource handle for reading the file */
private $_reader;
/** A lazy-loaded resource handle for writing the file */
private $_writer;
/** If magic_quotes_runtime is on, this will be true */
private $_quotes = false;
/** The internal pointer offset */
private $_offset = 0;
/** If stream is seekable true/false, or null if not known */
private $_seekable = null;
/**
* Create a new FileByteStream for $path.
* @param string $path
* @param string $writable if true
*/
public function __construct($path, $writable = false)
{
$this->_path = $path;
$this->_mode = $writable ? 'w+b' : 'rb';
if (function_exists('get_magic_quotes_runtime') && @get_magic_quotes_runtime() == 1)
/** The path to the file */
private $_path;
/** The mode this file is opened in for writing */
private $_mode;
/** A lazy-loaded resource handle for reading the file */
private $_reader;
/** A lazy-loaded resource handle for writing the file */
private $_writer;
/** If magic_quotes_runtime is on, this will be true */
private $_quotes = false;
/** If stream is seekable true/false, or null if not known */
private $_seekable = null;
/**
* Create a new FileByteStream for $path.
* @param string $path
* @param string $writable if true
*/
public function __construct($path, $writable = false)
{
$this->_quotes = true;
$this->_path = $path;
$this->_mode = $writable ? 'w+b' : 'rb';
if (function_exists('get_magic_quotes_runtime') && @get_magic_quotes_runtime() == 1) {
$this->_quotes = true;
}
}
}
/**
* Get the complete path to the file.
* @return string
*/
public function getPath()
{
return $this->_path;
}
/**
* Reads $length bytes from the stream into a string and moves the pointer
* through the stream by $length. If less bytes exist than are requested the
* remaining bytes are given instead. If no bytes are remaining at all, boolean
* false is returned.
* @param int $length
* @return string
* @throws Swift_IoException
*/
public function read($length)
{
$fp = $this->_getReadHandle();
if (!feof($fp))
/**
* Get the complete path to the file.
* @return string
*/
public function getPath()
{
if ($this->_quotes)
{
ini_set('magic_quotes_runtime', 0);
}
$bytes = fread($fp, $length);
if ($this->_quotes)
{
ini_set('magic_quotes_runtime', 1);
}
$this->_offset = ftell($fp);
return $bytes;
return $this->_path;
}
else
/**
* Reads $length bytes from the stream into a string and moves the pointer
* through the stream by $length. If less bytes exist than are requested the
* remaining bytes are given instead. If no bytes are remaining at all, boolean
* false is returned.
* @param int $length
* @return string
* @throws Swift_IoException
*/
public function read($length)
{
$this->_resetReadHandle();
return false;
$fp = $this->_getReadHandle();
if (!feof($fp)) {
if ($this->_quotes) {
ini_set('magic_quotes_runtime', 0);
}
$bytes = fread($fp, $length);
if ($this->_quotes) {
ini_set('magic_quotes_runtime', 1);
}
$this->_offset = ftell($fp);
return $bytes;
} else {
$this->_resetReadHandle();
return false;
}
}
}
/**
* Move the internal read pointer to $byteOffset in the stream.
* @param int $byteOffset
* @return boolean
*/
public function setReadPointer($byteOffset)
{
if (isset($this->_reader))
/**
* Move the internal read pointer to $byteOffset in the stream.
* @param int $byteOffset
* @return boolean
*/
public function setReadPointer($byteOffset)
{
$this->_seekReadStreamToPosition($byteOffset);
if (isset($this->_reader)) {
$this->_seekReadStreamToPosition($byteOffset);
}
$this->_offset = $byteOffset;
}
$this->_offset = $byteOffset;
}
// -- Private methods
/** Just write the bytes to the file */
protected function _commit($bytes)
{
fwrite($this->_getWriteHandle(), $bytes);
$this->_resetReadHandle();
}
/** Not used */
protected function _flush()
{
}
/** Get the resource for reading */
private function _getReadHandle()
{
if (!isset($this->_reader))
// -- Private methods
/** Just write the bytes to the file */
protected function _commit($bytes)
{
if (!$this->_reader = fopen($this->_path, 'rb'))
{
throw new Swift_IoException(
'Unable to open file for reading [' . $this->_path . ']'
);
}
if ($this->_offset <> 0)
{
$this->_getReadStreamSeekableStatus();
$this->_seekReadStreamToPosition($this->_offset);
}
fwrite($this->_getWriteHandle(), $bytes);
$this->_resetReadHandle();
}
return $this->_reader;
}
/** Get the resource for writing */
private function _getWriteHandle()
{
if (!isset($this->_writer))
/** Not used */
protected function _flush()
{
if (!$this->_writer = fopen($this->_path, $this->_mode))
{
throw new Swift_IoException(
'Unable to open file for writing [' . $this->_path . ']'
);
}
}
return $this->_writer;
}
/** Force a reload of the resource for reading */
private function _resetReadHandle()
{
if (isset($this->_reader))
/** Get the resource for reading */
private function _getReadHandle()
{
fclose($this->_reader);
$this->_reader = null;
if (!isset($this->_reader)) {
if (!$this->_reader = fopen($this->_path, 'rb')) {
throw new Swift_IoException(
'Unable to open file for reading [' . $this->_path . ']'
);
}
if ($this->_offset <> 0) {
$this->_getReadStreamSeekableStatus();
$this->_seekReadStreamToPosition($this->_offset);
}
}
return $this->_reader;
}
}
/** Check if ReadOnly Stream is seekable */
private function _getReadStreamSeekableStatus()
{
$metas = stream_get_meta_data($this->_reader);
$this->_seekable = $metas['seekable'];
}
/** Streams in a readOnly stream ensuring copy if needed */
private function _seekReadStreamToPosition($offset)
{
if ($this->_seekable===null)
/** Get the resource for writing */
private function _getWriteHandle()
{
$this->_getReadStreamSeekableStatus();
if (!isset($this->_writer)) {
if (!$this->_writer = fopen($this->_path, $this->_mode)) {
throw new Swift_IoException(
'Unable to open file for writing [' . $this->_path . ']'
);
}
}
return $this->_writer;
}
if ($this->_seekable === false)
/** Force a reload of the resource for reading */
private function _resetReadHandle()
{
$currentPos = ftell($this->_reader);
if ($currentPos<$offset)
{
$toDiscard = $offset-$currentPos;
fread($this->_reader, $toDiscard);
return;
}
$this->_copyReadStream();
if (isset($this->_reader)) {
fclose($this->_reader);
$this->_reader = null;
}
}
fseek($this->_reader, $offset, SEEK_SET);
}
/** Copy a readOnly Stream to ensure seekability */
private function _copyReadStream()
{
if ($tmpFile = fopen('php://temp/maxmemory:4096', 'w+b'))
/** Check if ReadOnly Stream is seekable */
private function _getReadStreamSeekableStatus()
{
/* We have opened a php:// Stream Should work without problem */
}
elseif (function_exists('sys_get_temp_dir') && is_writable(sys_get_temp_dir()) && ($tmpFile = tmpfile()))
{
/* We have opened a tmpfile */
}
else
{
throw new Swift_IoException('Unable to copy the file to make it seekable, sys_temp_dir is not writable, php://memory not available');
$metas = stream_get_meta_data($this->_reader);
$this->_seekable = $metas['seekable'];
}
$currentPos = ftell($this->_reader);
fclose($this->_reader);
$source = fopen($this->_path, 'rb');
if (!$source)
/** Streams in a readOnly stream ensuring copy if needed */
private function _seekReadStreamToPosition($offset)
{
throw new Swift_IoException('Unable to open file for copying [' . $this->_path . ']');
if ($this->_seekable===null) {
$this->_getReadStreamSeekableStatus();
}
if ($this->_seekable === false) {
$currentPos = ftell($this->_reader);
if ($currentPos<$offset) {
$toDiscard = $offset-$currentPos;
fread($this->_reader, $toDiscard);
return;
}
$this->_copyReadStream();
}
fseek($this->_reader, $offset, SEEK_SET);
}
fseek($tmpFile, 0, SEEK_SET);
while (!feof($source))
/** Copy a readOnly Stream to ensure seekability */
private function _copyReadStream()
{
fwrite($tmpFile, fread($source, 4096));
if ($tmpFile = fopen('php://temp/maxmemory:4096', 'w+b')) {
/* We have opened a php:// Stream Should work without problem */
} elseif (function_exists('sys_get_temp_dir') && is_writable(sys_get_temp_dir()) && ($tmpFile = tmpfile())) {
/* We have opened a tmpfile */
} else {
throw new Swift_IoException('Unable to copy the file to make it seekable, sys_temp_dir is not writable, php://memory not available');
}
$currentPos = ftell($this->_reader);
fclose($this->_reader);
$source = fopen($this->_path, 'rb');
if (!$source) {
throw new Swift_IoException('Unable to open file for copying [' . $this->_path . ']');
}
fseek($tmpFile, 0, SEEK_SET);
while (!feof($source)) {
fwrite($tmpFile, fread($source, 4096));
}
fseek($tmpFile, $currentPos, SEEK_SET);
fclose($source);
$this->_reader = $tmpFile;
}
fseek($tmpFile, $currentPos, SEEK_SET);
fclose($source);
$this->_reader = $tmpFile;
}
}

View File

@@ -17,44 +17,43 @@
*/
interface Swift_CharacterReader
{
const MAP_TYPE_INVALID = 0x01;
const MAP_TYPE_FIXED_LEN = 0x02;
const MAP_TYPE_POSITIONS = 0x03;
/**
* Returns the complete charactermap
*
* @param string $string
* @param int $startOffset
* @param array $currentMap
* @param mixed $ignoredChars
* @return int
*/
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars);
/**
* Returns mapType
* @return int mapType
*/
public function getMapType();
/**
* Returns an integer which specifies how many more bytes to read.
* A positive integer indicates the number of more bytes to fetch before invoking
* this method again.
* A value of zero means this is already a valid character.
* A value of -1 means this cannot possibly be a valid character.
* @param int[] $bytes
* @return int
*/
public function validateByteSequence($bytes, $size);
const MAP_TYPE_INVALID = 0x01;
const MAP_TYPE_FIXED_LEN = 0x02;
const MAP_TYPE_POSITIONS = 0x03;
/**
* Returns the number of bytes which should be read to start each character.
* For fixed width character sets this should be the number of
* octets-per-character. For multibyte character sets this will probably be 1.
* @return int
*/
public function getInitialByteSize();
/**
* Returns the complete charactermap
*
* @param string $string
* @param int $startOffset
* @param array $currentMap
* @param mixed $ignoredChars
* @return int
*/
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars);
/**
* Returns mapType
* @return int mapType
*/
public function getMapType();
/**
* Returns an integer which specifies how many more bytes to read.
* A positive integer indicates the number of more bytes to fetch before invoking
* this method again.
* A value of zero means this is already a valid character.
* A value of -1 means this cannot possibly be a valid character.
* @param int[] $bytes
* @return int
*/
public function validateByteSequence($bytes, $size);
/**
* Returns the number of bytes which should be read to start each character.
* For fixed width character sets this should be the number of
* octets-per-character. For multibyte character sets this will probably be 1.
* @return int
*/
public function getInitialByteSize();
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Provides fixed-width byte sizes for reading fixed-width character sets.
* @package Swift
@@ -16,76 +15,75 @@
* @author Chris Corbyn
* @author Xavier De Cock <xdecock@gmail.com>
*/
class Swift_CharacterReader_GenericFixedWidthReader
implements Swift_CharacterReader
class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterReader
{
/**
* The number of bytes in a single character.
* @var int
* @access private
*/
private $_width;
/**
* The number of bytes in a single character.
* @var int
* @access private
*/
private $_width;
/**
* Creates a new GenericFixedWidthReader using $width bytes per character.
* @param int $width
*/
public function __construct($width)
{
$this->_width = $width;
}
/**
* Creates a new GenericFixedWidthReader using $width bytes per character.
* @param int $width
*/
public function __construct($width)
{
$this->_width = $width;
}
/**
* Returns the complete charactermap
*
* @param string $string
* @param int $startOffset
* @param array $currentMap
* @param mixed $ignoredChars
* @return $int
*/
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
{
$strlen = strlen($string);
// % and / are CPU intensive, so, maybe find a better way
$ignored = $strlen%$this->_width;
$ignoredChars = substr($string, - $ignored);
$currentMap = $this->_width;
/**
* Returns the complete charactermap
*
* @param string $string
* @param int $startOffset
* @param array $currentMap
* @param mixed $ignoredChars
* @return $int
*/
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
{
$strlen = strlen($string);
// % and / are CPU intensive, so, maybe find a better way
$ignored = $strlen%$this->_width;
$ignoredChars = substr($string, - $ignored);
$currentMap = $this->_width;
return ($strlen - $ignored)/$this->_width;
}
/**
* Returns mapType
* @return int mapType
*/
public function getMapType()
{
return self::MAP_TYPE_FIXED_LEN;
}
return ($strlen - $ignored)/$this->_width;
}
/**
* Returns an integer which specifies how many more bytes to read.
* A positive integer indicates the number of more bytes to fetch before invoking
* this method again.
* A value of zero means this is already a valid character.
* A value of -1 means this cannot possibly be a valid character.
* @param string $bytes
* @return int
*/
public function validateByteSequence($bytes, $size)
{
$needed = $this->_width - $size;
/**
* Returns mapType
* @return int mapType
*/
public function getMapType()
{
return self::MAP_TYPE_FIXED_LEN;
}
return ($needed > -1) ? $needed : -1;
}
/**
* Returns an integer which specifies how many more bytes to read.
* A positive integer indicates the number of more bytes to fetch before invoking
* this method again.
* A value of zero means this is already a valid character.
* A value of -1 means this cannot possibly be a valid character.
* @param string $bytes
* @return int
*/
public function validateByteSequence($bytes, $size)
{
$needed = $this->_width - $size;
/**
* Returns the number of bytes which should be read to start each character.
* @return int
*/
public function getInitialByteSize()
{
return $this->_width;
}
return ($needed > -1) ? $needed : -1;
}
/**
* Returns the number of bytes which should be read to start each character.
* @return int
*/
public function getInitialByteSize()
{
return $this->_width;
}
}

View File

@@ -8,75 +8,68 @@
* file that was distributed with this source code.
*/
/**
* Analyzes US-ASCII characters.
* @package Swift
* @subpackage Encoder
* @author Chris Corbyn
*/
class Swift_CharacterReader_UsAsciiReader
implements Swift_CharacterReader
class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader
{
/**
* Returns the complete charactermap
*
* @param string $string
* @param int $startOffset
* @param string $ignoredChars
*/
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
{
$strlen=strlen($string);
$ignoredChars='';
for( $i = 0; $i < $strlen; ++$i)
/**
* Returns the complete charactermap
*
* @param string $string
* @param int $startOffset
* @param string $ignoredChars
*/
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
{
if ($string[$i]>"\x07F")
{ // Invalid char
$currentMap[$i+$startOffset]=$string[$i];
}
}
return $strlen;
}
/**
* Returns mapType
* @return int mapType
*/
public function getMapType()
{
return self::MAP_TYPE_INVALID;
}
/**
* Returns an integer which specifies how many more bytes to read.
* A positive integer indicates the number of more bytes to fetch before invoking
* this method again.
* A value of zero means this is already a valid character.
* A value of -1 means this cannot possibly be a valid character.
* @param string $bytes
* @return int
*/
public function validateByteSequence($bytes, $size)
{
$byte = reset($bytes);
if (1 == count($bytes) && $byte >= 0x00 && $byte <= 0x7F)
{
return 0;
}
else
{
return -1;
}
}
$strlen=strlen($string);
$ignoredChars='';
for ($i = 0; $i < $strlen; ++$i) {
if ($string[$i]>"\x07F") { // Invalid char
$currentMap[$i+$startOffset]=$string[$i];
}
}
/**
* Returns the number of bytes which should be read to start each character.
* @return int
*/
public function getInitialByteSize()
{
return 1;
}
return $strlen;
}
/**
* Returns mapType
* @return int mapType
*/
public function getMapType()
{
return self::MAP_TYPE_INVALID;
}
/**
* Returns an integer which specifies how many more bytes to read.
* A positive integer indicates the number of more bytes to fetch before invoking
* this method again.
* A value of zero means this is already a valid character.
* A value of -1 means this cannot possibly be a valid character.
* @param string $bytes
* @return int
*/
public function validateByteSequence($bytes, $size)
{
$byte = reset($bytes);
if (1 == count($bytes) && $byte >= 0x00 && $byte <= 0x7F) {
return 0;
} else {
return -1;
}
}
/**
* Returns the number of bytes which should be read to start each character.
* @return int
*/
public function getInitialByteSize()
{
return 1;
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Analyzes UTF-8 characters.
* @package Swift
@@ -16,167 +15,157 @@
* @author Chris Corbyn
* @author Xavier De Cock <xdecock@gmail.com>
*/
class Swift_CharacterReader_Utf8Reader
implements Swift_CharacterReader
class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader
{
/** Pre-computed for optimization */
private static $length_map=array(
/** Pre-computed for optimization */
private static $length_map=array(
//N=0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x0N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x1N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x2N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x3N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x4N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x5N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x6N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x7N
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0x8N
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0x9N
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0xAN
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0xBN
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, //0xCN
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, //0xDN
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, //0xEN
4,4,4,4,4,4,4,4,5,5,5,5,6,6,0,0 //0xFN
);
private static $s_length_map=array(
"\x00"=>1, "\x01"=>1, "\x02"=>1, "\x03"=>1, "\x04"=>1, "\x05"=>1, "\x06"=>1, "\x07"=>1,
"\x08"=>1, "\x09"=>1, "\x0a"=>1, "\x0b"=>1, "\x0c"=>1, "\x0d"=>1, "\x0e"=>1, "\x0f"=>1,
"\x10"=>1, "\x11"=>1, "\x12"=>1, "\x13"=>1, "\x14"=>1, "\x15"=>1, "\x16"=>1, "\x17"=>1,
"\x18"=>1, "\x19"=>1, "\x1a"=>1, "\x1b"=>1, "\x1c"=>1, "\x1d"=>1, "\x1e"=>1, "\x1f"=>1,
"\x20"=>1, "\x21"=>1, "\x22"=>1, "\x23"=>1, "\x24"=>1, "\x25"=>1, "\x26"=>1, "\x27"=>1,
"\x28"=>1, "\x29"=>1, "\x2a"=>1, "\x2b"=>1, "\x2c"=>1, "\x2d"=>1, "\x2e"=>1, "\x2f"=>1,
"\x30"=>1, "\x31"=>1, "\x32"=>1, "\x33"=>1, "\x34"=>1, "\x35"=>1, "\x36"=>1, "\x37"=>1,
"\x38"=>1, "\x39"=>1, "\x3a"=>1, "\x3b"=>1, "\x3c"=>1, "\x3d"=>1, "\x3e"=>1, "\x3f"=>1,
"\x40"=>1, "\x41"=>1, "\x42"=>1, "\x43"=>1, "\x44"=>1, "\x45"=>1, "\x46"=>1, "\x47"=>1,
"\x48"=>1, "\x49"=>1, "\x4a"=>1, "\x4b"=>1, "\x4c"=>1, "\x4d"=>1, "\x4e"=>1, "\x4f"=>1,
"\x50"=>1, "\x51"=>1, "\x52"=>1, "\x53"=>1, "\x54"=>1, "\x55"=>1, "\x56"=>1, "\x57"=>1,
"\x58"=>1, "\x59"=>1, "\x5a"=>1, "\x5b"=>1, "\x5c"=>1, "\x5d"=>1, "\x5e"=>1, "\x5f"=>1,
"\x60"=>1, "\x61"=>1, "\x62"=>1, "\x63"=>1, "\x64"=>1, "\x65"=>1, "\x66"=>1, "\x67"=>1,
"\x68"=>1, "\x69"=>1, "\x6a"=>1, "\x6b"=>1, "\x6c"=>1, "\x6d"=>1, "\x6e"=>1, "\x6f"=>1,
"\x70"=>1, "\x71"=>1, "\x72"=>1, "\x73"=>1, "\x74"=>1, "\x75"=>1, "\x76"=>1, "\x77"=>1,
"\x78"=>1, "\x79"=>1, "\x7a"=>1, "\x7b"=>1, "\x7c"=>1, "\x7d"=>1, "\x7e"=>1, "\x7f"=>1,
"\x80"=>0, "\x81"=>0, "\x82"=>0, "\x83"=>0, "\x84"=>0, "\x85"=>0, "\x86"=>0, "\x87"=>0,
"\x88"=>0, "\x89"=>0, "\x8a"=>0, "\x8b"=>0, "\x8c"=>0, "\x8d"=>0, "\x8e"=>0, "\x8f"=>0,
"\x90"=>0, "\x91"=>0, "\x92"=>0, "\x93"=>0, "\x94"=>0, "\x95"=>0, "\x96"=>0, "\x97"=>0,
"\x98"=>0, "\x99"=>0, "\x9a"=>0, "\x9b"=>0, "\x9c"=>0, "\x9d"=>0, "\x9e"=>0, "\x9f"=>0,
"\xa0"=>0, "\xa1"=>0, "\xa2"=>0, "\xa3"=>0, "\xa4"=>0, "\xa5"=>0, "\xa6"=>0, "\xa7"=>0,
"\xa8"=>0, "\xa9"=>0, "\xaa"=>0, "\xab"=>0, "\xac"=>0, "\xad"=>0, "\xae"=>0, "\xaf"=>0,
"\xb0"=>0, "\xb1"=>0, "\xb2"=>0, "\xb3"=>0, "\xb4"=>0, "\xb5"=>0, "\xb6"=>0, "\xb7"=>0,
"\xb8"=>0, "\xb9"=>0, "\xba"=>0, "\xbb"=>0, "\xbc"=>0, "\xbd"=>0, "\xbe"=>0, "\xbf"=>0,
"\xc0"=>2, "\xc1"=>2, "\xc2"=>2, "\xc3"=>2, "\xc4"=>2, "\xc5"=>2, "\xc6"=>2, "\xc7"=>2,
"\xc8"=>2, "\xc9"=>2, "\xca"=>2, "\xcb"=>2, "\xcc"=>2, "\xcd"=>2, "\xce"=>2, "\xcf"=>2,
"\xd0"=>2, "\xd1"=>2, "\xd2"=>2, "\xd3"=>2, "\xd4"=>2, "\xd5"=>2, "\xd6"=>2, "\xd7"=>2,
"\xd8"=>2, "\xd9"=>2, "\xda"=>2, "\xdb"=>2, "\xdc"=>2, "\xdd"=>2, "\xde"=>2, "\xdf"=>2,
"\xe0"=>3, "\xe1"=>3, "\xe2"=>3, "\xe3"=>3, "\xe4"=>3, "\xe5"=>3, "\xe6"=>3, "\xe7"=>3,
"\xe8"=>3, "\xe9"=>3, "\xea"=>3, "\xeb"=>3, "\xec"=>3, "\xed"=>3, "\xee"=>3, "\xef"=>3,
"\xf0"=>4, "\xf1"=>4, "\xf2"=>4, "\xf3"=>4, "\xf4"=>4, "\xf5"=>4, "\xf6"=>4, "\xf7"=>4,
"\xf8"=>5, "\xf9"=>5, "\xfa"=>5, "\xfb"=>5, "\xfc"=>6, "\xfd"=>6, "\xfe"=>0, "\xff"=>0,
);
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x0N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x1N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x2N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x3N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x4N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x5N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x6N
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //0x7N
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0x8N
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0x9N
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0xAN
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //0xBN
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, //0xCN
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, //0xDN
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, //0xEN
4,4,4,4,4,4,4,4,5,5,5,5,6,6,0,0 //0xFN
);
/**
* Returns the complete charactermap
*
* @param string $string
* @param int $startOffset
* @param array $currentMap
* @param mixed $ignoredChars
*/
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
{
if (!isset($currentMap['i']) || !isset($currentMap['p']))
private static $s_length_map=array(
"\x00"=>1, "\x01"=>1, "\x02"=>1, "\x03"=>1, "\x04"=>1, "\x05"=>1, "\x06"=>1, "\x07"=>1,
"\x08"=>1, "\x09"=>1, "\x0a"=>1, "\x0b"=>1, "\x0c"=>1, "\x0d"=>1, "\x0e"=>1, "\x0f"=>1,
"\x10"=>1, "\x11"=>1, "\x12"=>1, "\x13"=>1, "\x14"=>1, "\x15"=>1, "\x16"=>1, "\x17"=>1,
"\x18"=>1, "\x19"=>1, "\x1a"=>1, "\x1b"=>1, "\x1c"=>1, "\x1d"=>1, "\x1e"=>1, "\x1f"=>1,
"\x20"=>1, "\x21"=>1, "\x22"=>1, "\x23"=>1, "\x24"=>1, "\x25"=>1, "\x26"=>1, "\x27"=>1,
"\x28"=>1, "\x29"=>1, "\x2a"=>1, "\x2b"=>1, "\x2c"=>1, "\x2d"=>1, "\x2e"=>1, "\x2f"=>1,
"\x30"=>1, "\x31"=>1, "\x32"=>1, "\x33"=>1, "\x34"=>1, "\x35"=>1, "\x36"=>1, "\x37"=>1,
"\x38"=>1, "\x39"=>1, "\x3a"=>1, "\x3b"=>1, "\x3c"=>1, "\x3d"=>1, "\x3e"=>1, "\x3f"=>1,
"\x40"=>1, "\x41"=>1, "\x42"=>1, "\x43"=>1, "\x44"=>1, "\x45"=>1, "\x46"=>1, "\x47"=>1,
"\x48"=>1, "\x49"=>1, "\x4a"=>1, "\x4b"=>1, "\x4c"=>1, "\x4d"=>1, "\x4e"=>1, "\x4f"=>1,
"\x50"=>1, "\x51"=>1, "\x52"=>1, "\x53"=>1, "\x54"=>1, "\x55"=>1, "\x56"=>1, "\x57"=>1,
"\x58"=>1, "\x59"=>1, "\x5a"=>1, "\x5b"=>1, "\x5c"=>1, "\x5d"=>1, "\x5e"=>1, "\x5f"=>1,
"\x60"=>1, "\x61"=>1, "\x62"=>1, "\x63"=>1, "\x64"=>1, "\x65"=>1, "\x66"=>1, "\x67"=>1,
"\x68"=>1, "\x69"=>1, "\x6a"=>1, "\x6b"=>1, "\x6c"=>1, "\x6d"=>1, "\x6e"=>1, "\x6f"=>1,
"\x70"=>1, "\x71"=>1, "\x72"=>1, "\x73"=>1, "\x74"=>1, "\x75"=>1, "\x76"=>1, "\x77"=>1,
"\x78"=>1, "\x79"=>1, "\x7a"=>1, "\x7b"=>1, "\x7c"=>1, "\x7d"=>1, "\x7e"=>1, "\x7f"=>1,
"\x80"=>0, "\x81"=>0, "\x82"=>0, "\x83"=>0, "\x84"=>0, "\x85"=>0, "\x86"=>0, "\x87"=>0,
"\x88"=>0, "\x89"=>0, "\x8a"=>0, "\x8b"=>0, "\x8c"=>0, "\x8d"=>0, "\x8e"=>0, "\x8f"=>0,
"\x90"=>0, "\x91"=>0, "\x92"=>0, "\x93"=>0, "\x94"=>0, "\x95"=>0, "\x96"=>0, "\x97"=>0,
"\x98"=>0, "\x99"=>0, "\x9a"=>0, "\x9b"=>0, "\x9c"=>0, "\x9d"=>0, "\x9e"=>0, "\x9f"=>0,
"\xa0"=>0, "\xa1"=>0, "\xa2"=>0, "\xa3"=>0, "\xa4"=>0, "\xa5"=>0, "\xa6"=>0, "\xa7"=>0,
"\xa8"=>0, "\xa9"=>0, "\xaa"=>0, "\xab"=>0, "\xac"=>0, "\xad"=>0, "\xae"=>0, "\xaf"=>0,
"\xb0"=>0, "\xb1"=>0, "\xb2"=>0, "\xb3"=>0, "\xb4"=>0, "\xb5"=>0, "\xb6"=>0, "\xb7"=>0,
"\xb8"=>0, "\xb9"=>0, "\xba"=>0, "\xbb"=>0, "\xbc"=>0, "\xbd"=>0, "\xbe"=>0, "\xbf"=>0,
"\xc0"=>2, "\xc1"=>2, "\xc2"=>2, "\xc3"=>2, "\xc4"=>2, "\xc5"=>2, "\xc6"=>2, "\xc7"=>2,
"\xc8"=>2, "\xc9"=>2, "\xca"=>2, "\xcb"=>2, "\xcc"=>2, "\xcd"=>2, "\xce"=>2, "\xcf"=>2,
"\xd0"=>2, "\xd1"=>2, "\xd2"=>2, "\xd3"=>2, "\xd4"=>2, "\xd5"=>2, "\xd6"=>2, "\xd7"=>2,
"\xd8"=>2, "\xd9"=>2, "\xda"=>2, "\xdb"=>2, "\xdc"=>2, "\xdd"=>2, "\xde"=>2, "\xdf"=>2,
"\xe0"=>3, "\xe1"=>3, "\xe2"=>3, "\xe3"=>3, "\xe4"=>3, "\xe5"=>3, "\xe6"=>3, "\xe7"=>3,
"\xe8"=>3, "\xe9"=>3, "\xea"=>3, "\xeb"=>3, "\xec"=>3, "\xed"=>3, "\xee"=>3, "\xef"=>3,
"\xf0"=>4, "\xf1"=>4, "\xf2"=>4, "\xf3"=>4, "\xf4"=>4, "\xf5"=>4, "\xf6"=>4, "\xf7"=>4,
"\xf8"=>5, "\xf9"=>5, "\xfa"=>5, "\xfb"=>5, "\xfc"=>6, "\xfd"=>6, "\xfe"=>0, "\xff"=>0,
);
/**
* Returns the complete charactermap
*
* @param string $string
* @param int $startOffset
* @param array $currentMap
* @param mixed $ignoredChars
*/
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
{
$currentMap['p'] = $currentMap['i'] = array();
if (!isset($currentMap['i']) || !isset($currentMap['p'])) {
$currentMap['p'] = $currentMap['i'] = array();
}
$strlen=strlen($string);
$charPos=count($currentMap['p']);
$foundChars=0;
$invalid=false;
for ($i=0; $i<$strlen; ++$i)
{
$char=$string[$i];
$size=self::$s_length_map[$char];
if ($size==0)
{
/* char is invalid, we must wait for a resync */
$invalid=true;
continue;
}
else
{
if ($invalid==true)
{
$strlen=strlen($string);
$charPos=count($currentMap['p']);
$foundChars=0;
$invalid=false;
for ($i=0; $i<$strlen; ++$i) {
$char=$string[$i];
$size=self::$s_length_map[$char];
if ($size==0) {
/* char is invalid, we must wait for a resync */
$invalid=true;
continue;
} else {
if ($invalid==true) {
/* We mark the chars as invalid and start a new char */
$currentMap['p'][$charPos+$foundChars]=$startOffset+$i;
$currentMap['i'][$charPos+$foundChars]=true;
++$foundChars;
$invalid=false;
}
if (($i+$size) > $strlen){
if (($i+$size) > $strlen) {
$ignoredChars=substr($string, $i);
break;
}
for ($j=1; $j<$size; ++$j)
{
$char=$string[$i+$j];
if ($char>"\x7F" && $char<"\xC0")
{
// Valid - continue parsing
}
else
{
/* char is invalid, we must wait for a resync */
$invalid=true;
continue 2;
}
for ($j=1; $j<$size; ++$j) {
$char=$string[$i+$j];
if ($char>"\x7F" && $char<"\xC0") {
// Valid - continue parsing
} else {
/* char is invalid, we must wait for a resync */
$invalid=true;
continue 2;
}
}
/* Ok we got a complete char here */
$currentMap['p'][$charPos+$foundChars]=$startOffset+$i+$size;
$i+=$j-1;
++$foundChars;
}
}
return $foundChars;
}
/**
* Returns mapType
* @return int mapType
*/
public function getMapType()
{
return self::MAP_TYPE_POSITIONS;
}
/**
* Returns an integer which specifies how many more bytes to read.
* A positive integer indicates the number of more bytes to fetch before invoking
* this method again.
* A value of zero means this is already a valid character.
* A value of -1 means this cannot possibly be a valid character.
* @param string $bytes
* @return int
*/
public function validateByteSequence($bytes, $size)
{
if ($size<1){
return -1;
}
$needed = self::$length_map[$bytes[0]] - $size;
return ($needed > -1)
? $needed
: -1
;
}
}
/**
* Returns the number of bytes which should be read to start each character.
* @return int
*/
public function getInitialByteSize()
{
return 1;
}
return $foundChars;
}
/**
* Returns mapType
* @return int mapType
*/
public function getMapType()
{
return self::MAP_TYPE_POSITIONS;
}
/**
* Returns an integer which specifies how many more bytes to read.
* A positive integer indicates the number of more bytes to fetch before invoking
* this method again.
* A value of zero means this is already a valid character.
* A value of -1 means this cannot possibly be a valid character.
* @param string $bytes
* @return int
*/
public function validateByteSequence($bytes, $size)
{
if ($size<1) {
return -1;
}
$needed = self::$length_map[$bytes[0]] - $size;
return ($needed > -1)
? $needed
: -1
;
}
/**
* Returns the number of bytes which should be read to start each character.
* @return int
*/
public function getInitialByteSize()
{
return 1;
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* A factory for creating CharacterReaders.
* @package Swift
@@ -17,12 +16,10 @@
*/
interface Swift_CharacterReaderFactory
{
/**
* Returns a CharacterReader suitable for the charset applied.
* @param string $charset
* @return Swift_CharacterReader
*/
public function getReaderFor($charset);
/**
* Returns a CharacterReader suitable for the charset applied.
* @param string $charset
* @return Swift_CharacterReader
*/
public function getReaderFor($charset);
}

View File

@@ -8,126 +8,116 @@
* file that was distributed with this source code.
*/
/**
* Standard factory for creating CharacterReaders.
* @package Swift
* @subpackage Encoder
* @author Chris Corbyn
*/
class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory
implements Swift_CharacterReaderFactory
class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift_CharacterReaderFactory
{
/**
* A map of charset patterns to their implementation classes.
* @var array
* @access private
*/
private static $_map = array();
/**
* A map of charset patterns to their implementation classes.
* @var array
* @access private
*/
private static $_map = array();
/**
* Factories which have already been loaded.
* @var Swift_CharacterReaderFactory[]
* @access private
*/
private static $_loaded = array();
/**
* Creates a new CharacterReaderFactory.
*/
public function __construct()
{
$this->init();
}
/**
* Factories which have already been loaded.
* @var Swift_CharacterReaderFactory[]
* @access private
*/
private static $_loaded = array();
public function __wakeup()
{
$this->init();
}
public function init()
{
if(count(self::$_map) > 0)
/**
* Creates a new CharacterReaderFactory.
*/
public function __construct()
{
return;
$this->init();
}
$prefix = 'Swift_CharacterReader_';
$singleByte = array(
'class' => $prefix . 'GenericFixedWidthReader',
'constructor' => array(1)
);
$doubleByte = array(
'class' => $prefix . 'GenericFixedWidthReader',
'constructor' => array(2)
);
$fourBytes = array(
'class' => $prefix . 'GenericFixedWidthReader',
'constructor' => array(4)
);
//Utf-8
self::$_map['utf-?8'] = array(
'class' => $prefix . 'Utf8Reader',
'constructor' => array()
);
//7-8 bit charsets
self::$_map['(us-)?ascii'] = $singleByte;
self::$_map['(iso|iec)-?8859-?[0-9]+'] = $singleByte;
self::$_map['windows-?125[0-9]'] = $singleByte;
self::$_map['cp-?[0-9]+'] = $singleByte;
self::$_map['ansi'] = $singleByte;
self::$_map['macintosh'] = $singleByte;
self::$_map['koi-?7'] = $singleByte;
self::$_map['koi-?8-?.+'] = $singleByte;
self::$_map['mik'] = $singleByte;
self::$_map['(cork|t1)'] = $singleByte;
self::$_map['v?iscii'] = $singleByte;
//16 bits
self::$_map['(ucs-?2|utf-?16)'] = $doubleByte;
//32 bits
self::$_map['(ucs-?4|utf-?32)'] = $fourBytes;
//Fallback
self::$_map['.*'] = $singleByte;
}
/**
* Returns a CharacterReader suitable for the charset applied.
* @param string $charset
* @return Swift_CharacterReader
*/
public function getReaderFor($charset)
{
$charset = trim(strtolower($charset));
foreach (self::$_map as $pattern => $spec)
public function __wakeup()
{
$re = '/^' . $pattern . '$/D';
if (preg_match($re, $charset))
{
if (!array_key_exists($pattern, self::$_loaded))
{
$reflector = new ReflectionClass($spec['class']);
if ($reflector->getConstructor())
{
$reader = $reflector->newInstanceArgs($spec['constructor']);
}
else
{
$reader = $reflector->newInstance();
}
self::$_loaded[$pattern] = $reader;
$this->init();
}
public function init()
{
if (count(self::$_map) > 0) {
return;
}
$prefix = 'Swift_CharacterReader_';
$singleByte = array(
'class' => $prefix . 'GenericFixedWidthReader',
'constructor' => array(1)
);
$doubleByte = array(
'class' => $prefix . 'GenericFixedWidthReader',
'constructor' => array(2)
);
$fourBytes = array(
'class' => $prefix . 'GenericFixedWidthReader',
'constructor' => array(4)
);
//Utf-8
self::$_map['utf-?8'] = array(
'class' => $prefix . 'Utf8Reader',
'constructor' => array()
);
//7-8 bit charsets
self::$_map['(us-)?ascii'] = $singleByte;
self::$_map['(iso|iec)-?8859-?[0-9]+'] = $singleByte;
self::$_map['windows-?125[0-9]'] = $singleByte;
self::$_map['cp-?[0-9]+'] = $singleByte;
self::$_map['ansi'] = $singleByte;
self::$_map['macintosh'] = $singleByte;
self::$_map['koi-?7'] = $singleByte;
self::$_map['koi-?8-?.+'] = $singleByte;
self::$_map['mik'] = $singleByte;
self::$_map['(cork|t1)'] = $singleByte;
self::$_map['v?iscii'] = $singleByte;
//16 bits
self::$_map['(ucs-?2|utf-?16)'] = $doubleByte;
//32 bits
self::$_map['(ucs-?4|utf-?32)'] = $fourBytes;
//Fallback
self::$_map['.*'] = $singleByte;
}
/**
* Returns a CharacterReader suitable for the charset applied.
* @param string $charset
* @return Swift_CharacterReader
*/
public function getReaderFor($charset)
{
$charset = trim(strtolower($charset));
foreach (self::$_map as $pattern => $spec) {
$re = '/^' . $pattern . '$/D';
if (preg_match($re, $charset)) {
if (!array_key_exists($pattern, self::$_loaded)) {
$reflector = new ReflectionClass($spec['class']);
if ($reflector->getConstructor()) {
$reader = $reflector->newInstanceArgs($spec['constructor']);
} else {
$reader = $reflector->newInstance();
}
self::$_loaded[$pattern] = $reader;
}
return self::$_loaded[$pattern];
}
}
return self::$_loaded[$pattern];
}
}
}
}

View File

@@ -11,7 +11,6 @@
require_once dirname(__FILE__) . '/OutputByteStream.php';
require_once dirname(__FILE__) . '/CharacterReaderFactory.php';
/**
* An abstract means of reading and writing data in terms of characters as opposed
* to bytes.
@@ -23,64 +22,61 @@ require_once dirname(__FILE__) . '/CharacterReaderFactory.php';
*/
interface Swift_CharacterStream
{
/**
* Set the character set used in this CharacterStream.
* @param string $charset
*/
public function setCharacterSet($charset);
/**
* Set the character set used in this CharacterStream.
* @param string $charset
*/
public function setCharacterSet($charset);
/**
* Set the CharacterReaderFactory for multi charset support.
* @param Swift_CharacterReaderFactory $factory
*/
public function setCharacterReaderFactory(
Swift_CharacterReaderFactory $factory);
/**
* Overwrite this character stream using the byte sequence in the byte stream.
* @param Swift_OutputByteStream $os output stream to read from
*/
public function importByteStream(Swift_OutputByteStream $os);
/**
* Import a string a bytes into this CharacterStream, overwriting any existing
* data in the stream.
* @param string $string
*/
public function importString($string);
/**
* Read $length characters from the stream and move the internal pointer
* $length further into the stream.
* @param int $length
* @return string
*/
public function read($length);
/**
* Read $length characters from the stream and return a 1-dimensional array
* containing there octet values.
* @param int $length
* @return int[]
*/
public function readBytes($length);
/**
* Write $chars to the end of the stream.
* @param string $chars
*/
public function write($chars);
/**
* Move the internal pointer to $charOffset in the stream.
* @param int $charOffset
*/
public function setPointer($charOffset);
/**
* Empty the stream and reset the internal pointer.
*/
public function flushContents();
/**
* Set the CharacterReaderFactory for multi charset support.
* @param Swift_CharacterReaderFactory $factory
*/
public function setCharacterReaderFactory(Swift_CharacterReaderFactory $factory);
/**
* Overwrite this character stream using the byte sequence in the byte stream.
* @param Swift_OutputByteStream $os output stream to read from
*/
public function importByteStream(Swift_OutputByteStream $os);
/**
* Import a string a bytes into this CharacterStream, overwriting any existing
* data in the stream.
* @param string $string
*/
public function importString($string);
/**
* Read $length characters from the stream and move the internal pointer
* $length further into the stream.
* @param int $length
* @return string
*/
public function read($length);
/**
* Read $length characters from the stream and return a 1-dimensional array
* containing there octet values.
* @param int $length
* @return int[]
*/
public function readBytes($length);
/**
* Write $chars to the end of the stream.
* @param string $chars
*/
public function write($chars);
/**
* Move the internal pointer to $charOffset in the stream.
* @param int $charOffset
*/
public function setPointer($charOffset);
/**
* Empty the stream and reset the internal pointer.
*/
public function flushContents();
}

View File

@@ -8,310 +8,277 @@
* file that was distributed with this source code.
*/
/**
* A CharacterStream implementation which stores characters in an internal array.
* @package Swift
* @subpackage CharacterStream
* @author Chris Corbyn
*/
class Swift_CharacterStream_ArrayCharacterStream
implements Swift_CharacterStream
class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStream
{
/** A map of byte values and their respective characters */
private static $_charMap;
/** A map of characters and their derivative byte values */
private static $_byteMap;
/** The char reader (lazy-loaded) for the current charset */
private $_charReader;
/** A map of byte values and their respective characters */
private static $_charMap;
/** A factory for creatiing CharacterReader instances */
private $_charReaderFactory;
/** A map of characters and their derivative byte values */
private static $_byteMap;
/** The character set this stream is using */
private $_charset;
/** The char reader (lazy-loaded) for the current charset */
private $_charReader;
/** Array of characters */
private $_array = array();
/** A factory for creatiing CharacterReader instances */
private $_charReaderFactory;
/** Size of the array of character */
private $_array_size = array();
/** The character set this stream is using */
private $_charset;
/** The current character offset in the stream */
private $_offset = 0;
/** Array of characters */
private $_array = array();
/**
* Create a new CharacterStream with the given $chars, if set.
* @param Swift_CharacterReaderFactory $factory for loading validators
* @param string $charset used in the stream
*/
public function __construct(Swift_CharacterReaderFactory $factory,
$charset)
{
self::_initializeMaps();
$this->setCharacterReaderFactory($factory);
$this->setCharacterSet($charset);
}
/** Size of the array of character */
private $_array_size = array();
/**
* Set the character set used in this CharacterStream.
* @param string $charset
*/
public function setCharacterSet($charset)
{
$this->_charset = $charset;
$this->_charReader = null;
}
/** The current character offset in the stream */
private $_offset = 0;
/**
* Set the CharacterReaderFactory for multi charset support.
* @param Swift_CharacterReaderFactory $factory
*/
public function setCharacterReaderFactory(
Swift_CharacterReaderFactory $factory)
{
$this->_charReaderFactory = $factory;
}
/**
* Overwrite this character stream using the byte sequence in the byte stream.
* @param Swift_OutputByteStream $os output stream to read from
*/
public function importByteStream(Swift_OutputByteStream $os)
{
if (!isset($this->_charReader))
/**
* Create a new CharacterStream with the given $chars, if set.
* @param Swift_CharacterReaderFactory $factory for loading validators
* @param string $charset used in the stream
*/
public function __construct(Swift_CharacterReaderFactory $factory, $charset)
{
$this->_charReader = $this->_charReaderFactory
->getReaderFor($this->_charset);
self::_initializeMaps();
$this->setCharacterReaderFactory($factory);
$this->setCharacterSet($charset);
}
$startLength = $this->_charReader->getInitialByteSize();
while (false !== $bytes = $os->read($startLength))
/**
* Set the character set used in this CharacterStream.
* @param string $charset
*/
public function setCharacterSet($charset)
{
$c = array();
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i)
{
$c[] = self::$_byteMap[$bytes[$i]];
}
$size = count($c);
$need = $this->_charReader
->validateByteSequence($c, $size);
if ($need > 0 &&
false !== $bytes = $os->read($need))
{
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i)
{
$c[] = self::$_byteMap[$bytes[$i]];
$this->_charset = $charset;
$this->_charReader = null;
}
/**
* Set the CharacterReaderFactory for multi charset support.
* @param Swift_CharacterReaderFactory $factory
*/
public function setCharacterReaderFactory(Swift_CharacterReaderFactory $factory)
{
$this->_charReaderFactory = $factory;
}
/**
* Overwrite this character stream using the byte sequence in the byte stream.
* @param Swift_OutputByteStream $os output stream to read from
*/
public function importByteStream(Swift_OutputByteStream $os)
{
if (!isset($this->_charReader)) {
$this->_charReader = $this->_charReaderFactory
->getReaderFor($this->_charset);
}
}
$this->_array[] = $c;
++$this->_array_size;
}
}
/**
* Import a string a bytes into this CharacterStream, overwriting any existing
* data in the stream.
* @param string $string
*/
public function importString($string)
{
$this->flushContents();
$this->write($string);
}
/**
* Read $length characters from the stream and move the internal pointer
* $length further into the stream.
* @param int $length
* @return string
*/
public function read($length)
{
if ($this->_offset == $this->_array_size)
{
return false;
}
// Don't use array slice
$arrays = array();
$end = $length + $this->_offset;
for ($i = $this->_offset; $i < $end; ++$i)
{
if (!isset($this->_array[$i]))
{
break;
}
$arrays[] = $this->_array[$i];
}
$this->_offset += $i - $this->_offset; // Limit function calls
$chars = false;
foreach ($arrays as $array)
{
$chars .= implode('', array_map('chr', $array));
}
return $chars;
}
/**
* Read $length characters from the stream and return a 1-dimensional array
* containing there octet values.
* @param int $length
* @return int[]
*/
public function readBytes($length)
{
if ($this->_offset == $this->_array_size)
{
return false;
}
$arrays = array();
$end = $length + $this->_offset;
for ($i = $this->_offset; $i < $end; ++$i)
{
if (!isset($this->_array[$i]))
{
break;
}
$arrays[] = $this->_array[$i];
}
$this->_offset += ($i - $this->_offset); // Limit function calls
return call_user_func_array('array_merge', $arrays);
}
/**
* Write $chars to the end of the stream.
* @param string $chars
*/
public function write($chars)
{
if (!isset($this->_charReader))
{
$this->_charReader = $this->_charReaderFactory->getReaderFor(
$this->_charset);
}
$startLength = $this->_charReader->getInitialByteSize();
$fp = fopen('php://memory', 'w+b');
fwrite($fp, $chars);
unset($chars);
fseek($fp, 0, SEEK_SET);
$buffer = array(0);
$buf_pos = 1;
$buf_len = 1;
$has_datas = true;
do
{
$bytes = array();
// Buffer Filing
if ($buf_len - $buf_pos < $startLength)
{
$buf = array_splice($buffer, $buf_pos);
$new = $this->_reloadBuffer($fp, 100);
if ($new)
{
$buffer = array_merge($buf, $new);
$buf_len = count($buffer);
$buf_pos = 0;
}
else
{
$has_datas = false;
}
}
if ($buf_len - $buf_pos > 0)
{
$size = 0;
for ($i = 0; $i < $startLength && isset($buffer[$buf_pos]); ++$i)
{
++$size;
$bytes[] = $buffer[$buf_pos++];
}
$need = $this->_charReader->validateByteSequence(
$bytes, $size);
if ($need > 0)
{
if ($buf_len - $buf_pos < $need)
{
$new = $this->_reloadBuffer($fp, $need);
if ($new)
{
$buffer = array_merge($buffer, $new);
$buf_len = count($buffer);
$startLength = $this->_charReader->getInitialByteSize();
while (false !== $bytes = $os->read($startLength)) {
$c = array();
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
$c[] = self::$_byteMap[$bytes[$i]];
}
}
for ($i = 0; $i < $need && isset($buffer[$buf_pos]); ++$i)
{
$bytes[] = $buffer[$buf_pos++];
}
$size = count($c);
$need = $this->_charReader
->validateByteSequence($c, $size);
if ($need > 0 &&
false !== $bytes = $os->read($need))
{
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
$c[] = self::$_byteMap[$bytes[$i]];
}
}
$this->_array[] = $c;
++$this->_array_size;
}
$this->_array[] = $bytes;
++$this->_array_size;
}
}
while ($has_datas);
fclose($fp);
}
/**
* Move the internal pointer to $charOffset in the stream.
* @param int $charOffset
*/
public function setPointer($charOffset)
{
if ($charOffset > $this->_array_size)
/**
* Import a string a bytes into this CharacterStream, overwriting any existing
* data in the stream.
* @param string $string
*/
public function importString($string)
{
$charOffset = $this->_array_size;
$this->flushContents();
$this->write($string);
}
elseif ($charOffset < 0)
{
$charOffset = 0;
}
$this->_offset = $charOffset;
}
/**
* Empty the stream and reset the internal pointer.
*/
public function flushContents()
{
$this->_offset = 0;
$this->_array = array();
$this->_array_size = 0;
}
private function _reloadBuffer($fp, $len)
{
if (!feof($fp) && ($bytes = fread($fp, $len)) !== false)
/**
* Read $length characters from the stream and move the internal pointer
* $length further into the stream.
* @param int $length
* @return string
*/
public function read($length)
{
$buf = array();
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i)
{
$buf[] = self::$_byteMap[$bytes[$i]];
}
return $buf;
if ($this->_offset == $this->_array_size) {
return false;
}
// Don't use array slice
$arrays = array();
$end = $length + $this->_offset;
for ($i = $this->_offset; $i < $end; ++$i) {
if (!isset($this->_array[$i])) {
break;
}
$arrays[] = $this->_array[$i];
}
$this->_offset += $i - $this->_offset; // Limit function calls
$chars = false;
foreach ($arrays as $array) {
$chars .= implode('', array_map('chr', $array));
}
return $chars;
}
return false;
}
private static function _initializeMaps()
{
if (!isset(self::$_charMap))
/**
* Read $length characters from the stream and return a 1-dimensional array
* containing there octet values.
* @param int $length
* @return int[]
*/
public function readBytes($length)
{
self::$_charMap = array();
for ($byte = 0; $byte < 256; ++$byte)
{
self::$_charMap[$byte] = chr($byte);
}
self::$_byteMap = array_flip(self::$_charMap);
if ($this->_offset == $this->_array_size) {
return false;
}
$arrays = array();
$end = $length + $this->_offset;
for ($i = $this->_offset; $i < $end; ++$i) {
if (!isset($this->_array[$i])) {
break;
}
$arrays[] = $this->_array[$i];
}
$this->_offset += ($i - $this->_offset); // Limit function calls
return call_user_func_array('array_merge', $arrays);
}
/**
* Write $chars to the end of the stream.
* @param string $chars
*/
public function write($chars)
{
if (!isset($this->_charReader)) {
$this->_charReader = $this->_charReaderFactory->getReaderFor(
$this->_charset);
}
$startLength = $this->_charReader->getInitialByteSize();
$fp = fopen('php://memory', 'w+b');
fwrite($fp, $chars);
unset($chars);
fseek($fp, 0, SEEK_SET);
$buffer = array(0);
$buf_pos = 1;
$buf_len = 1;
$has_datas = true;
do {
$bytes = array();
// Buffer Filing
if ($buf_len - $buf_pos < $startLength) {
$buf = array_splice($buffer, $buf_pos);
$new = $this->_reloadBuffer($fp, 100);
if ($new) {
$buffer = array_merge($buf, $new);
$buf_len = count($buffer);
$buf_pos = 0;
} else {
$has_datas = false;
}
}
if ($buf_len - $buf_pos > 0) {
$size = 0;
for ($i = 0; $i < $startLength && isset($buffer[$buf_pos]); ++$i) {
++$size;
$bytes[] = $buffer[$buf_pos++];
}
$need = $this->_charReader->validateByteSequence(
$bytes, $size);
if ($need > 0) {
if ($buf_len - $buf_pos < $need) {
$new = $this->_reloadBuffer($fp, $need);
if ($new) {
$buffer = array_merge($buffer, $new);
$buf_len = count($buffer);
}
}
for ($i = 0; $i < $need && isset($buffer[$buf_pos]); ++$i) {
$bytes[] = $buffer[$buf_pos++];
}
}
$this->_array[] = $bytes;
++$this->_array_size;
}
} while ($has_datas);
fclose($fp);
}
/**
* Move the internal pointer to $charOffset in the stream.
* @param int $charOffset
*/
public function setPointer($charOffset)
{
if ($charOffset > $this->_array_size) {
$charOffset = $this->_array_size;
} elseif ($charOffset < 0) {
$charOffset = 0;
}
$this->_offset = $charOffset;
}
/**
* Empty the stream and reset the internal pointer.
*/
public function flushContents()
{
$this->_offset = 0;
$this->_array = array();
$this->_array_size = 0;
}
private function _reloadBuffer($fp, $len)
{
if (!feof($fp) && ($bytes = fread($fp, $len)) !== false) {
$buf = array();
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
$buf[] = self::$_byteMap[$bytes[$i]];
}
return $buf;
}
return false;
}
private static function _initializeMaps()
{
if (!isset(self::$_charMap)) {
self::$_charMap = array();
for ($byte = 0; $byte < 256; ++$byte) {
self::$_charMap[$byte] = chr($byte);
}
self::$_byteMap = array_flip(self::$_charMap);
}
}
}
}

View File

@@ -18,8 +18,6 @@
*/
/**
* A CharacterStream implementation which stores characters in an internal array.
* @package Swift
@@ -27,272 +25,259 @@
* @author Xavier De Cock <xdecock@gmail.com>
*/
Class Swift_CharacterStream_NgCharacterStream
implements Swift_CharacterStream
class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
{
/**
* The char reader (lazy-loaded) for the current charset.
* @var Swift_CharacterReader
* @access private
*/
private $_charReader;
/**
* The char reader (lazy-loaded) for the current charset.
* @var Swift_CharacterReader
* @access private
*/
private $_charReader;
/**
* A factory for creatiing CharacterReader instances.
* @var Swift_CharacterReaderFactory
* @access private
*/
private $_charReaderFactory;
/**
* A factory for creatiing CharacterReader instances.
* @var Swift_CharacterReaderFactory
* @access private
*/
private $_charReaderFactory;
/**
* The character set this stream is using.
* @var string
* @access private
*/
private $_charset;
/**
* The character set this stream is using.
* @var string
* @access private
*/
private $_charset;
/**
* The datas stored as is
*
* @var string
*/
private $_datas = "";
/**
* Number of bytes in the stream
*
* @var int
*/
private $_datasSize = 0;
/**
* Map
*
* @var mixed
*/
private $_map;
/**
* Map Type
*
* @var int
*/
private $_mapType = 0;
/**
* Number of characters in the stream
*
* @var int
*/
private $_charCount = 0;
/**
* Position in the stream
*
* @var unknown_type
*/
private $_currentPos = 0;
/**
* The constructor
*
* @param Swift_CharacterReaderFactory $factory
* @param unknown_type $charset
*/
public function __construct(Swift_CharacterReaderFactory $factory,
$charset)
{
$this->setCharacterReaderFactory($factory);
$this->setCharacterSet($charset);
}
/* -- Changing parameters of the stream -- */
/**
* The datas stored as is
*
* @var string
*/
private $_datas = "";
/**
* Set the character set used in this CharacterStream.
* @param string $charset
*/
public function setCharacterSet($charset)
{
$this->_charset = $charset;
$this->_charReader = null;
$this->_mapType = 0;
}
/**
* Number of bytes in the stream
*
* @var int
*/
private $_datasSize = 0;
/**
* Set the CharacterReaderFactory for multi charset support.
* @param Swift_CharacterReaderFactory $factory
*/
public function setCharacterReaderFactory(
Swift_CharacterReaderFactory $factory)
{
$this->_charReaderFactory = $factory;
}
/**
* Map
*
* @var mixed
*/
private $_map;
/**
* @see Swift_CharacterStream::flushContents()
*
*/
public function flushContents()
{
$this->_datas = null;
$this->_map = null;
$this->_charCount = 0;
$this->_currentPos = 0;
$this->_datasSize = 0;
}
/**
* @see Swift_CharacterStream::importByteStream()
*
* @param Swift_OutputByteStream $os
*/
public function importByteStream(Swift_OutputByteStream $os)
{
$this->flushContents();
$blocks=512;
$os->setReadPointer(0);
while(false!==($read = $os->read($blocks)))
$this->write($read);
}
/**
* @see Swift_CharacterStream::importString()
*
* @param string $string
*/
public function importString($string)
{
$this->flushContents();
$this->write($string);
}
/**
* @see Swift_CharacterStream::read()
*
* @param int $length
* @return string
*/
public function read($length)
{
if ($this->_currentPos>=$this->_charCount)
{
return false;
}
$ret=false;
$length = ($this->_currentPos+$length > $this->_charCount)
? $this->_charCount - $this->_currentPos
: $length;
switch ($this->_mapType)
{
case Swift_CharacterReader::MAP_TYPE_FIXED_LEN:
$len = $length*$this->_map;
$ret = substr($this->_datas,
$this->_currentPos * $this->_map,
$len);
$this->_currentPos += $length;
break;
case Swift_CharacterReader::MAP_TYPE_INVALID:
$end = $this->_currentPos + $length;
$end = $end > $this->_charCount
?$this->_charCount
:$end;
$ret = '';
for (; $this->_currentPos < $length; ++$this->_currentPos)
{
if (isset ($this->_map[$this->_currentPos]))
{
$ret .= '?';
}
else
{
$ret .= $this->_datas[$this->_currentPos];
}
}
break;
case Swift_CharacterReader::MAP_TYPE_POSITIONS:
$end = $this->_currentPos + $length;
$end = $end > $this->_charCount
?$this->_charCount
:$end;
$ret = '';
$start = 0;
if ($this->_currentPos>0)
{
$start = $this->_map['p'][$this->_currentPos-1];
}
$to = $start;
for (; $this->_currentPos < $end; ++$this->_currentPos)
{
if (isset($this->_map['i'][$this->_currentPos])) {
$ret .= substr($this->_datas, $start, $to - $start).'?';
$start = $this->_map['p'][$this->_currentPos];
} else {
$to = $this->_map['p'][$this->_currentPos];
}
}
$ret .= substr($this->_datas, $start, $to - $start);
break;
}
return $ret;
}
/**
* @see Swift_CharacterStream::readBytes()
*
* @param int $length
* @return int[]
*/
public function readBytes($length)
{
$read=$this->read($length);
if ($read!==false)
{
$ret = array_map('ord', str_split($read, 1));
return $ret;
}
return false;
}
/**
* @see Swift_CharacterStream::setPointer()
*
* @param int $charOffset
*/
public function setPointer($charOffset)
{
if ($this->_charCount<$charOffset){
$charOffset=$this->_charCount;
}
$this->_currentPos = $charOffset;
}
/**
* @see Swift_CharacterStream::write()
*
* @param string $chars
*/
public function write($chars)
{
if (!isset($this->_charReader))
/**
* Map Type
*
* @var int
*/
private $_mapType = 0;
/**
* Number of characters in the stream
*
* @var int
*/
private $_charCount = 0;
/**
* Position in the stream
*
* @var unknown_type
*/
private $_currentPos = 0;
/**
* The constructor
*
* @param Swift_CharacterReaderFactory $factory
* @param unknown_type $charset
*/
public function __construct(Swift_CharacterReaderFactory $factory, $charset)
{
$this->_charReader = $this->_charReaderFactory->getReaderFor(
$this->_charset);
$this->_map = array();
$this->_mapType = $this->_charReader->getMapType();
$this->setCharacterReaderFactory($factory);
$this->setCharacterSet($charset);
}
$ignored='';
$this->_datas .= $chars;
$this->_charCount += $this->_charReader->getCharPositions(substr($this->_datas, $this->_datasSize), $this->_datasSize, $this->_map, $ignored);
if ($ignored!==false) {
$this->_datasSize=strlen($this->_datas)-strlen($ignored);
}
else
/* -- Changing parameters of the stream -- */
/**
* Set the character set used in this CharacterStream.
* @param string $charset
*/
public function setCharacterSet($charset)
{
$this->_datasSize=strlen($this->_datas);
$this->_charset = $charset;
$this->_charReader = null;
$this->_mapType = 0;
}
}
}
/**
* Set the CharacterReaderFactory for multi charset support.
* @param Swift_CharacterReaderFactory $factory
*/
public function setCharacterReaderFactory(Swift_CharacterReaderFactory $factory)
{
$this->_charReaderFactory = $factory;
}
/**
* @see Swift_CharacterStream::flushContents()
*
*/
public function flushContents()
{
$this->_datas = null;
$this->_map = null;
$this->_charCount = 0;
$this->_currentPos = 0;
$this->_datasSize = 0;
}
/**
* @see Swift_CharacterStream::importByteStream()
*
* @param Swift_OutputByteStream $os
*/
public function importByteStream(Swift_OutputByteStream $os)
{
$this->flushContents();
$blocks=512;
$os->setReadPointer(0);
while(false!==($read = $os->read($blocks)))
$this->write($read);
}
/**
* @see Swift_CharacterStream::importString()
*
* @param string $string
*/
public function importString($string)
{
$this->flushContents();
$this->write($string);
}
/**
* @see Swift_CharacterStream::read()
*
* @param int $length
* @return string
*/
public function read($length)
{
if ($this->_currentPos>=$this->_charCount) {
return false;
}
$ret=false;
$length = ($this->_currentPos+$length > $this->_charCount)
? $this->_charCount - $this->_currentPos
: $length;
switch ($this->_mapType) {
case Swift_CharacterReader::MAP_TYPE_FIXED_LEN:
$len = $length*$this->_map;
$ret = substr($this->_datas,
$this->_currentPos * $this->_map,
$len);
$this->_currentPos += $length;
break;
case Swift_CharacterReader::MAP_TYPE_INVALID:
$end = $this->_currentPos + $length;
$end = $end > $this->_charCount
?$this->_charCount
:$end;
$ret = '';
for (; $this->_currentPos < $length; ++$this->_currentPos) {
if (isset ($this->_map[$this->_currentPos])) {
$ret .= '?';
} else {
$ret .= $this->_datas[$this->_currentPos];
}
}
break;
case Swift_CharacterReader::MAP_TYPE_POSITIONS:
$end = $this->_currentPos + $length;
$end = $end > $this->_charCount
?$this->_charCount
:$end;
$ret = '';
$start = 0;
if ($this->_currentPos>0) {
$start = $this->_map['p'][$this->_currentPos-1];
}
$to = $start;
for (; $this->_currentPos < $end; ++$this->_currentPos) {
if (isset($this->_map['i'][$this->_currentPos])) {
$ret .= substr($this->_datas, $start, $to - $start).'?';
$start = $this->_map['p'][$this->_currentPos];
} else {
$to = $this->_map['p'][$this->_currentPos];
}
}
$ret .= substr($this->_datas, $start, $to - $start);
break;
}
return $ret;
}
/**
* @see Swift_CharacterStream::readBytes()
*
* @param int $length
* @return int[]
*/
public function readBytes($length)
{
$read=$this->read($length);
if ($read!==false) {
$ret = array_map('ord', str_split($read, 1));
return $ret;
}
return false;
}
/**
* @see Swift_CharacterStream::setPointer()
*
* @param int $charOffset
*/
public function setPointer($charOffset)
{
if ($this->_charCount<$charOffset) {
$charOffset=$this->_charCount;
}
$this->_currentPos = $charOffset;
}
/**
* @see Swift_CharacterStream::write()
*
* @param string $chars
*/
public function write($chars)
{
if (!isset($this->_charReader)) {
$this->_charReader = $this->_charReaderFactory->getReaderFor(
$this->_charset);
$this->_map = array();
$this->_mapType = $this->_charReader->getMapType();
}
$ignored='';
$this->_datas .= $chars;
$this->_charCount += $this->_charReader->getCharPositions(substr($this->_datas, $this->_datasSize), $this->_datasSize, $this->_map, $ignored);
if ($ignored!==false) {
$this->_datasSize=strlen($this->_datas)-strlen($ignored);
} else {
$this->_datasSize=strlen($this->_datas);
}
}
}

View File

@@ -15,45 +15,45 @@
*/
abstract class Swift_ConfigurableSpool implements Swift_Spool
{
/** The maximum number of messages to send per flush */
private $_message_limit;
/** The time limit per flush */
private $_time_limit;
/**
* Sets the maximum number of messages to send per flush.
* @param int $limit The limit
*/
public function setMessageLimit($limit)
{
$this->_message_limit = (int) $limit;
}
/**
* Gets the maximum number of messages to send per flush.
* @return int The limit
*/
public function getMessageLimit()
{
return $this->_message_limit;
}
/**
* Sets the time limit (in seconds) per flush.
* @param int $limit The limit
*/
public function setTimeLimit($limit)
{
$this->_time_limit = (int) $limit;
}
/**
* Gets the time limit (in seconds) per flush.
* @return int The limit
*/
public function getTimeLimit()
{
return $this->_time_limit;
}
/** The maximum number of messages to send per flush */
private $_message_limit;
/** The time limit per flush */
private $_time_limit;
/**
* Sets the maximum number of messages to send per flush.
* @param int $limit The limit
*/
public function setMessageLimit($limit)
{
$this->_message_limit = (int) $limit;
}
/**
* Gets the maximum number of messages to send per flush.
* @return int The limit
*/
public function getMessageLimit()
{
return $this->_message_limit;
}
/**
* Sets the time limit (in seconds) per flush.
* @param int $limit The limit
*/
public function setTimeLimit($limit)
{
$this->_time_limit = (int) $limit;
}
/**
* Gets the time limit (in seconds) per flush.
* @return int The limit
*/
public function getTimeLimit()
{
return $this->_time_limit;
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Dependency Injection container.
* @package Swift
@@ -16,333 +15,327 @@
*/
class Swift_DependencyContainer
{
/** Constant for literal value types */
const TYPE_VALUE = 0x0001;
/** Constant for new instance types */
const TYPE_INSTANCE = 0x0010;
/** Constant for shared instance types */
const TYPE_SHARED = 0x0100;
/** Constant for aliases */
const TYPE_ALIAS = 0x1000;
/** Singleton instance */
private static $_instance = null;
/** The data container */
private $_store = array();
/** The current endpoint in the data container */
private $_endPoint;
/**
* Constructor should not be used.
* Use {@link getInstance()} instead.
*/
public function __construct() { }
/**
* Returns a singleton of the DependencyContainer.
* @return Swift_DependencyContainer
*/
public static function getInstance()
{
if (!isset(self::$_instance))
/** Constant for literal value types */
const TYPE_VALUE = 0x0001;
/** Constant for new instance types */
const TYPE_INSTANCE = 0x0010;
/** Constant for shared instance types */
const TYPE_SHARED = 0x0100;
/** Constant for aliases */
const TYPE_ALIAS = 0x1000;
/** Singleton instance */
private static $_instance = null;
/** The data container */
private $_store = array();
/** The current endpoint in the data container */
private $_endPoint;
/**
* Constructor should not be used.
* Use {@link getInstance()} instead.
*/
public function __construct() { }
/**
* Returns a singleton of the DependencyContainer.
* @return Swift_DependencyContainer
*/
public static function getInstance()
{
self::$_instance = new self();
if (!isset(self::$_instance)) {
self::$_instance = new self();
}
return self::$_instance;
}
return self::$_instance;
}
/**
* List the names of all items stored in the Container.
* @return array
*/
public function listItems()
{
return array_keys($this->_store);
}
/**
* Test if an item is registered in this container with the given name.
* @param string $itemName
* @return boolean
* @see register()
*/
public function has($itemName)
{
return array_key_exists($itemName, $this->_store)
&& isset($this->_store[$itemName]['lookupType']);
}
/**
* Lookup the item with the given $itemName.
* @param string $itemName
* @return mixed
* @throws Swift_DependencyException If the dependency is not found
* @see register()
*/
public function lookup($itemName)
{
if (!$this->has($itemName))
/**
* List the names of all items stored in the Container.
* @return array
*/
public function listItems()
{
throw new Swift_DependencyException(
'Cannot lookup dependency "' . $itemName . '" since it is not registered.'
);
return array_keys($this->_store);
}
switch ($this->_store[$itemName]['lookupType'])
/**
* Test if an item is registered in this container with the given name.
* @param string $itemName
* @return boolean
* @see register()
*/
public function has($itemName)
{
case self::TYPE_ALIAS:
return $this->_createAlias($itemName);
case self::TYPE_VALUE:
return $this->_getValue($itemName);
case self::TYPE_INSTANCE:
return $this->_createNewInstance($itemName);
case self::TYPE_SHARED:
return $this->_createSharedInstance($itemName);
return array_key_exists($itemName, $this->_store)
&& isset($this->_store[$itemName]['lookupType']);
}
}
/**
* Create an array of arguments passed to the constructor of $itemName.
* @param string $itemName
* @return array
*/
public function createDependenciesFor($itemName)
{
$args = array();
if (isset($this->_store[$itemName]['args']))
/**
* Lookup the item with the given $itemName.
* @param string $itemName
* @return mixed
* @throws Swift_DependencyException If the dependency is not found
* @see register()
*/
public function lookup($itemName)
{
$args = $this->_resolveArgs($this->_store[$itemName]['args']);
if (!$this->has($itemName)) {
throw new Swift_DependencyException(
'Cannot lookup dependency "' . $itemName . '" since it is not registered.'
);
}
switch ($this->_store[$itemName]['lookupType']) {
case self::TYPE_ALIAS:
return $this->_createAlias($itemName);
case self::TYPE_VALUE:
return $this->_getValue($itemName);
case self::TYPE_INSTANCE:
return $this->_createNewInstance($itemName);
case self::TYPE_SHARED:
return $this->_createSharedInstance($itemName);
}
}
return $args;
}
/**
* Register a new dependency with $itemName.
* This method returns the current DependencyContainer instance because it
* requires the use of the fluid interface to set the specific details for the
* dependency.
*
* @param string $itemName
* @return Swift_DependencyContainer
* @see asNewInstanceOf(), asSharedInstanceOf(), asValue()
*/
public function register($itemName)
{
$this->_store[$itemName] = array();
$this->_endPoint =& $this->_store[$itemName];
return $this;
}
/**
* Specify the previously registered item as a literal value.
* {@link register()} must be called before this will work.
*
* @param mixed $value
* @return Swift_DependencyContainer
*/
public function asValue($value)
{
$endPoint =& $this->_getEndPoint();
$endPoint['lookupType'] = self::TYPE_VALUE;
$endPoint['value'] = $value;
return $this;
}
/**
* Specify the previously registered item as an alias of another item.
* @param string $lookup
* @return Swift_DependencyContainer
*/
public function asAliasOf($lookup)
{
$endPoint =& $this->_getEndPoint();
$endPoint['lookupType'] = self::TYPE_ALIAS;
$endPoint['ref'] = $lookup;
return $this;
}
/**
* Specify the previously registered item as a new instance of $className.
* {@link register()} must be called before this will work.
* Any arguments can be set with {@link withDependencies()},
* {@link addConstructorValue()} or {@link addConstructorLookup()}.
*
* @param string $className
* @return Swift_DependencyContainer
* @see withDependencies(), addConstructorValue(), addConstructorLookup()
*/
public function asNewInstanceOf($className)
{
$endPoint =& $this->_getEndPoint();
$endPoint['lookupType'] = self::TYPE_INSTANCE;
$endPoint['className'] = $className;
return $this;
}
/**
* Specify the previously registered item as a shared instance of $className.
* {@link register()} must be called before this will work.
* @param string $className
* @return Swift_DependencyContainer
*/
public function asSharedInstanceOf($className)
{
$endPoint =& $this->_getEndPoint();
$endPoint['lookupType'] = self::TYPE_SHARED;
$endPoint['className'] = $className;
return $this;
}
/**
* Specify a list of injected dependencies for the previously registered item.
* This method takes an array of lookup names.
*
* @param array $lookups
* @return Swift_DependencyContainer
* @see addConstructorValue(), addConstructorLookup()
*/
public function withDependencies(array $lookups)
{
$endPoint =& $this->_getEndPoint();
$endPoint['args'] = array();
foreach ($lookups as $lookup)
/**
* Create an array of arguments passed to the constructor of $itemName.
* @param string $itemName
* @return array
*/
public function createDependenciesFor($itemName)
{
$this->addConstructorLookup($lookup);
$args = array();
if (isset($this->_store[$itemName]['args'])) {
$args = $this->_resolveArgs($this->_store[$itemName]['args']);
}
return $args;
}
return $this;
}
/**
* Specify a literal (non looked up) value for the constructor of the
* previously registered item.
*
* @param mixed $value
* @return Swift_DependencyContainer
* @see withDependencies(), addConstructorLookup()
*/
public function addConstructorValue($value)
{
$endPoint =& $this->_getEndPoint();
if (!isset($endPoint['args']))
/**
* Register a new dependency with $itemName.
* This method returns the current DependencyContainer instance because it
* requires the use of the fluid interface to set the specific details for the
* dependency.
*
* @param string $itemName
* @return Swift_DependencyContainer
* @see asNewInstanceOf(), asSharedInstanceOf(), asValue()
*/
public function register($itemName)
{
$endPoint['args'] = array();
$this->_store[$itemName] = array();
$this->_endPoint =& $this->_store[$itemName];
return $this;
}
$endPoint['args'][] = array('type' => 'value', 'item' => $value);
return $this;
}
/**
* Specify a dependency lookup for the constructor of the previously
* registered item.
*
* @param string $lookup
* @return Swift_DependencyContainer
* @see withDependencies(), addConstructorValue()
*/
public function addConstructorLookup($lookup)
{
$endPoint =& $this->_getEndPoint();
if (!isset($this->_endPoint['args']))
/**
* Specify the previously registered item as a literal value.
* {@link register()} must be called before this will work.
*
* @param mixed $value
* @return Swift_DependencyContainer
*/
public function asValue($value)
{
$endPoint['args'] = array();
$endPoint =& $this->_getEndPoint();
$endPoint['lookupType'] = self::TYPE_VALUE;
$endPoint['value'] = $value;
return $this;
}
$endPoint['args'][] = array('type' => 'lookup', 'item' => $lookup);
return $this;
}
// -- Private methods
/** Get the literal value with $itemName */
private function _getValue($itemName)
{
return $this->_store[$itemName]['value'];
}
/** Resolve an alias to another item */
private function _createAlias($itemName)
{
return $this->lookup($this->_store[$itemName]['ref']);
}
/** Create a fresh instance of $itemName */
private function _createNewInstance($itemName)
{
$reflector = new ReflectionClass($this->_store[$itemName]['className']);
if ($reflector->getConstructor())
/**
* Specify the previously registered item as an alias of another item.
* @param string $lookup
* @return Swift_DependencyContainer
*/
public function asAliasOf($lookup)
{
return $reflector->newInstanceArgs(
$this->createDependenciesFor($itemName)
);
$endPoint =& $this->_getEndPoint();
$endPoint['lookupType'] = self::TYPE_ALIAS;
$endPoint['ref'] = $lookup;
return $this;
}
else
/**
* Specify the previously registered item as a new instance of $className.
* {@link register()} must be called before this will work.
* Any arguments can be set with {@link withDependencies()},
* {@link addConstructorValue()} or {@link addConstructorLookup()}.
*
* @param string $className
* @return Swift_DependencyContainer
* @see withDependencies(), addConstructorValue(), addConstructorLookup()
*/
public function asNewInstanceOf($className)
{
return $reflector->newInstance();
$endPoint =& $this->_getEndPoint();
$endPoint['lookupType'] = self::TYPE_INSTANCE;
$endPoint['className'] = $className;
return $this;
}
}
/** Create and register a shared instance of $itemName */
private function _createSharedInstance($itemName)
{
if (!isset($this->_store[$itemName]['instance']))
/**
* Specify the previously registered item as a shared instance of $className.
* {@link register()} must be called before this will work.
* @param string $className
* @return Swift_DependencyContainer
*/
public function asSharedInstanceOf($className)
{
$this->_store[$itemName]['instance'] = $this->_createNewInstance($itemName);
$endPoint =& $this->_getEndPoint();
$endPoint['lookupType'] = self::TYPE_SHARED;
$endPoint['className'] = $className;
return $this;
}
return $this->_store[$itemName]['instance'];
}
/** Get the current endpoint in the store */
private function &_getEndPoint()
{
if (!isset($this->_endPoint))
/**
* Specify a list of injected dependencies for the previously registered item.
* This method takes an array of lookup names.
*
* @param array $lookups
* @return Swift_DependencyContainer
* @see addConstructorValue(), addConstructorLookup()
*/
public function withDependencies(array $lookups)
{
throw new BadMethodCallException(
'Component must first be registered by calling register()'
);
$endPoint =& $this->_getEndPoint();
$endPoint['args'] = array();
foreach ($lookups as $lookup) {
$this->addConstructorLookup($lookup);
}
return $this;
}
return $this->_endPoint;
}
/** Get an argument list with dependencies resolved */
private function _resolveArgs(array $args)
{
$resolved = array();
foreach ($args as $argDefinition)
/**
* Specify a literal (non looked up) value for the constructor of the
* previously registered item.
*
* @param mixed $value
* @return Swift_DependencyContainer
* @see withDependencies(), addConstructorLookup()
*/
public function addConstructorValue($value)
{
switch ($argDefinition['type'])
{
case 'lookup':
$resolved[] = $this->_lookupRecursive($argDefinition['item']);
break;
case 'value':
$resolved[] = $argDefinition['item'];
break;
}
$endPoint =& $this->_getEndPoint();
if (!isset($endPoint['args'])) {
$endPoint['args'] = array();
}
$endPoint['args'][] = array('type' => 'value', 'item' => $value);
return $this;
}
return $resolved;
}
/** Resolve a single dependency with an collections */
private function _lookupRecursive($item)
{
if (is_array($item))
/**
* Specify a dependency lookup for the constructor of the previously
* registered item.
*
* @param string $lookup
* @return Swift_DependencyContainer
* @see withDependencies(), addConstructorValue()
*/
public function addConstructorLookup($lookup)
{
$collection = array();
foreach ($item as $k => $v)
{
$collection[$k] = $this->_lookupRecursive($v);
}
return $collection;
$endPoint =& $this->_getEndPoint();
if (!isset($this->_endPoint['args'])) {
$endPoint['args'] = array();
}
$endPoint['args'][] = array('type' => 'lookup', 'item' => $lookup);
return $this;
}
else
// -- Private methods
/** Get the literal value with $itemName */
private function _getValue($itemName)
{
return $this->lookup($item);
return $this->_store[$itemName]['value'];
}
/** Resolve an alias to another item */
private function _createAlias($itemName)
{
return $this->lookup($this->_store[$itemName]['ref']);
}
/** Create a fresh instance of $itemName */
private function _createNewInstance($itemName)
{
$reflector = new ReflectionClass($this->_store[$itemName]['className']);
if ($reflector->getConstructor()) {
return $reflector->newInstanceArgs(
$this->createDependenciesFor($itemName)
);
} else {
return $reflector->newInstance();
}
}
/** Create and register a shared instance of $itemName */
private function _createSharedInstance($itemName)
{
if (!isset($this->_store[$itemName]['instance'])) {
$this->_store[$itemName]['instance'] = $this->_createNewInstance($itemName);
}
return $this->_store[$itemName]['instance'];
}
/** Get the current endpoint in the store */
private function &_getEndPoint()
{
if (!isset($this->_endPoint)) {
throw new BadMethodCallException(
'Component must first be registered by calling register()'
);
}
return $this->_endPoint;
}
/** Get an argument list with dependencies resolved */
private function _resolveArgs(array $args)
{
$resolved = array();
foreach ($args as $argDefinition) {
switch ($argDefinition['type']) {
case 'lookup':
$resolved[] = $this->_lookupRecursive($argDefinition['item']);
break;
case 'value':
$resolved[] = $argDefinition['item'];
break;
}
}
return $resolved;
}
/** Resolve a single dependency with an collections */
private function _lookupRecursive($item)
{
if (is_array($item)) {
$collection = array();
foreach ($item as $k => $v) {
$collection[$k] = $this->_lookupRecursive($v);
}
return $collection;
} else {
return $this->lookup($item);
}
}
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* DependencyException thrown when a requested dependeny is missing.
* @package Swift
@@ -16,14 +15,12 @@
*/
class Swift_DependencyException extends Swift_SwiftException
{
/**
* Create a new DependencyException with $message.
* @param string $message
*/
public function __construct($message)
{
parent::__construct($message);
}
/**
* Create a new DependencyException with $message.
* @param string $message
*/
public function __construct($message)
{
parent::__construct($message);
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* An embedded file, in a multipart message.
* @package Swift
@@ -17,54 +16,49 @@
*/
class Swift_EmbeddedFile extends Swift_Mime_EmbeddedFile
{
/**
* Create a new EmbeddedFile.
* Details may be optionally provided to the constructor.
* @param string|Swift_OutputByteStream $data
* @param string $filename
* @param string $contentType
*/
public function __construct($data = null, $filename = null,
$contentType = null)
{
call_user_func_array(
array($this, 'Swift_Mime_EmbeddedFile::__construct'),
Swift_DependencyContainer::getInstance()
->createDependenciesFor('mime.embeddedfile')
);
$this->setBody($data);
$this->setFilename($filename);
if ($contentType)
/**
* Create a new EmbeddedFile.
* Details may be optionally provided to the constructor.
* @param string|Swift_OutputByteStream $data
* @param string $filename
* @param string $contentType
*/
public function __construct($data = null, $filename = null, $contentType = null)
{
$this->setContentType($contentType);
call_user_func_array(
array($this, 'Swift_Mime_EmbeddedFile::__construct'),
Swift_DependencyContainer::getInstance()
->createDependenciesFor('mime.embeddedfile')
);
$this->setBody($data);
$this->setFilename($filename);
if ($contentType) {
$this->setContentType($contentType);
}
}
/**
* Create a new EmbeddedFile.
* @param string|Swift_OutputByteStream $data
* @param string $filename
* @param string $contentType
* @return Swift_Mime_EmbeddedFile
*/
public static function newInstance($data = null, $filename = null, $contentType = null)
{
return new self($data, $filename, $contentType);
}
/**
* Create a new EmbeddedFile from a filesystem path.
* @param string $path
* @return Swift_Mime_EmbeddedFile
*/
public static function fromPath($path)
{
return self::newInstance()->setFile(
new Swift_ByteStream_FileByteStream($path)
);
}
}
/**
* Create a new EmbeddedFile.
* @param string|Swift_OutputByteStream $data
* @param string $filename
* @param string $contentType
* @return Swift_Mime_EmbeddedFile
*/
public static function newInstance($data = null, $filename = null,
$contentType = null)
{
return new self($data, $filename, $contentType);
}
/**
* Create a new EmbeddedFile from a filesystem path.
* @param string $path
* @return Swift_Mime_EmbeddedFile
*/
public static function fromPath($path)
{
return self::newInstance()->setFile(
new Swift_ByteStream_FileByteStream($path)
);
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Interface for all Encoder schemes.
* @package Swift
@@ -17,15 +16,12 @@
*/
interface Swift_Encoder extends Swift_Mime_CharsetObserver
{
/**
* Encode a given string to produce an encoded string.
* @param string $string
* @param int $firstLineOffset if first line needs to be shorter
* @param int $maxLineLength - 0 indicates the default length for this encoding
* @return string
*/
public function encodeString($string, $firstLineOffset = 0,
$maxLineLength = 0);
/**
* Encode a given string to produce an encoded string.
* @param string $string
* @param int $firstLineOffset if first line needs to be shorter
* @param int $maxLineLength - 0 indicates the default length for this encoding
* @return string
*/
public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0);
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Handles Base 64 Encoding in Swift Mailer.
* @package Swift
@@ -17,46 +16,41 @@
*/
class Swift_Encoder_Base64Encoder implements Swift_Encoder
{
/**
* Takes an unencoded string and produces a Base64 encoded string from it.
* Base64 encoded strings have a maximum line length of 76 characters.
* If the first line needs to be shorter, indicate the difference with
* $firstLineOffset.
* @param string $string to encode
* @param int $firstLineOffset
* @param int $maxLineLength, optional, 0 indicates the default of 76 bytes
* @return string
*/
public function encodeString($string, $firstLineOffset = 0,
$maxLineLength = 0)
{
if (0 >= $maxLineLength || 76 < $maxLineLength)
/**
* Takes an unencoded string and produces a Base64 encoded string from it.
* Base64 encoded strings have a maximum line length of 76 characters.
* If the first line needs to be shorter, indicate the difference with
* $firstLineOffset.
* @param string $string to encode
* @param int $firstLineOffset
* @param int $maxLineLength, optional, 0 indicates the default of 76 bytes
* @return string
*/
public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
{
$maxLineLength = 76;
if (0 >= $maxLineLength || 76 < $maxLineLength) {
$maxLineLength = 76;
}
$encodedString = base64_encode($string);
$firstLine = '';
if (0 != $firstLineOffset) {
$firstLine = substr(
$encodedString, 0, $maxLineLength - $firstLineOffset
) . "\r\n";
$encodedString = substr(
$encodedString, $maxLineLength - $firstLineOffset
);
}
return $firstLine . trim(chunk_split($encodedString, $maxLineLength, "\r\n"));
}
$encodedString = base64_encode($string);
$firstLine = '';
if (0 != $firstLineOffset)
/**
* Does nothing.
*/
public function charsetChanged($charset)
{
$firstLine = substr(
$encodedString, 0, $maxLineLength - $firstLineOffset
) . "\r\n";
$encodedString = substr(
$encodedString, $maxLineLength - $firstLineOffset
);
}
return $firstLine . trim(chunk_split($encodedString, $maxLineLength, "\r\n"));
}
/**
* Does nothing.
*/
public function charsetChanged($charset)
{
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Handles Quoted Printable (QP) Encoding in Swift Mailer.
* Possibly the most accurate RFC 2045 QP implementation found in PHP.
@@ -18,279 +17,259 @@
*/
class Swift_Encoder_QpEncoder implements Swift_Encoder
{
/**
* The CharacterStream used for reading characters (as opposed to bytes).
* @var Swift_CharacterStream
* @access protected
*/
protected $_charStream;
/**
* The CharacterStream used for reading characters (as opposed to bytes).
* @var Swift_CharacterStream
* @access protected
*/
protected $_charStream;
/**
* A filter used if input should be canonicalized.
* @var Swift_StreamFilter
* @access protected
*/
protected $_filter;
/**
* A filter used if input should be canonicalized.
* @var Swift_StreamFilter
* @access protected
*/
protected $_filter;
/**
* Pre-computed QP for HUGE optmization.
* @var string[]
* @access protected
*/
protected static $_qpMap = array(
0 => '=00', 1 => '=01', 2 => '=02', 3 => '=03', 4 => '=04',
5 => '=05', 6 => '=06', 7 => '=07', 8 => '=08', 9 => '=09',
10 => '=0A', 11 => '=0B', 12 => '=0C', 13 => '=0D', 14 => '=0E',
15 => '=0F', 16 => '=10', 17 => '=11', 18 => '=12', 19 => '=13',
20 => '=14', 21 => '=15', 22 => '=16', 23 => '=17', 24 => '=18',
25 => '=19', 26 => '=1A', 27 => '=1B', 28 => '=1C', 29 => '=1D',
30 => '=1E', 31 => '=1F', 32 => '=20', 33 => '=21', 34 => '=22',
35 => '=23', 36 => '=24', 37 => '=25', 38 => '=26', 39 => '=27',
40 => '=28', 41 => '=29', 42 => '=2A', 43 => '=2B', 44 => '=2C',
45 => '=2D', 46 => '=2E', 47 => '=2F', 48 => '=30', 49 => '=31',
50 => '=32', 51 => '=33', 52 => '=34', 53 => '=35', 54 => '=36',
55 => '=37', 56 => '=38', 57 => '=39', 58 => '=3A', 59 => '=3B',
60 => '=3C', 61 => '=3D', 62 => '=3E', 63 => '=3F', 64 => '=40',
65 => '=41', 66 => '=42', 67 => '=43', 68 => '=44', 69 => '=45',
70 => '=46', 71 => '=47', 72 => '=48', 73 => '=49', 74 => '=4A',
75 => '=4B', 76 => '=4C', 77 => '=4D', 78 => '=4E', 79 => '=4F',
80 => '=50', 81 => '=51', 82 => '=52', 83 => '=53', 84 => '=54',
85 => '=55', 86 => '=56', 87 => '=57', 88 => '=58', 89 => '=59',
90 => '=5A', 91 => '=5B', 92 => '=5C', 93 => '=5D', 94 => '=5E',
95 => '=5F', 96 => '=60', 97 => '=61', 98 => '=62', 99 => '=63',
100 => '=64', 101 => '=65', 102 => '=66', 103 => '=67', 104 => '=68',
105 => '=69', 106 => '=6A', 107 => '=6B', 108 => '=6C', 109 => '=6D',
110 => '=6E', 111 => '=6F', 112 => '=70', 113 => '=71', 114 => '=72',
115 => '=73', 116 => '=74', 117 => '=75', 118 => '=76', 119 => '=77',
120 => '=78', 121 => '=79', 122 => '=7A', 123 => '=7B', 124 => '=7C',
125 => '=7D', 126 => '=7E', 127 => '=7F', 128 => '=80', 129 => '=81',
130 => '=82', 131 => '=83', 132 => '=84', 133 => '=85', 134 => '=86',
135 => '=87', 136 => '=88', 137 => '=89', 138 => '=8A', 139 => '=8B',
140 => '=8C', 141 => '=8D', 142 => '=8E', 143 => '=8F', 144 => '=90',
145 => '=91', 146 => '=92', 147 => '=93', 148 => '=94', 149 => '=95',
150 => '=96', 151 => '=97', 152 => '=98', 153 => '=99', 154 => '=9A',
155 => '=9B', 156 => '=9C', 157 => '=9D', 158 => '=9E', 159 => '=9F',
160 => '=A0', 161 => '=A1', 162 => '=A2', 163 => '=A3', 164 => '=A4',
165 => '=A5', 166 => '=A6', 167 => '=A7', 168 => '=A8', 169 => '=A9',
170 => '=AA', 171 => '=AB', 172 => '=AC', 173 => '=AD', 174 => '=AE',
175 => '=AF', 176 => '=B0', 177 => '=B1', 178 => '=B2', 179 => '=B3',
180 => '=B4', 181 => '=B5', 182 => '=B6', 183 => '=B7', 184 => '=B8',
185 => '=B9', 186 => '=BA', 187 => '=BB', 188 => '=BC', 189 => '=BD',
190 => '=BE', 191 => '=BF', 192 => '=C0', 193 => '=C1', 194 => '=C2',
195 => '=C3', 196 => '=C4', 197 => '=C5', 198 => '=C6', 199 => '=C7',
200 => '=C8', 201 => '=C9', 202 => '=CA', 203 => '=CB', 204 => '=CC',
205 => '=CD', 206 => '=CE', 207 => '=CF', 208 => '=D0', 209 => '=D1',
210 => '=D2', 211 => '=D3', 212 => '=D4', 213 => '=D5', 214 => '=D6',
215 => '=D7', 216 => '=D8', 217 => '=D9', 218 => '=DA', 219 => '=DB',
220 => '=DC', 221 => '=DD', 222 => '=DE', 223 => '=DF', 224 => '=E0',
225 => '=E1', 226 => '=E2', 227 => '=E3', 228 => '=E4', 229 => '=E5',
230 => '=E6', 231 => '=E7', 232 => '=E8', 233 => '=E9', 234 => '=EA',
235 => '=EB', 236 => '=EC', 237 => '=ED', 238 => '=EE', 239 => '=EF',
240 => '=F0', 241 => '=F1', 242 => '=F2', 243 => '=F3', 244 => '=F4',
245 => '=F5', 246 => '=F6', 247 => '=F7', 248 => '=F8', 249 => '=F9',
250 => '=FA', 251 => '=FB', 252 => '=FC', 253 => '=FD', 254 => '=FE',
255 => '=FF'
);
/**
* Pre-computed QP for HUGE optmization.
* @var string[]
* @access protected
*/
protected static $_qpMap = array(
0 => '=00', 1 => '=01', 2 => '=02', 3 => '=03', 4 => '=04',
5 => '=05', 6 => '=06', 7 => '=07', 8 => '=08', 9 => '=09',
10 => '=0A', 11 => '=0B', 12 => '=0C', 13 => '=0D', 14 => '=0E',
15 => '=0F', 16 => '=10', 17 => '=11', 18 => '=12', 19 => '=13',
20 => '=14', 21 => '=15', 22 => '=16', 23 => '=17', 24 => '=18',
25 => '=19', 26 => '=1A', 27 => '=1B', 28 => '=1C', 29 => '=1D',
30 => '=1E', 31 => '=1F', 32 => '=20', 33 => '=21', 34 => '=22',
35 => '=23', 36 => '=24', 37 => '=25', 38 => '=26', 39 => '=27',
40 => '=28', 41 => '=29', 42 => '=2A', 43 => '=2B', 44 => '=2C',
45 => '=2D', 46 => '=2E', 47 => '=2F', 48 => '=30', 49 => '=31',
50 => '=32', 51 => '=33', 52 => '=34', 53 => '=35', 54 => '=36',
55 => '=37', 56 => '=38', 57 => '=39', 58 => '=3A', 59 => '=3B',
60 => '=3C', 61 => '=3D', 62 => '=3E', 63 => '=3F', 64 => '=40',
65 => '=41', 66 => '=42', 67 => '=43', 68 => '=44', 69 => '=45',
70 => '=46', 71 => '=47', 72 => '=48', 73 => '=49', 74 => '=4A',
75 => '=4B', 76 => '=4C', 77 => '=4D', 78 => '=4E', 79 => '=4F',
80 => '=50', 81 => '=51', 82 => '=52', 83 => '=53', 84 => '=54',
85 => '=55', 86 => '=56', 87 => '=57', 88 => '=58', 89 => '=59',
90 => '=5A', 91 => '=5B', 92 => '=5C', 93 => '=5D', 94 => '=5E',
95 => '=5F', 96 => '=60', 97 => '=61', 98 => '=62', 99 => '=63',
100 => '=64', 101 => '=65', 102 => '=66', 103 => '=67', 104 => '=68',
105 => '=69', 106 => '=6A', 107 => '=6B', 108 => '=6C', 109 => '=6D',
110 => '=6E', 111 => '=6F', 112 => '=70', 113 => '=71', 114 => '=72',
115 => '=73', 116 => '=74', 117 => '=75', 118 => '=76', 119 => '=77',
120 => '=78', 121 => '=79', 122 => '=7A', 123 => '=7B', 124 => '=7C',
125 => '=7D', 126 => '=7E', 127 => '=7F', 128 => '=80', 129 => '=81',
130 => '=82', 131 => '=83', 132 => '=84', 133 => '=85', 134 => '=86',
135 => '=87', 136 => '=88', 137 => '=89', 138 => '=8A', 139 => '=8B',
140 => '=8C', 141 => '=8D', 142 => '=8E', 143 => '=8F', 144 => '=90',
145 => '=91', 146 => '=92', 147 => '=93', 148 => '=94', 149 => '=95',
150 => '=96', 151 => '=97', 152 => '=98', 153 => '=99', 154 => '=9A',
155 => '=9B', 156 => '=9C', 157 => '=9D', 158 => '=9E', 159 => '=9F',
160 => '=A0', 161 => '=A1', 162 => '=A2', 163 => '=A3', 164 => '=A4',
165 => '=A5', 166 => '=A6', 167 => '=A7', 168 => '=A8', 169 => '=A9',
170 => '=AA', 171 => '=AB', 172 => '=AC', 173 => '=AD', 174 => '=AE',
175 => '=AF', 176 => '=B0', 177 => '=B1', 178 => '=B2', 179 => '=B3',
180 => '=B4', 181 => '=B5', 182 => '=B6', 183 => '=B7', 184 => '=B8',
185 => '=B9', 186 => '=BA', 187 => '=BB', 188 => '=BC', 189 => '=BD',
190 => '=BE', 191 => '=BF', 192 => '=C0', 193 => '=C1', 194 => '=C2',
195 => '=C3', 196 => '=C4', 197 => '=C5', 198 => '=C6', 199 => '=C7',
200 => '=C8', 201 => '=C9', 202 => '=CA', 203 => '=CB', 204 => '=CC',
205 => '=CD', 206 => '=CE', 207 => '=CF', 208 => '=D0', 209 => '=D1',
210 => '=D2', 211 => '=D3', 212 => '=D4', 213 => '=D5', 214 => '=D6',
215 => '=D7', 216 => '=D8', 217 => '=D9', 218 => '=DA', 219 => '=DB',
220 => '=DC', 221 => '=DD', 222 => '=DE', 223 => '=DF', 224 => '=E0',
225 => '=E1', 226 => '=E2', 227 => '=E3', 228 => '=E4', 229 => '=E5',
230 => '=E6', 231 => '=E7', 232 => '=E8', 233 => '=E9', 234 => '=EA',
235 => '=EB', 236 => '=EC', 237 => '=ED', 238 => '=EE', 239 => '=EF',
240 => '=F0', 241 => '=F1', 242 => '=F2', 243 => '=F3', 244 => '=F4',
245 => '=F5', 246 => '=F6', 247 => '=F7', 248 => '=F8', 249 => '=F9',
250 => '=FA', 251 => '=FB', 252 => '=FC', 253 => '=FD', 254 => '=FE',
255 => '=FF'
);
protected static $_safeMapShare = array();
protected static $_safeMapShare = array();
/**
* A map of non-encoded ascii characters.
* @var string[]
* @access protected
*/
protected $_safeMap = array();
/**
* A map of non-encoded ascii characters.
* @var string[]
* @access protected
*/
protected $_safeMap = array();
/**
* Creates a new QpEncoder for the given CharacterStream.
* @param Swift_CharacterStream $charStream to use for reading characters
* @param Swift_StreamFilter $filter if input should be canonicalized
*/
public function __construct(Swift_CharacterStream $charStream,
Swift_StreamFilter $filter = null)
{
$this->_charStream = $charStream;
if(!isset(self::$_safeMapShare[$this->getSafeMapShareId()]))
/**
* Creates a new QpEncoder for the given CharacterStream.
* @param Swift_CharacterStream $charStream to use for reading characters
* @param Swift_StreamFilter $filter if input should be canonicalized
*/
public function __construct(Swift_CharacterStream $charStream, Swift_StreamFilter $filter = null)
{
$this->initSafeMap();
self::$_safeMapShare[$this->getSafeMapShareId()] = $this->_safeMap;
}
else
{
$this->_safeMap = self::$_safeMapShare[$this->getSafeMapShareId()];
}
$this->_filter = $filter;
}
public function __sleep()
{
return array('_charStream', '_filter');
}
public function __wakeup()
{
if(!isset(self::$_safeMapShare[$this->getSafeMapShareId()]))
{
$this->initSafeMap();
self::$_safeMapShare[$this->getSafeMapShareId()] = $this->_safeMap;
}
else
{
$this->_safeMap = self::$_safeMapShare[$this->getSafeMapShareId()];
}
}
protected function getSafeMapShareId()
{
return get_class($this);
}
protected function initSafeMap()
{
foreach (array_merge(
array(0x09, 0x20), range(0x21, 0x3C), range(0x3E, 0x7E)) as $byte)
{
$this->_safeMap[$byte] = chr($byte);
}
}
/**
* Takes an unencoded string and produces a QP encoded string from it.
* QP encoded strings have a maximum line length of 76 characters.
* If the first line needs to be shorter, indicate the difference with
* $firstLineOffset.
* @param string $string to encode
* @param int $firstLineOffset, optional
* @param int $maxLineLength, optional, 0 indicates the default of 76 chars
* @return string
*/
public function encodeString($string, $firstLineOffset = 0,
$maxLineLength = 0)
{
if ($maxLineLength > 76 || $maxLineLength <= 0)
{
$maxLineLength = 76;
}
$thisLineLength = $maxLineLength - $firstLineOffset;
$lines = array();
$lNo = 0;
$lines[$lNo] = '';
$currentLine =& $lines[$lNo++];
$size=$lineLen=0;
$this->_charStream->flushContents();
$this->_charStream->importString($string);
//Fetching more than 4 chars at one is slower, as is fetching fewer bytes
// Conveniently 4 chars is the UTF-8 safe number since UTF-8 has up to 6
// bytes per char and (6 * 4 * 3 = 72 chars per line) * =NN is 3 bytes
while (false !== $bytes = $this->_nextSequence())
{
//If we're filtering the input
if (isset($this->_filter))
{
//If we can't filter because we need more bytes
while ($this->_filter->shouldBuffer($bytes))
{
//Then collect bytes into the buffer
if (false === $moreBytes = $this->_nextSequence(1))
{
break;
}
foreach ($moreBytes as $b)
{
$bytes[] = $b;
}
$this->_charStream = $charStream;
if (!isset(self::$_safeMapShare[$this->getSafeMapShareId()])) {
$this->initSafeMap();
self::$_safeMapShare[$this->getSafeMapShareId()] = $this->_safeMap;
} else {
$this->_safeMap = self::$_safeMapShare[$this->getSafeMapShareId()];
}
//And filter them
$bytes = $this->_filter->filter($bytes);
}
$this->_filter = $filter;
}
$enc = $this->_encodeByteSequence($bytes, $size);
if ($currentLine && $lineLen+$size >= $thisLineLength)
{
public function __sleep()
{
return array('_charStream', '_filter');
}
public function __wakeup()
{
if (!isset(self::$_safeMapShare[$this->getSafeMapShareId()])) {
$this->initSafeMap();
self::$_safeMapShare[$this->getSafeMapShareId()] = $this->_safeMap;
} else {
$this->_safeMap = self::$_safeMapShare[$this->getSafeMapShareId()];
}
}
protected function getSafeMapShareId()
{
return get_class($this);
}
protected function initSafeMap()
{
foreach (array_merge(
array(0x09, 0x20), range(0x21, 0x3C), range(0x3E, 0x7E)) as $byte)
{
$this->_safeMap[$byte] = chr($byte);
}
}
/**
* Takes an unencoded string and produces a QP encoded string from it.
* QP encoded strings have a maximum line length of 76 characters.
* If the first line needs to be shorter, indicate the difference with
* $firstLineOffset.
* @param string $string to encode
* @param int $firstLineOffset, optional
* @param int $maxLineLength, optional, 0 indicates the default of 76 chars
* @return string
*/
public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
{
if ($maxLineLength > 76 || $maxLineLength <= 0) {
$maxLineLength = 76;
}
$thisLineLength = $maxLineLength - $firstLineOffset;
$lines = array();
$lNo = 0;
$lines[$lNo] = '';
$currentLine =& $lines[$lNo++];
$thisLineLength = $maxLineLength;
$lineLen=0;
}
$lineLen+=$size;
$currentLine .= $enc;
$size=$lineLen=0;
$this->_charStream->flushContents();
$this->_charStream->importString($string);
//Fetching more than 4 chars at one is slower, as is fetching fewer bytes
// Conveniently 4 chars is the UTF-8 safe number since UTF-8 has up to 6
// bytes per char and (6 * 4 * 3 = 72 chars per line) * =NN is 3 bytes
while (false !== $bytes = $this->_nextSequence()) {
//If we're filtering the input
if (isset($this->_filter)) {
//If we can't filter because we need more bytes
while ($this->_filter->shouldBuffer($bytes)) {
//Then collect bytes into the buffer
if (false === $moreBytes = $this->_nextSequence(1)) {
break;
}
foreach ($moreBytes as $b) {
$bytes[] = $b;
}
}
//And filter them
$bytes = $this->_filter->filter($bytes);
}
$enc = $this->_encodeByteSequence($bytes, $size);
if ($currentLine && $lineLen+$size >= $thisLineLength) {
$lines[$lNo] = '';
$currentLine =& $lines[$lNo++];
$thisLineLength = $maxLineLength;
$lineLen=0;
}
$lineLen+=$size;
$currentLine .= $enc;
}
return $this->_standardize(implode("=\r\n", $lines));
}
return $this->_standardize(implode("=\r\n", $lines));
}
/**
* Updates the charset used.
* @param string $charset
*/
public function charsetChanged($charset)
{
$this->_charStream->setCharacterSet($charset);
}
// -- Protected methods
/**
* Encode the given byte array into a verbatim QP form.
* @param int[] $bytes
* @return string
* @access protected
*/
protected function _encodeByteSequence(array $bytes, &$size)
{
$ret = '';
$size=0;
foreach ($bytes as $b)
/**
* Updates the charset used.
* @param string $charset
*/
public function charsetChanged($charset)
{
if (isset($this->_safeMap[$b]))
{
$ret .= $this->_safeMap[$b];
++$size;
}
else
{
$ret .= self::$_qpMap[$b];
$size+=3;
}
$this->_charStream->setCharacterSet($charset);
}
return $ret;
}
/**
* Get the next sequence of bytes to read from the char stream.
* @param int $size number of bytes to read
* @return int[]
* @access protected
*/
protected function _nextSequence($size = 4)
{
return $this->_charStream->readBytes($size);
}
// -- Protected methods
/**
* Make sure CRLF is correct and HT/SPACE are in valid places.
* @param string $string
* @return string
* @access protected
*/
protected function _standardize($string)
{
$string = str_replace(array("\t=0D=0A", " =0D=0A", "=0D=0A"),
array("=09\r\n", "=20\r\n", "\r\n"), $string
);
switch ($end = ord(substr($string, -1)))
/**
* Encode the given byte array into a verbatim QP form.
* @param int[] $bytes
* @return string
* @access protected
*/
protected function _encodeByteSequence(array $bytes, &$size)
{
case 0x09:
case 0x20:
$string = substr_replace($string, self::$_qpMap[$end], -1);
}
return $string;
}
$ret = '';
$size=0;
foreach ($bytes as $b) {
if (isset($this->_safeMap[$b])) {
$ret .= $this->_safeMap[$b];
++$size;
} else {
$ret .= self::$_qpMap[$b];
$size+=3;
}
}
return $ret;
}
/**
* Get the next sequence of bytes to read from the char stream.
* @param int $size number of bytes to read
* @return int[]
* @access protected
*/
protected function _nextSequence($size = 4)
{
return $this->_charStream->readBytes($size);
}
/**
* Make sure CRLF is correct and HT/SPACE are in valid places.
* @param string $string
* @return string
* @access protected
*/
protected function _standardize($string)
{
$string = str_replace(array("\t=0D=0A", " =0D=0A", "=0D=0A"),
array("=09\r\n", "=20\r\n", "\r\n"), $string
);
switch ($end = ord(substr($string, -1))) {
case 0x09:
case 0x20:
$string = substr_replace($string, self::$_qpMap[$end], -1);
}
return $string;
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Handles RFC 2231 specified Encoding in Swift Mailer.
* @package Swift
@@ -17,71 +16,66 @@
*/
class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder
{
/**
* A character stream to use when reading a string as characters instead of bytes.
* @var Swift_CharacterStream
* @access private
*/
private $_charStream;
/**
* Creates a new Rfc2231Encoder using the given character stream instance.
* @param Swift_CharacterStream
*/
public function __construct(Swift_CharacterStream $charStream)
{
$this->_charStream = $charStream;
}
/**
* Takes an unencoded string and produces a string encoded according to
* RFC 2231 from it.
* @param string $string to encode
* @param int $firstLineOffset
* @param int $maxLineLength, optional, 0 indicates the default of 75 bytes
* @return string
*/
public function encodeString($string, $firstLineOffset = 0,
$maxLineLength = 0)
{
$lines = array(); $lineCount = 0;
$lines[] = '';
$currentLine =& $lines[$lineCount++];
if (0 >= $maxLineLength)
/**
* A character stream to use when reading a string as characters instead of bytes.
* @var Swift_CharacterStream
* @access private
*/
private $_charStream;
/**
* Creates a new Rfc2231Encoder using the given character stream instance.
* @param Swift_CharacterStream
*/
public function __construct(Swift_CharacterStream $charStream)
{
$maxLineLength = 75;
$this->_charStream = $charStream;
}
$this->_charStream->flushContents();
$this->_charStream->importString($string);
$thisLineLength = $maxLineLength - $firstLineOffset;
while (false !== $char = $this->_charStream->read(4))
/**
* Takes an unencoded string and produces a string encoded according to
* RFC 2231 from it.
* @param string $string to encode
* @param int $firstLineOffset
* @param int $maxLineLength, optional, 0 indicates the default of 75 bytes
* @return string
*/
public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
{
$encodedChar = rawurlencode($char);
if (0 != strlen($currentLine)
&& strlen($currentLine . $encodedChar) > $thisLineLength)
{
$lines = array(); $lineCount = 0;
$lines[] = '';
$currentLine =& $lines[$lineCount++];
$thisLineLength = $maxLineLength;
}
$currentLine .= $encodedChar;
if (0 >= $maxLineLength) {
$maxLineLength = 75;
}
$this->_charStream->flushContents();
$this->_charStream->importString($string);
$thisLineLength = $maxLineLength - $firstLineOffset;
while (false !== $char = $this->_charStream->read(4)) {
$encodedChar = rawurlencode($char);
if (0 != strlen($currentLine)
&& strlen($currentLine . $encodedChar) > $thisLineLength)
{
$lines[] = '';
$currentLine =& $lines[$lineCount++];
$thisLineLength = $maxLineLength;
}
$currentLine .= $encodedChar;
}
return implode("\r\n", $lines);
}
/**
* Updates the charset used.
* @param string $charset
*/
public function charsetChanged($charset)
{
$this->_charStream->setCharacterSet($charset);
}
return implode("\r\n", $lines);
}
/**
* Updates the charset used.
* @param string $charset
*/
public function charsetChanged($charset)
{
$this->_charStream->setCharacterSet($charset);
}
}

View File

@@ -8,62 +8,59 @@
* file that was distributed with this source code.
*/
/**
* Provides quick access to each encoding type.
*
*
* @package Swift
* @subpackage Encoder
* @author Chris Corbyn
*/
class Swift_Encoding
{
/**
* Get the Encoder that provides 7-bit encoding.
*
* @return Swift_Mime_ContentEncoder
*/
public static function get7BitEncoding()
{
return self::_lookup('mime.7bitcontentencoder');
}
/**
* Get the Encoder that provides 8-bit encoding.
*
* @return Swift_Mime_ContentEncoder
*/
public static function get8BitEncoding()
{
return self::_lookup('mime.8bitcontentencoder');
}
/**
* Get the Encoder that provides Quoted-Printable (QP) encoding.
*
* @return Swift_Mime_ContentEncoder
*/
public static function getQpEncoding()
{
return self::_lookup('mime.qpcontentencoder');
}
/**
* Get the Encoder that provides Base64 encoding.
*
* @return Swift_Mime_ContentEncoder
*/
public static function getBase64Encoding()
{
return self::_lookup('mime.base64contentencoder');
}
// -- Private Static Methods
private static function _lookup($key)
{
return Swift_DependencyContainer::getInstance()->lookup($key);
}
/**
* Get the Encoder that provides 7-bit encoding.
*
* @return Swift_Mime_ContentEncoder
*/
public static function get7BitEncoding()
{
return self::_lookup('mime.7bitcontentencoder');
}
/**
* Get the Encoder that provides 8-bit encoding.
*
* @return Swift_Mime_ContentEncoder
*/
public static function get8BitEncoding()
{
return self::_lookup('mime.8bitcontentencoder');
}
/**
* Get the Encoder that provides Quoted-Printable (QP) encoding.
*
* @return Swift_Mime_ContentEncoder
*/
public static function getQpEncoding()
{
return self::_lookup('mime.qpcontentencoder');
}
/**
* Get the Encoder that provides Base64 encoding.
*
* @return Swift_Mime_ContentEncoder
*/
public static function getBase64Encoding()
{
return self::_lookup('mime.base64contentencoder');
}
// -- Private Static Methods
private static function _lookup($key)
{
return Swift_DependencyContainer::getInstance()->lookup($key);
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Generated when a command is sent over an SMTP connection.
* @package Swift
@@ -17,49 +16,46 @@
*/
class Swift_Events_CommandEvent extends Swift_Events_EventObject
{
/**
* The command sent to the server.
* @var string
*/
private $_command;
/**
* An array of codes which a successful response will contain.
* @var int[]
*/
private $_successCodes = array();
/**
* Create a new CommandEvent for $source with $command.
* @param Swift_Transport $source
* @param string $command
* @param array $successCodes
*/
public function __construct(Swift_Transport $source,
$command, $successCodes = array())
{
parent::__construct($source);
$this->_command = $command;
$this->_successCodes = $successCodes;
}
/**
* Get the command which was sent to the server.
* @return string
*/
public function getCommand()
{
return $this->_command;
}
/**
* Get the numeric response codes which indicate success for this command.
* @return int[]
*/
public function getSuccessCodes()
{
return $this->_successCodes;
}
}
/**
* The command sent to the server.
* @var string
*/
private $_command;
/**
* An array of codes which a successful response will contain.
* @var int[]
*/
private $_successCodes = array();
/**
* Create a new CommandEvent for $source with $command.
* @param Swift_Transport $source
* @param string $command
* @param array $successCodes
*/
public function __construct(Swift_Transport $source, $command, $successCodes = array())
{
parent::__construct($source);
$this->_command = $command;
$this->_successCodes = $successCodes;
}
/**
* Get the command which was sent to the server.
* @return string
*/
public function getCommand()
{
return $this->_command;
}
/**
* Get the numeric response codes which indicate success for this command.
* @return int[]
*/
public function getSuccessCodes()
{
return $this->_successCodes;
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Listens for Transports to send commands to the server.
* @package Swift
@@ -17,11 +16,9 @@
*/
interface Swift_Events_CommandListener extends Swift_Events_EventListener
{
/**
* Invoked immediately following a command being sent.
* @param Swift_Events_ResponseEvent $evt
*/
public function commandSent(Swift_Events_CommandEvent $evt);
/**
* Invoked immediately following a command being sent.
* @param Swift_Events_ResponseEvent $evt
*/
public function commandSent(Swift_Events_CommandEvent $evt);
}

View File

@@ -10,30 +10,28 @@
/**
* The minimum interface for an Event.
*
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
*/
interface Swift_Events_Event
{
/**
* Get the source object of this event.
* @return object
*/
public function getSource();
/**
* Prevent this Event from bubbling any further up the stack.
* @param boolean $cancel, optional
*/
public function cancelBubble($cancel = true);
/**
* Returns true if this Event will not bubble any further up the stack.
* @return boolean
*/
public function bubbleCancelled();
/**
* Get the source object of this event.
* @return object
*/
public function getSource();
/**
* Prevent this Event from bubbling any further up the stack.
* @param boolean $cancel, optional
*/
public function cancelBubble($cancel = true);
/**
* Returns true if this Event will not bubble any further up the stack.
* @return boolean
*/
public function bubbleCancelled();
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Interface for the EventDispatcher which handles the event dispatching layer.
* @package Swift
@@ -17,63 +16,57 @@
*/
interface Swift_Events_EventDispatcher
{
/**
* Create a new SendEvent for $source and $message.
* @param Swift_Transport $source
* @param Swift_Mime_Message
* @return Swift_Events_SendEvent
*/
public function createSendEvent(Swift_Transport $source,
Swift_Mime_Message $message);
/**
* Create a new CommandEvent for $source and $command.
* @param Swift_Transport $source
* @param string $command That will be executed
* @param array $successCodes That are needed
* @return Swift_Events_CommandEvent
*/
public function createCommandEvent(Swift_Transport $source,
$command, $successCodes = array());
/**
* Create a new ResponseEvent for $source and $response.
* @param Swift_Transport $source
* @param string $response
* @param boolean $valid If the response is valid
* @return Swift_Events_ResponseEvent
*/
public function createResponseEvent(Swift_Transport $source,
$response, $valid);
/**
* Create a new TransportChangeEvent for $source.
* @param Swift_Transport $source
* @return Swift_Events_TransportChangeEvent
*/
public function createTransportChangeEvent(Swift_Transport $source);
/**
* Create a new TransportExceptionEvent for $source.
* @param Swift_Transport $source
* @param Swift_TransportException $ex
* @return Swift_Events_TransportExceptionEvent
*/
public function createTransportExceptionEvent(Swift_Transport $source,
Swift_TransportException $ex);
/**
* Bind an event listener to this dispatcher.
* @param Swift_Events_EventListener $listener
*/
public function bindEventListener(Swift_Events_EventListener $listener);
/**
* Dispatch the given Event to all suitable listeners.
* @param Swift_Events_EventObject $evt
* @param string $target method
*/
public function dispatchEvent(Swift_Events_EventObject $evt, $target);
/**
* Create a new SendEvent for $source and $message.
* @param Swift_Transport $source
* @param Swift_Mime_Message
* @return Swift_Events_SendEvent
*/
public function createSendEvent(Swift_Transport $source, Swift_Mime_Message $message);
/**
* Create a new CommandEvent for $source and $command.
* @param Swift_Transport $source
* @param string $command That will be executed
* @param array $successCodes That are needed
* @return Swift_Events_CommandEvent
*/
public function createCommandEvent(Swift_Transport $source, $command, $successCodes = array());
/**
* Create a new ResponseEvent for $source and $response.
* @param Swift_Transport $source
* @param string $response
* @param boolean $valid If the response is valid
* @return Swift_Events_ResponseEvent
*/
public function createResponseEvent(Swift_Transport $source, $response, $valid);
/**
* Create a new TransportChangeEvent for $source.
* @param Swift_Transport $source
* @return Swift_Events_TransportChangeEvent
*/
public function createTransportChangeEvent(Swift_Transport $source);
/**
* Create a new TransportExceptionEvent for $source.
* @param Swift_Transport $source
* @param Swift_TransportException $ex
* @return Swift_Events_TransportExceptionEvent
*/
public function createTransportExceptionEvent(Swift_Transport $source, Swift_TransportException $ex);
/**
* Bind an event listener to this dispatcher.
* @param Swift_Events_EventListener $listener
*/
public function bindEventListener(Swift_Events_EventListener $listener);
/**
* Dispatch the given Event to all suitable listeners.
* @param Swift_Events_EventObject $evt
* @param string $target method
*/
public function dispatchEvent(Swift_Events_EventObject $evt, $target);
}

View File

@@ -15,5 +15,5 @@
* @author Chris Corbyn
*/
interface Swift_Events_EventListener
{
{
}

View File

@@ -8,57 +8,54 @@
* file that was distributed with this source code.
*/
/**
* A base Event which all Event classes inherit from.
*
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
*/
class Swift_Events_EventObject implements Swift_Events_Event
{
/** The source of this Event */
private $_source;
/** The state of this Event (should it bubble up the stack?) */
private $_bubbleCancelled = false;
/**
* Create a new EventObject originating at $source.
* @param object $source
*/
public function __construct($source)
{
$this->_source = $source;
}
/**
* Get the source object of this event.
* @return object
*/
public function getSource()
{
return $this->_source;
}
/**
* Prevent this Event from bubbling any further up the stack.
* @param boolean $cancel, optional
*/
public function cancelBubble($cancel = true)
{
$this->_bubbleCancelled = $cancel;
}
/**
* Returns true if this Event will not bubble any further up the stack.
* @return boolean
*/
public function bubbleCancelled()
{
return $this->_bubbleCancelled;
}
/** The source of this Event */
private $_source;
/** The state of this Event (should it bubble up the stack?) */
private $_bubbleCancelled = false;
/**
* Create a new EventObject originating at $source.
* @param object $source
*/
public function __construct($source)
{
$this->_source = $source;
}
/**
* Get the source object of this event.
* @return object
*/
public function getSource()
{
return $this->_source;
}
/**
* Prevent this Event from bubbling any further up the stack.
* @param boolean $cancel, optional
*/
public function cancelBubble($cancel = true)
{
$this->_bubbleCancelled = $cancel;
}
/**
* Returns true if this Event will not bubble any further up the stack.
* @return boolean
*/
public function bubbleCancelled()
{
return $this->_bubbleCancelled;
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Generated when a response is received on a SMTP connection.
* @package Swift
@@ -17,48 +16,47 @@
*/
class Swift_Events_ResponseEvent extends Swift_Events_EventObject
{
/**
* The overall result.
* @var boolean
*/
private $_valid;
/**
* The response received from the server.
* @var string
*/
private $_response;
/**
* Create a new ResponseEvent for $source and $response.
* @param Swift_Transport $source
* @param string $response
* @param boolean $valid
*/
public function __construct(Swift_Transport $source, $response, $valid = false)
{
parent::__construct($source);
$this->_response = $response;
$this->_valid = $valid;
}
/**
* Get the response which was received from the server.
* @return string
*/
public function getResponse()
{
return $this->_response;
}
/**
* Get the success status of this Event.
* @return boolean
*/
public function isValid()
{
return $this->_valid;
}
}
/**
* The overall result.
* @var boolean
*/
private $_valid;
/**
* The response received from the server.
* @var string
*/
private $_response;
/**
* Create a new ResponseEvent for $source and $response.
* @param Swift_Transport $source
* @param string $response
* @param boolean $valid
*/
public function __construct(Swift_Transport $source, $response, $valid = false)
{
parent::__construct($source);
$this->_response = $response;
$this->_valid = $valid;
}
/**
* Get the response which was received from the server.
* @return string
*/
public function getResponse()
{
return $this->_response;
}
/**
* Get the success status of this Event.
* @return boolean
*/
public function isValid()
{
return $this->_valid;
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Listens for responses from a remote SMTP server.
* @package Swift
@@ -17,11 +16,9 @@
*/
interface Swift_Events_ResponseListener extends Swift_Events_EventListener
{
/**
* Invoked immediately following a response coming back.
* @param Swift_Events_ResponseEvent $evt
*/
public function responseReceived(Swift_Events_ResponseEvent $evt);
/**
* Invoked immediately following a response coming back.
* @param Swift_Events_ResponseEvent $evt
*/
public function responseReceived(Swift_Events_ResponseEvent $evt);
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Generated when a message is being sent.
* @package Swift
@@ -17,104 +16,101 @@
*/
class Swift_Events_SendEvent extends Swift_Events_EventObject
{
/** Sending has yet to occur */
const RESULT_PENDING = 0x0001;
/** Sending was successful */
const RESULT_SUCCESS = 0x0010;
/** Sending worked, but there were some failures */
const RESULT_TENTATIVE = 0x0100;
/** Sending failed */
const RESULT_FAILED = 0x1000;
/**
* The Message being sent.
* @var Swift_Mime_Message
*/
private $_message;
/**
* Any recipients which failed after sending.
* @var string[]
*/
private $_failedRecipients = array();
/**
* The overall result as a bitmask from the class constants.
* @var int
*/
private $_result;
/**
* Create a new SendEvent for $source and $message.
* @param Swift_Transport $source
* @param Swift_Mime_Message $message
*/
public function __construct(Swift_Transport $source,
Swift_Mime_Message $message)
{
parent::__construct($source);
$this->_message = $message;
$this->_result = self::RESULT_PENDING;
}
/**
* Get the Transport used to send the Message.
* @return Swift_Transport
*/
public function getTransport()
{
return $this->getSource();
}
/**
* Get the Message being sent.
* @return Swift_Mime_Message
*/
public function getMessage()
{
return $this->_message;
}
/**
* Set the array of addresses that failed in sending.
* @param array $recipients
*/
public function setFailedRecipients($recipients)
{
$this->_failedRecipients = $recipients;
}
/**
* Get an recipient addresses which were not accepted for delivery.
* @return string[]
*/
public function getFailedRecipients()
{
return $this->_failedRecipients;
}
/**
* Set the result of sending.
* @return int
*/
public function setResult($result)
{
$this->_result = $result;
}
/**
* Get the result of this Event.
* The return value is a bitmask from
* {@link RESULT_PENDING, RESULT_SUCCESS, RESULT_TENTATIVE, RESULT_FAILED}
* @return int
*/
public function getResult()
{
return $this->_result;
}
/** Sending has yet to occur */
const RESULT_PENDING = 0x0001;
/** Sending was successful */
const RESULT_SUCCESS = 0x0010;
/** Sending worked, but there were some failures */
const RESULT_TENTATIVE = 0x0100;
/** Sending failed */
const RESULT_FAILED = 0x1000;
/**
* The Message being sent.
* @var Swift_Mime_Message
*/
private $_message;
/**
* Any recipients which failed after sending.
* @var string[]
*/
private $_failedRecipients = array();
/**
* The overall result as a bitmask from the class constants.
* @var int
*/
private $_result;
/**
* Create a new SendEvent for $source and $message.
* @param Swift_Transport $source
* @param Swift_Mime_Message $message
*/
public function __construct(Swift_Transport $source, Swift_Mime_Message $message)
{
parent::__construct($source);
$this->_message = $message;
$this->_result = self::RESULT_PENDING;
}
/**
* Get the Transport used to send the Message.
* @return Swift_Transport
*/
public function getTransport()
{
return $this->getSource();
}
/**
* Get the Message being sent.
* @return Swift_Mime_Message
*/
public function getMessage()
{
return $this->_message;
}
/**
* Set the array of addresses that failed in sending.
* @param array $recipients
*/
public function setFailedRecipients($recipients)
{
$this->_failedRecipients = $recipients;
}
/**
* Get an recipient addresses which were not accepted for delivery.
* @return string[]
*/
public function getFailedRecipients()
{
return $this->_failedRecipients;
}
/**
* Set the result of sending.
* @return int
*/
public function setResult($result)
{
$this->_result = $result;
}
/**
* Get the result of this Event.
* The return value is a bitmask from
* {@link RESULT_PENDING, RESULT_SUCCESS, RESULT_TENTATIVE, RESULT_FAILED}
* @return int
*/
public function getResult()
{
return $this->_result;
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Listens for Messages being sent from within the Transport system.
* @package Swift
@@ -17,17 +16,15 @@
*/
interface Swift_Events_SendListener extends Swift_Events_EventListener
{
/**
* Invoked immediately before the Message is sent.
* @param Swift_Events_SendEvent $evt
*/
public function beforeSendPerformed(Swift_Events_SendEvent $evt);
/**
* Invoked immediately after the Message is sent.
* @param Swift_Events_SendEvent $evt
*/
public function sendPerformed(Swift_Events_SendEvent $evt);
/**
* Invoked immediately before the Message is sent.
* @param Swift_Events_SendEvent $evt
*/
public function beforeSendPerformed(Swift_Events_SendEvent $evt);
/**
* Invoked immediately after the Message is sent.
* @param Swift_Events_SendEvent $evt
*/
public function sendPerformed(Swift_Events_SendEvent $evt);
}

View File

@@ -8,160 +8,149 @@
* file that was distributed with this source code.
*/
/**
* The EventDispatcher which handles the event dispatching layer.
*
*
* @package Swift
* @subpackage Events
* @author Chris Corbyn
*/
class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher
{
/** A map of event types to their associated listener types */
private $_eventMap = array();
/** Event listeners bound to this dispatcher */
private $_listeners = array();
/** Listeners queued to have an Event bubbled up the stack to them */
private $_bubbleQueue = array();
/**
* Create a new EventDispatcher.
*/
public function __construct()
{
$this->_eventMap = array(
'Swift_Events_CommandEvent' => 'Swift_Events_CommandListener',
'Swift_Events_ResponseEvent' => 'Swift_Events_ResponseListener',
'Swift_Events_SendEvent' => 'Swift_Events_SendListener',
'Swift_Events_TransportChangeEvent' => 'Swift_Events_TransportChangeListener',
'Swift_Events_TransportExceptionEvent' => 'Swift_Events_TransportExceptionListener'
);
}
/**
* Create a new SendEvent for $source and $message.
*
* @param Swift_Transport $source
* @param Swift_Mime_Message
* @return Swift_Events_SendEvent
*/
public function createSendEvent(Swift_Transport $source,
Swift_Mime_Message $message)
{
return new Swift_Events_SendEvent($source, $message);
}
/**
* Create a new CommandEvent for $source and $command.
*
* @param Swift_Transport $source
* @param string $command That will be executed
* @param array $successCodes That are needed
* @return Swift_Events_CommandEvent
*/
public function createCommandEvent(Swift_Transport $source,
$command, $successCodes = array())
{
return new Swift_Events_CommandEvent($source, $command, $successCodes);
}
/**
* Create a new ResponseEvent for $source and $response.
*
* @param Swift_Transport $source
* @param string $response
* @param boolean $valid If the response is valid
* @return Swift_Events_ResponseEvent
*/
public function createResponseEvent(Swift_Transport $source,
$response, $valid)
{
return new Swift_Events_ResponseEvent($source, $response, $valid);
}
/**
* Create a new TransportChangeEvent for $source.
*
* @param Swift_Transport $source
* @return Swift_Events_TransportChangeEvent
*/
public function createTransportChangeEvent(Swift_Transport $source)
{
return new Swift_Events_TransportChangeEvent($source);
}
/**
* Create a new TransportExceptionEvent for $source.
*
* @param Swift_Transport $source
* @param Swift_TransportException $ex
* @return Swift_Events_TransportExceptionEvent
*/
public function createTransportExceptionEvent(Swift_Transport $source,
Swift_TransportException $ex)
{
return new Swift_Events_TransportExceptionEvent($source, $ex);
}
/**
* Bind an event listener to this dispatcher.
*
* @param Swift_Events_EventListener $listener
*/
public function bindEventListener(Swift_Events_EventListener $listener)
{
foreach ($this->_listeners as $l)
/** A map of event types to their associated listener types */
private $_eventMap = array();
/** Event listeners bound to this dispatcher */
private $_listeners = array();
/** Listeners queued to have an Event bubbled up the stack to them */
private $_bubbleQueue = array();
/**
* Create a new EventDispatcher.
*/
public function __construct()
{
//Already loaded
if ($l === $listener)
{
return;
}
$this->_eventMap = array(
'Swift_Events_CommandEvent' => 'Swift_Events_CommandListener',
'Swift_Events_ResponseEvent' => 'Swift_Events_ResponseListener',
'Swift_Events_SendEvent' => 'Swift_Events_SendListener',
'Swift_Events_TransportChangeEvent' => 'Swift_Events_TransportChangeListener',
'Swift_Events_TransportExceptionEvent' => 'Swift_Events_TransportExceptionListener'
);
}
$this->_listeners[] = $listener;
}
/**
* Dispatch the given Event to all suitable listeners.
*
* @param Swift_Events_EventObject $evt
* @param string $target method
*/
public function dispatchEvent(Swift_Events_EventObject $evt, $target)
{
$this->_prepareBubbleQueue($evt);
$this->_bubble($evt, $target);
}
// -- Private methods
/** Queue listeners on a stack ready for $evt to be bubbled up it */
private function _prepareBubbleQueue(Swift_Events_EventObject $evt)
{
$this->_bubbleQueue = array();
$evtClass = get_class($evt);
foreach ($this->_listeners as $listener)
/**
* Create a new SendEvent for $source and $message.
*
* @param Swift_Transport $source
* @param Swift_Mime_Message
* @return Swift_Events_SendEvent
*/
public function createSendEvent(Swift_Transport $source, Swift_Mime_Message $message)
{
if (array_key_exists($evtClass, $this->_eventMap)
&& ($listener instanceof $this->_eventMap[$evtClass]))
{
$this->_bubbleQueue[] = $listener;
}
return new Swift_Events_SendEvent($source, $message);
}
}
/** Bubble $evt up the stack calling $target() on each listener */
private function _bubble(Swift_Events_EventObject $evt, $target)
{
if (!$evt->bubbleCancelled() && $listener = array_shift($this->_bubbleQueue))
/**
* Create a new CommandEvent for $source and $command.
*
* @param Swift_Transport $source
* @param string $command That will be executed
* @param array $successCodes That are needed
* @return Swift_Events_CommandEvent
*/
public function createCommandEvent(Swift_Transport $source, $command, $successCodes = array())
{
$listener->$target($evt);
$this->_bubble($evt, $target);
return new Swift_Events_CommandEvent($source, $command, $successCodes);
}
/**
* Create a new ResponseEvent for $source and $response.
*
* @param Swift_Transport $source
* @param string $response
* @param boolean $valid If the response is valid
* @return Swift_Events_ResponseEvent
*/
public function createResponseEvent(Swift_Transport $source, $response, $valid)
{
return new Swift_Events_ResponseEvent($source, $response, $valid);
}
/**
* Create a new TransportChangeEvent for $source.
*
* @param Swift_Transport $source
* @return Swift_Events_TransportChangeEvent
*/
public function createTransportChangeEvent(Swift_Transport $source)
{
return new Swift_Events_TransportChangeEvent($source);
}
/**
* Create a new TransportExceptionEvent for $source.
*
* @param Swift_Transport $source
* @param Swift_TransportException $ex
* @return Swift_Events_TransportExceptionEvent
*/
public function createTransportExceptionEvent(Swift_Transport $source, Swift_TransportException $ex)
{
return new Swift_Events_TransportExceptionEvent($source, $ex);
}
/**
* Bind an event listener to this dispatcher.
*
* @param Swift_Events_EventListener $listener
*/
public function bindEventListener(Swift_Events_EventListener $listener)
{
foreach ($this->_listeners as $l) {
//Already loaded
if ($l === $listener) {
return;
}
}
$this->_listeners[] = $listener;
}
/**
* Dispatch the given Event to all suitable listeners.
*
* @param Swift_Events_EventObject $evt
* @param string $target method
*/
public function dispatchEvent(Swift_Events_EventObject $evt, $target)
{
$this->_prepareBubbleQueue($evt);
$this->_bubble($evt, $target);
}
// -- Private methods
/** Queue listeners on a stack ready for $evt to be bubbled up it */
private function _prepareBubbleQueue(Swift_Events_EventObject $evt)
{
$this->_bubbleQueue = array();
$evtClass = get_class($evt);
foreach ($this->_listeners as $listener) {
if (array_key_exists($evtClass, $this->_eventMap)
&& ($listener instanceof $this->_eventMap[$evtClass]))
{
$this->_bubbleQueue[] = $listener;
}
}
}
/** Bubble $evt up the stack calling $target() on each listener */
private function _bubble(Swift_Events_EventObject $evt, $target)
{
if (!$evt->bubbleCancelled() && $listener = array_shift($this->_bubbleQueue)) {
$listener->$target($evt);
$this->_bubble($evt, $target);
}
}
}
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Generated when the state of a Transport is changed (i.e. stopped/started).
* @package Swift
@@ -17,14 +16,12 @@
*/
class Swift_Events_TransportChangeEvent extends Swift_Events_EventObject
{
/**
* Get the Transport.
* @return Swift_Transport
*/
public function getTransport()
{
return $this->getSource();
}
}
/**
* Get the Transport.
* @return Swift_Transport
*/
public function getTransport()
{
return $this->getSource();
}
}

View File

@@ -8,44 +8,41 @@
* file that was distributed with this source code.
*/
/**
* Listens for changes within the Transport system.
*
*
* @package Swift
* @subpackage Events
*
*
* @author Chris Corbyn
*/
interface Swift_Events_TransportChangeListener extends Swift_Events_EventListener
{
/**
* Invoked just before a Transport is started.
*
* @param Swift_Events_TransportChangeEvent $evt
*/
public function beforeTransportStarted(Swift_Events_TransportChangeEvent $evt);
/**
* Invoked immediately after the Transport is started.
*
* @param Swift_Events_TransportChangeEvent $evt
*/
public function transportStarted(Swift_Events_TransportChangeEvent $evt);
/**
* Invoked just before a Transport is stopped.
*
* @param Swift_Events_TransportChangeEvent $evt
*/
public function beforeTransportStopped(Swift_Events_TransportChangeEvent $evt);
/**
* Invoked immediately after the Transport is stopped.
*
* @param Swift_Events_TransportChangeEvent $evt
*/
public function transportStopped(Swift_Events_TransportChangeEvent $evt);
/**
* Invoked just before a Transport is started.
*
* @param Swift_Events_TransportChangeEvent $evt
*/
public function beforeTransportStarted(Swift_Events_TransportChangeEvent $evt);
/**
* Invoked immediately after the Transport is started.
*
* @param Swift_Events_TransportChangeEvent $evt
*/
public function transportStarted(Swift_Events_TransportChangeEvent $evt);
/**
* Invoked just before a Transport is stopped.
*
* @param Swift_Events_TransportChangeEvent $evt
*/
public function beforeTransportStopped(Swift_Events_TransportChangeEvent $evt);
/**
* Invoked immediately after the Transport is stopped.
*
* @param Swift_Events_TransportChangeEvent $evt
*/
public function transportStopped(Swift_Events_TransportChangeEvent $evt);
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Generated when a TransportException is thrown from the Transport system.
* @package Swift
@@ -17,32 +16,29 @@
*/
class Swift_Events_TransportExceptionEvent extends Swift_Events_EventObject
{
/**
* The Exception thrown.
* @var Swift_TransportException
*/
private $_exception;
/**
* Create a new TransportExceptionEvent for $transport.
* @param Swift_Transport $transport
* @param Swift_TransportException $ex
*/
public function __construct(Swift_Transport $transport,
Swift_TransportException $ex)
{
parent::__construct($transport);
$this->_exception = $ex;
}
/**
* Get the TransportException thrown.
* @return Swift_TransportException
*/
public function getException()
{
return $this->_exception;
}
/**
* The Exception thrown.
* @var Swift_TransportException
*/
private $_exception;
/**
* Create a new TransportExceptionEvent for $transport.
* @param Swift_Transport $transport
* @param Swift_TransportException $ex
*/
public function __construct(Swift_Transport $transport, Swift_TransportException $ex)
{
parent::__construct($transport);
$this->_exception = $ex;
}
/**
* Get the TransportException thrown.
* @return Swift_TransportException
*/
public function getException()
{
return $this->_exception;
}
}

View File

@@ -8,21 +8,17 @@
* file that was distributed with this source code.
*/
/**
* Listens for Exceptions thrown from within the Transport system.
* @package Swift
* @subpackage Events
* @author Chris Corbyn
*/
interface Swift_Events_TransportExceptionListener
extends Swift_Events_EventListener
interface Swift_Events_TransportExceptionListener extends Swift_Events_EventListener
{
/**
* Invoked as a TransportException is thrown in the Transport system.
* @param Swift_Events_TransportExceptionEvent $evt
*/
public function exceptionThrown(Swift_Events_TransportExceptionEvent $evt);
/**
* Invoked as a TransportException is thrown in the Transport system.
* @param Swift_Events_TransportExceptionEvent $evt
*/
public function exceptionThrown(Swift_Events_TransportExceptionEvent $evt);
}

View File

@@ -8,7 +8,6 @@
* file that was distributed with this source code.
*/
/**
* Contains a list of redundant Transports so when one fails, the next is used.
* @package Swift
@@ -17,30 +16,28 @@
*/
class Swift_FailoverTransport extends Swift_Transport_FailoverTransport
{
/**
* Creates a new FailoverTransport with $transports.
* @param array $transports
*/
public function __construct($transports = array())
{
call_user_func_array(
array($this, 'Swift_Transport_FailoverTransport::__construct'),
Swift_DependencyContainer::getInstance()
->createDependenciesFor('transport.failover')
);
$this->setTransports($transports);
}
/**
* Create a new FailoverTransport instance.
* @param string $transports
* @return Swift_FailoverTransport
*/
public static function newInstance($transports = array())
{
return new self($transports);
}
/**
* Creates a new FailoverTransport with $transports.
* @param array $transports
*/
public function __construct($transports = array())
{
call_user_func_array(
array($this, 'Swift_Transport_FailoverTransport::__construct'),
Swift_DependencyContainer::getInstance()
->createDependenciesFor('transport.failover')
);
$this->setTransports($transports);
}
/**
* Create a new FailoverTransport instance.
* @param string $transports
* @return Swift_FailoverTransport
*/
public static function newInstance($transports = array())
{
return new self($transports);
}
}

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