Updated code base & unit tests of WootookCore module

Added a Dependency Injection
Started to refactor the Database\Sql\Dml component

Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
Gregory PLANCHAT 2012-07-12 02:37:05 +02:00
commit d75265a8fe
451 changed files with 17743 additions and 6334 deletions

View file

@ -0,0 +1,167 @@
<?php return array(
'Wootook\\Core\\App\\App' => __DIR__ . '/src/Wootook/Core/App/App.php',
'Wootook\\Core\\Base\\BaseObject' => __DIR__ . '/src/Wootook/Core/Base/BaseObject.php',
'Wootook\\Core\\Base\\DataContainer' => __DIR__ . '/src/Wootook/Core/Base/DataContainer.php',
'Wootook\\Core\\Base\\Service\\App' => __DIR__ . '/src/Wootook/Core/Base/Service/App.php',
'Wootook\\Core\\Base\\Singleton' => __DIR__ . '/src/Wootook/Core/Base/Singleton.php',
'Wootook\\Core\\Block\\Concat' => __DIR__ . '/src/Wootook/Core/Block/Concat.php',
'Wootook\\Core\\Block\\Deprecated' => __DIR__ . '/src/Wootook/Core/Block/Deprecated.php',
'Wootook\\Core\\Block\\Html\\Form' => __DIR__ . '/src/Wootook/Core/Block/Html/Form.php',
'Wootook\\Core\\Block\\Html\\Head' => __DIR__ . '/src/Wootook/Core/Block/Html/Head.php',
'Wootook\\Core\\Block\\Html\\Home' => __DIR__ . '/src/Wootook/Core/Block/Html/Home.php',
'Wootook\\Core\\Block\\Html\\Navigation\\Link' => __DIR__ . '/src/Wootook/Core/Block/Html/Navigation/Link.php',
'Wootook\\Core\\Block\\Html\\Navigation\\Menu' => __DIR__ . '/src/Wootook/Core/Block/Html/Navigation/Menu.php',
'Wootook\\Core\\Block\\Html\\Navigation\\Node' => __DIR__ . '/src/Wootook/Core/Block/Html/Navigation/Node.php',
'Wootook\\Core\\Block\\Html\\Page' => __DIR__ . '/src/Wootook/Core/Block/Html/Page.php',
'Wootook\\Core\\Block\\Messages' => __DIR__ . '/src/Wootook/Core/Block/Messages.php',
'Wootook\\Core\\Block\\Template' => __DIR__ . '/src/Wootook/Core/Block/Template.php',
'Wootook\\Core\\Block\\Text' => __DIR__ . '/src/Wootook/Core/Block/Text.php',
'Wootook\\Core\\Config\\Adapter\\Adapter' => __DIR__ . '/src/Wootook/Core/Config/Adapter/Adapter.php',
'Wootook\\Core\\Config\\Adapter\\PhpArray' => __DIR__ . '/src/Wootook/Core/Config/Adapter/PhpArray.php',
'Wootook\\Core\\Config\\Node' => __DIR__ . '/src/Wootook/Core/Config/Node.php',
'Wootook\\Core\\Controller\\ErrorController' => __DIR__ . '/src/Wootook/Core/Controller/ErrorController.php',
'Wootook\\Core\\Controller\\IndexController' => __DIR__ . '/src/Wootook/Core/Controller/IndexController.php',
'Wootook\\Core\\Database\\Adapter\\Adapter' => __DIR__ . '/src/Wootook/Core/Database/Adapter/Adapter.php',
'Wootook\\Core\\Database\\Adapter\\Mysql' => __DIR__ . '/src/Wootook/Core/Database/Adapter/Mysql.php',
'Wootook\\Core\\Database\\Adapter\\Pdo' => __DIR__ . '/src/Wootook/Core/Database/Adapter/Pdo.php',
'Wootook\\Core\\Database\\Adapter\\Pdo\\Mysql' => __DIR__ . '/src/Wootook/Core/Database/Adapter/Pdo/Mysql.php',
'Wootook\\Core\\Database\\Adapter\\Pdo\\Sqlite' => __DIR__ . '/src/Wootook/Core/Database/Adapter/Pdo/Sqlite.php',
'Wootook\\Core\\Database\\ConnectionManager' => __DIR__ . '/src/Wootook/Core/Database/ConnectionManager.php',
'Wootook\\Core\\Database\\Orm\\DataMapper\\Config' => __DIR__ . '/src/Wootook/Core/Database/Orm/DataMapper/Config.php',
'Wootook\\Core\\Database\\Orm\\DataMapper\\DateTime' => __DIR__ . '/src/Wootook/Core/Database/Orm/DataMapper/DateTime.php',
'Wootook\\Core\\Database\\Orm\\DataMapper\\FieldMapper' => __DIR__ . '/src/Wootook/Core/Database/Orm/DataMapper/FieldMapper.php',
'Wootook\\Core\\Database\\Orm\\DataMapper\\PhpArray' => __DIR__ . '/src/Wootook/Core/Database/Orm/DataMapper/PhpArray.php',
'Wootook\\Core\\Database\\Orm\\DataMapper\\PhpObject' => __DIR__ . '/src/Wootook/Core/Database/Orm/DataMapper/PhpObject.php',
'Wootook\\Core\\Database\\Orm\\DataMapper' => __DIR__ . '/src/Wootook/Core/Database/Orm/DataMapper.php',
'Wootook\\Core\\Database\\Resource\\DataMapper' => __DIR__ . '/src/Wootook/Core/Database/Resource/DataMapper.php',
'Wootook\\Core\\Database\\Resource\\ReadConnection' => __DIR__ . '/src/Wootook/Core/Database/Resource/ReadConnection.php',
'Wootook\\Core\\Database\\Resource\\WriteConnection' => __DIR__ . '/src/Wootook/Core/Database/Resource/WriteConnection.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Delete' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Delete.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Dml' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Dml.php',
'Wootook\\Core\\Database\\Sql\\Dml\\DmlQuery' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/DmlQuery.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Insert' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Insert.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Select' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Select.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Update' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Update.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Condition\\Condition' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Condition/Condition.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Condition\\LogicalOperator' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Condition/LogicalOperator.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Condition\\MathOperator' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Condition/MathOperator.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Column' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Column.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\ColumnAware' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/ColumnAware.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\From' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/From.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\FromAware' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/FromAware.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Into' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Into.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\IntoAware' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/IntoAware.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Limit' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Limit.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\LimitAware' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/LimitAware.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Set' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Set.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\SetAware' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/SetAware.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Where' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Where.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\WhereAware' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/WhereAware.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\Column' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Column.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\ColumnAware' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/ColumnAware.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\From' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/From.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\FromAware' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/FromAware.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\Into' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Into.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\IntoAware' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/IntoAware.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\Limit' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Limit.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\LimitAware' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/LimitAware.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\Set' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Set.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\SetAware' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/SetAware.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\Where' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Where.php',
'Wootook\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\WhereAware' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/WhereAware.php',
'Wootook\\Core\\Database\\Sql\\Placeholder\\Expression' => __DIR__ . '/src/Wootook/Core/Database/Sql/Placeholder/Expression.php',
'Wootook\\Core\\Database\\Sql\\Placeholder\\Param' => __DIR__ . '/src/Wootook/Core/Database/Sql/Placeholder/Param.php',
'Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder' => __DIR__ . '/src/Wootook/Core/Database/Sql/Placeholder/Placeholder.php',
'Wootook\\Core\\Database\\Sql\\Placeholder\\Variable' => __DIR__ . '/src/Wootook/Core/Database/Sql/Placeholder/Variable.php',
'Wootook\\Core\\Database\\Statement\\Mysql' => __DIR__ . '/src/Wootook/Core/Database/Statement/Mysql.php',
'Wootook\\Core\\Database\\Statement\\Pdo' => __DIR__ . '/src/Wootook/Core/Database/Statement/Pdo.php',
'Wootook\\Core\\Database\\Statement\\Statement' => __DIR__ . '/src/Wootook/Core/Database/Statement/Statement.php',
'Wootook\\Core\\DateTime\\DateInterval' => __DIR__ . '/src/Wootook/Core/DateTime/DateInterval.php',
'Wootook\\Core\\DateTime\\DatePeriod' => __DIR__ . '/src/Wootook/Core/DateTime/DatePeriod.php',
'Wootook\\Core\\DateTime\\DateTime' => __DIR__ . '/src/Wootook/Core/DateTime/DateTime.php',
'Wootook\\Core\\DateTime\\DateTimeZone' => __DIR__ . '/src/Wootook/Core/DateTime/DateTimeZone.php',
'Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition' => __DIR__ . '/src/Wootook/Core/DependencyInjection/Definition/ClassDefinition.php',
'Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition' => __DIR__ . '/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php',
'Wootook\\Core\\DependencyInjection\\Definition\\ArgumentDefinition' => __DIR__ . '/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php',
'Wootook\\Core\\DependencyInjection\\Factory' => __DIR__ . '/src/Wootook/Core/DependencyInjection/Factory.php',
'Wootook\\Core\\DependencyInjection\\Registry' => __DIR__ . '/src/Wootook/Core/DependencyInjection/Registry.php',
'Wootook\\Core\\Email\\Email' => __DIR__ . '/src/Wootook/Core/Email/Email.php',
'Wootook\\Core\\Email\\Part\\Part' => __DIR__ . '/src/Wootook/Core/Email/Part/Part.php',
'Wootook\\Core\\Email\\Transport\\Sendmail' => __DIR__ . '/src/Wootook/Core/Email/Transport/Sendmail.php',
'Wootook\\Core\\Email\\Transport\\Transport' => __DIR__ . '/src/Wootook/Core/Email/Transport/Transport.php',
'Wootook\\Core\\Event\\Break' => __DIR__ . '/src/Wootook/Core/Event/Break.php',
'Wootook\\Core\\Event\\Event' => __DIR__ . '/src/Wootook/Core/Event/Event.php',
'Wootook\\Core\\Event\\EventTarget' => __DIR__ . '/src/Wootook/Core/Event/EventTarget.php',
'Wootook\\Core\\Exception\\CoreException' => __DIR__ . '/src/Wootook/Core/Exception/CoreException.php',
'Wootook\\Core\\Exception\\BadMethodCallException' => __DIR__ . '/src/Wootook/Core/Exception/BadMethodCallException.php',
'Wootook\\Core\\Exception\\DataAccessException' => __DIR__ . '/src/Wootook/Core/Exception/DataAccessException.php',
'Wootook\\Core\\Exception\\Database\\AdapterError' => __DIR__ . '/src/Wootook/Core/Exception/Database/AdapterError.php',
'Wootook\\Core\\Exception\\Database\\Error' => __DIR__ . '/src/Wootook/Core/Exception/Database/Error.php',
'Wootook\\Core\\Exception\\Database\\StatementError' => __DIR__ . '/src/Wootook/Core/Exception/Database/StatementError.php',
'Wootook\\Core\\Exception\\DependencyInjection\\BadMethodCallException' => __DIR__ . '/src/Wootook/Core/Exception/DependencyInjection/BadMethodCallException.php',
'Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException' => __DIR__ . '/src/Wootook/Core/Exception/DependencyInjection/InvalidArgumentException.php',
'Wootook\\Core\\Exception\\DependencyInjection\\RuntimeException' => __DIR__ . '/src/Wootook/Core/Exception/DependencyInjection/RuntimeException.php',
'Wootook\\Core\\Exception\\Deprecated' => __DIR__ . '/src/Wootook/Core/Exception/Deprecated.php',
'Wootook\\Core\\Exception\\Exception' => __DIR__ . '/src/Wootook/Core/Exception/Exception.php',
'Wootook\\Core\\Exception\\GameError' => __DIR__ . '/src/Wootook/Core/Exception/GameError.php',
'Wootook\\Core\\Exception\\InvalidArgumentException' => __DIR__ . '/src/Wootook/Core/Exception/InvalidArgumentException.php',
'Wootook\\Core\\Exception\\LayoutException' => __DIR__ . '/src/Wootook/Core/Exception/LayoutException.php',
'Wootook\\Core\\Exception\\RuntimeException' => __DIR__ . '/src/Wootook/Core/Exception/RuntimeException.php',
'Wootook\\Core\\Exception\\WebsiteError' => __DIR__ . '/src/Wootook/Core/Exception/WebsiteError.php',
'Wootook\\Core\\Form\\Element\\BaseElement' => __DIR__ . '/src/Wootook/Core/Form/Element/BaseElement.php',
'Wootook\\Core\\Form\\Element\\Button' => __DIR__ . '/src/Wootook/Core/Form/Element/Button.php',
'Wootook\\Core\\Form\\Element\\Text' => __DIR__ . '/src/Wootook/Core/Form/Element/Text.php',
'Wootook\\Core\\Form\\ElementLoader' => __DIR__ . '/src/Wootook/Core/Form/ElementLoader.php',
'Wootook\\Core\\Form\\Form' => __DIR__ . '/src/Wootook/Core/Form/Form.php',
'Wootook\\Core\\Form\\Validator\\Alnum' => __DIR__ . '/src/Wootook/Core/Form/Validator/Alnum.php',
'Wootook\\Core\\Form\\Validator\\Alpha' => __DIR__ . '/src/Wootook/Core/Form/Validator/Alpha.php',
'Wootook\\Core\\Form\\Validator\\BaseValidator' => __DIR__ . '/src/Wootook/Core/Form/Validator/BaseValidator.php',
'Wootook\\Core\\Form\\Validator\\Email' => __DIR__ . '/src/Wootook/Core/Form/Validator/Email.php',
'Wootook\\Core\\Form\\Validator\\FormKey' => __DIR__ . '/src/Wootook/Core/Form/Validator/FormKey.php',
'Wootook\\Core\\Form\\Validator\\Hex' => __DIR__ . '/src/Wootook/Core/Form/Validator/Hex.php',
'Wootook\\Core\\Form\\Validator\\Host' => __DIR__ . '/src/Wootook/Core/Form/Validator/Host.php',
'Wootook\\Core\\Form\\Validator\\Numeric' => __DIR__ . '/src/Wootook/Core/Form/Validator/Numeric.php',
'Wootook\\Core\\Form\\Validator\\Regex' => __DIR__ . '/src/Wootook/Core/Form/Validator/Regex.php',
'Wootook\\Core\\Form\\ValidatorLoader' => __DIR__ . '/src/Wootook/Core/Form/ValidatorLoader.php',
'Wootook\\Core\\Helper\\Config\\ConfigHandler' => __DIR__ . '/src/Wootook/Core/Helper/Config/ConfigHandler.php',
'Wootook\\Core\\Helper\\Config\\Events' => __DIR__ . '/src/Wootook/Core/Helper/Config/Events.php',
'Wootook\\Core\\Helper\\Config\\Modules' => __DIR__ . '/src/Wootook/Core/Helper/Config/Modules.php',
'Wootook\\Core\\Layout\\Manager' => __DIR__ . '/src/Wootook/Core/Layout/Manager.php',
'Wootook\\Core\\Layout\\Parser' => __DIR__ . '/src/Wootook/Core/Layout/Parser.php',
'Wootook\\Core\\Model\\Config' => __DIR__ . '/src/Wootook/Core/Model/Config.php',
'Wootook\\Core\\Model\\Game' => __DIR__ . '/src/Wootook/Core/Model/Game.php',
'Wootook\\Core\\Model\\Image\\Png' => __DIR__ . '/src/Wootook/Core/Model/Image/Png.php',
'Wootook\\Core\\Model\\Session' => __DIR__ . '/src/Wootook/Core/Model/Session.php',
'Wootook\\Core\\Model\\Translator' => __DIR__ . '/src/Wootook/Core/Model/Translator.php',
'Wootook\\Core\\Model\\Website' => __DIR__ . '/src/Wootook/Core/Model/Website.php',
'Wootook\\Core\\Mvc\\Controller\\Action' => __DIR__ . '/src/Wootook/Core/Mvc/Controller/Action.php',
'Wootook\\Core\\Mvc\\Controller\\Front' => __DIR__ . '/src/Wootook/Core/Mvc/Controller/Front.php',
'Wootook\\Core\\Mvc\\Controller\\Request\\Http' => __DIR__ . '/src/Wootook/Core/Mvc/Controller/Request/Http.php',
'Wootook\\Core\\Mvc\\Controller\\Request\\Request' => __DIR__ . '/src/Wootook/Core/Mvc/Controller/Request/Request.php',
'Wootook\\Core\\Mvc\\Controller\\Response\\Http' => __DIR__ . '/src/Wootook/Core/Mvc/Controller/Response/Http.php',
'Wootook\\Core\\Mvc\\Controller\\Response\\Response' => __DIR__ . '/src/Wootook/Core/Mvc/Controller/Response/Response.php',
'Wootook\\Core\\Mvc\\Model\\Action\\Deletable' => __DIR__ . '/src/Wootook/Core/Mvc/Model/Action/Deletable.php',
'Wootook\\Core\\Mvc\\Model\\Action\\Delete' => __DIR__ . '/src/Wootook/Core/Mvc/Model/Action/Delete.php',
'Wootook\\Core\\Mvc\\Model\\Action\\Load' => __DIR__ . '/src/Wootook/Core/Mvc/Model/Action/Load.php',
'Wootook\\Core\\Mvc\\Model\\Action\\Loadable' => __DIR__ . '/src/Wootook/Core/Mvc/Model/Action/Loadable.php',
'Wootook\\Core\\Mvc\\Model\\Action\\Savable' => __DIR__ . '/src/Wootook/Core/Mvc/Model/Action/Savable.php',
'Wootook\\Core\\Mvc\\Model\\Action\\Save' => __DIR__ . '/src/Wootook/Core/Mvc/Model/Action/Save.php',
'Wootook\\Core\\Mvc\\Model\\Entity' => __DIR__ . '/src/Wootook/Core/Mvc/Model/Entity.php',
'Wootook\\Core\\Mvc\\Model\\EntityInterface' => __DIR__ . '/src/Wootook/Core/Mvc/Model/EntityInterface.php',
'Wootook\\Core\\Mvc\\Model\\SubTable' => __DIR__ . '/src/Wootook/Core/Mvc/Model/SubTable.php',
'Wootook\\Core\\Mvc\\Model\\Type\\Base' => __DIR__ . '/src/Wootook/Core/Mvc/Model/Type/Base.php',
'Wootook\\Core\\Mvc\\Model\\Type\\Full' => __DIR__ . '/src/Wootook/Core/Mvc/Model/Type/Full.php',
'Wootook\\Core\\Mvc\\Model\\Type\\Readonly' => __DIR__ . '/src/Wootook/Core/Mvc/Model/Type/Readonly.php',
'Wootook\\Core\\Mvc\\View\\View' => __DIR__ . '/src/Wootook/Core/Mvc/View/View.php',
'Wootook\\Core\\PluginLoader\\PluginLoader' => __DIR__ . '/src/Wootook/Core/PluginLoader/PluginLoader.php',
'Wootook\\Core\\Profiler\\ErrorProfiler' => __DIR__ . '/src/Wootook/Core/Profiler/ErrorProfiler.php',
'Wootook\\Core\\Resource\\Entity' => __DIR__ . '/src/Wootook/Core/Resource/Entity.php',
'Wootook\\Core\\Resource\\EntityCollection\\Action\\Load' => __DIR__ . '/src/Wootook/Core/Resource/EntityCollection/Action/Load.php',
'Wootook\\Core\\Resource\\EntityCollection\\Action\\Loadable' => __DIR__ . '/src/Wootook/Core/Resource/EntityCollection/Action/Loadable.php',
'Wootook\\Core\\Resource\\EntityCollection' => __DIR__ . '/src/Wootook/Core/Resource/EntityCollection.php',
'Wootook\\Core\\Setup\\Exception\\RuntimeException' => __DIR__ . '/src/Wootook/Core/Setup/Exception/RuntimeException.php',
'Wootook\\Core\\Setup\\Exception\\VersionStageError' => __DIR__ . '/src/Wootook/Core/Setup/Exception/VersionStageError.php',
'Wootook\\Core\\Setup\\Exception\\VersionValueError' => __DIR__ . '/src/Wootook/Core/Setup/Exception/VersionValueError.php',
'Wootook\\Core\\Setup\\Updater\\ScriptQueue' => __DIR__ . '/src/Wootook/Core/Setup/Updater/ScriptQueue.php',
'Wootook\\Core\\Setup\\Updater' => __DIR__ . '/src/Wootook/Core/Setup/Updater.php',
);

View file

@ -0,0 +1,11 @@
<?php return function ($class) {
static $map;
if (!$map) {
$map = include __DIR__ . '/autoload_classmap.php';
}
if (!isset($map[$class])) {
return false;
}
return include $map[$class];
};

View file

@ -0,0 +1 @@
<?php spl_autoload_register(include __DIR__ . '/autoload_function.php');

View file

@ -0,0 +1,52 @@
<?php
return array(
'router' => array(
'routes' => array(
'default' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'IndexController',
'action' => 'index',
),
),
),
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'IndexController',
'action' => 'index',
),
),
),
),
),
'controller' => array(
'classes' => array(
'IndexController' => 'Application\Controller\IndexController'
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'index/index' => __DIR__ . '/../view/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
'application' => __DIR__ . '/../view',
),
),
);

View file

@ -0,0 +1,33 @@
<?php return array(
'global' => array(
'modules' => array(
'WootookCore' => array(
'version' => '1.5.0'
)
),
'models' => array(
'core' => array(
'namespace' => 'Wootook\\Core\\Model',
'connection' => array(
'read' => 'core_read',
'write' => 'core_write',
'setup' => 'core_setup',
)
)
),
'blocks' => array(
'core' => array(
'namespace' => 'Wootook\\Core\\Block'
)
)
),
'frontend' => array(
'routes' => array(
'core' => array(
'controllers' => array(
'core' => 'Wootook\\Core\\Controller'
)
)
)
)
);

View file

@ -0,0 +1,208 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
$this->setSetupConnection('core_setup');
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('core_website')} (
`website_id` TINYINT UNSIGNED NOT NULL,
`code` VARCHAR(64) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`sort_order` TINYINT UNSIGNED NOT NULL,
`default_group_id` TINYINT UNSIGNED NOT NULL,
`is_default` BOOL NOT NULL,
`is_staging` BOOL NOT NULL,
`is_active` BOOL NOT NULL,
PRIMARY KEY (`website_id`),
UNIQUE (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('core_game_group')} (
`group_id` TINYINT UNSIGNED NOT NULL,
`website_id` TINYINT UNSIGNED NOT NULL,
`code` VARCHAR(64) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`sort_order` TINYINT UNSIGNED NOT NULL,
`is_default` BOOL NOT NULL,
PRIMARY KEY (`group_id`),
INDEX (`website_id`),
UNIQUE (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('core_game')} (
`game_id` SMALLINT UNSIGNED NOT NULL,
`group_id` TINYINT UNSIGNED NOT NULL,
`website_id` TINYINT UNSIGNED NOT NULL,
`code` VARCHAR(64) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`sort_order` TINYINT UNSIGNED NOT NULL,
`is_default` BOOL NOT NULL,
`is_staging` BOOL NOT NULL,
`is_active` BOOL NOT NULL,
PRIMARY KEY (`group_id`),
INDEX (`website_id`),
UNIQUE (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
INSERT INTO {$this->getTableName('core_website')} (`website_id`, `code`, `name`, `sort_order`, `default_group_id`, `is_default`, `is_staging`, `is_active`)
VALUES
(0, "admin", "Administration", 0, 0, 0, 0, 1),
(1, "default", "Default Website", 1, 1, 1, 0, 1);
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
INSERT INTO {$this->getTableName('core_game_group')} (`group_id`, `website_id`, `code`, `name`, `sort_order`, `is_default`)
VALUES
(0, 0, "admin", "Administration", 0, 0),
(1, 1, "default", "Default Group", 1, 1);
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
INSERT INTO {$this->getTableName('core_game')} (`game_id`, `group_id`, `website_id`, `code`, `name`, `sort_order`, `is_default`, `is_staging`, `is_active`)
VALUES
(0, 0, 0, "admin", "Administration", 0, 0, 0, 1),
(1, 1, 1, "default", "Default Game", 1, 1, 0, 1);
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('core_config')} (
`website_id` TINYINT UNSIGNED NOT NULL,
`game_id` TINYINT UNSIGNED NOT NULL,
`config_path` VARCHAR(64) NOT NULL,
`config_value` VARCHAR(255) NOT NULL,
PRIMARY KEY (`website_id`, `game_id`, `config_path`),
INDEX (`website_id`),
INDEX (`game_id`),
INDEX (`config_path`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
INSERT IGNORE INTO {$this->getTableName('core_config')} (`website_id`, `game_id`, `config_path`, `config_value`) VALUES
(1, 1, 'resources/base-income/metal', '20'),
(1, 1, 'resources/base-income/cristal', '10'),
(1, 1, 'resources/base-income/deuterium', '0'),
(1, 1, 'resources/base-income/energy', '0'),
(1, 1, 'planet/initial/fields', '163'),
(1, 1, 'resources/initial/metal', '500'),
(1, 1, 'resources/initial/cristal', '500'),
(1, 1, 'resources/initial/deuterium', '0'),
(1, 1, 'resources/initial/energy', '0'),
(1, 1, 'game/general/name', 'Wootook'),
(1, 1, 'game/general/boards-url', 'http://wootook.org/board/'),
(1, 1, 'game/general/extra-url-title', 'Wootook!'),
(1, 1, 'game/general/extra-url', 'http://wootook.org/'),
(1, 1, 'game/general/active', '1'),
(1, 1, 'game/general/closing-message', 'Le jeu est clos pour le moment.'),
(1, 1, 'game/general/locale', 'fr_FR'),
(1, 1, 'game/resource/multiplier', '1000'),
(1, 1, 'game/speed/general', '2500'),
(1, 1, 'game/speed/fleet', '2500'),
(1, 1, 'game/debris/metal-percent', '30'),
(1, 1, 'game/debris/cristal-percent', '30'),
(1, 1, 'game/debris/deuterium-percent', '0'),
(1, 1, 'game/debris/energy-percent', '0'),
(1, 1, 'game/debris/fleet', '1'),
(1, 1, 'game/debris/defense', '0'),
(1, 1, 'game/noob-protection/active', '0'),
(1, 1, 'game/noob-protection/points-cap', '5000'),
(1, 1, 'game/noob-protection/multiplier', '5'),
-- (0, 0, 'web/cookie/name', '__wtk'),
-- (0, 0, 'web/cookie/time', '2592000'),
-- (0, 0, 'web/cookie/domain', ''),
-- (0, 0, 'web/cookie/path', ''),
(1, 1, 'web/cookie/name', '__wtk_1_1'),
-- (0, 0, 'web/session/time', '900'),
-- (0, 0, 'web/session/domain', '.wootook.org'),
-- (0, 0, 'web/session/path', '/'),
(0, 0, 'engine/options/bbcode', '1'),
(0, 0, 'engine/options/ga', '1'),
(0, 0, 'engine/options/announces', '0'),
(0, 0, 'engine/options/retailer', '0'),
(0, 0, 'engine/options/notes', '0'),
(0, 0, 'engine/options/chat', '0'),
(0, 0, 'engine/options/banner', '0'),
(0, 0, 'engine/options/vacation-min-time', '172800'),
(0, 0, 'game/news/active', '0'),
(0, 0, 'game/news/content', 'Bienvenue sur le nouveau serveur de jeu Wootook!'),
(0, 0, 'engine/ban/duration', '86400'),
(0, 0, 'engine/bot/active', '0'),
(0, 0, 'engine/bot/name', 'Woot'),
(0, 0, 'engine/bot/email', 'contact@wootook.org');
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('errors')} (
`error_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`error_sender` VARCHAR(32) NOT NULL,
`error_time` TIMESTAMP NOT NULL,
`error_type` VARCHAR(32) NOT NULL DEFAULT 'unknown',
`error_text` TEXT,
PRIMARY KEY (`error_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);

View file

@ -0,0 +1,73 @@
<?php
/**
* This file is part of Wootook
*
* @license Modified BSD
* @see https://github.com/gplanchat/one.platform
*
* Copyright (c) 2009-2010, Grégory PLANCHAT <g.planchat at gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of Grégory PLANCHAT nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing One.Platform.
*
*/
$this->setSetupConnection('core_setup');
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('core_website')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('core_game_group')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('core_game')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('core_config')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('errors')};
SQL_EOF;
$this->query($sql);

View file

@ -0,0 +1,498 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\App;
use Wootook\Core,
Wootook\Core\Config\Adapter as ConfigAdapter,
Wootook\Core\Database,
Wootook\Core\Exception as CoreException,
Wootook\Core\Mvc\Controller as MvcController,
Wootook\Core\Profiler;
/**
*
*/
class App
{
const ENV_PRODUCTION = 'prod';
const ENV_INTEGRATION = 'inte';
const ENV_TESTING = 'test';
const ENV_DEVELOPMENT = 'devel';
const DOMAIN_INSTALL = 'install';
const DOMAIN_BACKEND = 'backend';
const DOMAIN_FRONTEND = 'frontend';
const DOMAIN_WEBSOCKET = 'websocket';
const SCOPE_GLOBAL = 'global';
const SCOPE_WEBSITE = 'website';
const SCOPE_GAME = 'game';
/**
*
* Enter description here ...
* @var ConfigAdapter\Adapter
*/
private $_rootConfig = null;
private $_globalConfig = null;
protected $_websiteList = array();
protected $_gameList = array();
protected $_defaultWebsiteId = 1;
protected $_defaultGameId = 1;
protected $_blockSingletons = array();
protected $_modelSingletons = array();
protected $_resourceSingletons = array();
protected $_helperSingletons = array();
protected $_frontController = null;
protected $_connectionManager = null;
public function __construct($configPath, $domain = self::DOMAIN_FRONTEND, $environment = self::ENV_PRODUCTION)
{
try {
$this->_rootConfig = new ConfigAdapter\PhpArray();
$this->_rootConfig->load($configPath . DIRECTORY_SEPARATOR . 'system.php');
$localConfig = new ConfigAdapter\PhpArray();
$localConfig->load($configPath . DIRECTORY_SEPARATOR . 'local.php');
$this->_rootConfig->merge($localConfig);
$directoryIterator = new \FilesystemIterator($configPath . DIRECTORY_SEPARATOR . 'modules');
foreach ($directoryIterator as $file) {
$modulesConfig = new ConfigAdapter\PhpArray();
$modulesConfig->load($file->getPathname());
$this->_rootConfig->merge($modulesConfig);
}
foreach ($this->_rootConfig->getConfig('global/modules') as $moduleName => $moduleConfig) {
if (!$moduleConfig->getConfig('active')) {
continue;
}
$path = $moduleName . '/config/module.php';
try {
$additionalModuleConfig = new ConfigAdapter\PhpArray();
$additionalModuleConfig->load($path);
$this->_rootConfig->merge($additionalModuleConfig);
} catch (CoreException\DataAccessException $e) {
Profiler\ErrorProfiler::getSingleton()->addException($e);
continue;
}
}
if (empty($domain) || !$this->_rootConfig[$domain]) {
$domain = self::DOMAIN_FRONTEND;
}
if (empty($environment) || !$this->_rootConfig[$environment]) {
$environment = self::ENV_PRODUCTION;
}
$this->_globalConfig = clone $this->_rootConfig['default'];
$this->appendEnvironmentConfig($this->_globalConfig, 'global')
->appendEnvironmentConfig($this->_globalConfig, $environment)
->appendEnvironmentConfig($this->_globalConfig, $domain);
} catch (CoreException\DataAccessException $e) {
Profiler\ErrorProfiler::getSingleton()->addException($e);
}
}
/**
* @return MvcController\Front
*/
public function getFrontController()
{
if ($this->_frontController === null) {
$this->_frontController = new MvcController\Front($this);
}
return $this->_frontController;
}
/**
* @return MvcController\Front
*/
public function getConnectionManager()
{
if ($this->_connectionManager === null) {
$this->_connectionManager = new Database\ConnectionManager($this);
}
return $this->_connectionManager;
}
/**
* @param MvcController\Front $frontController
* @return Core\App
*/
public function setFrontController(MvcController\Front $frontController)
{
$this->_frontController = $frontController;
return $this;
}
public function appendEnvironmentConfig(Core\Config\Node $config, $environment)
{
if (isset($this->_rootConfig[$environment])) {
$config->merge($this->_rootConfig[$environment]);
}
return $this;
}
public function appendDatabaseConfig(Core\Config\Node $config, $scope = self::SCOPE_GLOBAL, $scopeId = 0)
{
if (empty($scope)) {
$scope = self::SCOPE_GLOBAL;
}
if ($scope !== self::SCOPE_GLOBAL && $scopeId <= 0) {
$scope = self::SCOPE_GLOBAL;
Profiler\ErrorProfiler::getSingleton()
->addException(new CoreException\RuntimeException('Please specify a valid scope ID.'));
}
if ($scope === self::SCOPE_GLOBAL && $scopeId != 0) {
$scopeId = 0;
}
$readAdapter = $this->getConnectionManager()
->getConnection('core_read');
$select = $readAdapter->select()
->column(array('path' => 'config_path', 'value' => 'config_value'))
->from(array('config' => $readAdapter->getTable('core_config')))
;
switch ($scope) {
case self::SCOPE_GLOBAL:
$select->where('game_id', 0)->where('website_id', 0);
break;
case self::SCOPE_WEBSITE:
$select->where('website_id', $scopeId);
break;
case self::SCOPE_GAME:
$select->where('game_id', $scopeId);
break;
}
/** @var Core\Database\Statement\Statement $statement */
$statement = $select->prepare();
$statement->execute();
foreach ($statement as $row) {
$config->setConfig($row['path'], $row['value']);
}
return $this;
}
public function setDefaultWebsiteId($websiteIdentifier)
{
$this->_defaultWebsiteId = $websiteIdentifier;
return $this;
}
public function getDefaultWebsiteId()
{
return $this->_defaultWebsiteId;
}
/**
* @return \Wootook\Core\Model\Website
*/
public function getDefaultWebsite()
{
return $this->getWebsite($this->_defaultWebsiteId);
}
public function setDefaultGameId($gameIdentifier)
{
$this->_defaultGameId = $gameIdentifier;
return $this;
}
public function getDefaultGameId()
{
return $this->_defaultGameId;
}
public function getDefaultGame()
{
return $this->getGame($this->_defaultGameId);
}
/**
* @param string|int $websiteIdentifier
* @return \Wootook\Core\Model\Website
*/
public function getWebsite($websiteIdentifier)
{
if (!isset($this->_websiteList[$websiteIdentifier])) {
/** @var Model\Website $website */
//$website = $this->getModel('core', 'website', array($this));
$website = new Model\Website($this);
if (is_numeric($websiteIdentifier)) {
$website->load($websiteIdentifier);
} else if ($websiteIdentifier !== null) {
$website->load($websiteIdentifier, 'code');
} else {
throw new CoreException\RuntimeException('Website identifier should be specified.');
}
$this->_websiteList[$website->getId()] = $website;
$this->_websiteList[$website->getCode()] = $website;
}
return $this->_websiteList[$websiteIdentifier];
}
/**
* @param string|int $gameIdentifier
* @return \Wootook\Core\Model\Game
*/
public function getGame($gameIdentifier)
{
if (!isset($this->_gameList[$gameIdentifier])) {
/** @var Model\Game $game */
//$game = $this->getModel('core', 'game', array($this));
$game = new Model\Game($this);
if (is_numeric($gameIdentifier)) {
$game->load($gameIdentifier);
} else if ($gameIdentifier !== null) {
$game->load($gameIdentifier, 'code');
} else {
throw new CoreException\RuntimeException('Game identifier should be specified.');
}
$this->_gameList[$game->getId()] = $game;
$this->_gameList[$game->getCode()] = $game;
}
return $this->_gameList[$gameIdentifier];
}
public function getGlobalConfig($path = null)
{
if ($this->_globalConfig === null) {
return null;
}
if ($path !== null) {
return $this->_globalConfig->getConfig($path);
}
return $this->_globalConfig;
}
protected function _resolveClassType(&$namespaces, $module, $class)
{
$classSuffix = str_replace(' ', '', ucwords(str_replace('-', ' ', $class)));
$classSuffix = str_replace(' ', '_', ucwords(str_replace('.', ' ', $classSuffix)));
if (isset($namespaces[$module])) {
foreach ($namespaces[$module] as $namespace => $path) {
$className = $namespace . $classSuffix;
$fileName = $path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $classSuffix) . '.php';
Profiler\ErrorProfiler::getSingleton()->sleep();
if (!($fp = @fopen($fileName, 'r', true))) {
Profiler\ErrorProfiler::getSingleton()->wakeup();
continue;
}
Profiler\ErrorProfiler::getSingleton()->wakeup();
fclose($fp);
if (!class_exists($className, true)) {
continue;
}
return $className;
}
}
Profiler\ErrorProfiler::getSingleton()
->addException(new CoreException\RuntimeException(sprintf('Class type "%1$s/%2$s" could not be resolved.', $module, $class)));
return null;
}
protected function _newInstance($className, Array $constructorParams)
{
if ($className === null) {
return null;
}
if (empty($constructorParams)) {
return new $className;
} else {
$reflection = new ReflectionClass($className);
return $reflection->newInstanceArgs($constructorParams);
}
}
protected function _parseIdentifier($identifier, &$module, &$class)
{
$offset = strpos($identifier, '/');
if ($offset === false) {
$module = $identifier;
$class = null;
return;
}
$module = substr($identifier, 0, $offset);
$class = substr($identifier, $offset + 1);
}
public function block($identifier, Array $constructorParams = array())
{
$this->_parseIdentifier($identifier, $module, $class);
if ($class === null) {
$class = 'view';
}
return $this->getBlock($module, $class, $constructorParams);
}
public function model($identifier, Array $constructorParams = array())
{
$this->_parseIdentifier($identifier, $module, $class);
if ($class === null) {
$class = 'entity';
}
return $this->getModel($module, $class, $constructorParams);
}
public function resource($identifier, Array $constructorParams = array())
{
$this->_parseIdentifier($identifier, $module, $class);
if ($class === null) {
$class = 'entity';
}
return $this->getResource($module, $class, $constructorParams);
}
public function helper($identifier, Array $constructorParams = array())
{
$this->_parseIdentifier($identifier, $module, $class);
if ($class === null) {
$class = 'data';
}
return $this->getResource($module, $class, $constructorParams);
}
public function getBlock($module, $class, Array $constructorParams = array())
{
$className = $this->_resolveClassType($this->_globalConfig->getConfig('blocks'), $module, $class);
return $this->_newInstance($className, $constructorParams);
}
public function getModel($module, $class, Array $constructorParams = array())
{
$className = $this->_resolveClassType($this->_globalConfig->getConfig('models'), $module, $class);
return $this->_newInstance($className, $constructorParams);
}
public function getResource($module, $class, Array $constructorParams = array())
{
$className = $this->_resolveClassType($this->_globalConfig->getConfig('resources'), $module, $class);
return $this->_newInstance($className, $constructorParams);
}
public function getHelper($module, $class, Array $constructorParams = array())
{
$className = $this->_resolveClassType($this->_globalConfig->getConfig('helpers'), $module, $class);
return $this->_newInstance($className, $constructorParams);
}
public function getBlockSingleton($module, $class, Array $constructorParams = array())
{
if (!isset($this->_blockSingletons[$module])) {
$this->_blockSingletons[$module] = array();
}
if (!isset($this->_blockSingletons[$module][$class])) {
$this->_blockSingletons[$module][$class] = $this->getBlock($module, $class, $constructorParams);
}
return $this->_blockSingletons[$module][$class];
}
public function getModelSingleton($module, $class, Array $constructorParams = array())
{
if (!isset($this->_modelSingletons[$module])) {
$this->_modelSingletons[$module] = array();
}
if (!isset($this->_modelSingletons[$module][$class])) {
$this->_modelSingletons[$module][$class] = $this->getModel($module, $class, $constructorParams);
}
return $this->_modelSingletons[$module][$class];
}
public function getResourceSingleton($module, $class, Array $constructorParams = array())
{
if (!isset($this->_resourceSingletons[$module])) {
$this->_resourceSingletons[$module] = array();
}
if (!isset($this->_resourceSingletons[$module][$class])) {
$this->_resourceSingletons[$module][$class] = $this->getResource($module, $class, $constructorParams);
}
return $this->_resourceSingletons[$module][$class];
}
public function getHelperSingleton($module, $class, Array $constructorParams = array())
{
if (!isset($this->_helperSingletons[$module])) {
$this->_helperSingletons[$module] = array();
}
if (!isset($this->_helperSingletons[$module][$class])) {
$this->_helperSingletons[$module][$class] = $this->getHelper($module, $class, $constructorParams);
}
return $this->_helperSingletons[$module][$class];
}
}

View file

@ -0,0 +1,68 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Base;
/**
*
* Enter description here ...
* @author Greg
*
*/
class BaseObject
implements \ArrayAccess
{
use Service\App, DataContainer;
protected function _construct(Array $data = array())
{
$this->addData($data);
}
public function offsetExists($offset)
{
return $this->hasData($offset);
}
public function offsetGet($offset)
{
return $this->getData($offset);
}
public function offsetSet($offset, $data)
{
return $this->setData($offset, $data);
}
public function offsetUnset($offset)
{
return $this->unsetData($offset);
}
}

View file

@ -0,0 +1,86 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Base;
trait DataContainer
{
protected $_data = array();
public function getData($key)
{
if ($this->hasData($key)) {
return $this->_data[$key];
}
return null;
}
public function getAllDatas()
{
return $this->_data;
}
public function hasData($key)
{
return (bool) isset($this->_data[$key]);
}
public function setData($key, $value)
{
$this->_data[$key] = $value;
return $this;
}
public function addData(Array $data)
{
foreach ($data as $key => $value) {
$this->setData($key, $value);
}
return $this;
}
public function unsetData($key)
{
if ($this->hasData($key)) {
unset($this->_data[$key]);
}
return $this;
}
public function clearData()
{
$this->_data = array();
return $this;
}
}

View file

@ -0,0 +1,67 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Base\Service;
use Wootook\Core;
/**
*
*
*/
trait App
{
/**
* @var \Wootook\Core\App
*/
protected $_app = null;
/**
* @param \Wootook\Core\App $app
* @param null $...
*/
public function __construct(Core\App\App $app, $_ = null)
{
$this->_app = $app;
$params = func_get_args();
array_shift($params);
call_user_func_array(array($this, '_construct'), $params);
}
/**
* @return \Wootook\Core\App
*/
public function app()
{
return $this->_app;
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Base;
/**
*
* Enter description here ...
* @author Greg
*
*/
interface Singleton
{
public static function getSingleton();
}

View file

@ -0,0 +1,46 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block;
use Wootook\Core\Mvc\View;
class Concat
extends View\View
{
public function render()
{
$content = '';
foreach ($this->_partials as $partial) {
$content .= $partial->render();
}
return $content;
}
}

View file

@ -0,0 +1,40 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block;
class Deprecated
extends Template
{
public function getScriptPath()
{
return $this->getLayout()->getScriptPath();
}
}

View file

@ -0,0 +1,41 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block;
class Form
extends Template
{
public function getFormKey()
{
$session = \Wootook::getSession('security');
return $session->getFormKey(true);
}
}

View file

@ -0,0 +1,317 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block;
class Head
extends Template
{
const TYPE_GLOBAL_CSS = 'global_css';
const TYPE_GLOBAL_JS = 'global_js';
const TYPE_SKIN_CSS = 'skin_css';
const TYPE_SKIN_JS = 'skin_js';
const TYPE_INLINE_CSS = 'inline_css';
const TYPE_INLINE_JS = 'inline_js';
const TITLE_CONCAT_BEFORE = 'BEFORE';
const TITLE_CONCAT_AFTER = 'AFTER';
const TITLE_OVERWRITE = 'OVERWRITE';
protected $_items = array();
protected $_title = null;
protected $_titleDefaultConcat = self::TITLE_CONCAT_AFTER;
protected $_titleSeparator = ' ¤ ';
protected $_titleConcatTypes = array(
self::TITLE_CONCAT_AFTER,
self::TITLE_CONCAT_BEFORE,
self::TITLE_OVERWRITE
);
public function setTitleSeparator($separator)
{
$this->_titleSeparator = $separator;
return $this;
}
public function getTitleSeparator()
{
return $this->_titleSeparator;
}
public function setTitleDefaultConcat($defaultConcat)
{
if (in_array($concatType, $this->_titleConcatTypes)) {
$this->_titleDefaultConcat = $defaultConcat;
}
return $this;
}
public function getTitleDefaultConcat()
{
return $this->_titleDefaultConcat;
}
public function setTitle($title, $concatType = self::TITLE_CONCAT_AFTER)
{
if (!in_array($concatType, $this->_titleConcatTypes)) {
$concatType = $this->getTitleDefaultConcat();
}
if ($concatType == self::TITLE_OVERWRITE || $this->_title === null) {
$this->_title = $title;
} else if ($concatType == self::TITLE_CONCAT_BEFORE) {
$this->_title = $title . $this->getTitleSeparator() . $this->_title;
} else if ($concatType == self::TITLE_CONCAT_AFTER) {
$this->_title .= $this->getTitleSeparator() . $title;
}
return $this;
}
public function getTitle()
{
return $this->_title;
}
public function addItem($type, Array $options = array())
{
if (!isset($this->_items[$type])) {
$this->_items[$type] = array();
}
$this->_items[$type][] = $options;
return $this;
}
public function addJs($script, $type = 'text/javascript', Array $options = array(), $theme = null, $package = null)
{
$options['type'] = $type;
$options['path'] = $script;
$options['theme'] = $theme;
$options['package'] = $package;
$this->addItem(self::TYPE_GLOBAL_JS, $options);
return $this;
}
public function addCss($stylesheet, $type = 'text/css', $condition = null, Array $options = array(), $theme = null, $package = null)
{
$options['type'] = $type;
$options['path'] = $stylesheet;
$options['condition'] = $condition;
$options['theme'] = $theme;
$options['package'] = $package;
$this->addItem(self::TYPE_GLOBAL_CSS, $options);
return $this;
}
public function addSkinJs($script, $type = 'text/javascript', Array $options = array(), $theme = null, $package = null)
{
$options['type'] = $type;
$options['path'] = $script;
$options['theme'] = $theme;
$options['package'] = $package;
$this->addItem(self::TYPE_SKIN_JS, $options);
return $this;
}
public function addSkinCss($stylesheet, $type = 'text/css', $condition = null, Array $options = array(), $theme = null, $package = null)
{
$options['type'] = $type;
$options['path'] = $stylesheet;
$options['condition'] = $condition;
$options['theme'] = $theme;
$options['package'] = $package;
$this->addItem(self::TYPE_SKIN_CSS, $options);
return $this;
}
public function addInlineJs($content, $type = 'text/javascript', Array $options = array())
{
$options['type'] = $type;
$options['content'] = $content;
$this->addItem(self::TYPE_INLINE_JS, $options);
return $this;
}
public function addInlineCss($content, $type = 'text/css', Array $options = array())
{
$options['type'] = $type;
$options['content'] = $content;
$this->addItem(self::TYPE_INLINE_CSS, $options);
return $this;
}
public function getCss()
{
if (isset($this->_items[self::TYPE_GLOBAL_CSS])) {
return $this->_items[self::TYPE_GLOBAL_CSS];
}
return array();
}
public function getSkinCss()
{
if (isset($this->_items[self::TYPE_SKIN_CSS])) {
return $this->_items[self::TYPE_SKIN_CSS];
}
return array();
}
public function getInlineCss()
{
if (isset($this->_items[self::TYPE_INLINE_CSS])) {
return $this->_items[self::TYPE_INLINE_CSS];
}
return array();
}
public function getJs()
{
if (isset($this->_items[self::TYPE_GLOBAL_JS])) {
return $this->_items[self::TYPE_GLOBAL_JS];
}
return array();
}
public function getSkinJs()
{
if (isset($this->_items[self::TYPE_SKIN_JS])) {
return $this->_items[self::TYPE_SKIN_JS];
}
return array();
}
public function getInlineJs()
{
if (isset($this->_items[self::TYPE_INLINE_JS])) {
return $this->_items[self::TYPE_INLINE_JS];
}
return array();
}
public function renderCss()
{
$render = '';
foreach ($this->getCss() as $css) {
if (!isset($css['media'])) {
$css['media'] = 'all';
}
$url = $this->getStaticUrl($css['path'], array());
$render .=<<<HTML_EOF
<link rel="stylesheet" type="{$css['type']}" src="{$url}" media="{$css['media']}" />
HTML_EOF;
}
}
public function renderSkinCss()
{
$render = '';
foreach ($this->getSkinCss() as $css) {
if (!isset($css['media'])) {
$css['media'] = 'all';
}
$url = $this->getSkinUrl($css['path'], array(), $css['theme'], $css['package']);
$render .=<<<HTML_EOF
<link rel="stylesheet" type="{$css['type']}" src="{$url}" media="{$css['media']}" />
HTML_EOF;
}
}
public function renderInlineCss()
{
foreach ($this->getInlineCss() as $css) {
if (!isset($css['media'])) {
$css['media'] = 'all';
}
$render .=<<<HTML_EOF
<style type="{$css['type']}">/*<![CDATA[*/{$css['content']}/*]]>*/</style>
HTML_EOF;
}
return $render;
}
public function renderJs()
{
$render = '';
foreach ($this->getJs() as $js) {
if (!isset($js['type'])) {
$js['type'] = 'text/javascript';
}
$url = $this->getStaticUrl($js['path']);
$render .=<<<HTML_EOF
<script type="{$js['type']}" src="{$url}"></script>
HTML_EOF;
}
return $render;
}
public function renderSkinJs()
{
$render = '';
foreach ($this->getJs() as $js) {
if (!isset($js['type'])) {
$js['type'] = 'text/javascript';
}
$url = $this->getSkinUrl($js['path'], array(), $js['theme'], $js['package']);
$render .=<<<HTML_EOF
<script type="{$js['type']}" src="{$url}"></script>
HTML_EOF;
}
return $render;
}
public function renderInlineJs()
{
foreach ($this->getInlineJs() as $js) {
$render .=<<<HTML_EOF
<script type="{$js['type']}">/*<![CDATA[*/{$js['content']}/*]]>*/</script>
HTML_EOF;
}
return $render;
}
}

View file

@ -0,0 +1,45 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block;
class Home
extends Template
{
public function getTitle()
{
return \Wootook::app()->getDefaultGame()->getConfig('game/home/title');
}
public function getFormattedWelcomeText()
{
return \Wootook::app()->getDefaultGame()->getConfig('game/home/formatted-welcome-text');
}
}

View file

@ -0,0 +1,233 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block\Html\Navigation;
use Wootook\Core\Block;
class Link
extends Block\Template
{
protected $_label = '';
protected $_title = '';
protected $_uri = null;
protected $_url = null;
protected $_params = array();
protected $_classes = array('link');
protected $_attributes = array();
public function getTemplate()
{
if ($this->_template !== null) {
return $this->_template;
}
return 'page/html/navigation/link.phtml';
}
public function setLabel($label)
{
$this->_label = $label;
return $this;
}
public function getLabel()
{
return $this->_label;
}
public function setTitle($title)
{
$this->_title = $title;
return $this;
}
public function getTitle()
{
return $this->_title;
}
public function setStaticUrl($uri, $params = array())
{
if ($uri === null) {
return $this;
}
$this->_uri = $uri;
$this->_params = $params;
$this->_url = $this->getStaticUrl($uri, $params);
return $this;
}
public function setUrl($uri, $params = array())
{
if ($uri === null) {
return $this;
}
$this->_uri = $uri;
$this->_params = $params;
$this->_url = $this->getUrl($uri, $params);
return $this;
}
public function setExternalUrl($url)
{
$this->_url = $url;
$this->_uri = null;
$this->_params = array();
return $this;
}
public function getLinkUrl($moreParams = array())
{
if (empty($moreParams) || $this->_uri === null) {
return $this->_url;
}
$params = array_merge($this->_params, $moreParams);
return $this->getStaticUrl($this->_uri, $params);
}
public function setAttribute($attributeName, $attributeValue)
{
$this->_attributes[$attributeName] = $attributeValue;
return $this;
}
public function getAttribute($attributeName)
{
if ($this->hasAttribute($attributeName)) {
return $this->_attributes[$attributeName];
}
return null;
}
public function hasAttribute($attributeName)
{
if (isset($this->_attributes[$attributeName])) {
return true;
}
return false;
}
public function unsetAttribute($attributeName)
{
if ($this->hasAttribute($attributeName)) {
unset($this->_attributes[$attributeName]);
}
return $this;
}
public function getAttributes()
{
return $this->_attributes;
}
public function addClass($class)
{
$this->_classes[] = $class;
return $this;
}
public function clearClasses()
{
$this->_classes = array();
return $this;
}
public function renderClasses(Array $moreClasses = array())
{
$classes = array_merge($this->_classes, $moreClasses);
return implode(' ', $classes);
}
public function __construct(Array $data = array())
{
if (isset($data['label'])) {
$this->setLabel($data['label']);
unset($data['label']);
}
if (isset($data['title'])) {
$this->setTitle($data['title']);
unset($data['title']);
}
if (isset($data['url'])) {
if (is_array($data['url']) && isset($data['url']['uri'])) {
if (isset($data['url']['static']) && $data['url']['static']) {
if (isset($data['url']['params'])) {
$this->setStaticUrl($data['url']['uri'], $data['url']['params']);
} else {
$this->setStaticUrl($data['url']['uri']);
}
} else {
if (isset($data['url']['params'])) {
$this->setUrl($data['url']['uri'], $data['url']['params']);
} else {
$this->setUrl($data['url']['uri']);
}
}
} else {
$this->setExternalUrl($data['url']);
}
unset($data['url']);
}
if (isset($data['classes'])) {
$classes = (array) $data['classes'];
unset($data['classes']);
foreach ($classes as $class) {
$this->addClass(trim($class));
}
}
if (isset($data['attributes'])) {
$attributes = (array) $data['attributes'];
unset($data['attributes']);
foreach ($attributes as $attributeName => $attributeValue) {
$this->setAttribute($attributeName, $attributeValue);
}
}
parent::__construct($data);
return $this;
}
}

View file

@ -0,0 +1,160 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block\Html\Navigation;
use Wootook\Core\Block,
Wootook\Core\Exception as CoreException;
class Menu
extends Block\Template
{
public function addLink($name, $label, $title, $uri, Array $params = array(), Array $classes = array(), $template = null, Array $attributes = array())
{
$explodedPath = explode('/', $name);
$baseName = array_pop($explodedPath);
$parent = $this->_getNode($explodedPath);
$child = $this->getLayout()
->createBlock('core/html.navigation.link', $this->getNameInLayout() . '.' . $baseName, array(
'url' => array(
'uri' => $uri,
'params' => $params
),
'label' => $label,
'title' => $title,
'classes' => $classes,
'attributes' => $attributes
));
$parent->setPartial($baseName, $child);
if ($template !== null) {
$child->setTemplate($template);
}
return $this;
}
public function addStaticLink($name, $label, $title, $uri, Array $params = array(), Array $classes = array(), $template = null, Array $attributes = array())
{
$explodedPath = explode('/', $name);
$baseName = array_pop($explodedPath);
$parent = $this->_getNode($explodedPath);
$child = $this->getLayout()
->createBlock('core/html.navigation.link', $this->getNameInLayout() . '.' . $baseName, array(
'url' => array(
'uri' => $uri,
'params' => $params,
'static' => true
),
'label' => $label,
'title' => $title,
'classes' => $classes,
'attributes' => $attributes
));
$parent->setPartial($baseName, $child);
if ($template !== null) {
$child->setTemplate($template);
}
return $this;
}
public function addExternalLink($name, $label, $title, $url, Array $classes = array(), $template = null, Array $attributes = array())
{
$explodedPath = explode('/', $name);
$baseName = array_pop($explodedPath);
$parent = $this->_getNode($explodedPath);
$child = $this->getLayout()
->createBlock('core/html.navigation.link', $this->getNameInLayout() . '.' . $baseName, array(
'url' => $url,
'label' => $label,
'title' => $title,
'classes' => $classes,
'attributes' => $attributes
));
$parent->setPartial($baseName, $child);
if ($template !== null) {
$child->setTemplate($template);
}
return $this;
}
public function addPopupLink($name, $label, $title, $uri, Array $params = array(), Array $classes = array(), $template = null, Array $attributes = array())
{
$uri = $this->getStaticUrl($uri, $params);
$attributes['onclick'] = "f('{$params}', '{$label}');return false;";
return $this->addLink($name, $label, $title, null, array(), $classes, $template, $attributes);
}
public function setNodeTitle($path, $title)
{
return $this->getNode($path)->setTitle($title);
}
public function setNodeTemplate($path, $template)
{
return $this->getNode($path)->setTemplate($template);
}
public function getNode($path)
{
return $this->_getNode(explode('/', $path));
}
protected function _getNode($explodedPath)
{
$name = array_shift($explodedPath);
if ($this->hasPartial($name)) {
$child = $this->getPartial($name);
} else {
$child = $this->getLayout()
->createBlock('core/html.navigation.node', $this->getNameInLayout() . '.' . $name);
$this->setPartial($name, $child);
}
if ($child instanceof Link) {
throw new CoreException\RuntimeException('Node is a link. Could not append a child node to a link node.');
}
if (count($explodedPath) == 0) {
return $child;
}
return $child->_getNode($explodedPath);
}
}

View file

@ -0,0 +1,57 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block\Html\Navigation;
class Node
extends Menu
{
protected $_title = '';
public function setTitle($title)
{
$this->_title = $title;
return $this;
}
public function getTitle()
{
return $this->_title;
}
public function getTemplate()
{
if ($this->_template !== null) {
return $this->_template;
}
return 'page/html/navigation/node.phtml';
}
}

View file

@ -0,0 +1,51 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block\Html;
use Wootook\Core\Block;
class Page
extends Block\Template
{
protected $_bodyClasses = array();
public function getBodyClasses()
{
return implode(' ', $this->_bodyClasses);
}
public function addBodyClass($class)
{
$this->_bodyClasses[] = $class;
return $this;
}
}

View file

@ -0,0 +1,77 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block;
class Messages
extends Template
{
protected $_storages = array();
public function prepareMessages($namespace)
{
$this->_storages[] = $namespace;
}
public function renderGroupedHtml()
{
$messages = array();
foreach ($this->_storages as $namespace) {
$session = \Wootook::getSession($namespace);
$messageList = $session->getMessages();
if (!is_array($messageList)) {
continue;
}
foreach ($messageList as $messageLevel => $messageList) {
if (!isset($messages[$messageLevel])) {
$messages[$messageLevel] = $messageList;
} else {
$messages[$messageLevel] += $messageList;
}
}
}
rsort($messages, SORT_NUMERIC);
$output = '<div class="messages">';
foreach ($messages as $messageLevel => $messageList) {
$output .= "<ul class=\"{$messageLevel}\">";
foreach ($messageList as $message) {
$output .= "<li>{$message}</li>";
}
$output .= '</ul>';
}
$output .= '</div>';
return $output;
}
}

View file

@ -0,0 +1,81 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block;
use Wootook\Core\Profiler,
Wootook\Core\Mvc\View,
Wootook\Core\Model,
Wootook\Core\Exception as CoreException;
class Template
extends View\View
{
protected function _getTemplatePath($file)
{
if ($this->getScriptPath() == '') {
Profiler\ErrorProfiler::getSingleton()
->addException(new CoreException\RuntimeException("No script path defined in block {$this->getNameInLayout()}."));
return null;
}
$pattern = "{$this->getScriptPath()}/%s/%s/scripts/{$file}";
if (($layout = $this->getLayout()) !== null) {
$package = $this->getLayout()->getPackage();
$theme = $this->getLayout()->getTheme();
if ($package !== Model\Layout::DEFAULT_PACKAGE) {
if ($theme !== Model\Layout::DEFAULT_THEME) {
$path = sprintf($pattern, $package, $theme);
if (\Wootook::fileExists($path)) {
return $path;
}
}
$path = sprintf($pattern, $package, Model\Layout::DEFAULT_THEME);
if (\Wootook::fileExists($path)) {
return $path;
}
}
} else {
Profiler\ErrorProfiler::getSingleton()
->addException(new CoreException\RuntimeException("No layout defined."));
}
$path = sprintf($pattern, Model\Layout::DEFAULT_PACKAGE, Model\Layout::DEFAULT_THEME);
if (\Wootook::fileExists($path)) {
return $path;
}
Profiler\ErrorProfiler::getSingleton()
->addException(new CoreException\RuntimeException("Template '{$file}' could not be found."));
return null;
}
}

View file

@ -0,0 +1,60 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block;
use Wootook\Core\Mvc\View;
class Text
extends View\View
{
protected $_content = null;
public function setContent($content)
{
$this->_content = $content;
return $this;
}
public function getContent()
{
return $this->_content;
}
public function render()
{
$content = $this->getContent();
if (empty($content)) {
return null;
}
return $content;
}
}

View file

@ -0,0 +1,55 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Bootstrap;
use Wootook\Core\Config,
Wootook\Core\Base\Service;
class Module
{
use Service\App;
protected function _construct(Config\Node $rootConfig)
{
return;
foreach ($rootConfig->getConfig('global/modules') as $moduleAlias => $moduleConfig) {
if ($moduleConfig->getConfig('active') !== true) {
continue;
}
if (($codePool = $moduleConfig->getConfig('code-pool')) === null) {
continue;
}
}
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Config\Adapter;
use Wootook\Core\Config;
abstract class Adapter
extends Config\Node
{
}

View file

@ -0,0 +1,68 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Config\Adapter;
use Wootook\Core\Exception as CoreException;
class PhpArray
extends Adapter
{
public function __construct($filename = null)
{
if ($filename !== null) {
$this->load($filename);
}
}
public function load($filename)
{
// Undesired dependency to the \Wootook class
if (!\Wootook::fileExists($filename)) {
throw new CoreException\DataAccessException(sprintf('Could not load config file "%s"', $filename));
}
$data = include $filename;
if (!is_array($data)) {
throw new CoreException\DataAccessException('Configuration file could not be loaded.');
}
$this->_init($data);
return $this;
}
public function save($filename)
{
file_put_contents($filename, '<' . '?p' . 'hp return ' . var_export($this->toArray(), true) . ';');
return $this;
}
}

View file

@ -0,0 +1,279 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Config;
use Wootook\Core\Exception as CoreException;
class Node
implements \ArrayAccess, \Iterator, \Countable
{
protected $_children = array();
protected $_parent = null;
protected static $_attributeNameCache = array();
public function __construct(Array $data = array(), $parent = null)
{
$this->_init($data, $parent);
}
public function setData(Array $data = array())
{
$this->_init($data);
return $this;
}
protected function _init(Array $data, $parent = null)
{
if ($parent !== null) {
$this->_parent = $parent;
}
$this->_children = array();
foreach ($data as $key => $value) {
if (is_array($value)) {
$this->offsetSet($key, new self($value, $this));
} else {
$this->offsetSet($key, $value);
}
}
return $this;
}
public function getParent()
{
return $this->_parent;
}
public function setConfig($path, $value)
{
$explodedPath = explode('/', $path);
$length = count($explodedPath);
$currentNode = $this;
for ($i = 0; $i < $length; $i++) {
if ($i < ($length - 1)) {
if (!$currentNode->offsetExists($explodedPath[$i])) {
$newNode = new Node(array(), $currentNode);
$currentNode->offsetSet($explodedPath[$i], $newNode);
}
} else if (is_array($value)) {
$currentNode->offsetSet($explodedPath[$i], new self($value, $this));
break;
} else {
$currentNode->offsetSet($explodedPath[$i], $value);
break;
}
$currentNode = $currentNode->offsetGet($explodedPath[$i]);
if (!$currentNode instanceof Node) {
throw new CoreException\RuntimeException();
}
}
return $this;
}
public function getConfig($path)
{
$explodedPath = explode('/', $path);
$length = count($explodedPath);
$currentNode = $this;
for ($i = 0; $i < $length; $i++) {
if (!$currentNode instanceof Node) {
throw new CoreException\RuntimeException();
}
if (!$currentNode->offsetExists($explodedPath[$i])) {
return null;
}
$currentNode = $currentNode->offsetGet($explodedPath[$i]);
}
return $currentNode;
}
public function toArray()
{
$result = array();
foreach ($this->_children as $key => $child) {
if ($child instanceof self) {
$result[$key] = $child->toArray();
} else if ($child instanceof Leaf) {
$result[$key] = $child->getValue();
} else {
$result[$key] = $child;
}
}
return $result;
}
public function reset()
{
$this->_children = array();
$this->_parent = null;
return $this;
}
public function merge(self $node)
{
foreach ($node->_children as $offset => $value) {
if ($value instanceof self) {
if (!$this->offsetExists($offset)) {
$this->offsetSet($offset, new self(array(), $this));
}
$this->offsetGet($offset)->merge($value);
} else {
$this->offsetSet($offset, $value);
}
}
return $this;
}
private function _resolveAttributeName($key)
{
if (is_numeric($key)) {
return $key;
}
if (!isset(self::$_attributeNameCache[$key])) {
self::$_attributeNameCache[$key] = strtolower(preg_replace('#([A-Z])#', '-\\1', $key));
}
return self::$_attributeNameCache[$key];
}
public function __get($offset)
{
return $this->offsetGet($this->_resolveAttributeName($offset));
}
public function __set($offset, $value)
{
return $this->offsetSet($this->_resolveAttributeName($offset), $value);
}
public function __isset($offset)
{
return $this->offsetExists($this->_resolveAttributeName($offset));
}
public function __unset($offset)
{
return $this->offsetUnset($this->_resolveAttributeName($offset));
}
public function __clone()
{
$clone = new self();
foreach ($this->_children as $childName => $childNode) {
if ($childNode instanceof self) {
$childNode = clone $childNode;
$childNode->_parent = $clone;
}
$clone->offsetSet($childName, $childNode);
}
return $clone;
}
public function offsetGet($offset)
{
if ($this->offsetExists($offset)) {
return $this->_children[$offset];
}
return null;
}
public function offsetSet($offset, $value)
{
if ($offset === null) {
$this->_children[] = $value;
} else {
$this->_children[$offset] = $value;
}
return $value;
}
public function offsetExists($offset)
{
if (isset($this->_children[$offset])) {
return true;
}
return false;
}
public function offsetUnset($offset)
{
if ($this->offsetExists($offset)) {
unset($this->_children[$offset]);
}
}
public function current()
{
return current($this->_children);
}
public function key()
{
return key($this->_children);
}
public function next()
{
return next($this->_children);
}
public function rewind()
{
return reset($this->_children);
}
public function valid()
{
return key($this->_children) !== null;
}
public function count()
{
return count($this->_children);
}
}

View file

@ -0,0 +1,43 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Controller;
use Wootook\Core\Mvc\Controller as MvcController;
class ErrorController
extends MvcController\Action
{
public function noRouteAction()
{
$this->loadLayout('no-route');
$this->renderLayout();
}
}

View file

@ -0,0 +1,43 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Controller;
use Wootook\Core\Mvc\Controller as MvcController;
class IndexController
extends MvcController\Action
{
public function indexAction()
{
$this->loadLayout('home');
$this->renderLayout();
}
}

View file

@ -0,0 +1,281 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Adapter;
use Wootook\Core,
Wootook\Core\Database\Orm,
Wootook\Core\Database\Sql,
Wootook\Core\Database\Statement,
Wootook\Core\Event,
Wootook\Core\Exception as CoreException;
abstract class Adapter
{
use Event\EventTarget;
protected $_handler = null;
protected $_tablePrefix = null;
protected $_statementClass = null;
public function setStatementClass($statementClass)
{
$this->_statementClass = $statementClass;
return $this;
}
public function getStatementClass()
{
return $this->_statementClass;
}
public function getDriverHandler()
{
return $this->_handler;
}
public function getDataMapper()
{
return new Orm\DataMapper();
}
/**
*
* @param string $prefix
* @return Adapter
*/
public function setTablePrefix($prefix)
{
$this->_tablePrefix = $prefix;
return $this;
}
/**
* @return string
*/
public function getTablePrefix()
{
return $this->_tablePrefix;
}
/**
* @return string
*/
public function getTable($table)
{
return $this->getTablePrefix() . $table;
}
/**
* @return Sql\Select
*/
public function select()
{
return new Sql\Select($this);
}
/**
* @return Sql\Insert
*/
public function insert()
{
return new Sql\Insert($this);
}
/**
* @return Sql\Update
*/
public function update()
{
return new Sql\Update($this);
}
/**
* @return Sql\Delete
*/
public function delete()
{
return new Sql\Delete($this);
}
/**
* @param string $data
* @return string
*/
abstract public function quote($data);
/**
* @param string $identifier
* @return string
*/
abstract public function quoteIdentifier($identifier);
/**
* @param string $identifier
* @return string
*/
public function quoteInto($string, $values)
{
$parts = preg_split('#(:[\w_]+|[?])#', $string, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$result = '';
if (is_array($values)) {
$index = 0;
foreach ($parts as $part) {
if ($part == '?') {
$result .= $this->quote($values[$index++]);
} else if (!empty($part) && $part[0] == ':') {
$key = substr($part, 1);
if (isset($values[$key])) {
$result .= $this->quote($values[$key]);
} else if (isset($values[$part])) {
$result .= $this->quote($values[$part]);
} else {
$result .= $part;
}
} else {
$result .= $part;
}
}
} else {
foreach ($parts as $part) {
if ($part == '?' || $part[0] == ':') {
$result .= $this->quote($values);
} else {
$result .= $part;
}
}
}
return $result;
}
/**
* @param $sql
* @param array|null $params
* @param Closure|null $asynchronousCallback
* @return \Wootook\Core\Database\Statement\Statement
* @throws \Wootook\Core\Exception\Database\StatementError
*/
public function query($sql, Array $params = null, Closure $asynchronousCallback = null)
{
$statement = $this->prepare($sql, $params);
if ($asynchronousCallback !== null) {
$statement->registerEventListener(Statement\Statement::EVENT_READY, $asynchronousCallback);
}
if (!$statement->execute(null, $asynchronousCallback !== null)) {
$message = sprintf('[SQLSTATE %s] Could not execute query: %s', $statement->errorState(), $statement->errorMessage());
throw new CoreException\Database\StatementError($statement, $message);
}
return $statement;
}
/**
* @param $sql
* @param array|null $params
* @param Closure|null $asynchronousCallback
* @return bool
*/
public function execute($sql, Array $params = null, Closure $asynchronousCallback = null)
{
$statement = $this->prepare($sql, $params);
if ($asynchronousCallback !== null) {
$statement->registerEventListener(Statement\Statement::EVENT_READY, $asynchronousCallback);
}
return $statement->execute(null, $asynchronousCallback !== null);
}
/**
* @param $sql
* @param array|null $params
* @return \Wootook\Core\Database\Statement\Statement
*/
public function prepare($sql, Array $params = null)
{
$statement = new $this->_statementClass($this, $sql);
if ($params !== null) {
foreach ($params as $paramKey => $paramValue) {
$statement->bindValue($paramKey, $paramValue, $statement->getParamType($paramValue));
}
}
return $statement;
}
/**
* @return bool
*/
abstract public function beginTransaction();
/**
* @return bool
*/
abstract public function commit();
/**
* @return bool
*/
abstract public function rollback();
/**
* @return bool
*/
abstract public function lastInsertId();
/**
* @return string
*/
abstract public function errorCode();
/**
* @return string
*/
abstract public function errorMessage();
/**
* @return array
*/
abstract public function errorInfo();
/**
* @return string
*/
abstract public function errorState();
}

View file

@ -0,0 +1,178 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Adapter;
use Wootook\Core\Config,
Wootook\Core\Database,
Wootook\Core\Database\Statement,
Wootook\Core\Database\Sql,
Wootook\Core\Exception as CoreException;
class Mysql
extends Adapter
{
protected $_statementClass = 'Wootook\\Core\\Database\\Statement\\Mysql';
/**
*
* Enter description here ...
* @param Config\Node $config
* @param array $params
*/
public function __construct(Config\Node $config, Array $options = array())
{
if (!isset($options[Database\ConnectionManager::ATTR_ERRMODE])) {
$options[Database\ConnectionManager::ATTR_ERRMODE] = Database\ConnectionManager::ERRMODE_EXCEPTION;
}
try {
$this->_handler = new \mysqli($config->hostname, $config->username, $config->password, $config->database, (int) $config->port, $options);
} catch (\mysqli_sql_exception $e) {
throw new CoreException\Database\AdapterError($this, $e->getMessage(), null, $e);
}
if ($this->_handler->connect_errno) {
throw new CoreException\Database\AdapterError($this, $this->_handler->connect_error, $this->_handler->connect_errno);
}
}
/**
* (non-PHPdoc)
* @see Adapter\Adapter::quoteIdentifier()
*/
public function quoteIdentifier($identifier)
{
return "`$identifier`";
}
public function quote($data)
{
$result = $this->_handler->real_escape_string($data);
if ($this->_handler->errno) {
throw new CoreException\Database\AdapterError($this, $this->_handler->connect_error, $this->_handler->connect_errno);
}
return $result;
}
/**
* @return bool
*/
public function beginTransaction()
{
$result = $this->_handler->autocommit(false);
if ($this->_handler->errno) {
throw new CoreException\Database\AdapterError($this, $this->_handler->connect_error, $this->_handler->connect_errno);
}
return $result;
}
/**
* @return bool
*/
public function commit()
{
$result = $this->_handler->commit();
$this->_handler->autocommit(true);
if ($this->_handler->errno) {
throw new CoreException\Database\AdapterError($this, $this->_handler->connect_error, $this->_handler->connect_errno);
}
return $result;
}
/**
* @return bool
*/
public function rollback()
{
$result = $this->_handler->rollback();
$this->_handler->autocommit(true);
if ($this->_handler->errno) {
throw new CoreException\Database\AdapterError($this, $this->_handler->connect_error, $this->_handler->connect_errno);
}
return $result;
}
/**
* @return int
*/
public function lastInsertId()
{
return $this->_handler->insert_id;
}
/**
* @return string
*/
public function errorCode()
{
return $this->_handler->errno;
}
/**
* @return array
*/
public function errorInfo()
{
return array(
$this->_handler->sqlstate,
$this->_handler->errno,
$this->_handler->error,
);
}
/**
* @return string
*/
public function errorMessage()
{
$info = $this->_handler->error;
return $info[2];
}
/**
* @return string
*/
public function errorState()
{
$info = $this->_handler->sqlstate;
return $info[0];
}
}

View file

@ -0,0 +1,180 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Adapter;
use Wootook\Core\Config,
Wootook\Core\Database,
Wootook\Core\Database\Statement,
Wootook\Core\Database\Sql,
Wootook\Core\Exception as CoreException;
abstract class Pdo
extends Adapter
{
/**
*
* Enter description here ...
* @param Config\Node $config
* @param array $params
*/
public function __construct(Config\Node $config, Array $options = array())
{
if (!isset($options[Database\ConnectionManager::ATTR_ERRMODE])) {
$options[Database\ConnectionManager::ATTR_ERRMODE] = Database\ConnectionManager::ERRMODE_EXCEPTION;
}
try {
$this->_handler = new \PDO($this->_buildDsn($config), $config->username, $config->password, $options);
} catch (\PDOException $e) {
throw new CoreException\Database\AdapterError($this, $e->getMessage(), null, $e);
}
}
/**
* @abstract
* @param \Wootook\Core\Config\Node $config
* @return string
*/
abstract protected function _buildDsn(Config\Node $config);
public function quote($data)
{
try {
return $this->_handler->quote($data);
} catch (\PDOException $e) {
throw new CoreException\Database\AdapterError($this, $e->getMessage(), null, $e);
}
}
/**
* @return Statement\Statement
*/
public function prepare($sql, Array $params = null)
{
$statement = new $this->_statementClass($this, $sql);
if ($params !== null) {
foreach ($params as $paramKey => $paramValue) {
$statement->bindValue($paramKey, $paramValue, $statement->getParamType($paramValue));
}
}
return $statement;
}
/**
* @return bool
*/
public function beginTransaction()
{
try {
return $this->_handler->beginTransaction();
} catch (\PDOException $e) {
throw new CoreException\Database\AdapterError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
* @return bool
*/
public function commit()
{
try {
return $this->_handler->commit();
} catch (\PDOException $e) {
throw new CoreException\Database\AdapterError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
* @return bool
*/
public function rollback()
{
try {
return $this->_handler->rollback();
} catch (\PDOException $e) {
throw new CoreException\Database\AdapterError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
* @return int
*/
public function lastInsertId()
{
try {
return $this->_handler->lastInsertId();
} catch (\PDOException $e) {
throw new CoreException\Database\AdapterError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
* @return string
*/
public function errorCode()
{
return $this->_handler->errorCode();
}
/**
* @return array
*/
public function errorInfo()
{
return $this->_handler->errorInfo();
}
/**
* @return string
*/
public function errorMessage()
{
$info = $this->_handler->errorInfo();
return $info[2];
}
/**
* @return string
*/
public function errorState()
{
$info = $this->_handler->errorInfo();
return $info[0];
}
}

View file

@ -0,0 +1,63 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Adapter\Pdo;
use Wootook\Core\Config,
Wootook\Core\Database,
Wootook\Core\Database\Adapter,
Wootook\Core\Database\Statement,
Wootook\Core\Database\Sql,
Wootook\Core\Exception as CoreException;
class Mysql
extends Adapter\Pdo
{
protected $_statementClass = 'Wootook\\Core\\Database\\Statement\\Pdo\\Mysql';
protected function _buildDsn(Config\Node $config)
{
$dsn = "mysql:host={$config->hostname};dbname={$config->database}";
if (is_numeric($config->port)) {
$dsn .= ";port={$config->database}";
}
return $dsn;
}
/**
* (non-PHPdoc)
* @see Adapter\Adapter::quoteIdentifier()
*/
public function quoteIdentifier($identifier)
{
return "`$identifier`";
}
}

View file

@ -0,0 +1,60 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Adapter\Pdo;
use Wootook\Core\Config,
Wootook\Core\Database,
Wootook\Core\Database\Adapter,
Wootook\Core\Database\Statement,
Wootook\Core\Database\Sql,
Wootook\Core\Exception as CoreException;
class Sqlite
extends Adapter\Pdo
{
protected $_statementClass = 'Wootook\\Core\\Database\\Statement\\Pdo\\Sqlite';
protected function _buildDsn(Config\Node $config)
{
$dsn = "sqlite:{$config->database}";
return $dsn;
}
/**
* (non-PHPdoc)
* @see Adapter\Adapter::quoteIdentifier()
*/
public function quoteIdentifier($identifier)
{
return "\"$identifier\"";
}
}

View file

@ -0,0 +1,245 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database;
use Wootook\Core,
Wootook\Core\Base\Service,
Wootook\Core\Config,
Wootook\Core\Exception as CoreException,
Wootook\Core\PluginLoader,
Wootook\Core\Profiler;
class ConnectionManager
extends PluginLoader\PluginLoader
implements Core\Base\Singleton
{
use Service\App;
const PROFILER = 'profiler';
const CASE_FOLDING = 'case-folding';
const AUTO_QUOTE_IDENTIFIERS = 'auto-quote-identifiers';
const ALLOW_SERIALIZATION = 'allow-serialization';
const AUTO_RECONNECT_ON_UNSERIALIZE = 'auto-reconnect-on-unserialize';
const INT_TYPE = 0;
const BIGINT_TYPE = 1;
const FLOAT_TYPE = 2;
const ATTR_AUTOCOMMIT = 0;
const ATTR_PREFETCH = 1;
const ATTR_TIMEOUT = 2;
const ATTR_ERRMODE = 3;
const ATTR_SERVER_VERSION = 4;
const ATTR_CLIENT_VERSION = 5;
const ATTR_SERVER_INFO = 6;
const ATTR_CONNECTION_STATUS = 7;
const ATTR_CASE = 8;
const ATTR_CURSOR_NAME = 9;
const ATTR_CURSOR = 10;
const ATTR_ORACLE_NULLS = 11;
const ATTR_PERSISTENT = 12;
const ATTR_STATEMENT_CLASS = 13;
const ATTR_FETCH_TABLE_NAMES = 14;
const ATTR_FETCH_CATALOG_NAMES = 15;
const ATTR_DRIVER_NAME = 16;
const ATTR_STRINGIFY_FETCHES = 17;
const ATTR_MAX_COLUMN_LEN = 18;
const CASE_NATURAL = 0;
const CASE_UPPER = 1;
const CASE_LOWER = 2;
const CURSOR_FWDONLY = 0;
const CURSOR_SCROLL = 1;
const ERR_ALREADY_EXISTS = null;
const ERR_CANT_MAP = null;
const ERR_CONSTRAINT = null;
const ERR_DISCONNECTED = null;
const ERR_MISMATCH = null;
const ERR_NO_PERM = null;
const ERR_NONE = '00000';
const ERR_NOT_FOUND = null;
const ERR_NOT_IMPLEMENTED = null;
const ERR_SYNTAX = null;
const ERR_TRUNCATED = null;
const ERRMODE_SILENT = 0;
const ERRMODE_WARNING = 1;
const ERRMODE_EXCEPTION = 2;
const FETCH_LAZY = 0x000001;
const FETCH_ASSOC = 0x000002;
const FETCH_NUM = 0x000003;
const FETCH_BOTH = 0x000004;
const FETCH_OBJ = 0x000005;
const FETCH_BOUND = 0x000006;
const FETCH_COLUMN = 0x000007;
const FETCH_CLASS = 0x000008;
const FETCH_INTO = 0x000009;
const FETCH_FUNC = 0x00000A;
const FETCH_NAMED = 0x00000B;
const FETCH_GROUP = 0x010000;
const FETCH_UNIQUE = 0x030000;
const FETCH_CLASSTYPE = 0x040000;
const FETCH_SERIALIZE = 0x080000;
const FETCH_ORI_NEXT = 0;
const FETCH_ORI_PRIOR = 1;
const FETCH_ORI_FIRST = 2;
const FETCH_ORI_LAST = 3;
const FETCH_ORI_ABS = 4;
const FETCH_ORI_REL = 5;
const PARAM_BOOL = 5;
const PARAM_INPUT_OUTPUT = 0xFFFFFFFF80000000;
const PARAM_INT = 1;
const PARAM_LOB = 3;
const PARAM_NULL = 0;
const PARAM_STMT = 4;
const PARAM_STR = 2;
const NULL_EMPTY_STRING = 1;
const NULL_NATURAL = 0;
const NULL_TO_STRING = null;
const DEFAULT_CONNECTION_NAME = 'default';
protected $_connections = array();
protected $_connectionAliases = array();
protected static $_singleton = null;
protected function _construct()
{
$this->registerNamespace('Wootook\\Core\\Database\\Adapter');
}
/**
* @return ConnectionManager
*/
public static function getSingleton()
{
Profiler\ErrorProfiler::getSingleton()
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
return \Wootook::app()->getConnectionManager();
}
protected $_defaultOptions = array(
self::ATTR_ERRMODE => self::ERRMODE_EXCEPTION
);
/**
* @param $connectionName
* @return Adapter\Adapter
*/
public function getConnection($connectionName)
{
if (empty($connectionName) || $connectionName === null) {
return null;
}
if (!isset($this->_connections[$connectionName])) {
if (isset($this->_connectionAliases[$connectionName])) {
return $this->_connectionAliases[$connectionName];
}
$connectionConfig = \Wootook::app()->getGlobalConfig("resource/database/{$connectionName}");
if ($connectionConfig === null) {
return null;
}
if ($alias = $connectionConfig->use) {
$this->_connectionAliases[$connectionName] = self::getConnection($alias);
return $this->_connectionAliases[$connectionName];
}
$this->_connections[$connectionName] = self::_initConnection($connectionName,
$connectionConfig->engine, $connectionConfig->params, $connectionConfig->options);
}
return $this->_connections[$connectionName];
}
private function _initConnection($connectionName, $engine, $params, $options = array())
{
if (is_array($params)) {
$params = new Config\Node($params);
} else if (!$params instanceof Config\Node) {
$params = new Config\Node(array());
}
if ($options instanceof Config\Node) {
$options = $options->toArray();
} else if (!is_array($options)) {
$options = array();
}
if (empty($params->hostname) || empty($params->username) || empty($params->database)) {
return null;
}
$event = \Wootook::dispatchEvent('database.prepare-options', array(
'name' => $connectionName,
'options' => array_merge($this->_defaultOptions, $options)
));
$options = $event->getData('options');
try {
$connection = $this->load($engine, false, array($params, $options));
} catch (CoreException\Database\AdapterError $e) {
Profiler\ErrorProfiler::getSingleton()->addException($e);
return null;
}
if (!$connection) {
throw new CoreException\DataAccessException('Could not find data connection handler.');
}
if (($prefix = \Wootook::app()->getGlobalConfig("resource/database/{$connectionName}/table_prefix")) !== null) {
$connection->setTablePrefix($prefix);
}
\Wootook::dispatchEvent('database.init', array(
'name' => $connectionName,
'handler' => $connection
));
return $connection;
}
protected function _load($className, $useSingleton, Array $constructorParams = array())
{
$reflection = new \ReflectionClass($className);
return $reflection->newInstanceArgs($constructorParams);
}
}

View file

@ -0,0 +1,151 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Orm;
use Wootook\Core\Config,
Wootook\Core\Database,
Wootook\Core\Mvc\Model,
Wootook\Core\PluginLoader,
Wootook\Core\Profiler;
class DataMapper
extends PluginLoader\PluginLoader
{
protected $_rules = array();
protected $_alias = array();
public function __construct($config = array())
{
$this->registerNamespace('Wootook\\Core\\Database\\Orm\\DataMapper');
if (!is_array($config) || !$config instanceof Config\Node) {
return;
}
foreach ($config as $field => $typeConfig) {
if (is_string($typeConfig)) {
$this->addRule($field, $typeConfig);
} else if (is_array($typeConfig) && isset($typeConfig['type'])) {
if (isset($typeConfig['alias'])) {
$this->addRule($field, $typeConfig['type'], $typeConfig['alias']);
} else {
$this->addRule($field, $typeConfig['type']);
}
}
}
}
public function addRule($field, $type, $alias = null)
{
if (($instance = $this->load($type)) !== null) {
$this->_rules[$field] = $instance;
}
if ($alias === null) {
$alias = $field;
}
$this->_alias[$field] = $alias;
return $this;
}
public function removeRule($field)
{
unset($this->_rules[$field]);
unset($this->_alias[$field]);
return $this;
}
protected function _load($className, $useSingleton, Array $constructorParams = array())
{
$reflection = new \ReflectionClass($className);
if ($useSingleton && $reflection->implementsInterface('Wootook\\Core\\Base\\Singleton')) {
$method = $reflection->getMethod('getSingleton');
return $method->invoke(null);
}
try {
return $reflection->newInstance($this);
} catch (\ReflectionException $e) {
Profiler\ErrorProfiler::getSingleton()
->addException($e);
return null;
}
}
/**
*
* @param Database\Resource $entity
* @param Array $datas
* @return Array
*/
public function encode(Model\Entity $entity, Array $datas = array())
{
$aliasTable = array_flip($this->_alias);
foreach ($entity->getAllDatas() as $aliasedField => $decodedValue) {
if (!isset($aliasTable[$aliasedField])) {
$field = $aliasedField;
} else {
$field = $aliasTable[$aliasedField];
}
if (isset($this->_rules[$field])) {
$datas[$field] = $this->_rules[$field]->encode($decodedValue);
} else {
$datas[$field] = $decodedValue;
}
}
return $datas;
}
/**
*
* @param Database\Resource $entity
* @param Array $datas
* @return Database\Resource
*/
public function decode(Model\Entity $entity, Array $datas = array())
{
foreach ($datas as $field => $encodedValue) {
if (isset($this->_rules[$field])) {
$entity->setData($this->_alias[$field], $this->_rules[$field]->decode($encodedValue));
} else {
$entity->setData($field, $encodedValue);
}
}
return $entity;
}
}

View file

@ -0,0 +1,47 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Orm\DataMapper;
use Wootook\Core\Config as CoreConfig;
class Config
extends FieldMapper
{
public function encode($value)
{
return parent::encode($value->toArray());
}
public function decode($value)
{
return new CoreConfig\Node(parent::decode($value));
}
}

View file

@ -0,0 +1,70 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Orm\DataMapper;
use Wootook\Core;
class DateTime
extends FieldMapper
{
const DATE_FORMAT_MYSQL = 'Y-m-d G:i:s';
protected $_format = self::DATE_FORMAT_MYSQL;
public function setFormat($format = null)
{
if ($format === null) {
$this->_format = self::DATE_FORMAT_MYSQL;
} else {
$this->_format = $format;
}
return $this;
}
public function getFormat()
{
return $this->_format;
}
public function encode($value)
{
if (!$value instanceof Core\DateTime) {
$value = new Core\DateTime($value);
}
return $value->toString($this->getFormat());
}
public function decode($value)
{
return new Core\DateTime($value, $this->getFormat());
}
}

View file

@ -0,0 +1,47 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Orm\DataMapper;
use Wootook\Core\Database\Orm;
abstract class FieldMapper
{
protected $_mapper = null;
public function __construct(Orm\DataMapper $mapper = null)
{
$this->_mapper = $mapper;
}
abstract public function encode($value);
abstract public function decode($value);
}

View file

@ -0,0 +1,45 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Orm\DataMapper;
class PhpArray
extends FieldMapper
{
public function encode($value)
{
return serialize($value);
}
public function decode($value)
{
return unserialize($value);
}
}

View file

@ -0,0 +1,73 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Orm\DataMapper;
class PhpObject
extends FieldMapper
{
protected $_entityClass = null;
protected $_reflectionClass = null;
public function setEntityClass($class)
{
$this->_entityClass = $class;
return $this;
}
public function getEntityClass()
{
return $this->_entityClass;
}
protected function _newInstance(Array $args = array())
{
if ($this->_reflectionClass === null && $this->_entityClass !== null) {
$this->_reflectionClass = new ReflectionClass($this->_entityClass);
}
return $this->newInstanceArgs($args);
}
public function encode($value)
{
return parent::encode($value->getAllDatas());
}
public function decode($value)
{
$object = $this->_newInstance();
$object->addData(parent::decode($value));
return $object;
}
}

View file

@ -0,0 +1,61 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Resource;
use Wootook\Core\Database\Orm;
trait DataMapper
{
protected $_dataMapper = null;
/**
*
* @return Orm\DataMapper
*/
public function getDataMapper()
{
if ($this->_dataMapper === null) {
$this->_dataMapper = new Orm\DataMapper();
}
return $this->_dataMapper;
}
/**
*
* @param Orm\DataMapper $dataMapper
*/
public function setDataMapper(Orm\DataMapper $dataMapper)
{
$this->_dataMapper = $dataMapper;
return $this;
}
}

View file

@ -0,0 +1,72 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Resource;
use Wootook\Core,
Wootook\Core\Database,
Wootook\Core\Database\Adapter as DatabaseAdapter,
Wootook\Core\Exception as CoreException;
/**
*
*/
trait ReadConnection
{
protected $_readConnection = null;
/**
* @return DatabaseAdapter\Adapter
*/
public function getReadConnection()
{
if ($this->_readConnection === null) {
$this->_readConnection = $this->app()->getConnectionManager()
->getConnection('core_read');
}
return $this->_readConnection;
}
public function setReadConnection($connection)
{
if ($connection instanceof DatabaseAdapter\Adapter) {
$this->_readConnection = $connection;
} else if (is_string($connection)) {
$this->_readConnection = $this->app()->getConnectionManager()
->getConnection($connection);
} else {
throw new CoreException\RuntimeException(
'First parameter should be either a database connection object or a string identifier.');
}
return $this;
}
}

View file

@ -0,0 +1,70 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Resource;
use Wootook\Core,
Wootook\Core\Database\Adapter as DatabaseAdapter,
Wootook\Core\Exception as CoreException;
/**
*
*/
trait WriteConnection
{
protected $_writeConnection = null;
/**
* @return DatabaseAdapter\Adapter
*/
public function getWriteConnection()
{
if ($this->_writeConnection === null) {
$this->_writeConnection = $this->app()->getConnectionManager()
->getConnection('core_write');
}
return $this->_writeConnection;
}
public function setWriteConnection($connection)
{
if ($connection instanceof DatabaseAdapter\Adapter) {
$this->_readConnection = $connection;
} else if (is_string($connection)) {
$this->_readConnection = $this->app()->getConnectionManager()
->getConnection($connection);
} else {
throw new CoreException\RuntimeException(
'First parameter should be either a database connection object or a string identifier.');
}
return $this;
}
}

View file

@ -0,0 +1,123 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Condition;
use Wootook\Core\Database\Adapter,
Wootook\Core\Database\Sql\Placeholder,
Wootook\Core\Database\Sql\Dml,
Wootook\Core\Database\Statement;
abstract class Condition
{
protected $_query = null;
protected $_placeholders = array();
abstract public function render();
public function __toString()
{
return (string) $this->render();
}
abstract public function reset();
public function setQuery(Dml\Dml $query)
{
$this->_query = $query;
return $this;
}
public function getQuery()
{
return $this->_query;
}
protected function _addPlaceholder(Placeholder\Placeholder $placeholder)
{
$this->_placeholders[] = $placeholder;
return $this;
}
protected function _clearPlaceholders()
{
$this->_placeholders = array();
return $this;
}
protected function _getAllPlaceholders()
{
return $this->_placeholders;
}
public function beforePrepare(Statement\Statement $statement)
{
foreach ($this->_getAllPlaceholders() as $placeholder) {
/** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */
$placeholder->beforePrepare($statement);
}
return $this;
}
public function afterPrepare(Statement\Statement $statement)
{
foreach ($this->_getAllPlaceholders() as $placeholder) {
/** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */
$placeholder->afterPrepare($statement);
}
return $this;
}
public function beforeExecute(Statement\Statement $statement)
{
foreach ($this->_getAllPlaceholders() as $placeholder) {
/** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */
$placeholder->beforeExecute($statement);
}
return $this;
}
public function afterExecute(Statement\Statement $statement)
{
foreach ($this->_getAllPlaceholders() as $placeholder) {
/** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */
$placeholder->afterExecute($statement);
}
return $this;
}
}

View file

@ -0,0 +1,127 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Condition;
use Wootook\Core\Database\Sql\Dml,
Wootook\Core\Database\Sql\Placeholder;
class InListOperator
extends Condition
{
protected $_operator = null;
protected $_field = null;
protected $_values = array();
public function __construct(Dml\Dml $query, $operator)
{
$this->_query = $query;
$this->_operator = $operator;
}
protected function _render($rawOperator)
{
$output = array();
foreach ($this->_values as $value) {
if ($this->_value instanceof Placeholder\Placeholder) {
$output[] = $value;
}
$output[] = $this->getQuery()->quote($value);
}
return $rawOperator . '(' . implode(', ', $output) . ')';
}
public function render()
{
switch ($this->_operator) {
case Dml\Section\WhereAware::OPERATOR_IN:
return $this->_render('=');
case Dml\Section\WhereAware::OPERATOR_NOT_IN:
return $this->_render('!=');
}
return '';
}
public function reset()
{
$this->_operator = null;
$this->_field = null;
$this->_values = array();
$this->_clearPlaceholders();
return $this;
}
public function setOperator($operator)
{
$this->_operator = $operator;
return $this;
}
public function getOperator()
{
return $this->_operator;
}
public function setField($field)
{
$this->_field = $field;
return $this;
}
public function getField()
{
return $this->_field;
}
public function addValue($value)
{
if ($value instanceof Placeholder\Placeholder) {
$this->_addPlaceholder($value);
}
$this->_values[] = $value;
return $this;
}
public function getAllValues()
{
return $this->_values;
}
}

View file

@ -0,0 +1,264 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Condition;
use Wootook\Core\Database\Sql\Dml,
Wootook\Core\Exception as CoreException;
class LogicalOperator
extends Condition
implements \ArrayAccess, \Countable, \Iterator
{
/**
* @var string|int
*/
protected $_operator = null;
/**
* @var array
*/
protected $_conditions = array();
/**
* @var array
*/
protected $_allowedOperators = array();
public function __construct(Dml\Dml $query, $operator = null, Array $allowedOperators = array())
{
$this->_query = $query;
$this->_operator = $operator;
$this->_allowedOperators = array(
Dml\Section\WhereAware::OPERATOR_NOT => function(LogicalOperator $conditions) {
return '(NOT (' . $conditions[0] . ')';
},
Dml\Section\WhereAware::OPERATOR_AND => function(LogicalOperator $conditions) {
return '(' . implode(') AND (', $conditions->getAllConditions()) . ')';
},
Dml\Section\WhereAware::OPERATOR_NAND => function(LogicalOperator $conditions) {
return '(NOT (' . implode(') AND (', $conditions->getAllConditions()) . '))';
},
Dml\Section\WhereAware::OPERATOR_OR => function(LogicalOperator $conditions) {
return '(' . implode(') OR (', $conditions->getAllConditions()) . ')';
},
Dml\Section\WhereAware::OPERATOR_NOR => function(LogicalOperator $conditions) {
return '(NOT (' . implode(') OR (', $conditions->getAllConditions()) . '))';
},
Dml\Section\WhereAware::OPERATOR_XOR => function(LogicalOperator $conditions) {
return '(' . implode(') XOR (', $conditions->getAllConditions()) . ')';
},
Dml\Section\WhereAware::OPERATOR_NXOR => function(LogicalOperator $conditions) {
return '(NOT (' . implode(') XOR (', $conditions->getAllConditions()) . '))';
},
);
foreach ($allowedOperators as $operatorKey => $operator) {
if (!$operator instanceof \Closure) {
continue;
}
/** @var \Closure $operator */
$this->addAllowedOperator($operatorKey, $operator);
}
}
/**
* @return LogicalOperator
*/
public function reset()
{
$this->_operator = null;
$this->_conditions = array();
$this->_clearPlaceholders();
return $this;
}
/**
* @return string
*/
public function render()
{
if (isset($this->_allowedOperators[$this->_operator])) {
return $this->_allowedOperators[$this->_operator]($this);
}
return '';
}
/**
* @param string|int $operator
* @return LogicalOperator
*/
public function setOperator($operator)
{
if (!isset($this->_allowedOperators[$operator])) {
throw new CoreException\InvalidArgumentException('Inexistent operator');
}
$this->_operator = $operator;
return $this;
}
/**
* @return string|int
*/
public function getOperator()
{
return $this->_operator;
}
/**
* @param string|int $operator
* @param Closure $renderer
* @return LogicalOperator
*/
public function addAllowedOperator($operator, \Closure $renderer)
{
$this->_allowedOperators[$operator] = $renderer;
return $this;
}
/**
* @param string|int $operator
* @return LogicalOperator
*/
public function removeAllowedOperator($operator)
{
$key = array_search($operator, $this->_allowedOperators);
if ($key !== null) {
unset($this->_allowedOperators[$key]);
}
return $this;
}
/**
* @param string|int $operator
* @param Closure $renderer
* @return \Closure
*/
public function getAllowedOperatorRenderer($operator)
{
if (!isset($this->_allowedOperators[$operator])) {
throw new CoreException\InvalidArgumentException('Inexistent operator');
}
return $this->_allowedOperators[$operator];
}
/**
* @return array
*/
public function getAllAllowedOperators()
{
return $this->_allowedOperators;
}
/**
* @param Condition $condition
* @return LogicalOperator
*/
public function addCondition(Condition $condition)
{
$this->_conditions[] = $condition;
return $this;
}
/**
* @return array
*/
public function getAllConditions()
{
return $this->_conditions;
}
public function count()
{
return count($this->_conditions);
}
public function current()
{
return current($this->_conditions);
}
public function key()
{
return key($this->_conditions);
}
public function valid()
{
return key($this->_conditions) !== false;
}
public function next()
{
next($this->_conditions);
}
public function rewind()
{
reset($this->_conditions);
}
public function offsetExists($offset)
{
return isset($this->_conditions[$offset]);
}
public function offsetSet($offset, $value)
{
if (!is_int($offset)) {
throw new CoreException\InvalidArgumentException('Offset should be an integer');
}
$this->_conditions[$offset] = $value;
}
public function offsetGet($offset)
{
if (!is_int($offset)) {
throw new CoreException\InvalidArgumentException('Offset should be an integer');
}
return $this->_conditions[$offset];
}
public function offsetUnset($offset)
{
if (!is_int($offset)) {
throw new CoreException\InvalidArgumentException('Offset should be an integer');
}
unset($this->_conditions[$offset]);
}
}

View file

@ -0,0 +1,136 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Condition;
use Wootook\Core\Database\Sql\Dml,
Wootook\Core\Database\Sql\Placeholder;
class MathOperator
extends Condition
{
protected $_operator = null;
protected $_field = null;
protected $_value = null;
public function __construct(Dml\Dml $query, $field, $operator, $value)
{
$this->_query = $query;
$this->_field = $field;
$this->_operator = $operator;
$this->_value = $value;
}
protected function _render($rawOperator)
{
if ($this->_value instanceof Placeholder\Placeholder) {
return "{$this->getQuery()->quoteIdentifier($this->_field)}{$rawOperator}{$this->_value}";
}
return "{$this->getQuery()->quoteIdentifier($this->_field)}{$rawOperator}{$this->getQuery()->quote($this->_value)}";
}
public function render()
{
switch ($this->_operator) {
case Dml\Section\WhereAware::OPERATOR_EQUALS:
return $this->_render('=');
case Dml\Section\WhereAware::OPERATOR_NOT_EQUALS:
return $this->_render('!=');
case Dml\Section\WhereAware::OPERATOR_LOWER:
return $this->_render('<');
case Dml\Section\WhereAware::OPERATOR_GREATER:
return $this->_render('>');
case Dml\Section\WhereAware::OPERATOR_LOWER_EQUALS:
return $this->_render('<=');
case Dml\Section\WhereAware::OPERATOR_GREATER_EQUALS:
return $this->_render('>=');
}
return '';
}
public function reset()
{
$this->_operator = null;
$this->_field = null;
$this->_value = null;
$this->_clearPlaceholders();
return $this;
}
public function setOperator($operator)
{
$this->_operator = $operator;
return $this;
}
public function getOperator()
{
return $this->_operator;
}
public function setField($field)
{
$this->_field = $field;
return $this;
}
public function getField()
{
return $this->_field;
}
public function setValue($value)
{
if ($value instanceof Placeholder\Placeholder) {
$this->_addPlaceholder($value);
}
$this->_value = $value;
return $this;
}
public function getValue()
{
return $this->_value;
}
}

View file

@ -0,0 +1,72 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Condition;
use Wootook\Core\Database\Sql\Placeholder as SqlPlaceholder;
class Placeholder
extends Condition
{
protected $_placeholder = null;
public function __construct(SqlPlaceholder\Placeholder $placeholder)
{
$this->_placeholder = $placeholder;
$this->_addPlaceholder($placeholder);
}
public function render()
{
return $this->_placeholder->toString();
}
public function reset()
{
$this->_placeholder = null;
$this->_clearPlaceholders();
return $this;
}
public function setPlaceholder($placeholder)
{
$this->_placeholder = $placeholder;
return $this;
}
public function getPlaceholder()
{
return $this->_placeholder;
}
}

View file

@ -0,0 +1,120 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql;
class Delete
extends DmlFilterableQuery
{
const FROM = 'FROM';
protected function _init($tableName = null)
{
parent::_init($tableName);
if ($tableName !== null) {
$this->into($tableName);
}
return $this;
}
public function reset($part = null)
{
if ($part === null) {
$this->_parts = array(
self::FROM => null,
self::WHERE => array(),
self::OFFSET => null,
self::LIMIT => null,
);
} else if (isset($this->_parts[$part])) {
$this->_parts[$part] = array();
}
return $this;
}
public function from($table, $schema = null)
{
$this->_parts[self::FROM] = array(
'table' => $table,
'schema' => $schema
);
return $this;
}
public function __toString()
{
return $this->render();
}
public function toString($part = null)
{
if ($part === null) {
return $this->render();
}
switch ($part) {
case self::FROM:
return $this->renderFrom();
break;
case self::WHERE:
return $this->renderWhere();
break;
case self::WHERE:
return $this->renderWhere();
break;
case self::LIMIT:
return $this->renderLimit();
break;
}
return null;
}
public function renderFrom()
{
if ($this->_parts[self::FROM]['schema'] !== null) {
return "DELETE FROM {$this->getConnection()->quoteIdentifier($this->_parts[self::FROM]['schema'])}.{$this->getConnection()->quoteIdentifier($this->_parts[self::FROM]['table'])}";
}
return "DELETE FROM {$this->getConnection()->quoteIdentifier($this->_parts[self::FROM]['table'])}";
}
public function render()
{
return implode("\n", array(
$this->renderFrom(),
$this->renderWhere(),
$this->renderLimit(),
));
}
}

View file

@ -0,0 +1,63 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml;
use Wootook\Core\Database\Adapter,
Wootook\Core\Database\Sql\Placeholder,
Wootook\Core\Database\Statement;
interface Dml
{
function __construct(Adapter\Adapter $connection, $param = null);
function render();
function toString($part = null);
function reset($part = null);
function quote($data);
function quoteIdentifier($identifier);
function setConnection(Adapter\Adapter $connection);
function getConnection();
function beforePrepare(Statement\Statement $statement);
function afterPrepare(Statement\Statement $statement);
function beforeExecute(Statement\Statement $statement);
function afterExecute(Statement\Statement $statement);
function getPart($part);
function setPart($part, $value);
function getAllParts();
function addPlaceholder(Placeholder\Placeholder $placeholder);
}

View file

@ -0,0 +1,162 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml;
use Wootook\Core\Database\Adapter,
Wootook\Core\Database\Sql\Placeholder,
Wootook\Core\Database\Statement;
abstract class DmlQuery
implements Dml
{
protected $_parts = array();
protected $_connection = null;
protected $_placeholders = array();
public function __construct(Adapter\Adapter $connection, $tableName = null)
{
$this->setConnection($connection);
$this->reset();
$this->_init($tableName);
}
/**
* @return \Wootook\Core\Database\Adapter\Adapter
*/
public function getConnection()
{
return $this->_connection;
}
public function setConnection(Adapter\Adapter $connection)
{
$this->_connection = $connection;
return $this;
}
protected function _init($param = null)
{
return $this;
}
public function setPart($part, $value)
{
$this->_parts[$part] = $value;
return $this;
}
public function getPart($part)
{
if (isset($this->_parts[$part])) {
return $this->_parts[$part];
}
return null;
}
public function getAllParts()
{
return $this->_parts;
}
public function quote($data)
{
return $this->getConnection()->quote($data);
}
public function quoteIdentifier($identifier)
{
return $this->getConnection()->quoteIdentifier($identifier);
}
public function quoteInto($identifier, $values)
{
return $this->getConnection()->quoteInto($identifier, $values);
}
public function addPlaceholder(Placeholder\Placeholder $placeholder)
{
$this->_placeholders[] = $placeholder;
return $this;
}
public function beforePrepare(Statement\Statement $statement)
{
foreach ($this->_placeholders as $placeholder) {
$placeholder->beforePrepare($statement);
}
return $this;
}
public function afterPrepare(Statement\Statement $statement)
{
foreach ($this->_placeholders as $placeholder) {
$placeholder->afterPrepare($statement);
}
return $this;
}
public function beforeExecute(Statement\Statement $statement)
{
foreach ($this->_placeholders as $placeholder) {
$placeholder->beforeExecute($statement);
}
return $this;
}
public function afterExecute(Statement\Statement $statement)
{
foreach ($this->_placeholders as $placeholder) {
$placeholder->afterExecute($statement);
}
return $this;
}
public function prepare()
{
return $this->getConnection()->prepare($this);
}
public function execute(Array $params = null)
{
return $this->getConnection()->execute($this, $params);
}
}

View file

@ -0,0 +1,182 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql;
use Wootook\Core\Database\Sql\Placeholder;
class Insert
extends DmlQuery
{
const SET = 'SET';
const INTO = 'INTO';
const SELECT = 'SELECT';
protected function _init($tableName = null)
{
parent::_init($tableName);
if ($tableName !== null) {
$this->into($tableName);
}
return $this;
}
public function reset($part = null)
{
if ($part === null) {
$this->_parts = array(
self::INTO => array(),
self::SET => array(),
self::SELECT => array(),
);
} else if (isset($this->_parts[$part])) {
$this->_parts[$part] = array();
}
return $this;
}
public function set($column, $value = null)
{
if (!is_array($column)) {
$column = array($column => $value);
}
foreach ($column as $field => $value) {
if ($value instanceof Placeholder\Placeholder) {
$this->_placeholders[] = $value;
}
$this->_parts[self::SET][] = array(
'value' => $value,
'field' => $field
);
}
return $this;
}
public function into($table, $schema = null)
{
$this->_parts[self::INTO] = array(
'table' => $table,
'schema' => $schema,
);
return $this;
}
public function select()
{
if (!isset($this->_parts[self::SELECT])) {
$this->_parts[self::SELECT] = $this->getConnection()->select();
}
return $this->_parts[self::SELECT];
}
public function __toString()
{
return $this->render();
}
public function toString($part = null)
{
if ($part === null) {
return $this->render();
}
switch ($part) {
case self::COLUMNS:
return $this->renderSet();
break;
case self::INTO:
return $this->renderInto();
break;
case self::SELECT:
return $this->renderSelect();
break;
}
return null;
}
public function renderSet()
{
$fields = array();
foreach ($this->_parts[self::SET] as $field) {
if ($field['value'] instanceof Placeholder\Placeholder) {
$fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$field['value']->toString()}";
} else {
$fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$this->_connection->quote($field['value'])}";
}
}
if (!empty($fields)) {
return "SET " . implode(", ", $fields);
}
}
public function renderInto()
{
if ($this->_parts[self::INTO]['schema'] !== null) {
$output = "{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['schema'])}.{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['table'])}";
} else {
$output = "{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['table'])}";
}
return "INSERT INTO " . $output;
}
public function renderSelect()
{
if (isset($this->_parts[self::SELECT])) {
return ' ' . $this->_parts[self::SELECT]->render();
}
return '';
}
public function render()
{
if (empty($this->_parts[self::SELECT])) {
return implode("\n", array(
$this->renderInto(),
$this->renderSet(),
));
} else {
return implode("\n", array(
$this->renderInto(),
$this->renderSelect(),
));
}
}
}

View file

@ -0,0 +1,44 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql;
use Wootook\Core\Database\Adapter,
Wootook\Core\Database\Statement;
interface Renderer
{
function __construct(Adapter\Adapter $connection);
function render(Dml $query);
function quote($data);
function quoteIdentifier($identifier);
}

View file

@ -0,0 +1,72 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section;
use Wootook\Core\Database\Sql\Dml,
Wootook\Core\Database\Sql\Placeholder;
trait Column
{
public function column($column = '*', $table = null)
{
$parts = $this->getPart(Dml\Section\ColumnAware::COLUMNS);
if (is_array($column)) {
foreach ($column as $alias => $field) {
if (is_int($alias)) {
$parts[] = array(
'table' => $table,
'alias' => null,
'field' => $field
);
} else {
$parts[] = array(
'table' => $table,
'alias' => $alias,
'field' => $field
);
}
}
} else {
if ($column instanceof Placeholder\Placeholder) {
$this->_placeholders[] = $column;
}
$parts[] = array(
'table' => $table,
'alias' => null,
'field' => $column
);
}
$this->setPart(Dml\Section\ColumnAware::COLUMNS, $parts);
return $this;
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section;
interface ColumnAware
{
const COLUMNS = 'COLUMNS';
public function column($column = '*', $table = null);
}

View file

@ -0,0 +1,61 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section;
use Wootook\Core\Database\Sql\Dml;
trait From
{
public function from($table, $schema = null)
{
if (is_array($table)) {
$alias = key($table);
$table = current($table);
} else {
$alias = null;
}
$part = $this->getPart(FromAware::FROM);
if (!is_array($part)) {
$part = array();
}
$part[] = array(
'table' => $table,
'alias' => $alias,
'schema' => $schema
);
$this->setPart(FromAware::FROM, $part);
return $this;
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section;
interface FromAware
{
const FROM = 'FROM';
public function from($table, $schema = null);
}

View file

@ -0,0 +1,44 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section;
trait Into
{
public function into($table, $schema = null)
{
$this->setPart(IntoAware::INTO, array(
'table' => $table,
'schema' => $schema,
));
return $this;
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section;
interface IntoAware
{
const INTO = 'INTO';
public function into($table, $schema = null);
}

View file

@ -0,0 +1,42 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section;
trait Limit
{
public function limit($limit, $offset = null)
{
$this->setPart(LimitAware::LIMIT, intval($limit));
$this->setPart(LimitAware::OFFSET, intval($offset));
return $this;
}
}

View file

@ -0,0 +1,39 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section;
interface LimitAware
{
const LIMIT = 'LIMIT';
const OFFSET = 'OFFSET';
public function limit($limit, $offset = null);
}

View file

@ -0,0 +1,73 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section\Renderer;
use Wootook\Core\Database\Sql\Dml,
Wootook\Core\Database\Sql\Placeholder;
trait Column
{
public function renderColumn(Dml\Dml $query)
{
$fields = array();
$part = $query->getPart(Dml\Section\ColumnAware::COLUMNS);
foreach ($part as $field) {
if ($field['field'] instanceof Dml\Dml) {
if ($field['alias'] !== null) {
$fields[] = "({$field['field']}) AS {$field['alias']}";
} else {
$fields[] = "({$field['field']})";
}
} else if ($field['field'] instanceof Placeholder\Placeholder) {
if ($field['alias'] !== null) {
$fields[] = "({$field['field']}) AS {$field['alias']}";
} else {
$fields[] = "({$field['field']})";
}
} else if ($field['alias'] !== null) {
if ($field['table'] !== null) {
$fields[] = "{$field['table']}.{$field['field']} AS {$field['alias']}";
} else {
$fields[] = "{$field['field']} AS {$field['alias']}";
}
} else if ($field['table'] !== null) {
$fields[] = "{$field['table']}.{$field['field']}";
} else {
$fields[] = "{$field['field']}";
}
}
if (!empty($fields)) {
return implode(", ", $fields);
}
return '*';
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section\Renderer;
use Wootook\Core\Database\Sql\Dml;
interface ColumnAware
{
public function renderColumn(Dml\Dml $query);
}

View file

@ -0,0 +1,68 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section\Renderer;
use Wootook\Core\Database\Sql\Dml;
trait From
{
public function renderFrom(Dml\Dml $query)
{
$part = $query->getPart(Dml\Section\FromAware::FROM);
if (!is_array($part)) {
return '';
}
$tables = array();
foreach ($part as $table) {
if ($table['table'] instanceof Dml\Dml) {
if ($table['alias'] !== null) {
$tables[] = "({$table['table']}) AS {$query->quoteIdentifier($table['alias'])}";
} else {
$tables[] = "({$table['table']})";
}
} else if ($table['alias'] !== null) {
if ($table['schema'] !== null) {
$tables[] = "{$query->quoteIdentifier($table['schema'])}.{$query->quoteIdentifier($table['table'])} AS {$query->quoteIdentifier($table['alias'])}";
} else {
$tables[] = "{$query->quoteIdentifier($table['table'])} AS {$query->quoteIdentifier($table['alias'])}";
}
} else if ($table['schema'] !== null) {
$tables[] = "{$query->quoteIdentifier($table['schema'])}.{$query->quoteIdentifier($table['table'])}";
} else {
$tables[] = "{$query->quoteIdentifier($table['table'])}";
}
}
return " FROM " . implode(', ', $tables);
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section\Renderer;
use Wootook\Core\Database\Sql\Dml;
interface FromAware
{
public function renderFrom(Dml\Dml $query);
}

View file

@ -0,0 +1,48 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section\Renderer;
use Wootook\Core\Database\Sql\Dml;
trait Into
{
public function renderInto(Dml\Dml $query)
{
$part = $query->getPart(Dml\Section\IntoAware::INTO);
if ($part['schema'] !== null) {
return "{$query->quoteIdentifier($part['schema'])}.{$query->quoteIdentifier($part['table'])}";
}
return "{$query->quoteIdentifier($part['table'])}";
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section\Renderer;
use Wootook\Core\Database\Sql\Dml;
interface IntoAware
{
public function renderLimit(Dml\Dml $query);
}

View file

@ -0,0 +1,47 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section\Renderer;
use Wootook\Core\Database\Sql\Dml;
trait Limit
{
public function renderLimit(Dml\Dml $query)
{
if (!($limit = $query->getPart(Dml\Section\LimitAware::LIMIT))) {
return '';
}
if (!($offset = $query->getPart(Dml\Section\LimitAware::OFFSET))) {
return sprintf(" LIMIT %d", $limit);
}
return sprintf(" LIMIT %d,%d", $limit, $offset);
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section\Renderer;
use Wootook\Core\Database\Sql\Dml;
interface LimitAware
{
public function renderLimit(Dml\Dml $query);
}

View file

@ -0,0 +1,60 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section\Renderer;
use Wootook\Core\Database\Sql\Dml,
Wootook\Core\Database\Sql\Placeholder;
trait Set
{
public function renderSet(Dml\Dml $query)
{
$fields = array();
$parts = $query->getPart(Dml\Section\SetAware::SET);
if (is_array($parts)) {
foreach ($parts as $field) {
if ($field['value'] instanceof Placeholder\Placeholder) {
$fields[] = "{$query->quoteIdentifier($field['field'])}={$field['value']->toString()}";
} else if ($field['value'] === null) {
$fields[] = "{$query->quoteIdentifier($field['field'])}=NULL";
} else {
$fields[] = "{$query->quoteIdentifier($field['field'])}={$query->quote($field['value'])}";
}
}
}
if (!empty($fields)) {
return ' SET ' . implode(', ', $fields);
}
return '';
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section\Renderer;
use Wootook\Core\Database\Sql\Dml;
interface SetAware
{
public function renderSet(Dml\Dml $query);
}

View file

@ -0,0 +1,222 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section\Renderer;
use Wootook\Core,
Wootook\Core\Database\Adapter,
Wootook\Core\Database\Statement,
Wootook\Core\Database\Sql\Placeholder;
trait Where
{
const WHERE = 'WHERE';
const OPERATOR_AND = 'AND';
const OPERATOR_OR = 'OR';
const OPERATOR_XOR = 'XOR';
const OPERATOR_EQUALS = 'EQ';
const OPERATOR_NOT_EQUALS = 'NEQ';
const OPERATOR_LOWER = 'LT';
const OPERATOR_GREATER = 'GT';
const OPERATOR_LOWER_EQUALS = 'LTEQ';
const OPERATOR_GREATER_EQUALS = 'GTEQ';
const OPERATOR_IS_NULL = 'NULL';
const OPERATOR_IN = 'IN';
const OPERATOR_NOT_IN = 'NIN';
const OPERATOR_FIND_IN_SET = 'FINSET';
const OPERATOR_NOT_FIND_IN_SET = 'NFINSET';
const OPERATOR_DATE = 'DATE';
public function where($condition, $value = null)
{
if ($condition instanceof Placeholder\Placeholder) {
$this->_placeholders[] = $condition;
$this->_parts[self::WHERE][] = $condition;
} else if (is_array($value)) {
$where = $this->_translateSqlWhere($condition, 'or', $value);
if ($where !== null) {
$this->_parts[self::WHERE][] = $where;
}
} else if ($value instanceof Placeholder\Placeholder) {
$this->_parts[self::WHERE][] = "{$this->getConnection()->quoteIdentifier($condition)}=" . $value;
} else {
$this->_parts[self::WHERE][] = $this->getConnection()->quoteInto("{$this->getConnection()->quoteIdentifier($condition)}=?", $value);
}
return $this;
}
public function renderWhere()
{
if (count($this->_parts[self::WHERE]) <= 0) {
return '';
}
return " WHERE (" . implode(")\n AND (", $this->_parts[self::WHERE]) . ')';
}
protected function _translateSqlWhere($field, $operator, $value)
{
if ($value === null) {
return null;
}
$operator = strtoupper($operator);
$adapter = $this->getConnection();
$basicBinayOperatorList = array(
self::OPERATOR_EQUALS => '=',
self::OPERATOR_NOT_EQUALS => '!=',
self::OPERATOR_LOWER => '<',
self::OPERATOR_GREATER => '>',
self::OPERATOR_LOWER_EQUALS => '<=',
self::OPERATOR_GREATER_EQUALS => '>='
);
if (in_array($operator, $basicBinayOperatorList)) {
if ($value === true) {
return "{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}TRUE";
} else if ($value === false) {
return "{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}FALSE";
} else if (is_numeric($value)) {
return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%d", $value);
} else if ($value instanceof Placeholder\Placeholder) {
$this->_placeholders[] = $value;
return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%s", $adapter->quote($value->toString()));
} else {
return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%s", $adapter->quote($value));
}
}
switch ($operator) {
case self::OPERATOR_IS_NULL:
if ($value == false) {
return "{$adapter->quoteIdentifier($field)} IS NOT NULL";
} else {
return "{$adapter->quoteIdentifier($field)} IS NULL";
}
break;
case self::OPERATOR_AND:
case self::OPERATOR_OR:
case self::OPERATOR_XOR:
$where = array();
foreach ($value as $valueItem) {
$subOperator = key($valueItem);
$realValue = current($valueItem);
if (is_array($realValue) && isset($realValue['field'])) {
if (!isset($realValue['value'])) {
continue;
}
$realField = $realValue['field'];
$realValue = $realValue['value'];
} else {
$realField = $field;
}
if ($realValue === null) {
continue;
}
$actualValue = $this->_translateSqlWhere($realField, $subOperator, $realValue);
if ($actualValue !== null) {
$where[] = $actualValue;
}
}
if (count($where)) {
return '((' . implode(') ' . strtoupper($operator) . ' (', $where) . '))';
}
break;
case self::OPERATOR_IN:
$valueList = array();
foreach ($value as $setValue) {
$valueList[] = $adapter->quote($setValue);
}
$implodedList = implode(',', $valueList);
return "{$adapter->quoteIdentifier($field)} IN({$implodedList})";
break;
case self::OPERATOR_NOT_IN:
$valueList = array();
foreach ($value as $setValue) {
$valueList[] = $adapter->quote($setValue);
}
$implodedList = implode(',', $valueList);
return "{$adapter->quoteIdentifier($field)} NOT IN({$implodedList})";
break;
case self::OPERATOR_FIND_IN_SET:
if (is_array($value)) {
$subField = current($value);
$subOperator = key($value);
if (in_array($subOperator, $basicBinayOperatorList)) {
return "FIND_IN_SET({$adapter->quote($value)}, {$adapter->quoteIdentifier($field)}){$basicBinayOperatorList[$operator]}{$adapter->quoteIdentifier($subField)}";
}
} else {
return "0 < FIND_IN_SET({$adapter->quote($value)}, {$adapter->quoteIdentifier($field)})";
}
break;
case self::OPERATOR_NOT_FIND_IN_SET:
return "0 = FIND_IN_SET({$adapter->quote($value)}, {$adapter->quoteIdentifier($field)})";
break;
case self::OPERATOR_DATE:
$dateValues = array();
if (isset($value['from'])) {
if ($value['from'] instanceof Core\DateTime) {
$dateValues['from'] = "{$adapter->quoteIdentifier($field)} >= {$adapter->quote($this->getConnection()->getDataMapper()->load('DateTime')->encode($value['from']))}";
} else if (is_string($value['from'])) {
$dateValues['from'] = "{$adapter->quoteIdentifier($field)} >= {$adapter->quote($value['from'])}";
} else if (is_numeric($value['from'])) {
$dateValues['from'] = "UNIX_TIMESTAMP({$adapter->quoteIdentifier($field)}) >= {$adapter->quote($value['from'])}";
}
}
if (isset($value['to'])) {
if ($value['to'] instanceof Core\DateTime) {
$dateValues['to'] = "{$adapter->quoteIdentifier($field)} <= {$adapter->quote($this->getConnection()->getDataMapper()->load('DateTime')->encode($value['to']))}";
} else if (is_string($value['to'])) {
$dateValues['to'] = "{$adapter->quoteIdentifier($field)} <= {$adapter->quote($value['to'])}";
} else if (is_numeric($value['to'])) {
$dateValues['to'] = "UNIX_TIMESTAMP({$adapter->quoteIdentifier($field)}) <= {$adapter->quote($value['to'])}";
}
}
return '(' . implode(' AND ', $dateValues) . ')';
break;
}
return null;
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section\Renderer;
use Wootook\Core\Database\Sql\Dml;
interface WhereAware
{
public function renderWhere(Dml\Dml $query);
}

View file

@ -0,0 +1,63 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section;
use Wootook\Core\Database\Sql\Placeholder;
trait Set
{
public function set($column, $value = null)
{
if (!is_array($column)) {
$column = array($column => $value);
}
$parts = $this->getPart(SetAware::SET);
if (!is_array($parts)) {
$parts = array();
}
foreach ($column as $field => $value) {
if ($value instanceof Placeholder\Placeholder) {
$this->addPlaceholder($value);
}
$parts[] = array(
'value' => $value,
'field' => $field
);
}
$this->setPart(SetAware::SET, $parts);
return $this;
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section;
interface SetAware
{
const SET = 'SET';
public function set($column, $value = null);
}

View file

@ -0,0 +1,204 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section;
use Wootook\Core,
Wootook\Core\Database\Adapter,
Wootook\Core\Database\Statement,
Wootook\Core\Database\Sql\Placeholder;
trait Where
{
public function where($condition, $value = null)
{
if ($condition instanceof Placeholder\Placeholder) {
$this->_placeholders[] = $condition;
$this->_parts[WhereAware::WHERE][] = $condition;
} else if (is_array($value)) {
$where = $this->_translateSqlWhere($condition, 'or', $value);
if ($where !== null) {
$this->_parts[WhereAware::WHERE][] = $where;
}
} else if ($value instanceof Placeholder\Placeholder) {
$this->_parts[WhereAware::WHERE][] = "{$this->getConnection()->quoteIdentifier($condition)}=" . $value;
} else {
$this->_parts[WhereAware::WHERE][] = $this->getConnection()->quoteInto("{$this->getConnection()->quoteIdentifier($condition)}=?", $value);
}
return $this;
}
public function renderWhere()
{
if (count($this->_parts[self::WHERE]) <= 0) {
return '';
}
return " WHERE (" . implode(")\n AND (", $this->_parts[self::WHERE]) . ')';
}
protected function _translateSqlWhere($field, $operator, $value)
{
if ($value === null) {
return null;
}
$operator = strtoupper($operator);
$adapter = $this->getConnection();
$basicBinayOperatorList = array(
WhereAware::OPERATOR_EQUALS => '=',
WhereAware::OPERATOR_NOT_EQUALS => '!=',
WhereAware::OPERATOR_LOWER => '<',
WhereAware::OPERATOR_GREATER => '>',
WhereAware::OPERATOR_LOWER_EQUALS => '<=',
WhereAware::OPERATOR_GREATER_EQUALS => '>='
);
if (in_array($operator, $basicBinayOperatorList)) {
if ($value === true) {
return "{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}TRUE";
} else if ($value === false) {
return "{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}FALSE";
} else if (is_numeric($value)) {
return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%d", $value);
} else if ($value instanceof Placeholder\Placeholder) {
$this->_placeholders[] = $value;
return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%s", $adapter->quote($value->toString()));
} else {
return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%s", $adapter->quote($value));
}
}
switch ($operator) {
case WhereAware::OPERATOR_IS_NULL:
if ($value == false) {
return "{$adapter->quoteIdentifier($field)} IS NOT NULL";
} else {
return "{$adapter->quoteIdentifier($field)} IS NULL";
}
break;
case WhereAware::OPERATOR_AND:
case WhereAware::OPERATOR_OR:
case WhereAware::OPERATOR_XOR:
$where = array();
foreach ($value as $valueItem) {
$subOperator = key($valueItem);
$realValue = current($valueItem);
if (is_array($realValue) && isset($realValue['field'])) {
if (!isset($realValue['value'])) {
continue;
}
$realField = $realValue['field'];
$realValue = $realValue['value'];
} else {
$realField = $field;
}
if ($realValue === null) {
continue;
}
$actualValue = $this->_translateSqlWhere($realField, $subOperator, $realValue);
if ($actualValue !== null) {
$where[] = $actualValue;
}
}
if (count($where)) {
return '((' . implode(') ' . strtoupper($operator) . ' (', $where) . '))';
}
break;
case WhereAware::OPERATOR_IN:
$valueList = array();
foreach ($value as $setValue) {
$valueList[] = $adapter->quote($setValue);
}
$implodedList = implode(',', $valueList);
return "{$adapter->quoteIdentifier($field)} IN({$implodedList})";
break;
case WhereAware::OPERATOR_NOT_IN:
$valueList = array();
foreach ($value as $setValue) {
$valueList[] = $adapter->quote($setValue);
}
$implodedList = implode(',', $valueList);
return "{$adapter->quoteIdentifier($field)} NOT IN({$implodedList})";
break;
case WhereAware::OPERATOR_FIND_IN_SET:
if (is_array($value)) {
$subField = current($value);
$subOperator = key($value);
if (in_array($subOperator, $basicBinayOperatorList)) {
return "FIND_IN_SET({$adapter->quote($value)}, {$adapter->quoteIdentifier($field)}){$basicBinayOperatorList[$operator]}{$adapter->quoteIdentifier($subField)}";
}
} else {
return "0 < FIND_IN_SET({$adapter->quote($value)}, {$adapter->quoteIdentifier($field)})";
}
break;
case WhereAware::OPERATOR_NOT_FIND_IN_SET:
return "0 = FIND_IN_SET({$adapter->quote($value)}, {$adapter->quoteIdentifier($field)})";
break;
case WhereAware::OPERATOR_DATE:
$dateValues = array();
if (isset($value['from'])) {
if ($value['from'] instanceof Core\DateTime) {
$dateValues['from'] = "{$adapter->quoteIdentifier($field)} >= {$adapter->quote($this->getConnection()->getDataMapper()->load('DateTime')->encode($value['from']))}";
} else if (is_string($value['from'])) {
$dateValues['from'] = "{$adapter->quoteIdentifier($field)} >= {$adapter->quote($value['from'])}";
} else if (is_numeric($value['from'])) {
$dateValues['from'] = "UNIX_TIMESTAMP({$adapter->quoteIdentifier($field)}) >= {$adapter->quote($value['from'])}";
}
}
if (isset($value['to'])) {
if ($value['to'] instanceof Core\DateTime) {
$dateValues['to'] = "{$adapter->quoteIdentifier($field)} <= {$adapter->quote($this->getConnection()->getDataMapper()->load('DateTime')->encode($value['to']))}";
} else if (is_string($value['to'])) {
$dateValues['to'] = "{$adapter->quoteIdentifier($field)} <= {$adapter->quote($value['to'])}";
} else if (is_numeric($value['to'])) {
$dateValues['to'] = "UNIX_TIMESTAMP({$adapter->quoteIdentifier($field)}) <= {$adapter->quote($value['to'])}";
}
}
return '(' . implode(' AND ', $dateValues) . ')';
break;
}
return null;
}
}

View file

@ -0,0 +1,58 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section;
interface WhereAware
{
const WHERE = 'WHERE';
const OPERATOR_NOT = 'NOT';
const OPERATOR_AND = 'AND';
const OPERATOR_OR = 'OR';
const OPERATOR_XOR = 'XOR';
const OPERATOR_NAND = 'NAND';
const OPERATOR_NOR = 'NOR';
const OPERATOR_NXOR = 'NXOR';
const OPERATOR_EQUALS = 'EQ';
const OPERATOR_NOT_EQUALS = 'NEQ';
const OPERATOR_LOWER = 'LT';
const OPERATOR_GREATER = 'GT';
const OPERATOR_LOWER_EQUALS = 'LTEQ';
const OPERATOR_GREATER_EQUALS = 'GTEQ';
const OPERATOR_IS_NULL = 'NULL';
const OPERATOR_IN = 'IN';
const OPERATOR_NOT_IN = 'NIN';
const OPERATOR_FIND_IN_SET = 'FINSET';
const OPERATOR_NOT_FIND_IN_SET = 'NFINSET';
const OPERATOR_DATE = 'DATE';
public function where($condition, $value = null);
}

View file

@ -0,0 +1,366 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql;
use Wootook\Core\Database\Sql\Dml\Section,
Wootook\Core\Database\Sql\Placeholder;
class Select
extends DmlQuery
{
use Section\Where, Section\Limit;
const COLUMNS = 'COLUMNS';
const JOIN = 'JOIN';
const ORDER = 'ORDER';
const UNION = 'UNION';
const GROUP = 'GROUP';
const HAVING = 'HAVING';
const JOIN_INNER = 'INNER';
const JOIN_OUTER = 'OUTER';
const JOIN_LEFT = 'LEFT';
const JOIN_RIGHT = 'RIGHT';
protected function _init($tableName = null)
{
parent::_init($tableName);
if ($tableName !== null) {
$this->from($tableName);
}
return $this;
}
public function reset($part = null)
{
if ($part === null) {
$this->_parts = array(
self::COLUMNS => array(),
self::FROM => array(),
self::JOIN => array(),
self::WHERE => array(),
self::UNION => array(),
self::LIMIT => null,
self::OFFSET => null,
self::GROUP => array(),
self::HAVING => array(),
self::ORDER => array(),
);
} else if (isset($this->_parts[$part])) {
$this->_parts[$part] = array();
}
return $this;
}
public function column($column = '*', $table = null)
{
if (is_array($column)) {
foreach ($column as $alias => $field) {
if (is_int($alias)) {
$this->_parts[self::COLUMNS][] = array(
'table' => $table,
'alias' => null,
'field' => $field
);
} else {
$this->_parts[self::COLUMNS][] = array(
'table' => $table,
'alias' => $alias,
'field' => $field
);
}
}
} else {
if ($column instanceof Placeholder\Placeholder) {
$this->_placeholders[] = $column;
}
$this->_parts[self::COLUMNS][] = array(
'table' => $table,
'alias' => null,
'field' => $column
);
}
return $this;
}
public function from($table, $schema = null)
{
if (is_array($table)) {
$alias = key($table);
$table = current($table);
} else {
$alias = null;
}
$this->_parts[self::FROM][] = array(
'table' => $table,
'alias' => $alias,
'schema' => $schema
);
return $this;
}
public function join($table, $condition, $fields = array('*'), $mode = self::JOIN_INNER, $schema = null)
{
$this->column($fields);
if (is_array($table)) {
$alias = key($table);
$table = $this->_connection->getTable(current($table));
if ($schema !== null) {
$this->_parts[self::JOIN][] = "\n{$mode} JOIN {$this->_connection->quoteIdentifier($schema)}{$this->_connection->quoteIdentifier($table)} AS {$this->_connection->quoteIdentifier($alias)}"
. "\n ON {$condition}";
} else {
$this->_parts[self::JOIN][] = "\n{$mode} JOIN {$this->_connection->quoteIdentifier($table)} AS {$this->_connection->quoteIdentifier($alias)}"
. "\n ON {$condition}";
}
} else {
$this->_parts[self::JOIN][] = "\n{$mode} JOIN {$this->_connection->quoteIdentifier($table)}"
. "\n ON {$condition}";
}
return $this;
}
public function joinLeft($table, $condition, $fields = array('*'))
{
return $this->join($table, $condition, $fields, self::JOIN_LEFT);
}
public function joinRight($table, $condition, $fields = array('*'))
{
return $this->join($table, $condition, $fields, self::JOIN_RIGHT);
}
public function joinInner($table, $condition, $fields = array('*'))
{
return $this->join($table, $condition, $fields, self::JOIN_INNER);
}
public function joinOuter($table, $condition, $fields = array('*'))
{
return $this->join($table, $condition, $fields, self::JOIN_OUTER);
}
public function order($field, $direction = 'ASC')
{
$this->_parts[self::ORDER][] = "{$field} {$direction}";
return $this;
}
public function union($collection)
{
$this->_parts[self::UNION][] = $collection;
return $this;
}
public function group($groupField)
{
$this->_parts[self::GROUP][] = $groupField;
return $this;
}
public function __toString()
{
return $this->render();
}
public function toString($part = null)
{
if ($part === null) {
return $this->render();
}
switch ($part) {
case self::COLUMNS:
return $this->renderColumns();
break;
case self::FROM:
return $this->renderFrom();
break;
case self::WHERE:
return $this->renderWhere();
break;
case self::JOIN:
return $this->renderJoin();
break;
case self::ORDER:
return $this->renderOrder();
break;
case self::UNION:
return $this->renderUnion();
break;
case self::LIMIT:
return $this->renderLimit();
break;
case self::GROUP:
return $this->renderGroup();
break;
case self::HAVING:
return $this->renderHaving();
break;
}
return null;
}
public function renderColumns()
{
$fields = array();
foreach ($this->_parts[self::COLUMNS] as $field) {
if ($field['field'] instanceof Dml) {
if ($field['alias'] !== null) {
$fields[] = "({$field['field']}) AS {$field['alias']}";
} else {
$fields[] = "({$field['field']})";
}
} else if ($field['field'] instanceof Placeholder\Placeholder) {
if ($field['alias'] !== null) {
$fields[] = "({$field['field']}) AS {$field['alias']}";
} else {
$fields[] = "({$field['field']})";
}
} else if ($field['alias'] !== null) {
if ($field['table'] !== null) {
$fields[] = "{$field['table']}.{$field['field']} AS {$field['alias']}";
} else {
$fields[] = "{$field['field']} AS {$field['alias']}";
}
} else if ($field['table'] !== null) {
$fields[] = "{$field['table']}.{$field['field']}";
} else {
$fields[] = "{$field['field']}";
}
}
if (!empty($fields)) {
return 'SELECT ' . implode(", ", $fields);
}
return 'SELECT *';
}
public function renderFrom()
{
$tables = array();
foreach ($this->_parts[self::FROM] as $table) {
if ($table['table'] instanceof Dml) {
if ($table['alias'] !== null) {
$tables[] = "({$table['table']}) AS {$this->_connection->quoteIdentifier($table['alias'])}";
} else {
$tables[] = "({$table['table']})";
}
} else if ($table['alias'] !== null) {
if ($table['schema'] !== null) {
$tables[] = "{$this->_connection->quoteIdentifier($table['schema'])}.{$this->_connection->quoteIdentifier($table['table'])} AS {$this->_connection->quoteIdentifier($table['alias'])}";
} else {
$tables[] = "{$this->_connection->quoteIdentifier($table['table'])} AS {$this->_connection->quoteIdentifier($table['alias'])}";
}
} else if ($table['schema'] !== null) {
$tables[] = "{$this->_connection->quoteIdentifier($table['schema'])}.{$this->_connection->quoteIdentifier($table['table'])}";
} else {
$tables[] = "({$this->_connection->quoteIdentifier($table['table'])})";
}
}
return " FROM " . implode(', ', $tables);
}
public function renderJoin()
{
return implode('', $this->_parts[self::JOIN]);
}
public function renderOrder()
{
if (count($this->_parts[self::ORDER]) <= 0) {
return null;
}
return " ORDER BY " . implode(', ', $this->_parts[self::ORDER]);
}
public function renderUnion()
{
$statements = array();
foreach ($this->_parts[self::UNION] as $statement) {
$statements[] = $statement->render();
}
return " (\n" . implode(" )\n UNION\n (\n", $statements) . "\n )";
}
public function renderGroup()
{
if (count($this->_parts[self::GROUP]) <= 0) {
return null;
}
return " GROUP BY " . implode(', ', $this->_parts[self::GROUP]);
}
public function renderHaving()
{
if (count($this->_parts[self::HAVING]) <= 0) {
return null;
}
return " HAVING " . implode(', ', $this->_parts[self::HAVING]);
}
public function render()
{
if (empty($this->_parts[self::UNION])) {
return implode("\n", array(
$this->renderColumns(),
$this->renderFrom(),
$this->renderJoin(),
$this->renderWhere(),
$this->renderGroup(),
$this->renderHaving(),
$this->renderOrder(),
$this->renderLimit()
));
} else {
return implode("\n", array(
$this->renderUnion(),
$this->renderWhere(),
$this->renderOrder(),
$this->renderLimit()
));
}
}
}

View file

@ -0,0 +1,129 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql;
use Wootook\Core\Database\Sql\Dml\Section,
Wootook\Core\Database\Sql\Placeholder;
class Update
extends DmlQuery
implements Section\IntoAware, Section\LimitAware, Section\SetAware
{
use Section\Set, Section\Into, Section\Where, Section\Limit;
protected function _init($tableName = null)
{
parent::_init($tableName);
if ($tableName !== null) {
$this->into($tableName);
}
return $this;
}
public function reset($part = null)
{
if ($part === null) {
$this->_parts = array(
self::INTO => array(),
self::SET => array(),
self::WHERE => array(),
self::LIMIT => null,
self::OFFSET => null,
);
} else if (isset($this->_parts[$part])) {
$this->_parts[$part] = array();
}
return $this;
}
public function __toString()
{
return $this->render();
}
public function toString($part = null)
{
if ($part === null) {
return $this->render();
}
switch ($part) {
case self::SET:
return $this->renderSet();
break;
case self::INTO:
return $this->renderInto();
break;
}
return null;
}
public function renderSet()
{
$fields = array();
foreach ($this->_parts[self::SET] as $field) {
if ($field['value'] instanceof Placeholder\Placeholder) {
$fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$field['value']->toString()}";
} else {
$fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$this->_connection->quote($field['value'])}";
}
}
if (!empty($fields)) {
return ' SET ' . implode(', ', $fields);
}
}
public function renderInto()
{
if ($this->_parts[self::INTO]['schema'] !== null) {
$output = "{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['schema'])}.{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['table'])}";
} else {
$output = "{$this->_connection->quoteIdentifier($this->_parts[self::INTO]['table'])}";
}
return "UPDATE " . $output;
}
public function render()
{
return implode("\n", array(
$this->renderInto(),
$this->renderSet(),
$this->renderWhere(),
$this->renderLimit()
));
}
}

View file

@ -0,0 +1,62 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Placeholder;
use Wootook\Core\Database\Statement;
class Expression
extends Placeholder
{
protected $_expression = null;
protected $_params = array();
public function __construct($expression, Array $params = array())
{
$this->_expression = (string) $expression;
$this->_params = $params;
}
public function __toString()
{
return $this->_expression;
}
public function beforeExecute(Statement\Statement $statement)
{
parent::beforeExecute($statement);
foreach ($this->_params as $paramName => $value) {
$statement->bindValue($paramName, $value, $statement->getParamType($value));
}
return $this;
}
}

View file

@ -0,0 +1,63 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Placeholder;
use Wootook\Core\Database\Statement;
class Param
extends Placeholder
{
protected $_paramType = null;
protected $_paramName = null;
protected $_value = null;
public function __construct($paramName, $value, $type = null)
{
$this->_paramName = $paramName;
$this->_paramType = $type;
$this->_value = $value;
}
public function __toString()
{
return ':' . $this->_paramName;
}
public function beforeExecute(Statement\Statement $statement)
{
parent::beforeExecute($statement);
$type = $this->_paramType !== null ? $this->_paramType : $statement->getParamType($this->_value);
$statement->bindValue($this->_paramName, $this->_value, $type);
return $this;
}
}

View file

@ -0,0 +1,63 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Placeholder;
use Wootook\Core\Database\Statement;
abstract class Placeholder
{
public function toString()
{
return $this->__toString();
}
abstract public function __toString();
public function beforePrepare(Statement\Statement $statement)
{
return $this;
}
public function afterPrepare(Statement\Statement $statement)
{
return $this;
}
public function beforeExecute(Statement\Statement $statement)
{
return $this;
}
public function afterExecute(Statement\Statement $statement)
{
return $this;
}
}

View file

@ -0,0 +1,52 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Placeholder;
use Wootook\Core\Database\Statement;
class Variable
extends Placeholder
{
protected $_paramType = null;
protected $_paramName = null;
protected $_value = null;
public function __construct($paramName, $type = null)
{
$this->_paramName = $paramName;
$this->_paramType = $type;
}
public function __toString()
{
return ':' . $this->_paramName;
}
}

View file

@ -0,0 +1,8 @@
<?php
namespace Wootook\Core\Database\Sql\QueryBuilder;
interface QueryBuilder
{
}

View file

@ -0,0 +1,390 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Statement;
use Wootook\Core\Database,
Wootook\Core\Database\Adapter,
Wootook\Core\Database\Statement,
Wootook\Core\Database\Sql,
Wootook\Core\Exception as CoreException;
class Mysql
extends Statement
{
/**
* @var \mysqli_stmt
*/
protected $_handler = null;
/**
* @var string|Sql\Dml
*/
protected $_query = null;
protected function _init($query)
{
$this->_query = $query;
if ($this->_query instanceof Sql\Dml) {
$this->_query->beforePrepare($this);
}
try {
$this->_handler = $this->_adapter->getDriverHandler()->stmt_init();
if (!$this->_handler->prepare($this->_query)) {
throw new CoreException\Database\StatementError($this, $this->_handler->error, $this->_handler->errno);
}
} catch (\mysqli_sql_exception $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
if ($this->_query instanceof Sql\Dml) {
$this->_query->afterPrepare($this);
}
$this->dispatchEvent(self::EVENT_INIT);
return $this;
}
/**
*
* @param string|int $column
* @param mixed $param
* @param int $type
* @return Statement
*/
public function bindColumn($column, &$param, $type = null)
{
try {
return $this->_handler->bindColumn($column, $param, $type);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), null, $e);
}
}
/**
*
* @param string|int $parameter
* @param mixed $variable
* @param int $type
* @param int $length
* @param unknown_type $options
* @return Statement
*/
public function bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
{
try {
return $this->_handler->bindParam($parameter, $variable, $type, $length, $options);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
*
* @param string|int $parameter
* @param mixed $value
* @param int $type
* @return Statement\Statement
*/
public function bindValue($parameter, $value, $type = null)
{
try {
return $this->_handler->bindValue($parameter, $value, $type);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
*
* @param array $params
* @return bool
*/
public function execute(Array $params = null, $asynchronous = false)
{
if ($this->_query instanceof Sql\Dml) {
$this->_query->beforeExecute($this);
}
try {
foreach ($params as $paramKey => $paramValue) {
$this->_handler->bind_param('', $paramValue);
}
$result = $this->_handler->execute($params);
} catch (\mysqli_sql_exception $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
if ($this->_query instanceof Sql\Dml) {
$this->_query->afterExecute($this);
}
$this->dispatchEvent(self::EVENT_READY, array(
'result' => $result
));
return $result;
}
/**
*
* @param int $style
* @param int $col
* @return mixed
*/
public function fetchAll($style = null, $col = null)
{
try {
if ($style !== null) {
if ($col !== null) {
$result = $this->_handler->fetchAll($style, $col);
} else {
$result = $this->_handler->fetchAll($style);
}
} else {
$result = $this->_handler->fetchAll($style);
}
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
$this->dispatchEvent(self::EVENT_FETCH_ALL, array(
'result' => $result
));
return $result;
}
/**
*
* @param int $col
* @return mixed
*/
public function fetchColumn($col = 0)
{
try {
$result = $this->_handler->fetchColumn($col);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
$this->dispatchEvent(self::EVENT_FETCH_COL, array(
'result' => $result
));
return $result;
}
/**
*
* @return Database\Adapter\Adapter
*/
public function getAdapter()
{
return $this->_adapter;
}
/**
*
* @param string $key
*/
public function getAttribute($key)
{
try {
return $this->_handler->getAttribute($key);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
*
* @param string $key
* @param mixed $value
* @return Statement\Statement
*/
public function setAttribute($key, $value)
{
try {
return $this->_handler->setAttribute($key, $value);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
* @param unknown_type $mode
* @return Statement\Statement
*/
public function setFetchMode($mode)
{
try {
$params = func_get_args();
return call_user_func_array(array($this->_handler, 'setFetchMode'), $params);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
* @return int
*/
public function columnCount()
{
try {
return $this->_handler->columnCount();
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
* @return int
*/
public function rowCount()
{
try {
return $this->_handler->rowCount();
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
* @param int $col
* @return mixed
*/
public function fetch($style = null, $orientation = Database\ConnectionManager::FETCH_ORI_NEXT, $cursorOffset = 0)
{
try {
$result = $this->_handler->fetch($style, $orientation, $cursorOffset);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
$this->dispatchEvent(self::EVENT_FETCH, array(
'result' => $result,
'style' => $style,
'orientation' => $orientation,
'offset' => $cursorOffset
));
return $result;
}
/**
* @param string $class
* @param array $config
* @return Wootook\Core\BaseBaseObject
*/
public function fetchObject($class = 'Wootook\\Core\\BaseBaseObject', Array $constructorArgs = array())
{
try {
array_unshift($constructorArgs, $this->app());
$result = $this->_handler->fetchObject($class, $constructorArgs);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
$this->dispatchEvent(self::EVENT_FETCH, array(
'result' => $result,
'style' => Database\ConnectionManager::FETCH_OBJ,
'orientation' => Database\ConnectionManager::FETCH_ORI_NEXT,
'offset' => 0
));
return $result;
}
/**
* @return bool
*/
public function closeCursor()
{
try {
return $this->_handler->closeCursor();
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
* @return bool
*/
public function nextRowset()
{
try {
return $this->_handler->nextRowset();
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
* @return string
*/
public function errorCode()
{
return $this->_handler->errorCode();
}
/**
* @return array
*/
public function errorInfo()
{
return $this->_handler->errorInfo();
}
/**
* @return string
*/
public function errorMessage()
{
$info = $this->_handler->errorInfo();
return $info[2];
}
/**
* @return string
*/
public function errorState()
{
$info = $this->_handler->errorInfo();
return $info[0];
}
}

View file

@ -0,0 +1,387 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Statement;
use Wootook\Core\Database,
Wootook\Core\Database\Adapter,
Wootook\Core\Database\Statement,
Wootook\Core\Database\Sql,
Wootook\Core\Exception as CoreException;
class Pdo
extends Statement
{
/**
* @var \PDOStatement
*/
protected $_handler = null;
/**
* @var string|Sql\Dml
*/
protected $_query = null;
protected function _init($query)
{
$this->_query = $query;
if ($this->_query instanceof Sql\Dml) {
$this->_query->beforePrepare($this);
}
try {
$this->_handler = $this->_adapter->getDriverHandler()->prepare($this->_query);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), null, $e);
}
if ($this->_query instanceof Sql\Dml) {
$this->_query->afterPrepare($this);
}
$this->dispatchEvent(self::EVENT_INIT);
return $this;
}
/**
*
* @param string|int $column
* @param mixed $param
* @param int $type
* @return Statement\Statement
*/
public function bindColumn($column, &$param, $type = null)
{
try {
return $this->_handler->bindColumn($column, $param, $type);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), null, $e);
}
}
/**
*
* @param string|int $parameter
* @param mixed $variable
* @param int $type
* @param int $length
* @param unknown_type $options
* @return Statement\Statement
*/
public function bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
{
try {
return $this->_handler->bindParam($parameter, $variable, $type, $length, $options);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
*
* @param string|int $parameter
* @param mixed $value
* @param int $type
* @return Statement\Statement
*/
public function bindValue($parameter, $value, $type = null)
{
try {
return $this->_handler->bindValue($parameter, $value, $type);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
*
* @param array $params
* @return bool
*/
public function execute(Array $params = null, $asynchronous = false)
{
if ($this->_query instanceof Sql\Dml) {
$this->_query->beforeExecute($this);
}
if ($asynchronous === true) {
throw new CoreException\Database\StatementError($this, 'Asynchronous calls are not available with this driver.');
}
try {
$result = $this->_handler->execute($params);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
if ($this->_query instanceof Sql\Dml) {
$this->_query->afterExecute($this);
}
$this->dispatchEvent(self::EVENT_READY, array(
'result' => $result
));
return $result;
}
/**
*
* @param int $style
* @param int $col
* @return mixed
*/
public function fetchAll($style = null, $col = null)
{
try {
if ($style !== null) {
if ($col !== null) {
$result = $this->_handler->fetchAll($style, $col);
} else {
$result = $this->_handler->fetchAll($style);
}
} else {
$result = $this->_handler->fetchAll($style);
}
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
$this->dispatchEvent(self::EVENT_FETCH_ALL, array(
'result' => $result
));
return $result;
}
/**
*
* @param int $col
* @return mixed
*/
public function fetchColumn($col = 0)
{
try {
$result = $this->_handler->fetchColumn($col);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
$this->dispatchEvent(self::EVENT_FETCH_COL, array(
'result' => $result
));
return $result;
}
/**
*
* @return Database\Adapter\Adapter
*/
public function getAdapter()
{
return $this->_adapter;
}
/**
*
* @param string $key
*/
public function getAttribute($key)
{
try {
return $this->_handler->getAttribute($key);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
*
* @param string $key
* @param mixed $value
* @return Statement\Statement
*/
public function setAttribute($key, $value)
{
try {
return $this->_handler->setAttribute($key, $value);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
* @param unknown_type $mode
* @return Statement\Statement
*/
public function setFetchMode($mode)
{
try {
$params = func_get_args();
return call_user_func_array(array($this->_handler, 'setFetchMode'), $params);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
* @return int
*/
public function columnCount()
{
try {
return $this->_handler->columnCount();
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
* @return int
*/
public function rowCount()
{
try {
return $this->_handler->rowCount();
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
* @param int $col
* @return mixed
*/
public function fetch($style = null, $orientation = Database\ConnectionManager::FETCH_ORI_NEXT, $cursorOffset = 0)
{
try {
$result = $this->_handler->fetch($style, $orientation, $cursorOffset);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
$this->dispatchEvent(self::EVENT_FETCH, array(
'result' => $result,
'style' => $style,
'orientation' => $orientation,
'offset' => $cursorOffset
));
return $result;
}
/**
* @param string $class
* @param array $config
* @return Wootook\Core\BaseBaseObject
*/
public function fetchObject($class = 'Wootook\\Core\\BaseBaseObject', Array $constructorArgs = array())
{
try {
array_unshift($constructorArgs, $this->app());
$result = $this->_handler->fetchObject($class, $constructorArgs);
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
$this->dispatchEvent(self::EVENT_FETCH, array(
'result' => $result,
'style' => Database\ConnectionManager::FETCH_OBJ,
'orientation' => Database\ConnectionManager::FETCH_ORI_NEXT,
'offset' => 0
));
return $result;
}
/**
* @return bool
*/
public function closeCursor()
{
try {
return $this->_handler->closeCursor();
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
* @return bool
*/
public function nextRowset()
{
try {
return $this->_handler->nextRowset();
} catch (\PDOException $e) {
throw new CoreException\Database\StatementError($this, $e->getMessage(), $e->getCode(), $e);
}
}
/**
* @return string
*/
public function errorCode()
{
return $this->_handler->errorCode();
}
/**
* @return array
*/
public function errorInfo()
{
return $this->_handler->errorInfo();
}
/**
* @return string
*/
public function errorMessage()
{
$info = $this->_handler->errorInfo();
return $info[2];
}
/**
* @return string
*/
public function errorState()
{
$info = $this->_handler->errorInfo();
return $info[0];
}
}

View file

@ -0,0 +1,275 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Statement;
use Wootook\Core\Database,
Wootook\Core\Database\Adapter,
Wootook\Core\Event,
Wootook\Core\Exception as CoreException;
abstract class Statement
implements \Iterator
{
use Event\EventTarget;
const EVENT_INIT = 'init';
const EVENT_READY = 'ready';
const EVENT_ERROR = 'error';
const EVENT_FETCH = 'fetch';
const EVENT_FETCH_ALL = 'fetch-all';
const EVENT_FETCH_COL = 'fetch-column';
protected $_adapter = null;
protected $_currentIndex = 0;
protected $_currentRow = null;
protected $_asynchronousCallbacks = array();
public function __construct(Adapter\Adapter $adapter, $sql)
{
$this->_adapter = $adapter;
$this->_init($sql);
}
abstract protected function _init($sql);
/**
*
* @param string|int $column
* @param mixed $param
* @param int $type
* @return Statement
*/
abstract public function bindColumn($column, &$param, $type = null);
/**
*
* @param string|int $parameter
* @param mixed $variable
* @param int $type
* @param int $length
* @param unknown_type $options
* @return Statement
*/
abstract public function bindParam($parameter, &$variable, $type = null, $length = null, $options = null);
/**
*
* @param string|int $parameter
* @param mixed $value
* @param int $type
* @return Statement
*/
abstract public function bindValue($parameter, $value, $type = null);
/**
* @abstract
* @param array|null $params
* @param bool $synchronous
* @return bool
*/
abstract public function execute(Array $params = null, $synchronous = false);
/**
* @abstract
* @param null $style
* @param int $orientation
* @param int $cursorOffset
* @return mixed
*/
abstract public function fetch($style = null, $orientation = Database\ConnectionManager::FETCH_ORI_NEXT, $cursorOffset = 0);
/**
* @param int $style
* @param int $col
* @return mixed
*/
abstract public function fetchAll($style = null, $col = null);
/**
* @param int $col
* @return mixed
*/
abstract public function fetchColumn($col = 0);
/**
*
* @param string $class
* @param array $config
* @return \Wootook\Core\Base\BaseObject
*/
abstract public function fetchObject($class = 'Wootook\\Core\\Base\\BaseObject', Array $constructorArgs = array());
/**
*
* @param string $class
* @param array $config
* @return \Wootook\Core\Mvc\Model\Entity
*/
public function fetchEntity($class = 'Wootook\\Core\\Mvc\\Model\\Entity', Array $constructorArgs = array())
{
$reflection = new ReflectionClass($class);
$object = $reflection->newInstanceArgs($constructorArgs);
if (!$object instanceof Wootook\Core\Mvc\Model\Entity) {
throw new CoreException\Database\StatementError($this, 'Destination object should be a Wootook\\Core\\Mvc\\Model\\Entity instance.');
}
$data = $this->fetch(Database\ConnectionManager::FETCH_ASSOC);
$object->getDataMapper()->decode($object, $data);
return $object;
}
/**
*
* @return \Wootook\Core\Database\Adapter\Adapter
*/
abstract public function getAdapter();
/**
* @param mixed $key
*/
abstract public function getAttribute($key);
/**
* @param string $key
* @param mixed $value
* @return Statement
*/
abstract public function setAttribute($key, $value);
/**
* @param int $mode
* @return Statement
*/
abstract public function setFetchMode($mode);
/**
* @return int
*/
abstract public function columnCount();
/**
* @return string
*/
abstract public function errorCode();
/**
* @return string
*/
abstract public function errorMessage();
/**
* @return array
*/
abstract public function errorInfo();
/**
* @return string
*/
abstract public function errorState();
/**
* @return int
*/
abstract public function rowCount();
/**
* @return bool
*/
abstract public function closeCursor();
/**
* @return bool
*/
abstract public function nextRowset();
/**
* @param mixed $value
* @return int|null
*/
public function getParamType($value)
{
if (is_numeric($value)) {
return Database\ConnectionManager::PARAM_INT;
} else if (is_bool($value)) {
return Database\ConnectionManager::PARAM_BOOL;
} else if (is_string($value)) {
return Database\ConnectionManager::PARAM_STR;
}
return null;
}
/**
* @return null|mixed
*/
public function current()
{
return $this->_currentRow;
}
/**
* @return void
*/
public function next()
{
$this->_currentRow = $this->fetch();
$this->_currentIndex++;
}
/**
* @return int
*/
public function key()
{
return $this->_currentIndex;
}
/**
* @return int
*/
public function rewind()
{
return $this->_currentIndex;
}
/**
* @return bool
*/
public function valid()
{
return $this->_currentIndex < $this->rowCount() && $this->_currentIndex >= 0;
}
}

View file

@ -0,0 +1,39 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\DateTime;
/**
* Date interval management class
*/
class DateInterval
extends \DateInterval
{
}

View file

@ -0,0 +1,39 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\DateTime;
/**
* Date period management class
*/
class DatePeriod
extends \DatePeriod
{
}

View file

@ -0,0 +1,226 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\DateTime;
use Wootook\Core\Exception as CoreException;
/**
* Date period management class
*/
class DateTime
extends \DateTime
{
/**
* @var Formatter
*/
protected $_formatter = null;
/**
* @param string|int $dateTime
* @param null|DateTimeZone $timeZone
* @param Formatter $formatter
*/
public function __construct($dateTime = null, DateTimeZone $timeZone = null, Formatter $formatter = null, $useIntlParsing = true)
{
if ($formatter === null || $useIntlParsing === false) {
parent::__construct($dateTime, $timeZone);
} else {
parent::__construct();
$this->setTimestamp($formatter->parse($dateTime));
}
$this->_formatter = $formatter;
}
/**
* @param Formatter $formatter
* @return DateTime
*/
public function setFormatter(Formatter $formatter)
{
$this->_formatter = $formatter;
return $this;
}
/**
* @return null|Formatter
*/
public function getFormatter()
{
return $this->_formatter;
}
/**
* @param string|int $dateTime
* @param Formatter $formatter
* @param null|DateTimeZone $timeZone
*/
public function set($dateTime, DateTimeZone $timeZone = null, Formatter $formatter)
{
if ($formatter === null) {
$this->setTimestamp(strtotime($dateTime));
} else {
$this->setTimestamp($formatter->parse($dateTime));
}
return $this;
}
/**
* @param DateTime $dateTime
* @return bool
*/
public function isEarlier(\DateTime $dateTime)
{
return $this < $dateTime;
}
/**
* @param DateTime $dateTime
* @return bool
*/
public function isLater(\DateTime $dateTime)
{
return $this > $dateTime;
}
/**
* @param DateTime $dateTime
* @return bool
*/
public function isToday(\DateTime $today = null)
{
if ($today === null) {
$today = new self(null, $this->getTimezone());
} else {
$today = clone $today;
}
$today->setTime(0, 0, 0);
if ($this->isEarlier($today)) {
return false;
}
$today->setTime(23, 59, 59);
if ($this->isLater($today)) {
return false;
}
return true;
}
/**
* @param DateTime $dateTime
* @return bool
*/
public function isTomorrow(\DateTime $tomorrow = null)
{
if ($tomorrow === null) {
$tomorrow = new self(null, $this->getTimezone());
} else {
$tomorrow = clone $tomorrow;
}
$tomorrow->add(new \DateInterval('P1D'));
$tomorrow->setTime(0, 0, 0);
if ($this->isEarlier($tomorrow)) {
return false;
}
$tomorrow->setTime(23, 59, 59);
if ($this->isLater($tomorrow)) {
return false;
}
return true;
}
/**
* @param DateTime $dateTime
* @return bool
*/
public function isYesterday(\DateTime $yesterday = null)
{
if ($yesterday === null) {
$yesterday = new self(null, $this->getTimezone());
} else {
$yesterday = clone $yesterday;
}
$yesterday->sub(new \DateInterval('P1D'));
$yesterday->setTime(0, 0, 0);
if ($this->isEarlier($yesterday)) {
return false;
}
$yesterday->setTime(23, 59, 59);
if ($this->isLater($yesterday)) {
return false;
}
return true;
}
/**
* @param null|Formatter $formatter
* @param string $pattern
* @return string
*/
public function toString(Formatter $formatter = null, $pattern = null)
{
if ($formatter === null) {
$formatter = $this->_formatter;
}
if ($formatter === null) {
return null;
}
if ($pattern !== null) {
$formatter = clone $this->_formatter;
$formatter->setPattern($pattern);
return $formatter->format($this);
}
return $this->_formatter->format($this);
}
/**
* @param DateTime $dateTime
* @return bool
*/
public function __toString()
{
return $this->toString();
}
}

View file

@ -0,0 +1,343 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\DateTime;
/**
* Date and time management class
* @todo : refactor to be compatible with \DateTime
*/
class DateTime
{
const ISO_8601 = 'c';
const YEAR = 'year';
const YEAR_ISO = 'year_iso';
const MONTH = 'mon';
const DAY = 'mday';
const WEEK = 'week';
const WEEKDAY = 'wday';
const HOUR = 'hours';
const MINUTE = 'minutes';
const SECOND = 'seconds';
const MICROSECOND = 'microsecond';
const DAYLIGHT = 'daylight';
const MERIDIEM = 'meridiem';
const MERIDIEM_AM = 'am';
const MERIDIEM_PM = 'pm';
const TIMESTAMP = 'timestamp';
const PARSER = 'cb';
const OPERATOR_ADD = '+';
const OPERATOR_SUB = '-';
const OPERATOR_SET = '=';
protected static $_rules = array(
'd' => array(self::DAY => '#(0[1-9]|[12][0-9]|3[01])#'),
'j' => array(self::DAY => '#([1-9]|[12][0-9]|3[01])#'),
'D' => array(self::WEEKDAY => '#(Mon|Tue|Wed|Thu|Fri|Sat|Sun)#i', self::PARSER => '_parseShortWeekday'),
'N' => array(self::WEEKDAY => '#([1-7])#', self::PARSER => '_parseWeekday'),
'w' => array(self::WEEKDAY => '#([0-6])#'),
'm' => array(self::MONTH => '#(0[1-9]|1[0-2])#'),
'M' => array(self::MONTH => '#(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)#i', self::PARSER => '_parseShortMonth'),
'n' => array(self::MONTH => '#([1-9]|1[0-2])#'),
'o' => array(self::YEAR_ISO => '#([0-9]{4})#'),
'Y' => array(self::YEAR => '#([0-9]{4})#'),
'y' => array(self::YEAR => '#([0-9]{2})#', self::PARSER => '_parseShortYear'),
'a' => array(self::MERIDIEM => '#(am|pm)#', self::PARSER => '_parseMeridiem'),
'A' => array(self::MERIDIEM => '#(AM|PM)#', self::PARSER => '_parseMeridiem'),
'g' => array(self::HOUR => '#([0-9]{1,2})#'),
'G' => array(self::HOUR => '#([0-9]{1,2})#'),
'h' => array(self::HOUR => '#([0-9]{2})#'),
'H' => array(self::HOUR => '#([0-9]{2})#'),
'i' => array(self::MINUTE => '#([0-9]{2})#'),
's' => array(self::SECOND => '#([0-9]{2})#'),
'u' => array(self::MICROSECOND => '#([0-9]{6})#'),
'I' => array(self::DAYLIGHT => '#(0|1)#'),
// Unimplemented and ignored modifiers
'l' => array(null => '#.#'),
'S' => array(null => '#.#'),
'z' => array(null => '#.#'),
'W' => array(null => '#.#'),
'f' => array(null => '#.#'),
't' => array(null => '#.#'),
'L' => array(null => '#.#'),
'O' => array(null => '#.#'),
'P' => array(null => '#.#'),
'T' => array(null => '#.#'),
'Z' => array(null => '#.#'),
'c' => array(null => '#.#'),
'r' => array(null => '#.#'),
'U' => array(null => '#.#')
);
protected $_datetime = null;
protected $_timezone = null;
public static function init($timezone = null, $force = false)
{
static $init = false;
if ($init === false || $force === true) {
if ($timezone === null) {
//$timezone = \Wootook::app()->getGlobalConfig('system/date/timezone');
}
if ($timezone === null) {
$timezone = 'UTC';
}
date_default_timezone_set($timezone);
$init = true;
}
}
/**
* @param null|string|int $timestamp
* @param string $format
*/
public function __construct($timestamp = null, $format = null, $timezone = 'UTC')
{
self::init();
if ($timestamp === null) {
$this->_datetime = time();
} else if ($format === null) {
$this->_datetime = intval($timestamp);
} else {
$this->_datetime = $this->_parse($timestamp, $format);
}
$this->_timezone = $timezone;
}
public function getIso($useTimezone = false)
{
return $this->toString(self::ISO_8601, $useTimezone);
}
public function getTimestamp()
{
return $this->_datetime;
}
public function now()
{
return $this->calc(time(), self::TIMESTAMP, self::OPERATOR_SET);
}
public function set($value, $part = self::TIMESTAMP)
{
return $this->calc($value, $part, self::OPERATOR_SET);
}
public function add($value, $part = self::TIMESTAMP)
{
return $this->calc($value, $part, self::OPERATOR_ADD);
}
public function sub($value, $part = self::TIMESTAMP)
{
return $this->calc($value, $part, self::OPERATOR_SUB);
}
public function calc($value, $part = self::TIMESTAMP, $type = self::OPERATOR_ADD)
{
switch ($part) {
case self::YEAR:
case self::MONTH:
case self::WEEK:
case self::DAY:
case self::HOUR:
case self::MINUTE:
case self::SECOND:
$current = getdate($this->_datetime);
if ($type === self::OPERATOR_ADD) {
$current[$part] += $value;
} else if ($type === self::OPERATOR_SUB) {
$current[$part] -= $value;
} else if ($type === self::OPERATOR_SET) {
$current[$part] = $value;
}
$this->_datetime = $this->_mktime($current);
break;
case self::TIMESTAMP:
if ($type === self::OPERATOR_ADD) {
$this->_datetime += intval($value);
} else if ($type === self::OPERATOR_SUB) {
$this->_datetime -= intval($value);
} else if ($type === self::OPERATOR_SET) {
$this->_datetime = intval($value);
}
break;
// default: break; // omitted
}
return $this;
}
public function diff(self $date)
{
return $this->_datetime - $date->_datetime;
}
public function isEarlier(self $date = null)
{
if ($date === null) {
$date = new self();
}
return (bool) ($this->diff($date) > 0);
}
public function isLater(self $date = null)
{
if ($date === null) {
$date = new self();
}
return (bool) ($this->diff($date) < 0);
}
protected function _mktime(Array $parts)
{
return mktime($parts[self::HOUR], $parts[self::MINUTE], $parts[self::SECOND],
$parts[self::MONTH], $parts[self::DAY], $parts[self::YEAR]);
}
public function toString($format, $useTimezone = true)
{
if ($useTimezone) {
return date($format, $this->_datetime);
} else {
return gmdate($format, $this->_datetime);
}
}
public function __toString()
{
return $this->toString(self::ISO_8601, false);
}
protected function _parseShortYear($match)
{
$year = intval($match);
if ($year < 70) {
$year += 2000;
} else if ($year < 100) {
$year += 1900;
}
return $year;
}
protected function _parseShortMonth($match)
{
return 1 + array_search(strtolower($match), array('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'));
}
protected function _parseShortWeekday($match)
{
return array_search(strtolower($match), array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'));
}
protected function _parseWeekday($match)
{
return intval($match) % 7;
}
protected function _parseMeridiem($match)
{
return strtolower($match);
}
protected function _parse($datetime, $format)
{
$parts = array(
self::YEAR => false,
self::YEAR_ISO => false,
self::MONTH => false,
self::DAY => false,
self::WEEKDAY => false,
self::HOUR => false,
self::MINUTE => false,
self::SECOND => false,
self::MICROSECOND => false,
self::DAYLIGHT => false,
self::MERIDIEM => false,
);
$offset = 0;
$length = strlen($format);
for ($i = 0; $i < $length; $i++) {
$modifier = $format[$i];
if (!isset(self::$_rules[$modifier])) {
$offset = (strpos($datetime, $format[$i], $offset)) + 1;
continue;
}
$rule = self::$_rules[$modifier];
$callback = null;
if (isset($rule[self::PARSER])) {
$callback = $rule[self::PARSER];
unset($rule[self::PARSER]);
}
foreach ($rule as $part => $regex) {
if (!preg_match($regex, $datetime, $matches, null, $offset)) {
continue;
}
if ($callback === null) {
$parts[$part] = intval($matches[1]);
} else if (is_callable($callback)) {
$parts[$part] = call_user_func($callback, $matches[1]);
} else {
$parts[$part] = $this->$callback($matches[1]);
}
$offset += strlen($matches[1]);
}
}
if ($parts[self::MERIDIEM] !== false && $parts[self::MERIDIEM] === self::MERIDIEM_PM) {
$parts[self::HOUR] = ($parts[self::HOUR] + 12) % 24;
}
if ($parts[self::YEAR] !== false || $parts[self::YEAR_ISO] === false) {
return $this->_mktime($parts);
} else {
return $this->_mktime($parts);
}
}
}

View file

@ -0,0 +1,39 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\DateTime;
/**
* Date time zone management class
*/
class DateTimeZone
extends \DateTimeZone
{
}

View file

@ -0,0 +1,39 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\DateTime;
/**
* Date formatter and parser
*/
class Formatter
extends \IntlDateFormatter
{
}

View file

@ -0,0 +1,129 @@
<?php
namespace Wootook\Core\DependencyInjection\Definition;
use Wootook\Core\Base\Service,
Wootook\Core\Config,
Wootook\Core\DependencyInjection,
Wootook\Core\Exception as CoreException;
class ArgumentDefinition
{
const TYPE_VALUE = 0x01;
const TYPE_VARIABLE = 0x02;
const TYPE_REGISTRY = 0x03;
/**
* @var ClassDefinition
*/
protected $_methodDefinition = null;
/**
* @var string
*/
protected $_argumentName = null;
/**
* @var \ReflectionParameter
*/
protected $_reflector = null;
/**
* @var array
*/
protected $_value = null;
/**
* @var array
*/
protected $_type = null;
/**
* @var null|\Wootook\Core\DependencyInjection\Registry
*/
protected $_registry = null;
/**
* @param ClassDefinition $classDefinition
* @param $methodName
* @param null|\Wootook\Core\DependencyInjection\Registry $registry
*/
public function __construct(MethodDefinition $methodDefinition, $argumentName, DependencyInjection\Registry $registry = null)
{
$this->_methodDefinition = $methodDefinition;
$this->_argumentName = $argumentName;
try {
$this->setReflector($methodDefinition->getArgumentReflector($argumentName));
} catch (\ReflectionException $e) {
throw new CoreException\DependencyInjection\BadMethodCallException($e->getMessage(), $e->getCode(), $e);
}
$this->_registry = $registry;
}
public function setRegistry(DependencyInjection\Registry $registry)
{
$this->_registry = $registry;
return $this;
}
public function getRegistry()
{
return $this->_registry;
}
public function bindValue($argumentValue)
{
$this->_value = $argumentValue;
$this->_type = self::TYPE_VALUE;
return $this;
}
public function bindVariable(&$argumentVariable)
{
$this->_value = &$argumentVariable;
$this->_type = self::TYPE_VARIABLE;
return $this;
}
public function bindRegistryEntry($registryKey)
{
$this->_value = $registryKey;
$this->_type = self::TYPE_REGISTRY;
return $this;
}
public function getReflector()
{
return $this->_reflector;
}
public function setReflector(\ReflectionParameter $reflector)
{
$this->_reflector = $reflector;
return $this;
}
public function compileInto(Array &$compiledArgs)
{
$position = $this->getReflector()->getPosition();
if ($this->_type === self::TYPE_VALUE) {
$compiledArgs[$position] = $this->_value;
} else if ($this->_type === self::TYPE_VARIABLE) {
$compiledArgs[$position] = &$this->_value;
} else if ($this->_type === self::TYPE_REGISTRY) {
if (($registry = $this->getRegistry()) === null) {
throw new CoreException\DependencyInjection\RuntimeException('No registry available');
}
$compiledArgs[$position] = $registry->get($this->_value);
}
}
}

View file

@ -0,0 +1,121 @@
<?php
namespace Wootook\Core\DependencyInjection\Definition;
use Wootook\Core\Base\Service,
Wootook\Core\Config,
Wootook\Core\DependencyInjection,
Wootook\Core\Exception as CoreException;
class ClassDefinition
{
protected $_className = null;
protected $_reflector = null;
protected $_methods = array();
protected $_methodDefinitionHandlerClass = null;
/**
* @param string $className
* @param null|string $methodDefinitionHandlerClass
*/
public function __construct($className, $methodDefinitionHandlerClass = null)
{
$this->_className = $className;
try {
$this->_reflector = new \ReflectionClass($className);
} catch (\ReflectionException $e) {
throw new CoreException\DependencyInjection\BadMethodCallException($e->getMessage(), $e->getCode(), $e);
}
if (is_string($methodDefinitionHandlerClass)) {
$this->_methodDefinitionHandlerClass = $methodDefinitionHandlerClass;
} else {
$this->_methodDefinitionHandlerClass = __NAMESPACE__ . '\\MethodDefinition';
}
}
/**
* @param string $methodName
* @return \Wootook\Core\DependencyInjection\Definition\MethodDefinition
*/
protected function _getMethodDefinitionInstance($methodName)
{
return new $this->_methodDefinitionHandlerClass($this, $methodName);
}
/**
* @param string $methodName
* @return \Wootook\Core\DependencyInjection\Definition\MethodDefinition
* @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException
*/
public function getMethodDefinition($methodName)
{
if (!is_string($methodName)) {
throw new CoreException\DependencyInjection\InvalidArgumentException('Method names only accept string.');
}
if (!isset($this->_methods[$methodName])) {
$this->_methods[$methodName] = $this->_getMethodDefinitionInstance($methodName);
}
return $this->_methods[$methodName];
}
public function setMethodDefinition($methodName, MethodDefinition $definition)
{
if (!is_string($methodName)) {
throw new CoreException\DependencyInjection\InvalidArgumentException('Method names only accept string.');
}
$this->_methods[$methodName] = $definition;
return $this;
}
public function getAllMethodDefinitions()
{
return $this->_methods;
}
public function newInstance(Array $args = array(), $withoutConstructorCall = false)
{
try {
if ($this->getReflector()->hasMethod('__construct')) {
$methodDefinition = $this->getMethodDefinition('__construct');
return $this->getReflector()->newInstanceArgs($methodDefinition->compileArgs($args));
} else {
return $this->getReflector()->newInstance();
}
} catch (\ReflectionException $e) {
throw new CoreException\DependencyInjection\RuntimeException('Could not instantiate class : constructor may be non-public.', null, $e);
}
}
public function newInstanceWithoutConstructor()
{
try {
return $this->getReflector()->newInstanceWithoutConstructor();
} catch (\ReflectionException $e) {
throw new CoreException\DependencyInjection\RuntimeException('Could not instantiate class : may be a PHP-internal class.', null, $e);
}
}
public function reset()
{
return $this->_methods = array();
}
public function getReflector()
{
return $this->_reflector;
}
public function setReflector(\ReflectionClass $reflector)
{
$this->_reflector = $reflector;
return $this;
}
}

View file

@ -0,0 +1,197 @@
<?php
namespace Wootook\Core\DependencyInjection\Definition;
use Wootook\Core\Base\Service,
Wootook\Core\Config,
Wootook\Core\DependencyInjection,
Wootook\Core\Exception as CoreException;
class MethodDefinition
{
/**
* @var ClassDefinition
*/
protected $_classDefinition = null;
/**
* @var string
*/
protected $_methodName = null;
/**
* @var \ReflectionMethod
*/
protected $_reflector = null;
/**
* @var array
*/
protected $_arguments = array();
/**
* @var array
*/
protected $_argumentIndex = array();
/**
* @var array
*/
protected $_argumentReflectors = array();
/**
* @var null|\Wootook\Core\DependencyInjection\Registry
*/
protected $_registry = null;
protected $_argumentDefinitionHandlerClass = null;
/**
* @param ClassDefinition $classDefinition
* @param $methodName
* @param null|\Wootook\Core\DependencyInjection\Registry $registry
*/
public function __construct(ClassDefinition $classDefinition, $methodName, DependencyInjection\Registry $registry = null, $argumentDefinitionHandlerClass = null)
{
$this->_classDefinition = $classDefinition;
$this->_methodName = $methodName;
try {
$this->setReflector($classDefinition->getReflector()->getMethod($methodName));
} catch (\ReflectionException $e) {
throw new CoreException\DependencyInjection\BadMethodCallException($e->getMessage(), $e->getCode(), $e);
}
if (is_string($argumentDefinitionHandlerClass)) {
$this->_argumentDefinitionHandlerClass = $argumentDefinitionHandlerClass;
} else {
$this->_argumentDefinitionHandlerClass = __NAMESPACE__ . '\\ArgumentDefinition';
}
$this->_registry = $registry;
}
protected function _getArgumentDefinitionInstance($argumentPosition)
{
return new $this->_argumentDefinitionHandlerClass($this, $argumentPosition);
}
public function setRegistry(DependencyInjection\Registry $registry)
{
$this->_registry = $registry;
return $this;
}
public function getRegistry()
{
return $this->_registry;
}
public function bindArgumentValue($argumentPosition, $argumentValue)
{
if (is_numeric($argumentPosition)) {
$this->_arguments[$argumentPosition] = $argumentValue;
} else if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) {
$this->_arguments[$this->_argumentIndex[$argumentPosition]] = $argumentValue;
} else {
throw new CoreException\DependencyInjection\InvalidArgumentException('No such argument');
}
return $this;
}
public function bindArgumentVariable($argumentPosition, &$argumentVariable)
{
if (is_numeric($argumentPosition)) {
if (is_object($argumentVariable)) {
$this->_arguments[$argumentPosition] = $argumentVariable;
} else {
$this->_arguments[$argumentPosition] = &$argumentVariable;
}
} else if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) {
if (is_object($argumentVariable)) {
$this->_arguments[$this->_argumentIndex[$argumentPosition]] = $argumentVariable;
} else {
$this->_arguments[$this->_argumentIndex[$argumentPosition]] = &$argumentVariable;
}
} else {
throw new CoreException\DependencyInjection\InvalidArgumentException('No such argument');
}
return $this;
}
public function bindArgumentRegistry($argumentPosition, $argumentKey)
{
if (($registry = $this->getRegistry()) === null) {
throw new CoreException\DependencyInjection\RuntimeException('No registry available');
}
if (is_numeric($argumentPosition)) {
$this->_arguments[$argumentPosition] = $argumentVariable;
} else if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) {
$this->_arguments[$this->_argumentIndex[$argumentPosition]] = $argumentVariable;
} else {
throw new CoreException\DependencyInjection\InvalidArgumentException('No such argument');
}
return $this;
}
public function getArgumentDefinition($argumentPosition)
{
if (is_numeric($argumentPosition)) {
if (!isset($this->_arguments[$argumentPosition])) {
$this->_arguments[$argumentPosition] = $this->_getArgumentDefinitionInstance($argumentPosition);
}
return $this->_arguments[$argumentPosition];
} else if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) {
if (!isset($this->_arguments[$this->_argumentIndex[$argumentPosition]])) {
$this->_arguments[$this->_argumentIndex[$argumentPosition]] = $this->_getArgumentDefinitionInstance($this->_argumentIndex[$argumentPosition]);
}
return $this->_arguments[$this->_argumentIndex[$argumentPosition]];
} else {
throw new CoreException\InvalidArgumentException('Argument not found.');
}
}
public function getAllArgumentDefinitions()
{
return $this->_arguments;
}
public function getReflector()
{
return $this->_reflector;
}
public function setReflector(\ReflectionMethod $reflector)
{
$this->_reflector = $reflector;
foreach ($this->_reflector->getParameters() as $argumentReflector) {
$argumentName = $argumentReflector->getName();
$argumentPosition = $argumentReflector->getPosition();
$this->_argumentIndex[$argumentName] = $argumentPosition;
$this->_argumentReflectors[$argumentPosition] = $argumentReflector;
}
return $this;
}
public function getArgumentReflector($argumentPosition)
{
if (is_numeric($argumentPosition)) {
return $this->_argumentReflectors[$argumentPosition];
} else if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) {
return $this->_argumentReflectors[$this->_argumentIndex[$argumentPosition]];
} else {
throw new CoreException\DependencyInjection\InvalidArgumentException('No such argument');
}
}
}

View file

@ -0,0 +1,91 @@
<?php
namespace Wootook\Core\DependencyInjection;
use Wootook\Core\Base\Service,
Wootook\Core\Exception as CoreException,
Wootook\Core\Config;
class Factory
{
use Service\App;
protected $_registry = null;
protected $_definitions = array();
protected function _construct(Config\Node $config, Registry $registry = null)
{
if ($registry !== null) {
$this->setRegistry($registry);
}
foreach ($config as $className => $constructorArguments) {
$definition = $this->getDefinition($className);
if ($constructorArguments === null) {
continue;
}
foreach ($constructorArguments as $argumentId => $argumentConfig) {
$argumentType = key($argumentConfig);
$argumentValue = key($argumentConfig);
$definition->addConstructorArgument($argumentId, $argumentType, $argumentValue);
}
}
}
public function setRegistry(Registry $registry)
{
$this->_registry = $registry;
return $this;
}
public function getRegistry()
{
if ($this->_registry === null) {
$this->_registry = new Registry($this->app());
}
return $this->_registry;
}
public function getDefinition($className)
{
if (!isset($this->_definitions[$className])) {
$this->_definitions[$className] = new Definition\ClassDefinition($className);
}
return $this->_definitions[$className];
}
public function get($className, Array $additionalArguments = array())
{
$definition = $this->getDefinition($className);
try {
$reflectionClass = new \ReflectionClass($className);
} catch (\ReflectionException $e) {
throw new CoreException\RuntimeException(sprintf('Class "%s" not found', $className), null, $e);
}
if (!$reflectionClass->hasMethod('__construct')) {
return $reflectionClass->newInstance();
}
try {
$reflectionMethod = $reflectionClass->getMethod('__construct');
} catch (\ReflectionException $e) {
throw new CoreException\RuntimeException(sprintf('Class "%s" has no contructor', $className), null, $e);
}
$constructorArguments = $definition->prepareArguments($reflectionMethod, $this->getRegistry(), $additionalArguments);
try {
return $reflectionClass->newInstanceArgs($constructorArguments);
} catch (\ReflectionException $e) {
throw new CoreException\RuntimeException(sprintf('Class "%s" could not be instanciated', $className), null, $e);
}
}
}

View file

@ -0,0 +1,60 @@
<?php
namespace Wootook\Core\DependencyInjection;
use Wootook\Core\Base\Service,
Wootook\Core\Config,
Wootook\Core\Exception as CoreException;
class Registry
{
use Service\App;
protected $_instances = array();
protected function _construct()
{
}
public function clear()
{
$this->_instances = array();
return $this;
}
public function add($identifier, $value)
{
if ($this->has($identifier)) {
throw new CoreException\RuntimeException('Instance already exists.');
}
$this->set($identifier, $value);
}
public function set($identifier, $value)
{
if (isset($this->_instances[$identifier])) {
throw new CoreException\BadMethodCallException;
}
$this->_instances[$identifier] = $value;
return $this;
}
public function get($identifier)
{
return $this->_instances[$identifier];
}
public function delete($identifier)
{
unset($this->_instances[$identifier]);
return $this;
}
public function has($identifier)
{
return isset($this->_instances[$identifier]);
}
}

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