From d75265a8feeb530e8c1ade5fccf183f9ab91f917 Mon Sep 17 00:00:00 2001 From: Gregory PLANCHAT Date: Thu, 12 Jul 2012 02:37:05 +0200 Subject: [PATCH 01/14] 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 --- .gitmodules | 3 + src/.htaccess | 3 + src/add_declare.php | 2 +- src/admin/ElementQueueFixer.php | 4 +- src/admin/QueryExecute.php | 4 +- src/admin/ShowFlyingFleets.php | 2 +- src/admin/XNovaResetUnivers.php | 4 +- src/admin/activeplanet.php | 2 +- src/admin/add_fleet.php | 2 +- src/admin/add_money.php | 2 +- src/admin/add_moon.php | 4 +- src/admin/autounban.php | 2 +- src/admin/banned.php | 4 +- src/admin/changelog.php | 4 +- src/admin/chat.php | 4 +- src/admin/credit.php | 4 +- src/admin/declare_list.php | 4 +- src/admin/deletuser.php | 4 +- src/admin/errors.php | 2 +- src/admin/leftmenu.php | 2 +- src/admin/md5changepass.php | 4 +- src/admin/md5enc.php | 4 +- src/admin/messagelist.php | 2 +- src/admin/messall.php | 4 +- src/admin/moonlist.php | 4 +- src/admin/multi.php | 4 +- src/admin/overview.php | 2 +- src/admin/paneladmina.php | 2 +- src/admin/planetlist.php | 4 +- src/admin/settings.php | 2 +- src/admin/statbuilder.php | 2 +- src/admin/unbanned.php | 4 +- src/admin/userlist.php | 4 +- src/admin/variables.php | 2 +- src/alliance.php | 4 +- src/annonce.php | 2 +- src/annonce2.php | 4 +- src/application/bc.php | 103 + src/application/bootstrap.php | 98 +- .../Empire/Block/Planet/ResearchLab/Item.php | 4 +- .../Block/Planet/ResearchLab/Queue/Item.php | 2 +- .../Empire/Block/Planet/Shipyard/Item.php | 2 +- .../Block/Planet/Shipyard/Queue/Item.php | 2 +- .../Planet/Building/ResearchLab/Builder.php | 4 +- .../Planet/Building/Shipyard/Builder.php | 2 +- src/application/code/core/Wootook.php | 676 +++---- .../code/core/Wootook/Core/App.php | 155 -- .../code/core/Wootook/Core/Block/Concat.php | 14 - .../core/Wootook/Core/Block/Deprecated.php | 10 - .../core/Wootook/Core/Block/Html/Form.php | 11 - .../core/Wootook/Core/Block/Html/Home.php | 22 - .../Core/Block/Html/Navigation/Node.php | 27 - .../core/Wootook/Core/Block/Html/Page.php | 19 - .../code/core/Wootook/Core/Block/Messages.php | 47 - .../code/core/Wootook/Core/Block/Template.php | 46 - .../code/core/Wootook/Core/Block/Text.php | 28 - .../Wootook/Core/Config/Adapter/Adapter.php | 6 - .../Wootook/Core/Config/Adapter/Array.php | 35 - .../Core/Controller/ErrorController.php | 11 - .../Core/Controller/IndexController.php | 11 - .../Wootook/Core/Database/Adapter/Adapter.php | 199 -- .../Core/Database/Adapter/Pdo/Mysql.php | 170 -- .../Core/Database/Orm/DataMapper/Array.php | 15 - .../Core/Database/Orm/DataMapper/Config.php | 15 - .../Core/Database/Orm/DataMapper/DateTime.php | 38 - .../Database/Orm/DataMapper/FieldMapper.php | 15 - .../Core/Database/Orm/DataMapper/Object.php | 43 - .../core/Wootook/Core/Database/Resource.php | 89 - .../core/Wootook/Core/Database/Sql/Dml.php | 24 - .../Wootook/Core/Database/Sql/DmlQuery.php | 107 - .../Core/Database/Sql/Mysql/Select.php | 6 - .../Database/Sql/Placeholder/Expression.php | 30 - .../Core/Database/Sql/Placeholder/Param.php | 31 - .../Database/Sql/Placeholder/Placeholder.php | 31 - .../Database/Sql/Placeholder/Variable.php | 20 - .../Core/Database/Statement/Pdo/Mysql.php | 321 --- .../Core/Database/Statement/Statement.php | 215 -- .../code/core/Wootook/Core/Email.php | 51 - .../core/Wootook/Core/Email/Part/Part.php | 16 - .../Core/Email/Transport/Transport.php | 22 - .../code/core/Wootook/Core/Event/Break.php | 7 - .../Core/Exception/DataAccessException.php | 6 - .../Core/Exception/Database/AdapterError.php | 20 - .../Wootook/Core/Exception/Database/Error.php | 5 - .../Exception/Database/StatementError.php | 20 - .../Wootook/Core/Exception/Deprecated.php | 7 - .../core/Wootook/Core/Exception/Exception.php | 25 - .../core/Wootook/Core/Exception/GameError.php | 7 - .../Core/Exception/LayoutException.php | 6 - .../Core/Exception/RuntimeException.php | 32 - .../Wootook/Core/Exception/WebsiteError.php | 7 - .../core/Wootook/Core/Form/Element/Button.php | 11 - .../core/Wootook/Core/Form/Element/Text.php | 11 - .../core/Wootook/Core/Form/ElementLoader.php | 37 - .../Wootook/Core/Form/Validator/Alnum.php | 21 - .../Wootook/Core/Form/Validator/Alpha.php | 21 - .../Wootook/Core/Form/Validator/Email.php | 21 - .../Wootook/Core/Form/Validator/FormKey.php | 20 - .../core/Wootook/Core/Form/Validator/Hex.php | 22 - .../core/Wootook/Core/Form/Validator/Host.php | 21 - .../Wootook/Core/Form/Validator/Numeric.php | 22 - .../Wootook/Core/Form/Validator/Regex.php | 28 - .../Wootook/Core/Form/ValidatorAbstract.php | 15 - .../Wootook/Core/Form/ValidatorLoader.php | 37 - .../Core/Helper/Config/ConfigHandler.php | 59 - .../Wootook/Core/Helper/Config/Events.php | 56 - .../Wootook/Core/Helper/Config/Modules.php | 47 - .../code/core/Wootook/Core/Model/Config.php | 61 - .../code/core/Wootook/Core/Model/Game.php | 23 - .../core/Wootook/Core/Model/Translator.php | 37 - .../code/core/Wootook/Core/Model/Website.php | 23 - .../Core/Mvc/Controller/Request/Request.php | 35 - .../Core/Mvc/Controller/Response/Response.php | 21 - .../core/Wootook/Core/Mvc/Model/Entity.php | 142 -- .../core/Wootook/Core/Mvc/Model/Model.php | 205 -- .../Core/Setup/Exception/RuntimeException.php | 7 - .../Setup/Exception/VersionStageError.php | 7 - .../Setup/Exception/VersionValueError.php | 7 - .../code/core/Wootook/Core/Setup/Updater.php | 124 -- .../Empire/Block/Overview/DestroyPlanet.php | 28 + .../Empire/Block/Overview/Fleet/List.php | 28 + .../Empire/Block/Overview/Fleet/List/Item.php | 36 +- .../Empire/Block/Overview/RenamePlanet.php | 28 + .../Block/Planet/Builder/ItemAbstract.php | 28 + .../Planet/Builder/Queue/ItemAbstract.php | 28 + .../Block/Planet/Builder/QueueAbstract.php | 28 + .../Empire/Block/Planet/BuilderAbstract.php | 28 + .../Wootook/Empire/Block/Planet/Buildings.php | 28 + .../Empire/Block/Planet/Buildings/Item.php | 41 +- .../Empire/Block/Planet/Buildings/Queue.php | 28 + .../Block/Planet/Buildings/Queue/Item.php | 13 +- .../Wootook/Empire/Block/Planet/Overview.php | 28 + .../core/Wootook/Empire/Block/PlanetList.php | 28 + .../code/core/Wootook/Empire/Block/Topnav.php | 28 + .../Empire/Controller/BuildingsController.php | 31 +- .../code/core/Wootook/Empire/Exception.php | 28 + .../Wootook/Empire/Exception/Exception.php | 28 + .../core/Wootook/Empire/Exception/Planet.php | 28 + .../Empire/Exception/RuntimeException.php | 28 + .../Wootook/Empire/Helper/Config/Combat.php | 32 +- .../Empire/Helper/Config/FieldsAlias.php | 32 +- .../Wootook/Empire/Helper/Config/Labels.php | 30 +- .../Wootook/Empire/Helper/Config/Prices.php | 32 +- .../Empire/Helper/Config/Production.php | 32 +- .../Empire/Helper/Config/Requirements.php | 32 +- .../Empire/Helper/Config/Resources.php | 32 +- .../Wootook/Empire/Helper/Config/Types.php | 32 +- .../Wootook/Empire/Model/Builder/Break.php | 28 + .../Wootook/Empire/Model/Builder/Item.php | 38 +- .../Wootook/Empire/Model/BuilderAbstract.php | 28 + .../code/core/Wootook/Empire/Model/Fleet.php | 30 +- .../Wootook/Empire/Model/Galaxy/Position.php | 28 + .../code/core/Wootook/Empire/Model/Planet.php | 74 +- .../Empire/Model/Planet/Builder/Item.php | 28 + .../Empire/Model/Planet/BuildingInterface.php | 28 + .../Empire/Model/Planet/PluginLoader.php | 28 + .../Empire/Model/Planet/QueueInterface.php | 28 + .../Planet/ResourceProductionInterface.php | 28 + .../Empire/Model/Planet/ShipAbstract.php | 28 + .../Empire/Model/Planet/ShipInterface.php | 28 + .../Model/Player/TechnologyInterface.php | 28 + .../Empire/Resource/Fleet/Collection.php | 28 + .../Empire/Resource/Planet/Collection.php | 28 + .../code/core/Wootook/Exception.php | 4 +- .../core/Wootook/Player/Block/Overview.php | 28 + .../code/core/Wootook/Player/Block/TopBar.php | 28 + .../Player/Controller/OverviewController.php | 28 + .../code/core/Wootook/Player/Exception.php | 28 + .../Wootook/Player/Exception/Exception.php | 28 + .../core/Wootook/Player/Exception/Session.php | 28 + .../code/core/Wootook/Player/Model/Entity.php | 35 +- .../core/Wootook/Player/Model/Message.php | 28 + .../core/Wootook/Player/Model/Session.php | 28 + .../Player/Mvc/Controller/Registered.php | 28 + .../Player/Resource/Entity/Collection.php | 28 + .../Player/Resource/Message/Collection.php | 28 + .../code/libraries/Wildfire/Stream.php | 1753 ----------------- src/application/configs/modules/Wootook.php | 17 + src/application/configs/system.php | 2 +- .../backend/base/default/layouts/admin.php | 2 +- .../backend/base/default/layouts/admin.xml | 2 +- .../frontend/base/default/layouts/empire.xml | 2 +- .../base/default/scripts/page/html/home.phtml | 2 +- .../gamedata/legacies/default/events.php | 4 +- .../legacies/default/locale/fr_FR/labels.php | 4 +- .../modules/WootookCore/autoload_classmap.php | 167 ++ .../modules/WootookCore/autoload_function.php | 11 + .../modules/WootookCore/autoload_register.php | 1 + .../WootookCore/config/module.config.php | 52 + .../WootookCore/config}/module.php | 18 +- .../install/mysql5/install-1.5.0.beta2.php} | 0 .../install/mysql5/uninstall-1.5.0.beta2.php} | 0 .../WootookCore/src/Wootook/Core/App/App.php | 498 +++++ .../src/Wootook/Core/Base/BaseObject.php | 68 + .../src/Wootook/Core/Base/DataContainer.php} | 36 +- .../src/Wootook/Core/Base/Service/App.php | 67 + .../src/Wootook/Core/Base}/Singleton.php | 6 +- .../src/Wootook/Core/Block/Concat.php | 46 + .../src/Wootook/Core/Block/Deprecated.php | 40 + .../src/Wootook/Core/Block/Html/Form.php | 41 + .../src}/Wootook/Core/Block/Html/Head.php | 36 +- .../src/Wootook/Core/Block/Html/Home.php | 45 + .../Core/Block/Html/Navigation/Link.php | 36 +- .../Core/Block/Html/Navigation/Menu.php} | 41 +- .../Core/Block/Html/Navigation/Node.php | 57 + .../src/Wootook/Core/Block/Html/Page.php | 51 + .../src/Wootook/Core/Block/Messages.php | 77 + .../src/Wootook/Core/Block/Template.php | 81 + .../src/Wootook/Core/Block/Text.php | 60 + .../src/Wootook/Core/Bootstrap/Module.php | 55 + .../Wootook/Core/Config/Adapter/Adapter.php | 38 + .../Wootook/Core/Config/Adapter/PhpArray.php | 68 + .../src}/Wootook/Core/Config/Node.php | 78 +- .../Core/Controller/ErrorController.php | 43 + .../Core/Controller/IndexController.php | 43 + .../Wootook/Core/Database/Adapter/Adapter.php | 281 +++ .../Wootook/Core/Database/Adapter/Mysql.php | 178 ++ .../src/Wootook/Core/Database/Adapter/Pdo.php | 180 ++ .../Core/Database/Adapter/Pdo/Mysql.php | 63 + .../Core/Database/Adapter/Pdo/Sqlite.php | 60 + .../Core/Database/ConnectionManager.php | 89 +- .../Wootook/Core/Database/Orm/DataMapper.php | 64 +- .../Core/Database/Orm/DataMapper/Config.php | 47 + .../Core/Database/Orm/DataMapper/DateTime.php | 70 + .../Database/Orm/DataMapper/FieldMapper.php | 47 + .../Core/Database/Orm/DataMapper/PhpArray.php | 45 + .../Database/Orm/DataMapper/PhpObject.php | 73 + .../Core/Database/Resource/DataMapper.php | 61 + .../Core/Database/Resource/ReadConnection.php | 72 + .../Database/Resource/WriteConnection.php | 70 + .../Database/Sql/Dml/Condition/Condition.php | 123 ++ .../Sql/Dml/Condition/InListOperator.php | 127 ++ .../Sql/Dml/Condition/LogicalOperator.php | 264 +++ .../Sql/Dml/Condition/MathOperator.php | 136 ++ .../Sql/Dml/Condition/Placeholder.php | 72 + .../Wootook/Core/Database/Sql/Dml}/Delete.php | 34 +- .../src/Wootook/Core/Database/Sql/Dml/Dml.php | 63 + .../Core/Database/Sql/Dml/DmlQuery.php | 162 ++ .../Wootook/Core/Database/Sql/Dml}/Insert.php | 40 +- .../Core/Database/Sql/Dml/Renderer.php | 44 + .../Core/Database/Sql/Dml/Section/Column.php | 72 + .../Database/Sql/Dml/Section/ColumnAware.php | 38 + .../Core/Database/Sql/Dml/Section/From.php | 61 + .../Database/Sql/Dml/Section/FromAware.php | 38 + .../Core/Database/Sql/Dml/Section/Into.php | 44 + .../Database/Sql/Dml/Section/IntoAware.php | 38 + .../Core/Database/Sql/Dml/Section/Limit.php | 42 + .../Database/Sql/Dml/Section/LimitAware.php | 39 + .../Sql/Dml/Section/Renderer/Column.php | 73 + .../Sql/Dml/Section/Renderer/ColumnAware.php | 38 + .../Sql/Dml/Section/Renderer/From.php | 68 + .../Sql/Dml/Section/Renderer/FromAware.php | 38 + .../Sql/Dml/Section/Renderer/Into.php | 48 + .../Sql/Dml/Section/Renderer/IntoAware.php | 38 + .../Sql/Dml/Section/Renderer/Limit.php | 47 + .../Sql/Dml/Section/Renderer/LimitAware.php | 38 + .../Database/Sql/Dml/Section/Renderer/Set.php | 60 + .../Sql/Dml/Section/Renderer/SetAware.php | 38 + .../Sql/Dml/Section/Renderer/Where.php} | 69 +- .../Sql/Dml/Section/Renderer/WhereAware.php | 38 + .../Core/Database/Sql/Dml/Section/Set.php | 63 + .../Database/Sql/Dml/Section/SetAware.php | 38 + .../Core/Database/Sql/Dml/Section/Where.php | 204 ++ .../Database/Sql/Dml/Section/WhereAware.php | 58 + .../Wootook/Core/Database/Sql/Dml}/Select.php | 48 +- .../Wootook/Core/Database/Sql/Dml}/Update.php | 73 +- .../Database/Sql/Placeholder/Expression.php | 62 + .../Core/Database/Sql/Placeholder/Param.php | 63 + .../Database/Sql/Placeholder/Placeholder.php | 63 + .../Database/Sql/Placeholder/Variable.php | 52 + .../Sql/QueryBuilder/QueryBuilder.php | 8 + .../Wootook/Core/Database/Statement/Mysql.php | 390 ++++ .../Wootook/Core/Database/Statement/Pdo.php | 387 ++++ .../Core/Database/Statement/Statement.php | 275 +++ .../Wootook/Core/DateTime/DateInterval.php | 39 + .../src/Wootook/Core/DateTime/DatePeriod.php | 39 + .../src/Wootook/Core/DateTime/DateTime.php | 226 +++ .../Wootook/Core/DateTime/DateTime.php.old} | 64 +- .../Wootook/Core/DateTime/DateTimeZone.php | 39 + .../src/Wootook/Core/DateTime/Formatter.php | 39 + .../Definition/ArgumentDefinition.php | 129 ++ .../Definition/ClassDefinition.php | 121 ++ .../Definition/MethodDefinition.php | 197 ++ .../Core/DependencyInjection/Factory.php | 91 + .../Core/DependencyInjection/Registry.php | 60 + .../src/Wootook/Core/Email/Email.php | 104 + .../src/Wootook/Core/Email/Part/Part.php | 46 + .../Wootook/Core/Email/Transport/Sendmail.php | 43 +- .../Core/Email/Transport/Transport.php | 54 + .../src/Wootook/Core/Event/Break.php | 38 + .../src/Wootook/Core/Event/Event.php | 117 ++ .../src/Wootook/Core/Event/EventTarget.php | 94 + .../Core/Exception/BadMethodCallException.php | 37 + .../Wootook/Core/Exception/CoreException.php | 40 + .../Core/Exception/DataAccessException.php | 36 + .../Core/Exception/Database/AdapterError.php | 53 + .../Wootook/Core/Exception/Database/Error.php | 35 + .../Exception/Database/StatementError.php | 53 + .../BadMethodCallException.php | 39 + .../InvalidArgumentException.php | 39 + .../DependencyInjection/RuntimeException.php | 39 + .../src/Wootook/Core/Exception/Deprecated.php | 37 + .../src/Wootook/Core/Exception/Exception.php | 37 + .../src/Wootook/Core/Exception/GameError.php | 37 + .../Exception/InvalidArgumentException.php | 37 + .../Core/Exception/LayoutException.php | 36 + .../Core/Exception/RuntimeException.php | 37 + .../Wootook/Core/Exception/WebsiteError.php | 37 + .../Core/Form/Element/BaseElement.php} | 43 +- .../src/Wootook/Core/Form/Element/Button.php | 40 + .../src/Wootook/Core/Form/Element/Text.php | 40 + .../src/Wootook/Core/Form/ElementLoader.php | 70 + .../src/Wootook/Core/Form}/Form.php | 106 +- .../src/Wootook/Core/Form/Validator/Alnum.php | 53 + .../src/Wootook/Core/Form/Validator/Alpha.php | 53 + .../Core/Form/Validator/BaseValidator.php | 48 + .../src/Wootook/Core/Form/Validator/Email.php | 53 + .../Wootook/Core/Form/Validator/FormKey.php | 52 + .../src/Wootook/Core/Form/Validator/Hex.php | 54 + .../src/Wootook/Core/Form/Validator/Host.php | 53 + .../Wootook/Core/Form/Validator/Numeric.php | 54 + .../src/Wootook/Core/Form/Validator/Regex.php | 60 + .../src/Wootook/Core/Form/ValidatorLoader.php | 70 + .../Core/Helper/Config/ConfigHandler.php | 93 + .../src/Wootook/Core/Helper/Config/Events.php | 71 + .../Wootook/Core/Helper/Config/Modules.php | 79 + .../src/Wootook/Core/Layout/Manager.php} | 114 +- .../src/Wootook/Core}/Layout/Parser.php | 66 +- .../src/Wootook/Core/Model/Config.php | 93 + .../src/Wootook/Core/Model/Game.php | 139 ++ .../src}/Wootook/Core/Model/Image/Png.php | 34 +- .../src}/Wootook/Core/Model/Session.php | 48 +- .../src/Wootook/Core/Model/Translator.php | 67 + .../src/Wootook/Core/Model/Website.php | 96 + .../Wootook/Core/Mvc/Controller/Action.php | 73 +- .../Wootook/Core/Mvc/Controller/Front.php | 155 +- .../Core/Mvc/Controller/Request/Http.php | 40 +- .../Core/Mvc/Controller/Request/Request.php | 67 + .../Core/Mvc/Controller/Response/Http.php | 38 +- .../Core/Mvc/Controller/Response/Response.php | 53 + .../Core/Mvc/Model/Action/Deletable.php} | 11 +- .../Wootook/Core/Mvc/Model/Action/Delete.php | 75 + .../Wootook/Core/Mvc/Model/Action/Load.php | 77 + .../Core/Mvc/Model/Action/Loadable.php | 39 + .../Core/Mvc/Model/Action/Savable.php} | 10 +- .../Wootook/Core/Mvc/Model/Action/Save.php | 77 + .../src/Wootook/Core/Mvc/Model/Entity.php | 193 ++ .../Core/Mvc/Model/EntityInterface.php | 4 +- .../src/Wootook/Core/Mvc/Model}/SubTable.php | 43 +- .../src/Wootook/Core/Mvc/Model/Type/Base.php | 96 + .../src/Wootook/Core/Mvc/Model/Type/Full.php | 46 + .../Wootook/Core/Mvc/Model/Type/Readonly.php | 46 + .../src}/Wootook/Core/Mvc/View/View.php | 49 +- .../Core/PluginLoader/PluginLoader.php | 46 +- .../Wootook/Core/Profiler}/ErrorProfiler.php | 232 ++- .../src/Wootook/Core/Resource/Entity.php | 36 + .../Core/Resource/EntityCollection.php | 144 +- .../Resource/EntityCollection/Action/Load.php | 144 ++ .../EntityCollection/Action/Loadable.php | 39 + .../Core/Setup/Exception/RuntimeException.php | 40 + .../Setup/Exception/VersionStageError.php | 39 + .../Setup/Exception/VersionValueError.php | 42 + .../src/Wootook/Core/Setup/Updater.php | 159 ++ .../Core/Setup/Updater/ScriptQueue.php | 54 +- .../unit/php/WootookTest/Core/App/AppTest.php | 19 + .../WootookTest/Core/Base/BaseObjectTest.php | 226 +++ .../php/WootookTest/Core/Config/NodeTest.php | 517 +++++ .../Sql/Dml/Condition/ConditionTest.php | 205 ++ .../Sql/Dml/Condition/LogicalOperatorTest.php | 67 + .../Database/Sql/Dml/Section/ColumnMock.php | 13 + .../Database/Sql/Dml/Section/ColumnTest.php | 75 + .../Database/Sql/Dml/Section/FromMock.php | 13 + .../Database/Sql/Dml/Section/FromTest.php | 75 + .../Database/Sql/Dml/Section/IntoMock.php | 13 + .../Database/Sql/Dml/Section/IntoTest.php | 39 + .../Database/Sql/Dml/Section/LimitMock.php | 13 + .../Database/Sql/Dml/Section/LimitTest.php | 33 + .../Sql/Dml/Section/Renderer/ColumnMock.php | 12 + .../Sql/Dml/Section/Renderer/ColumnTest.php | 53 + .../Sql/Dml/Section/Renderer/FromMock.php | 12 + .../Sql/Dml/Section/Renderer/FromTest.php | 53 + .../Sql/Dml/Section/Renderer/IntoMock.php | 12 + .../Sql/Dml/Section/Renderer/IntoTest.php | 39 + .../Sql/Dml/Section/Renderer/LimitMock.php | 12 + .../Sql/Dml/Section/Renderer/LimitTest.php | 38 + .../Sql/Dml/Section/Renderer/SetMock.php | 12 + .../Sql/Dml/Section/Renderer/SetTest.php | 67 + .../Core/Database/Sql/Dml/Section/SetMock.php | 13 + .../Core/Database/Sql/Dml/Section/SetTest.php | 73 + .../Database/Sql/Dml/Section/WhereMock.php | 13 + .../Database/Sql/Dml/Section/WhereTest.php | 79 + .../Core/DateTime/DateTimeTest.php | 42 + .../Core/DateTime/DateTimeTest.php.old | 243 +++ .../Definition/ArgumentDefinitionTest.php | 186 ++ .../Definition/ClassDefinitionTest.php | 202 ++ .../Definition/MethodDefinitionTest.php | 113 ++ .../Core/DependencyInjection/FactoryTest.php | 73 + .../Core/DependencyInjection/RegistryTest.php | 133 ++ .../WootookCore/test/unit/php/bootstrap.php | 14 + .../WootookPlayer/autoload_classmap.php | 123 ++ .../WootookPlayer/autoload_function.php | 11 + .../WootookPlayer/autoload_register.php | 1 + src/application/test/build_classmap.php | 42 + src/banned.php | 4 +- src/buddy.php | 2 +- src/changelog.php | 4 +- src/chat.php | 4 +- src/chat_add.php | 4 +- src/chat_msg.php | 4 +- src/contact.php | 2 +- src/fleet.php | 2 +- src/fleetback.php | 2 +- src/fleetshortcut.php | 2 +- src/floten1.php | 2 +- src/floten2.php | 2 +- src/floten3.php | 2 +- src/flotenajax.php | 4 +- src/galaxy.php | 6 +- src/imperium.php | 2 +- .../functions/GalaxyCheckFunctions.php | 36 +- src/includes/functions/GalaxyRowPlanet.php | 6 +- .../functions/GalaxyRowPlanetName.php | 40 +- src/includes/functions/GalaxyRowUser.php | 6 +- .../functions/MissionCaseColonisation.php | 2 + src/index.php | 26 +- src/infos.php | 2 +- src/jumpgate.php | 4 +- src/lostpassword.php | 2 +- src/marchand.php | 4 +- src/messages.php | 4 +- src/mipattack.php | 4 +- src/multi.php | 2 +- src/neusuw.php | 4 +- src/notes.php | 2 +- src/options.php | 2 +- src/phalanx.php | 2 +- src/quickfleet.php | 4 +- src/raketenangriff.php | 2 +- src/records.php | 4 +- src/resources.php | 2 +- src/rules.php | 2 +- src/rw.php | 2 +- src/scripts/createbanner.php | 2 +- src/search.php | 2 +- src/skin/frontend/base/default/css/base.css | 16 +- src/skin/frontend/base/default/css/canvas.css | 120 ++ src/stat.php | 2 +- src/techdetails.php | 4 +- src/techtree.php | 2 +- src/verband.php | 4 +- vendor/ZendFramework | 1 + 451 files changed, 17784 insertions(+), 6375 deletions(-) create mode 100644 .gitmodules create mode 100644 src/application/bc.php delete mode 100644 src/application/code/core/Wootook/Core/App.php delete mode 100644 src/application/code/core/Wootook/Core/Block/Concat.php delete mode 100644 src/application/code/core/Wootook/Core/Block/Deprecated.php delete mode 100644 src/application/code/core/Wootook/Core/Block/Html/Form.php delete mode 100644 src/application/code/core/Wootook/Core/Block/Html/Home.php delete mode 100644 src/application/code/core/Wootook/Core/Block/Html/Navigation/Node.php delete mode 100644 src/application/code/core/Wootook/Core/Block/Html/Page.php delete mode 100644 src/application/code/core/Wootook/Core/Block/Messages.php delete mode 100644 src/application/code/core/Wootook/Core/Block/Template.php delete mode 100644 src/application/code/core/Wootook/Core/Block/Text.php delete mode 100644 src/application/code/core/Wootook/Core/Config/Adapter/Adapter.php delete mode 100644 src/application/code/core/Wootook/Core/Config/Adapter/Array.php delete mode 100644 src/application/code/core/Wootook/Core/Controller/ErrorController.php delete mode 100644 src/application/code/core/Wootook/Core/Controller/IndexController.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Adapter/Adapter.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Adapter/Pdo/Mysql.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Orm/DataMapper/Array.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Orm/DataMapper/Config.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Orm/DataMapper/DateTime.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Orm/DataMapper/FieldMapper.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Orm/DataMapper/Object.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Resource.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Sql/Dml.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Sql/DmlQuery.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Sql/Mysql/Select.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Expression.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Param.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Placeholder.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Variable.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Statement/Pdo/Mysql.php delete mode 100644 src/application/code/core/Wootook/Core/Database/Statement/Statement.php delete mode 100644 src/application/code/core/Wootook/Core/Email.php delete mode 100644 src/application/code/core/Wootook/Core/Email/Part/Part.php delete mode 100644 src/application/code/core/Wootook/Core/Email/Transport/Transport.php delete mode 100644 src/application/code/core/Wootook/Core/Event/Break.php delete mode 100644 src/application/code/core/Wootook/Core/Exception/DataAccessException.php delete mode 100644 src/application/code/core/Wootook/Core/Exception/Database/AdapterError.php delete mode 100644 src/application/code/core/Wootook/Core/Exception/Database/Error.php delete mode 100644 src/application/code/core/Wootook/Core/Exception/Database/StatementError.php delete mode 100644 src/application/code/core/Wootook/Core/Exception/Deprecated.php delete mode 100644 src/application/code/core/Wootook/Core/Exception/Exception.php delete mode 100644 src/application/code/core/Wootook/Core/Exception/GameError.php delete mode 100644 src/application/code/core/Wootook/Core/Exception/LayoutException.php delete mode 100644 src/application/code/core/Wootook/Core/Exception/RuntimeException.php delete mode 100644 src/application/code/core/Wootook/Core/Exception/WebsiteError.php delete mode 100644 src/application/code/core/Wootook/Core/Form/Element/Button.php delete mode 100644 src/application/code/core/Wootook/Core/Form/Element/Text.php delete mode 100644 src/application/code/core/Wootook/Core/Form/ElementLoader.php delete mode 100644 src/application/code/core/Wootook/Core/Form/Validator/Alnum.php delete mode 100644 src/application/code/core/Wootook/Core/Form/Validator/Alpha.php delete mode 100644 src/application/code/core/Wootook/Core/Form/Validator/Email.php delete mode 100644 src/application/code/core/Wootook/Core/Form/Validator/FormKey.php delete mode 100644 src/application/code/core/Wootook/Core/Form/Validator/Hex.php delete mode 100644 src/application/code/core/Wootook/Core/Form/Validator/Host.php delete mode 100644 src/application/code/core/Wootook/Core/Form/Validator/Numeric.php delete mode 100644 src/application/code/core/Wootook/Core/Form/Validator/Regex.php delete mode 100644 src/application/code/core/Wootook/Core/Form/ValidatorAbstract.php delete mode 100644 src/application/code/core/Wootook/Core/Form/ValidatorLoader.php delete mode 100644 src/application/code/core/Wootook/Core/Helper/Config/ConfigHandler.php delete mode 100644 src/application/code/core/Wootook/Core/Helper/Config/Events.php delete mode 100644 src/application/code/core/Wootook/Core/Helper/Config/Modules.php delete mode 100644 src/application/code/core/Wootook/Core/Model/Config.php delete mode 100644 src/application/code/core/Wootook/Core/Model/Game.php delete mode 100644 src/application/code/core/Wootook/Core/Model/Translator.php delete mode 100644 src/application/code/core/Wootook/Core/Model/Website.php delete mode 100644 src/application/code/core/Wootook/Core/Mvc/Controller/Request/Request.php delete mode 100644 src/application/code/core/Wootook/Core/Mvc/Controller/Response/Response.php delete mode 100644 src/application/code/core/Wootook/Core/Mvc/Model/Entity.php delete mode 100644 src/application/code/core/Wootook/Core/Mvc/Model/Model.php delete mode 100644 src/application/code/core/Wootook/Core/Setup/Exception/RuntimeException.php delete mode 100644 src/application/code/core/Wootook/Core/Setup/Exception/VersionStageError.php delete mode 100644 src/application/code/core/Wootook/Core/Setup/Exception/VersionValueError.php delete mode 100644 src/application/code/core/Wootook/Core/Setup/Updater.php delete mode 100644 src/application/code/libraries/Wildfire/Stream.php create mode 100644 src/application/configs/modules/Wootook.php create mode 100644 src/application/modules/WootookCore/autoload_classmap.php create mode 100644 src/application/modules/WootookCore/autoload_function.php create mode 100644 src/application/modules/WootookCore/autoload_register.php create mode 100644 src/application/modules/WootookCore/config/module.config.php rename src/application/{code/core/Wootook/Core/configs => modules/WootookCore/config}/module.php (65%) rename src/application/{code/core/Wootook/Core/install/mysql5/install-1.5.0.php => modules/WootookCore/install/mysql5/install-1.5.0.beta2.php} (100%) rename src/application/{code/core/Wootook/Core/install/mysql5/uninstall-1.5.0.php => modules/WootookCore/install/mysql5/uninstall-1.5.0.beta2.php} (100%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/App/App.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Base/BaseObject.php rename src/application/{code/core/Wootook/Object.php => modules/WootookCore/src/Wootook/Core/Base/DataContainer.php} (77%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Base/Service/App.php rename src/application/{code/core/Wootook/Core => modules/WootookCore/src/Wootook/Core/Base}/Singleton.php (96%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Block/Concat.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Block/Deprecated.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Form.php rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Block/Html/Head.php (86%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Home.php rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Block/Html/Navigation/Link.php (79%) rename src/application/{code/core/Wootook/Core/Block/Html/Navigation.php => modules/WootookCore/src/Wootook/Core/Block/Html/Navigation/Menu.php} (73%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Navigation/Node.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Page.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Block/Messages.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Block/Template.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Block/Text.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Bootstrap/Module.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/Adapter.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/PhpArray.php rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Config/Node.php (75%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Controller/ErrorController.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Controller/IndexController.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Adapter.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Mysql.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Pdo.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Pdo/Mysql.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Pdo/Sqlite.php rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Database/ConnectionManager.php (65%) rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Database/Orm/DataMapper.php (56%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/Config.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/DateTime.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/FieldMapper.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/PhpArray.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/PhpObject.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Resource/DataMapper.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Resource/ReadConnection.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Resource/WriteConnection.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Condition.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/InListOperator.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/LogicalOperator.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/MathOperator.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Placeholder.php rename src/application/{code/core/Wootook/Core/Database/Sql => modules/WootookCore/src/Wootook/Core/Database/Sql/Dml}/Delete.php (62%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Dml.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/DmlQuery.php rename src/application/{code/core/Wootook/Core/Database/Sql => modules/WootookCore/src/Wootook/Core/Database/Sql/Dml}/Insert.php (71%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Renderer.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Column.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/ColumnAware.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/From.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/FromAware.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Into.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/IntoAware.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Limit.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/LimitAware.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Column.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/ColumnAware.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/From.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/FromAware.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Into.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/IntoAware.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Limit.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/LimitAware.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Set.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/SetAware.php rename src/application/{code/core/Wootook/Core/Database/Sql/DmlFilterableQuery.php => modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Where.php} (81%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/WhereAware.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Set.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/SetAware.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Where.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/WhereAware.php rename src/application/{code/core/Wootook/Core/Database/Sql => modules/WootookCore/src/Wootook/Core/Database/Sql/Dml}/Select.php (85%) rename src/application/{code/core/Wootook/Core/Database/Sql => modules/WootookCore/src/Wootook/Core/Database/Sql/Dml}/Update.php (60%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Expression.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Param.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Placeholder.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Variable.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/QueryBuilder/QueryBuilder.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Mysql.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Pdo.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Statement.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateInterval.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/DateTime/DatePeriod.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateTime.php rename src/application/{code/core/Wootook/Core/DateTime.php => modules/WootookCore/src/Wootook/Core/DateTime/DateTime.php.old} (83%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateTimeZone.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/DateTime/Formatter.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ClassDefinition.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Factory.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Registry.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Email/Email.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Email/Part/Part.php rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Email/Transport/Sendmail.php (69%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Email/Transport/Transport.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Event/Break.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Event/Event.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Event/EventTarget.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/BadMethodCallException.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/CoreException.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/DataAccessException.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/Database/AdapterError.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/Database/Error.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/Database/StatementError.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/DependencyInjection/BadMethodCallException.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/DependencyInjection/InvalidArgumentException.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/DependencyInjection/RuntimeException.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/Deprecated.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/Exception.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/GameError.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/InvalidArgumentException.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/LayoutException.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/RuntimeException.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Exception/WebsiteError.php rename src/application/{code/core/Wootook/Core/Form/ElementAbstract.php => modules/WootookCore/src/Wootook/Core/Form/Element/BaseElement.php} (61%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Form/Element/Button.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Form/Element/Text.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Form/ElementLoader.php rename src/application/{code/core/Wootook/Core => modules/WootookCore/src/Wootook/Core/Form}/Form.php (65%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Alnum.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Alpha.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/BaseValidator.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Email.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/FormKey.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Hex.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Host.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Numeric.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Regex.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Form/ValidatorLoader.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Helper/Config/ConfigHandler.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Helper/Config/Events.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Helper/Config/Modules.php rename src/application/{code/core/Wootook/Core/Model/Layout.php => modules/WootookCore/src/Wootook/Core/Layout/Manager.php} (84%) rename src/application/{code/core/Wootook/Core/Model => modules/WootookCore/src/Wootook/Core}/Layout/Parser.php (63%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Model/Config.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Model/Game.php rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Model/Image/Png.php (79%) rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Model/Session.php (76%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Model/Translator.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Model/Website.php rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Mvc/Controller/Action.php (57%) rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Mvc/Controller/Front.php (62%) rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Mvc/Controller/Request/Http.php (86%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Request/Request.php rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Mvc/Controller/Response/Http.php (75%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Response/Response.php rename src/application/{code/core/Wootook/Core/Event.php => modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Deletable.php} (92%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Delete.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Load.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Loadable.php rename src/application/{code/core/Wootook/Core/Exception.php => modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Savable.php} (91%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Save.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Entity.php rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Mvc/Model/EntityInterface.php (96%) rename src/application/{code/core/Wootook/Core/Mvc/Model/Entity => modules/WootookCore/src/Wootook/Core/Mvc/Model}/SubTable.php (67%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Type/Base.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Type/Full.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Type/Readonly.php rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Mvc/View/View.php (85%) rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/PluginLoader/PluginLoader.php (53%) rename src/application/{code/core/Wootook/Core => modules/WootookCore/src/Wootook/Core/Profiler}/ErrorProfiler.php (70%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Resource/Entity.php rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Resource/EntityCollection.php (50%) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Resource/EntityCollection/Action/Load.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Resource/EntityCollection/Action/Loadable.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Setup/Exception/RuntimeException.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Setup/Exception/VersionStageError.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Setup/Exception/VersionValueError.php create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Setup/Updater.php rename src/application/{code/core => modules/WootookCore/src}/Wootook/Core/Setup/Updater/ScriptQueue.php (89%) create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/App/AppTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Base/BaseObjectTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Config/NodeTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Condition/ConditionTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Condition/LogicalOperatorTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/ColumnMock.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/ColumnTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/FromMock.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/FromTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/IntoMock.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/IntoTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/LimitMock.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/LimitTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/ColumnMock.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/ColumnTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/FromMock.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/FromTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/IntoMock.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/IntoTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/LimitMock.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/LimitTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/SetMock.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/SetTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/SetMock.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/SetTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/WhereMock.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/WhereTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DateTime/DateTimeTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DateTime/DateTimeTest.php.old create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/ArgumentDefinitionTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/ClassDefinitionTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/MethodDefinitionTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/FactoryTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/RegistryTest.php create mode 100644 src/application/modules/WootookCore/test/unit/php/bootstrap.php create mode 100644 src/application/modules/WootookPlayer/autoload_classmap.php create mode 100644 src/application/modules/WootookPlayer/autoload_function.php create mode 100644 src/application/modules/WootookPlayer/autoload_register.php create mode 100644 src/application/test/build_classmap.php create mode 100644 src/skin/frontend/base/default/css/canvas.css create mode 160000 vendor/ZendFramework diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8f630ff --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/ZendFramework"] + path = vendor/ZendFramework + url = git://github.com/zendframework/zf2.git diff --git a/src/.htaccess b/src/.htaccess index ca113c2..008dc77 100644 --- a/src/.htaccess +++ b/src/.htaccess @@ -16,3 +16,6 @@ SetEnv DEPRECATION On RewriteCond %{REQUEST_FILENAME} !-l RewriteRule .* index.php [L] + +# OVH.com +SetEnv PHP_VER 5_4 \ No newline at end of file diff --git a/src/add_declare.php b/src/add_declare.php index b2d6eaf..76cd8d8 100644 --- a/src/add_declare.php +++ b/src/add_declare.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; $mode = Wootook::getRequest()->getPost('mode'); diff --git a/src/admin/ElementQueueFixer.php b/src/admin/ElementQueueFixer.php index be19843..b396724 100644 --- a/src/admin/ElementQueueFixer.php +++ b/src/admin/ElementQueueFixer.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { includeLang('admin'); @@ -76,4 +76,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); } -?> \ No newline at end of file +?> diff --git a/src/admin/QueryExecute.php b/src/admin/QueryExecute.php index 9e75ebf..31f2cfd 100644 --- a/src/admin/QueryExecute.php +++ b/src/admin/QueryExecute.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN))) { includeLang('admin/Queries'); @@ -56,4 +56,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); } -?> \ No newline at end of file +?> diff --git a/src/admin/ShowFlyingFleets.php b/src/admin/ShowFlyingFleets.php index c41270d..4c892b7 100644 --- a/src/admin/ShowFlyingFleets.php +++ b/src/admin/ShowFlyingFleets.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; include(ROOT_PATH . 'includes/functions/BuildFlyingFleetTable.'.PHPEXT); diff --git a/src/admin/XNovaResetUnivers.php b/src/admin/XNovaResetUnivers.php index e789d4d..08f17ee 100644 --- a/src/admin/XNovaResetUnivers.php +++ b/src/admin/XNovaResetUnivers.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; includeLang('admin'); @@ -135,4 +135,4 @@ function WootookResetUnivers ( $CurrentUser ) { display ($Page, $lang['Reset'], false, '', true); } -?> \ No newline at end of file +?> diff --git a/src/admin/activeplanet.php b/src/admin/activeplanet.php index 8a5b941..eae2cf2 100644 --- a/src/admin/activeplanet.php +++ b/src/admin/activeplanet.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; $user = Wootook_Player_Model_Session::getSingleton()->getPlayer(); diff --git a/src/admin/add_fleet.php b/src/admin/add_fleet.php index ca6be77..e0c8056 100644 --- a/src/admin/add_fleet.php +++ b/src/admin/add_fleet.php @@ -32,7 +32,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; $user = Wootook_Player_Model_Session::getSingleton()->getPlayer(); diff --git a/src/admin/add_money.php b/src/admin/add_money.php index 7bca4b4..934d21c 100644 --- a/src/admin/add_money.php +++ b/src/admin/add_money.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; $user = Wootook_Player_Model_Session::getSingleton()->getPlayer(); diff --git a/src/admin/add_moon.php b/src/admin/add_moon.php index 63c2851..5a83d90 100644 --- a/src/admin/add_moon.php +++ b/src/admin/add_moon.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { includeLang('admin/addmoon'); @@ -66,4 +66,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; } else { AdminMessage ( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); } -?> \ No newline at end of file +?> diff --git a/src/admin/autounban.php b/src/admin/autounban.php index 5d9a6a9..3636c39 100644 --- a/src/admin/autounban.php +++ b/src/admin/autounban.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN))) { doquery("UPDATE {{table}} SET `banaday` =` banaday` - '1' WHERE `banaday` != '0';",'users'); diff --git a/src/admin/banned.php b/src/admin/banned.php index 89b6f01..a11642f 100644 --- a/src/admin/banned.php +++ b/src/admin/banned.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { includeLang('admin'); @@ -86,4 +86,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; AdminMessage ($lang['sys_noalloaw'], $lang['sys_noaccess']); } -?> \ No newline at end of file +?> diff --git a/src/admin/changelog.php b/src/admin/changelog.php index 6ef7ced..09e3590 100644 --- a/src/admin/changelog.php +++ b/src/admin/changelog.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; includeLang('changelog'); $template = gettemplate('changelog_table'); @@ -53,4 +53,4 @@ $page .= parsetemplate(gettemplate('changelog_body'), $parse); display( $page, "Changelog", false, '', true); -?> \ No newline at end of file +?> diff --git a/src/admin/chat.php b/src/admin/chat.php index b6ca379..f2b5dbe 100644 --- a/src/admin/chat.php +++ b/src/admin/chat.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; includeLang('admin'); $parse = $lang; @@ -63,4 +63,4 @@ $parse = $lang; message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); } -?> \ No newline at end of file +?> diff --git a/src/admin/credit.php b/src/admin/credit.php index 00c282d..5c37590 100644 --- a/src/admin/credit.php +++ b/src/admin/credit.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; includeLang('credit'); $parse = $lang; @@ -70,4 +70,4 @@ if (in_array($user['authlevel'], array(LEVEL_ADMIN))) { message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); } -?> \ No newline at end of file +?> diff --git a/src/admin/declare_list.php b/src/admin/declare_list.php index 6ecc761..d0bdadb 100644 --- a/src/admin/declare_list.php +++ b/src/admin/declare_list.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { includeLang('admin'); @@ -84,4 +84,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); } -?> \ No newline at end of file +?> diff --git a/src/admin/deletuser.php b/src/admin/deletuser.php index 370ddcb..05f3dc7 100644 --- a/src/admin/deletuser.php +++ b/src/admin/deletuser.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($CurrentUser['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { $PageTpl = gettemplate( "admin/deletuser" ); @@ -47,4 +47,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); } -?> \ No newline at end of file +?> diff --git a/src/admin/errors.php b/src/admin/errors.php index 0ff6a7b..a14fdc9 100644 --- a/src/admin/errors.php +++ b/src/admin/errors.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; includeLang('admin'); $parse = $lang; diff --git a/src/admin/leftmenu.php b/src/admin/leftmenu.php index cce8699..50555b7 100644 --- a/src/admin/leftmenu.php +++ b/src/admin/leftmenu.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; includeLang('leftmenu'); diff --git a/src/admin/md5changepass.php b/src/admin/md5changepass.php index 71bf636..3352ed6 100644 --- a/src/admin/md5changepass.php +++ b/src/admin/md5changepass.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { includeLang('admin/changepass'); @@ -57,4 +57,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); } -?> \ No newline at end of file +?> diff --git a/src/admin/md5enc.php b/src/admin/md5enc.php index ba3c4e5..1aaff6a 100644 --- a/src/admin/md5enc.php +++ b/src/admin/md5enc.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { includeLang('admin/md5enc'); @@ -54,4 +54,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); } -?> \ No newline at end of file +?> diff --git a/src/admin/messagelist.php b/src/admin/messagelist.php index a4c75cf..977bf7f 100644 --- a/src/admin/messagelist.php +++ b/src/admin/messagelist.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { includeLang('admin/messagelist'); diff --git a/src/admin/messall.php b/src/admin/messall.php index 7aebd2b..b6b0f25 100644 --- a/src/admin/messall.php +++ b/src/admin/messall.php @@ -32,7 +32,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { if (!empty($_POST)) { @@ -72,4 +72,4 @@ if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERA } } else { message($lang['sys_noalloaw'], $lang['sys_noaccess']); -} \ No newline at end of file +} diff --git a/src/admin/moonlist.php b/src/admin/moonlist.php index 932e607..1bf6fb5 100644 --- a/src/admin/moonlist.php +++ b/src/admin/moonlist.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { includeLang('overview'); @@ -59,4 +59,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; } else { message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); } -?> \ No newline at end of file +?> diff --git a/src/admin/multi.php b/src/admin/multi.php index 4b41308..3858bf4 100644 --- a/src/admin/multi.php +++ b/src/admin/multi.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { includeLang('admin/multi'); @@ -62,4 +62,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); } -?> \ No newline at end of file +?> diff --git a/src/admin/overview.php b/src/admin/overview.php index 2fc17a3..f5da7ab 100644 --- a/src/admin/overview.php +++ b/src/admin/overview.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { includeLang('admin'); diff --git a/src/admin/paneladmina.php b/src/admin/paneladmina.php index 1ea59d8..1ea90b4 100644 --- a/src/admin/paneladmina.php +++ b/src/admin/paneladmina.php @@ -32,7 +32,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { diff --git a/src/admin/planetlist.php b/src/admin/planetlist.php index 4a154a5..0d41079 100644 --- a/src/admin/planetlist.php +++ b/src/admin/planetlist.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { @@ -60,4 +60,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; } // Created by e-Zobar. All rights reversed (C) Wootook Team 2008 -?> \ No newline at end of file +?> diff --git a/src/admin/settings.php b/src/admin/settings.php index 88fc5d1..96d3a06 100644 --- a/src/admin/settings.php +++ b/src/admin/settings.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; function DisplayGameSettingsPage($CurrentUser) { diff --git a/src/admin/statbuilder.php b/src/admin/statbuilder.php index 97caec7..056102f 100644 --- a/src/admin/statbuilder.php +++ b/src/admin/statbuilder.php @@ -32,7 +32,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; include(ROOT_PATH . 'admin/statfunctions.' . PHPEXT); diff --git a/src/admin/unbanned.php b/src/admin/unbanned.php index 8b0967d..9569d10 100644 --- a/src/admin/unbanned.php +++ b/src/admin/unbanned.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { @@ -54,4 +54,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); } -?> \ No newline at end of file +?> diff --git a/src/admin/userlist.php b/src/admin/userlist.php index 84fb74f..fdcb299 100644 --- a/src/admin/userlist.php +++ b/src/admin/userlist.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { includeLang('admin'); @@ -90,4 +90,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); } -?> \ No newline at end of file +?> diff --git a/src/admin/variables.php b/src/admin/variables.php index bcc6642..42360ef 100644 --- a/src/admin/variables.php +++ b/src/admin/variables.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('IN_ADMIN', true); -require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) .'/application/bc.php'; if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { diff --git a/src/alliance.php b/src/alliance.php index 6b815fd..2dab695 100644 --- a/src/alliance.php +++ b/src/alliance.php @@ -30,7 +30,7 @@ define('INSTALL' , false); define('INSIDE' , true); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; $user = Wootook_Player_Model_Session::getSingleton()->getPlayer(); $db = Wootook_Core_Database_ConnectionManager::getSingleton()->getConnection(Wootook_Core_Database_ConnectionManager::DEFAULT_CONNECTION_NAME); @@ -1228,4 +1228,4 @@ elseif ($user->getData('ally_id') != 0 && $user->getData('ally_request') == 0) { $page .= parsetemplate(gettemplate('alliance_frontpage'), $lang); display($page, $lang['your_alliance']); } -} \ No newline at end of file +} diff --git a/src/annonce.php b/src/annonce.php index 9c0b506..0847a63 100644 --- a/src/annonce.php +++ b/src/annonce.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; $readAdapter = Wootook_Core_Database_ConnectionManager::getSingleton()->getConnection('core_read'); $writeAdapter = Wootook_Core_Database_ConnectionManager::getSingleton()->getConnection('core_write'); diff --git a/src/annonce2.php b/src/annonce2.php index 29baec1..28598c9 100644 --- a/src/annonce2.php +++ b/src/annonce2.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; $actions = $_GET['action']; @@ -59,4 +59,4 @@ HTML; display($page); } -?> \ No newline at end of file +?> diff --git a/src/application/bc.php b/src/application/bc.php new file mode 100644 index 0000000..d2ad817 --- /dev/null +++ b/src/application/bc.php @@ -0,0 +1,103 @@ + + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see . + * + * --> 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. + * + */ + +require_once __DIR__ . '/bc.php'; + +if (defined('IN_ADMIN')) { + Wootook::app()->setDefaultWebsiteId(0); + Wootook::app()->setDefaultGameId(0); +} + +include ROOT_PATH . 'includes/constants.php'; + +if (!Wootook::$isInstalled) { + Wootook::app()->getFrontController() + ->getResponse() + ->setRedirect(Wootook::getStaticUrl('install/'), Wootook\Core\Mvc\Controller\Response\Http::REDIRECT_TEMPORARY) + ->sendHeaders(); + exit(0); +} + +$lang = array(); + +define('DEFAULT_LANG', 'fr'); + +include(ROOT_PATH . 'includes/functions.' . PHPEXT); +include(ROOT_PATH . 'includes/unlocalised.' . PHPEXT); +include(ROOT_PATH . 'includes/todofleetcontrol.' . PHPEXT); +include(ROOT_PATH . 'language/' . DEFAULT_LANG . '/lang_info.cfg'); +include(ROOT_PATH . 'includes/vars.' . PHPEXT); +include(ROOT_PATH . 'includes/strings.' . PHPEXT); + +$user = Wootook\Player\Model\Session::getSingleton()->getPlayer(); + +if (!defined('DISABLE_IDENTITY_CHECK')) { + if ($user === null || !$user->getId()) { + Wootook::getResponse() + ->setRedirect(Wootook::getUrl('player/account/login')) + ->sendHeaders(); + exit(0); + } + + if (!Wootook::getGameConfig('game/general/active') && !in_array($user->getData('authlevel'), array(LEVEL_ADMIN, LEVEL_MODERATOR, LEVEL_OPERATOR))) { + $layout = new Wootook\Core\Layout\Manager(Wootook\Core\Layout\Manager::DOMAIN_FRONTEND); + $layout->load('message'); + + $block = $layout->getBlock('message'); + $block['title'] = Wootook::__('Game is disabled.'); + $block['message'] = Wootook::getGameConfig('game/general/closing-message'); + + echo $layout->render(); + exit(0); + } +} + +includeLang('system'); +includeLang('tech'); + +if (($user !== null && $user->getId())) { + if (isset($_GET['cp']) && !empty($_GET['cp'])) { + $user->updateCurrentPlanet((int) $_GET['cp']); + } + + $planet = $user->getCurrentPlanet(); + + foreach ($user->getPlanetCollection() as $userPlanet) { + FlyingFleetHandler($userPlanet); // TODO: implement logic into a refactored model + } + + /* + * Update planet resources and constructions + */ + Wootook::dispatchEvent('planet.update', array( + 'planet' => $planet + )); + $planet->save(); +} diff --git a/src/application/bootstrap.php b/src/application/bootstrap.php index b0b3c9c..7d312a7 100644 --- a/src/application/bootstrap.php +++ b/src/application/bootstrap.php @@ -28,6 +28,9 @@ * */ +define('DEBUG', true); +define('DEPRECATION', true); + if (!defined('PHP_VERSION_ID')) { $version = explode('.',PHP_VERSION); define('PHP_VERSION_ID', (((int)$version[0]) * 10000 + ((int)$version[1]) * 100 + ((int)$version[2]))); @@ -67,97 +70,12 @@ defined('PHPEXT') || define('PHPEXT', 'php'); defined('VERSION') || define('VERSION', '1.5.0-beta2'); set_include_path(implode(PATH_SEPARATOR, array( - APPLICATION_PATH . DIRECTORY_SEPARATOR . 'code' . DIRECTORY_SEPARATOR . 'libraries', - APPLICATION_PATH . DIRECTORY_SEPARATOR . 'code' . DIRECTORY_SEPARATOR . 'local', - APPLICATION_PATH . DIRECTORY_SEPARATOR . 'code' . DIRECTORY_SEPARATOR . 'community', - APPLICATION_PATH . DIRECTORY_SEPARATOR . 'code' . DIRECTORY_SEPARATOR . 'core', + APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules', get_include_path() ))); -function __autoload($class) { - include_once str_replace('_', '/', $class) . '.php'; -} +include APPLICATION_PATH . 'code' . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'Wootook.php'; +include 'WootookCore' . DIRECTORY_SEPARATOR . 'autoload_register.php'; -if (defined('IN_ADMIN')) { - $website = new Wootook_Core_Model_Website(); - $website->setId(0)->setData('code', 'admin'); - Wootook::addWebsite($website); - Wootook::setDefaultWebsite($website); - - $game = new Wootook_Core_Model_Game(); - $game->setId(0)->setData('code', 'admin')->setData('website_id', $website->getId()); - Wootook::addGame($game); - Wootook::setDefaultGame($game); -} - -include ROOT_PATH . 'includes/constants.php'; - -if (defined('DEBUG')) { - Wootook_Core_ErrorProfiler::register(); -} -Wootook_Core_Helper_Config_Events::registerEvents(); - -if (!Wootook::$isInstalled) { - Wootook::getResponse() - ->setRedirect(Wootook::getStaticUrl('install/'), Wootook_Core_Mvc_Controller_Response_Http::REDIRECT_TEMPORARY) - ->sendHeaders(); - exit(0); -} - -$lang = array(); - -define('DEFAULT_LANG', 'fr'); - -include(ROOT_PATH . 'includes/functions.' . PHPEXT); -include(ROOT_PATH . 'includes/unlocalised.' . PHPEXT); -include(ROOT_PATH . 'includes/todofleetcontrol.' . PHPEXT); -include(ROOT_PATH . 'language/' . DEFAULT_LANG . '/lang_info.cfg'); -include(ROOT_PATH . 'includes/vars.' . PHPEXT); -include(ROOT_PATH . 'includes/strings.' . PHPEXT); - -$user = Wootook_Player_Model_Session::getSingleton()->getPlayer(); - -if (!defined('DISABLE_IDENTITY_CHECK')) { - if ($user === null || !$user->getId()) { - Wootook::getResponse() - ->setRedirect(Wootook::getUrl('player/account/login')) - ->sendHeaders(); - exit(0); - } - - //var_dump(Wootook::getGameConfig('game/general/active')); - if (!Wootook::getGameConfig('game/general/active')/* && !in_array($user->getData('authlevel'), array(LEVEL_ADMIN, LEVEL_MODERATOR, LEVEL_OPERATOR))*/) { - $layout = new Wootook_Core_Model_Layout(Wootook_Core_Model_Layout::DOMAIN_FRONTEND); - $layout->load('message'); - - $block = $layout->getBlock('message'); - $block['title'] = Wootook::__('Game is disabled.'); - $block['message'] = Wootook::getGameConfig('game/general/closing-message'); - - echo $layout->render(); - exit(0); - } -} - -includeLang('system'); -includeLang('tech'); - -if (($user !== null && $user->getId())) { - if (isset($_GET['cp']) && !empty($_GET['cp'])) { - $user->updateCurrentPlanet((int) $_GET['cp']); - } - - $planet = $user->getCurrentPlanet(); - - foreach ($user->getPlanetCollection() as $userPlanet) { - FlyingFleetHandler($userPlanet); // TODO: implement logic into a refactored model - } - - /* - * Update planet resources and constructions - */ - Wootook::dispatchEvent('planet.update', array( - 'planet' => $planet - )); - $planet->save(); -} +Wootook\Core\Profiler\ErrorProfiler::register(); +Wootook\Core\Helper\Config\Events::registerEvents(); diff --git a/src/application/code/core/Legacies/Empire/Block/Planet/ResearchLab/Item.php b/src/application/code/core/Legacies/Empire/Block/Planet/ResearchLab/Item.php index 8d5e448..558b7a5 100644 --- a/src/application/code/core/Legacies/Empire/Block/Planet/ResearchLab/Item.php +++ b/src/application/code/core/Legacies/Empire/Block/Planet/ResearchLab/Item.php @@ -63,7 +63,7 @@ class Legacies_Empire_Block_Planet_ResearchLab_Item $resourceConfig = array(); foreach ($resources as $resourceId => $resourceValue) { - $resourceConfig[$resourceId] = new Wootook_Object(array( + $resourceConfig[$resourceId] = new Wootook\Core\BaseObject(array( 'resource_id' => $resourceId, 'value' => $resourceValue )); @@ -87,4 +87,4 @@ class Legacies_Empire_Block_Planet_ResearchLab_Item { return $this->getBuildingTime($this->getNextLevel()); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Legacies/Empire/Block/Planet/ResearchLab/Queue/Item.php b/src/application/code/core/Legacies/Empire/Block/Planet/ResearchLab/Queue/Item.php index a825cfa..db1cb77 100644 --- a/src/application/code/core/Legacies/Empire/Block/Planet/ResearchLab/Queue/Item.php +++ b/src/application/code/core/Legacies/Empire/Block/Planet/ResearchLab/Queue/Item.php @@ -74,7 +74,7 @@ class Legacies_Empire_Block_Planet_ResearchLab_Queue_Item $resourceConfig = array(); foreach ($resources as $resourceId => $resourceValue) { - $resourceConfig[$resourceId] = new Wootook_Object(array( + $resourceConfig[$resourceId] = new Wootook\Core\BaseObject(array( 'resource_id' => $resourceId, 'value' => $resourceValue )); diff --git a/src/application/code/core/Legacies/Empire/Block/Planet/Shipyard/Item.php b/src/application/code/core/Legacies/Empire/Block/Planet/Shipyard/Item.php index 0b42ac2..f3b7c3c 100644 --- a/src/application/code/core/Legacies/Empire/Block/Planet/Shipyard/Item.php +++ b/src/application/code/core/Legacies/Empire/Block/Planet/Shipyard/Item.php @@ -68,7 +68,7 @@ class Legacies_Empire_Block_Planet_Shipyard_Item $resourceConfig = array(); foreach ($resources as $resourceId => $resourceValue) { - $resourceConfig[$resourceId] = new Wootook_Object(array( + $resourceConfig[$resourceId] = new Wootook\Core\BaseObject(array( 'resource_id' => $resourceId, 'value' => $resourceValue )); diff --git a/src/application/code/core/Legacies/Empire/Block/Planet/Shipyard/Queue/Item.php b/src/application/code/core/Legacies/Empire/Block/Planet/Shipyard/Queue/Item.php index 64eec1d..e4c3f1e 100644 --- a/src/application/code/core/Legacies/Empire/Block/Planet/Shipyard/Queue/Item.php +++ b/src/application/code/core/Legacies/Empire/Block/Planet/Shipyard/Queue/Item.php @@ -74,7 +74,7 @@ class Legacies_Empire_Block_Planet_Shipyard_Queue_Item $resourceConfig = array(); foreach ($resources as $resourceId => $resourceValue) { - $resourceConfig[$resourceId] = new Wootook_Object(array( + $resourceConfig[$resourceId] = new Wootook\Core\BaseObject(array( 'resource_id' => $resourceId, 'value' => $resourceValue )); diff --git a/src/application/code/core/Legacies/Empire/Model/Planet/Building/ResearchLab/Builder.php b/src/application/code/core/Legacies/Empire/Model/Planet/Building/ResearchLab/Builder.php index 467dcde..bbde4f3 100644 --- a/src/application/code/core/Legacies/Empire/Model/Planet/Building/ResearchLab/Builder.php +++ b/src/application/code/core/Legacies/Empire/Model/Planet/Building/ResearchLab/Builder.php @@ -54,7 +54,7 @@ class Legacies_Empire_Model_Planet_Building_ResearchLab_Builder { $this->_unserializeQueue($this->_currentPlanet->getData(self::FIELD_SERIALIZED)); - $this->_maxLength = Wootook::getGameConfig('engine/core/lab_queue_size'); + $this->_maxLength = Wootook::app()->getDefaultGame()->getConfig('engine/core/lab_queue_size'); } /** @@ -144,7 +144,7 @@ class Legacies_Empire_Model_Planet_Building_ResearchLab_Builder $partialLevelTime = Math::mul($firstLevelTime, Math::pow($prices[$technologyId][Legacies_Empire::RESOURCE_MULTIPLIER], $level)); $levelTime = Math::sub($partialLevelTime, $firstLevelTime); - $speedFactor = Wootook::getGameConfig('game/speed/general'); + $speedFactor = Wootook::app()->getDefaultGame()->getConfig('game/speed/general'); if ($speedFactor == null) { $speedFactor = 1; } diff --git a/src/application/code/core/Legacies/Empire/Model/Planet/Building/Shipyard/Builder.php b/src/application/code/core/Legacies/Empire/Model/Planet/Building/Shipyard/Builder.php index a9bee0b..ac8dff1 100644 --- a/src/application/code/core/Legacies/Empire/Model/Planet/Building/Shipyard/Builder.php +++ b/src/application/code/core/Legacies/Empire/Model/Planet/Building/Shipyard/Builder.php @@ -207,7 +207,7 @@ class Legacies_Empire_Model_Planet_Building_Shipyard_Builder Math::setPrecision(50); $buildingTime = Math::mul($prices[$shipId][Legacies_Empire::BASE_BUILDING_TIME], intval($qty)); - $speedFactor = Wootook::getGameConfig('game/speed/general') / 1000; + $speedFactor = Wootook::app()->getDefaultGame()->getConfig('game/speed/general') / 1000; $baseTime = Math::mul(Math::div($buildingTime, 5000), Math::mul($speedFactor, $this->getSpeedEnhancement())); Math::setPrecision(); diff --git a/src/application/code/core/Wootook.php b/src/application/code/core/Wootook.php index 0515ab1..f86f903 100644 --- a/src/application/code/core/Wootook.php +++ b/src/application/code/core/Wootook.php @@ -28,6 +28,9 @@ * */ +use Wootook\Core\Exception as CoreException, + Wootook\Core\Profiler; + /** * Bootstrap class, used to access main and global functionalities * @@ -50,20 +53,6 @@ class Wootook */ private static $_translators = array(); - /** - * HTTP request management object - * - * @var Legacies_Core_Controller_Request_Http - */ - private static $_request = null; - - /** - * HTTP response management object - * - * @var Legacies_Core_Controller_Response - */ - private static $_response = null; - /** * The current timestamp * @@ -78,34 +67,6 @@ class Wootook */ private static $_defaultLocale = 'fr_FR'; - /** - * - * Enter description here ... - * @var Wootook_Core_Helper_Config_ConfigHandler - */ - private static $_config = null; - - /** - * - * Enter description here ... - * @var Wootook_Core_Helper_Config_ConfigHandler - */ - private static $_globalConfig = null; - - /** - * - * Enter description here ... - * @var array - */ - private static $_websiteConfigs = array(); - - /** - * - * Enter description here ... - * @var array - */ - private static $_gameConfigs = array(); - /** * * Enter description here ... @@ -113,16 +74,10 @@ class Wootook */ private static $_ignoreDatabaseConfig = false; - private static $_defaultWebsite = null; - private static $_defaultGame = null; - - private static $_websitesById = array(); - private static $_websitesByCode = array(); - private static $_gamesById = array(); - private static $_gamesByCode = array(); - public static $isInstalled = true; + protected static $_app = array(); + /** * Registers an event listener to be called later in the application. * @@ -165,7 +120,7 @@ class Wootook */ public static function dispatchEvent($event, $params) { - $eventObject = new Wootook_Core_Event($params); + $eventObject = new Wootook\Core\Event\Event(self::app(), $params); if (!isset(self::$_listeners[$event])) { return $eventObject; @@ -182,17 +137,17 @@ class Wootook * * Enter description here ... * @param unknown_type $namespace - * @return Wootook_Core_Model_Session + * @return Wootook\Core\Model\Session */ public static function getSession($namespace) { - return Wootook_Core_Model_Session::factory($namespace); + return Wootook\Core\Model\Session::factory($namespace); } /** * @static * @param string|null $locale - * @return Wootook_Core_Model_Translator + * @return Wootook\Core\Model\Translator */ public static function getTranslator($locale = null) { @@ -202,7 +157,7 @@ class Wootook if (!isset($translator[$locale])) { $path = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'locale'; - $translator[$locale] = new Wootook_Core_Model_Translator($path, $locale); + $translator[$locale] = new Wootook\Core\Model\Translator($path, $locale); } return $translator[$locale]; } @@ -222,7 +177,7 @@ class Wootook public static function getLocale() { - $availableLocales = self::getWebsiteConfig('locales'); + $availableLocales = self::app()->getDefaultWebsite()->getConfig('locales'); if ($availableLocales !== null) { return self::getPreferredLocale($availableLocales->toArray()); } @@ -248,14 +203,17 @@ class Wootook return self::getDefaultLocale(); } - $userLocale = Wootook_Player_Model_Session::getSingleton()->getData('locale'); + // FIXME: Dependency should not exist + /* + $userLocale = Wootook\Player\Model\Session::getSingleton()->getData('locale'); if ($userLocale !== null && in_array($userLocale, $availableLocales)) { return $userLocale; } + */ $locales = array(); - if (($accept = self::getRequest()->getServer('HTTP_ACCEPT_LANGUAGE')) !== null) { + if (($accept = self::app()->getFrontController()->getRequest()->getServer('HTTP_ACCEPT_LANGUAGE')) !== null) { // break up string into pieces (languages and q factors) preg_match_all('/([a-z]{1,8}(?:-([a-z]{1,8}))?)\s*(?:;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $accept, $matches); @@ -287,437 +245,247 @@ class Wootook } } - Wootook_Player_Model_Session::getSingleton()->setData('locale', $preferredLocale); + // FIXME: Dependency should not exist + //Wootook\Player\Model\Session::getSingleton()->setData('locale', $preferredLocale); return $preferredLocale; } /** * @static - * @return Wootook_Core_DateTime + * @return Wootook\Core\DateTime */ public static function now() { if (self::$_now === null) { self::$_now = time(); } - return new Wootook_Core_DateTime(self::$_now); - } - - /** - * @return Wootook_Core_Mvc_Controller_Request_Http - */ - public static function getRequest() - { - if (self::$_request === null) { - self::$_request = new Wootook_Core_Mvc_Controller_Request_Http(); - } - return self::$_request; - } - - public static function setRequest($request) - { - self::$_request = $request; - } - - /** - * @return Wootook_Core_Mvc_Controller_Response_Http - */ - public static function getResponse() - { - if (self::$_response === null) { - self::$_response = new Wootook_Core_Mvc_Controller_Response_Http(); - } - return self::$_response; - } - - public static function setResponse($response) - { - self::$_response = $response; - } - - public static function loadConfig($filename = null) - { - self::$_websiteConfigs = array(); - self::$_gameConfigs = array(); - - self::$_config = new Wootook_Core_Config_Adapter_Array(); - try { - self::$_config->load(APPLICATION_PATH . 'configs' . DIRECTORY_SEPARATOR . 'system.php'); - - if ($filename === null) { - $filename = APPLICATION_PATH . 'configs' . DIRECTORY_SEPARATOR . 'local.php'; - } - - if (is_string($filename)) { - if (!self::$isInstalled) { - throw new Wootook_Core_Exception_DataAccessException(); - } - $localConfig = new Wootook_Core_Config_Adapter_Array($filename); - self::$_config->merge($localConfig); - } else if (is_array($filename)) { - $localConfig = new Wootook_Core_Config_Node($filename); - self::$_config->merge($localConfig); - } else if ($filename instanceof Wootook_Core_Config_Node) { - self::$_config->merge($filename); - } else { - throw new Wootook_Core_Exception_DataAccessException(); - } - } catch (Wootook_Core_Exception_DataAccessException $e) { - self::$_globalConfig = new Wootook_Core_Config_Node(array(), self::$_config); - self::$_ignoreDatabaseConfig = true; - return self::$_config; - } - - self::$_globalConfig = clone self::$_config['default']; - if (isset(self::$_config['global'])) { - self::$_globalConfig->merge(self::$_config['global']); - } - - self::_appendDatabaseConfig(self::$_globalConfig); - - return self::$_config; - } - - private static function _appendDatabaseConfig(Wootook_Core_Config_Node $config, $type = 'global', $model = null) - { - if (self::$_ignoreDatabaseConfig || !self::$isInstalled) { - return $config; - } - - try { - $adapter = Wootook_Core_Database_ConnectionManager::getSingleton() - ->getConnection('core_read'); - } catch (Wootook_Core_Exception_Database_AdapterError $e) { - // This may also occur when the pdo_sqlite driver isn't loaded - self::$isInstalled = false; - Wootook_Core_ErrorProfiler::getSingleton()->addException($e); - return $config; - } - - $select = $adapter->select($adapter->getTable('core_config')); - - switch ($type) { - case 'website': - $select->where(new Wootook_Core_Database_Sql_Placeholder_Expression('website_id = :website_id', array('website_id' => $model->getId()))); - break; - - case 'game': - $select->where(new Wootook_Core_Database_Sql_Placeholder_Expression('game_id = :game_id', array('game_id' => $model->getId()))); - break; - - default: - $select->where('website_id', 0); - $select->where('game_id', 0); - break; - } - - $statement = $select->prepare(); - $statement->execute(); - - foreach ($statement as $row) { - $config->setConfig($row['config_path'], $row['config_value']); - } - - return $config; - } - - public static function getWebsite($websiteId) - { - if (is_numeric($websiteId)) { - if (isset(self::$_websitesById[$websiteId])) { - return self::$_websitesById[$websiteId]; - } - $website = new Wootook_Core_Model_Website(); - try { - $website->load($websiteId); - $websiteCode = $website->getData('code'); - - self::$_websitesById[$websiteId] = $website; - self::$_websitesByCode[$websiteCode] = $website; - } catch (Wootook_Core_Exception_DataAccessException $e) { - throw new Wootook_Core_Exception_WebsiteError('Could not load website entity.', null, $e); - } - - return $website; - } else { - if (isset(self::$_websitesByCode[$websiteId])) { - return self::$_websitesByCode[$websiteId]; - } - $website = new Wootook_Core_Model_Website(); - try { - $website->load($websiteId, 'code'); - $websiteId = $website->getId(); - $websiteCode = $website->getData('code'); - - self::$_websitesById[$websiteId] = $website; - self::$_websitesByCode[$websiteCode] = $website; - } catch (Wootook_Core_Exception_DataAccessException $e) { - throw new Wootook_Core_Exception_WebsiteError('Could not load website entity.', null, $e); - } - - return $website; - } - } - - public static function getGame($gameId) - { - if (is_numeric($gameId)) { - if (isset(self::$_gamesById[$gameId])) { - return self::$_gamesById[$gameId]; - } - $game = new Wootook_Core_Model_Game(); - try { - $game->load($gameId); - $gameCode = $game->getData('code'); - - self::$_gamesById[$gameId] = $game; - self::$_gamesByCode[$gameCode] = $game; - } catch (Wootook_Core_Exception_DataAccessException $e) { - throw new Wootook_Core_Exception_GameError('Could not load game entity.', null, $e); - } - - return $game; - } else { - if (isset(self::$_gamesByCode[$gameId])) { - return self::$_gamesByCode[$gameId]; - } - $game = new Wootook_Core_Model_Game(); - try { - $game->load($gameId, 'code'); - $gameId = $game->getId(); - $gameCode = $game->getData('code'); - - self::$_gamesById[$gameId] = $game; - self::$_gamesByCode[$gameCode] = $game; - } catch (Wootook_Core_Exception_DataAccessException $e) { - throw new Wootook_Core_Exception_GameError('Could not load game entity.', null, $e); - } - - return $game; - } - } - - public static function addWebsite(Wootook_Core_Model_Website $website) - { - $websiteId = $website->getId(); - $websiteKey = $website->getData('code'); - self::$_websitesById[$websiteId] = $website; - self::$_websitesByCode[$websiteKey] = $website; - } - - public static function addGame(Wootook_Core_Model_Game $game) - { - $gameId = $game->getId(); - $gameKey = $game->getData('code'); - self::$_gamesById[$gameId] = $game; - self::$_gamesByCode[$gameKey] = $game; - } - - public static function setDefaultWebsite(Wootook_Core_Model_Website $website) - { - self::$_defaultWebsite = $website; - } - - public static function getDefaultWebsite() - { - if (self::$_defaultWebsite === null) { - self::$_defaultWebsite = new Wootook_Core_Model_Website(); - self::$_defaultWebsite->setId(1)->setData('code', Wootook_Core_Model_Website::DEFAULT_CODE); - } - return self::$_defaultWebsite; - } - - public static function getDefaultGame() - { - if (self::$_defaultGame === null) { - self::$_defaultGame = new Wootook_Core_Model_Game(); - self::$_defaultGame->setId(1)->setData('code', Wootook_Core_Model_Game::DEFAULT_CODE); - } - return self::$_defaultGame; - } - - public static function setDefaultGame(Wootook_Core_Model_Game $game) - { - self::$_defaultGame = $game; - } - - private static function _initWebsiteConfig($websiteId) - { - if (self::$_config === null) { - self::loadConfig(); - } - if (!self::$isInstalled) { - if (isset(self::$_config['default'])) { - self::$_websiteConfigs[Wootook_Core_Model_Website::DEFAULT_CODE] = clone self::$_config['default']; - } else { - self::$_websiteConfigs[Wootook_Core_Model_Website::DEFAULT_CODE] = new Wootook_Core_Config_Node(array(), self::$_config); - } - if (isset(self::$_config['install'])) { - self::$_websiteConfigs[Wootook_Core_Model_Website::DEFAULT_CODE]->merge(self::$_config['install']); - } - - return self::$_websiteConfigs[Wootook_Core_Model_Website::DEFAULT_CODE]; - } - - try { - $website = self::getWebsite($websiteId); - } catch (Wootook_Core_Exception_WebsiteError $e) { - self::$isInstalled = false; - Wootook_Core_ErrorProfiler::getSingleton()->addException($e); - - $website = new Wootook_Core_Model_Website(); - $website->setId(0)->setData('code', 'install'); - self::addWebsite($website); - self::setDefaultWebsite($website); - } catch (Wootook_Core_Exception_RuntimeException $e) { - Wootook_Core_ErrorProfiler::getSingleton()->exceptionManager($e); - return null; - } - $websiteKey = $website->getData('code'); - $websiteId = $website->getId(); - - if (!isset(self::$_websiteConfigs[$websiteKey])) { - self::$_websiteConfigs[$websiteKey] = clone self::$_config['default']; - if ($websiteId != 0 && isset(self::$_config['frontend'])) { - self::$_websiteConfigs[$websiteKey]->merge(self::$_config['frontend']); - } else if ($websiteId == 0 && isset(self::$_config['backend'])) { - self::$_websiteConfigs[$websiteKey]->merge(self::$_config['backend']); - } - - $websiteConfig = self::$_config->getConfig("website/{$websiteKey}"); - if ($websiteConfig !== null) { - self::$_websiteConfigs[$websiteKey]->merge($websiteConfig); - } - - self::_appendDatabaseConfig(self::$_websiteConfigs[$websiteKey], 'website', $website); - } - - return self::$_websiteConfigs[$websiteKey]; - } - - private static function _initGameConfig($gameId) - { - if (self::$_config === null) { - self::loadConfig(); - } - - if (!self::$isInstalled) { - if (isset(self::$_config['default'])) { - self::$_gameConfigs[Wootook_Core_Model_Game::DEFAULT_CODE] = clone self::$_config['default']; - } else { - self::$_gameConfigs[Wootook_Core_Model_Game::DEFAULT_CODE] = new Wootook_Core_Config_Node(array(), self::$_config); - } - if (isset(self::$_config['install'])) { - self::$_gameConfigs[Wootook_Core_Model_Game::DEFAULT_CODE]->merge(self::$_config['install']); - } - - return self::$_gameConfigs[Wootook_Core_Model_Game::DEFAULT_CODE]; - } - - try { - $game = self::getGame($gameId); - } catch (Wootook_Core_Exception_GameError $e) { - self::$isInstalled = false; - Wootook_Core_ErrorProfiler::getSingleton()->addException($e); - - $game = new Wootook_Core_Model_Game(); - $game->setId(0)->setData('code', 'install')->setData('website_id', self::getDefaultWebsite()->getId()); - self::addGame($game); - self::setDefaultGame($game); - } catch (Wootook_Core_Exception_RuntimeException $e) { - Wootook_Core_ErrorProfiler::getSingleton()->exceptionManager($e); - return null; - } - - $gameKey = $game->getData('code'); - $gameId = $game->getId(); - $websiteId = $game->getData('website_id'); - - if (!isset(self::$_gameConfigs[$gameKey])) { - $websiteConfig = self::_initWebsiteConfig($websiteId); - if ($websiteConfig === null) { - return null; - } - self::$_gameConfigs[$gameKey] = clone $websiteConfig; - - $gameConfig = self::$_config->getConfig("game/{$gameKey}"); - if ($gameConfig !== null) { - self::$_gameConfigs[$gameKey]->merge($gameConfig); - } - - self::_appendDatabaseConfig(self::$_gameConfigs[$gameKey], 'game', $game); - } - - return self::$_gameConfigs[$gameKey]; - } - - public static function getConfig($path = null) - { - if (self::$_config === null) { - self::loadConfig(); - } - - if ($path !== null) { - return self::$_globalConfig->getConfig($path); - } - return self::$_globalConfig; + return new Wootook\Core\DateTime(self::$_now); } /** * @static + * @return Wootook\Core\App + */ + public static function app($domain = Wootook\Core\App::DOMAIN_FRONTEND, $environment = Wootook\Core\App::ENV_PRODUCTION) + { + if (!isset(self::$_app[$environment])) { + self::$_app[$environment] = array(); + } + if (!isset(self::$_app[$environment][$domain])) { + $configPath = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'configs'; + self::$_app[$environment][$domain] = new Wootook\Core\App($configPath, $domain, $environment); + } + + return self::$_app[$environment][$domain]; + } + + /** + * @deprecated + * @return Wootook\Core\Mvc\Controller\Request\Request + */ + public static function getRequest() + { + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + return self::app()->getFrontController()->getRequest(); + } + + /** + * @static + * @deprecated + * @param Wootook\Core\Mvc\Controller\Request\Request $request + */ + public static function setRequest(Wootook\Core\Mvc\Controller\Request\Request $request) + { + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + self::app()->getFrontController()->setRequest($request); + } + + /** + * @deprecated + * @return Wootook\Core\Mvc\Controller\Response\Response + */ + public static function getResponse() + { + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + return self::app()->getFrontController()->getResponse(); + } + + /** + * @static + * @deprecated + * @param Wootook\Core\Mvc\Controller\Response\Response $response + */ + public static function setResponse(Wootook\Core\Mvc\Controller\Response\Response $response) + { + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + self::app()->getFrontController()->setResponse($response); + } + + /** + * @static + * @deprecated + * @param null $filename + * @return null|Wootook_Core_Helper_Config_ConfigHandler + * @throws CoreException\DataAccessException + */ + public static function loadConfig($filename = null) + { + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + return self::app()->getGlobalConfig(); + } + + /** + * @static + * @deprecated + * @param $websiteId + * @return mixed + */ + public static function getWebsite($websiteId) + { + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + return self::app()->getWebsite($websiteId); + } + + /** + * @static + * @deprecated + * @param $gameId + * @return Wootook_Core_Model_Game + * @throws CoreException\GameError + */ + public static function getGame($gameId) + { + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + return self::app()->getGame($gameId); + } + + /** + * @static + * @deprecated + * @param Wootook_Core_Model_Website $website + */ + public static function addWebsite(Wootook_Core_Model_Website $website) + { + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + } + + /** + * @static + * @deprecated + * @param Wootook_Core_Model_Game $game + */ + public static function addGame(Wootook_Core_Model_Game $game) + { + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + } + + /** + * @static + * @deprecated + * @param Wootook_Core_Model_Website $website + */ + public static function setDefaultWebsite(Wootook_Core_Model_Website $website) + { + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + self::app()->setDefaultWebsiteId($website->getId()); + } + + /** + * @static + * @deprecated + * @param Wootook_Core_Model_Game $game + */ + public static function setDefaultGame(Wootook_Core_Model_Game $game) + { + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + self::app()->setDefaultGameId($game->getId()); + } + + /** + * @static + * @deprecated + * @return mixed + */ + public static function getDefaultWebsite() + { + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + return self::app()->getDefaultWebsite(); + } + + /** + * @static + * @deprecated + * @return mixed + */ + public static function getDefaultGame() + { + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + return self::app()->getDefaultGame(); + } + + /** + * @static + * @deprecated + * @param null $path + * @return null|Wootook_Core_Config_Adapter_Array + */ + public static function getConfig($path = null) + { + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + return self::app()->getGlobalConfig($path); + } + + /** + * @static + * @deprecated * @param null $path * @param null $gameKey * @return Wootook_Core_Config_Node */ public static function getWebsiteConfig($path = null, $websiteKey = null) { - if (self::$_config === null) { - self::loadConfig(); - } + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); if ($websiteKey === null) { - //$websiteKey = Wootook_Core_Model_Website::DEFAULT_CODE; - $websiteKey = self::getDefaultWebsite()->getData('code'); + $websiteKey = self::app()->getDefaultWebsiteId(); } - $config = self::_initWebsiteConfig($websiteKey); - if ($config === null) { - return null; - } - - if ($path !== null) { - return $config->getConfig($path); - } - return $config; + return self::app()->getWebsite($websiteKey)->getConfig($path); } /** * @static + * @deprecated * @param null $path * @param null $gameKey * @return Wootook_Core_Config_Node */ public static function getGameConfig($path = null, $gameKey = null) { - if (self::$_config === null) { - self::loadConfig(); - } + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); if ($gameKey === null) { - //$gameKey = Wootook_Core_Model_Game::DEFAULT_CODE; - $gameKey = self::getDefaultGame()->getData('code'); + $gameKey = self::app()->getDefaultGameId(); } - $config = self::_initGameConfig($gameKey); - if ($config === null) { - return null; - } - - if ($path !== null) { - return $config->getConfig($path); - } - return $config; + return self::app()->getGame($gameKey)->getConfig($path); } public static function setConfig($path, $value, $websiteId = null, $gameId = null) @@ -756,7 +524,7 @@ class Wootook public static function getBaseUrl($domain = 'base') { - $urlConfig = self::getGameConfig('web/url'); + $urlConfig = self::app()->getDefaultGame()->getConfig('web/url'); if (!$urlConfig instanceof Wootook_Core_Config_Node) { return null; } @@ -768,7 +536,7 @@ class Wootook public static function getBasePath($domain = 'base') { - $pathConfig = self::getGameConfig('system/path'); + $pathConfig = self::app()->getDefaultGame()->getConfig('system/path'); if (!$pathConfig instanceof Wootook_Core_Config_Node) { return null; } @@ -831,13 +599,13 @@ class Wootook return false; } - Wootook_Core_ErrorProfiler::getSingleton()->sleep(); + Profiler\ErrorProfiler::getSingleton()->sleep(); if (($fp = @fopen($path, 'r', true)) === false) { - Wootook_Core_ErrorProfiler::getSingleton()->wakeup(); + Profiler\ErrorProfiler::getSingleton()->wakeup(); return false; } fclose($fp); - Wootook_Core_ErrorProfiler::getSingleton()->wakeup(); + Profiler\ErrorProfiler::getSingleton()->wakeup(); return true; } } diff --git a/src/application/code/core/Wootook/Core/App.php b/src/application/code/core/Wootook/Core/App.php deleted file mode 100644 index e21368a..0000000 --- a/src/application/code/core/Wootook/Core/App.php +++ /dev/null @@ -1,155 +0,0 @@ -_globalConfig = Wootook::getConfig(); - } - - protected function _resolveClassType(&$namespaces, $module, $class) - { - $class = str_replace(' ', '', ucwords(str_replace('-', ' ', $class))); - $class = str_replace(' ', '_', ucwords(str_replace('.', ' ', $class))); - - if (isset($namespaces[$module])) { - foreach ($namespaces[$module] as $namespace => $path) { - $className = $namespace . $class; - $fileName = $path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; - - Wootook_Core_ErrorProfiler::getSingleton()->sleep(); - if (!($fp = @fopen($fileName, 'r', true))) { - Wootook_Core_ErrorProfiler::getSingleton()->wakeup(); - continue; - } - Wootook_Core_ErrorProfiler::getSingleton()->wakeup(); - fclose($fp); - - if (!class_exists($className, true)) { - continue; - } - - return $className; - } - } - - Wootook_Core_ErrorProfiler::getSingleton() - ->addException(new Wootook_Core_Exception_LayoutException(sprintf('Class type "%s" could not be resolved.', $type))); - 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($type, 0, $offset); - $class = substr($type, $offset + 1); - } - - public function block($identifier) - { - $this->_parseIdentifier($identifier, $module, $class); - - return $this->getBlock($module, $class); - } - - public function model($identifier) - { - $this->_parseIdentifier($identifier, $module, $class); - - return $this->getModel($module, $class); - } - - public function resource($identifier) - { - $this->_parseIdentifier($identifier, $module, $class); - - return $this->getResource($module, $class); - } - - public function helper($identifier) - { - $this->_parseIdentifier($identifier, $module, $class); - - if ($class === null) { - $class = 'data'; - } - - return $this->getResource($module, $class); - } - - public function getBlock($module, $class, Array $constructorParams = array()) - { - $className = $this->_resolveClassType($this->_globalConfig->blocks, $module, $class); - - return $this->_newInstance($className, $constructorParams); - } - - public function getModel($module, $class, Array $constructorParams = array()) - { - $className = $this->_resolveClassType($this->_globalConfig->models, $module, $class); - - return $this->_newInstance($className, $constructorParams); - } - - public function getResource($module, $class, Array $constructorParams = array()) - { - $className = $this->_resolveClassType($this->_globalConfig->resources, $module, $class); - - return $this->_newInstance($className, $constructorParams); - } - - public function getHelper($module, $class, Array $constructorParams = array()) - { - $className = $this->_resolveClassType($this->_globalConfig->helpers, $module, $class); - - return $this->_newInstance($className, $constructorParams); - } - - public function getBlockSingleton($module, $class, Array $constructorParams = array()) - { - - } - - public function getModelSingleton($module, $class, Array $constructorParams = array()) - { - - } - - public function getResourceSingleton($module, $class, Array $constructorParams = array()) - { - - } - - public function getHelperSingleton($module, $class, Array $constructorParams = array()) - { - - } -} diff --git a/src/application/code/core/Wootook/Core/Block/Concat.php b/src/application/code/core/Wootook/Core/Block/Concat.php deleted file mode 100644 index cb8dc89..0000000 --- a/src/application/code/core/Wootook/Core/Block/Concat.php +++ /dev/null @@ -1,14 +0,0 @@ -_partials as $partial) { - $content .= $partial->render(); - } - return $content; - } -} diff --git a/src/application/code/core/Wootook/Core/Block/Deprecated.php b/src/application/code/core/Wootook/Core/Block/Deprecated.php deleted file mode 100644 index 5a26860..0000000 --- a/src/application/code/core/Wootook/Core/Block/Deprecated.php +++ /dev/null @@ -1,10 +0,0 @@ -getLayout()->getScriptPath(); - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Block/Html/Form.php b/src/application/code/core/Wootook/Core/Block/Html/Form.php deleted file mode 100644 index 299983a..0000000 --- a/src/application/code/core/Wootook/Core/Block/Html/Form.php +++ /dev/null @@ -1,11 +0,0 @@ -getFormKey(true); - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Block/Html/Home.php b/src/application/code/core/Wootook/Core/Block/Html/Home.php deleted file mode 100644 index ac43612..0000000 --- a/src/application/code/core/Wootook/Core/Block/Html/Home.php +++ /dev/null @@ -1,22 +0,0 @@ -_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'; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Block/Html/Page.php b/src/application/code/core/Wootook/Core/Block/Html/Page.php deleted file mode 100644 index 12c7775..0000000 --- a/src/application/code/core/Wootook/Core/Block/Html/Page.php +++ /dev/null @@ -1,19 +0,0 @@ -_bodyClasses); - } - - public function addBodyClass($class) - { - $this->_bodyClasses[] = $class; - - return $this; - } -} diff --git a/src/application/code/core/Wootook/Core/Block/Messages.php b/src/application/code/core/Wootook/Core/Block/Messages.php deleted file mode 100644 index 5aa7cb4..0000000 --- a/src/application/code/core/Wootook/Core/Block/Messages.php +++ /dev/null @@ -1,47 +0,0 @@ -_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 = '
'; - foreach ($messages as $messageLevel => $messageList) { - $output .= "
    "; - foreach ($messageList as $message) { - $output .= "
  • {$message}
  • "; - } - $output .= '
'; - } - $output .= '
'; - - return $output; - } -} diff --git a/src/application/code/core/Wootook/Core/Block/Template.php b/src/application/code/core/Wootook/Core/Block/Template.php deleted file mode 100644 index 1383a4e..0000000 --- a/src/application/code/core/Wootook/Core/Block/Template.php +++ /dev/null @@ -1,46 +0,0 @@ -getScriptPath() == '') { - Wootook_Core_ErrorProfiler::getSingleton() - ->addException(new Wootook_Core_Exception_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 !== Wootook_Core_Model_Layout::DEFAULT_PACKAGE) { - if ($theme !== Wootook_Core_Model_Layout::DEFAULT_THEME) { - $path = sprintf($pattern, $package, $theme); - if (Wootook::fileExists($path)) { - return $path; - } - } - - $path = sprintf($pattern, $package, Wootook_Core_Model_Layout::DEFAULT_THEME); - if (Wootook::fileExists($path)) { - return $path; - } - } - } else { - Wootook_Core_ErrorProfiler::getSingleton() - ->addException(new Wootook_Core_Exception_RuntimeException("No layout defined.")); - } - - $path = sprintf($pattern, Wootook_Core_Model_Layout::DEFAULT_PACKAGE, Wootook_Core_Model_Layout::DEFAULT_THEME); - if (Wootook::fileExists($path)) { - return $path; - } - - Wootook_Core_ErrorProfiler::getSingleton() - ->addException(new Wootook_Core_Exception_RuntimeException("Template '{$file}' could not be found.")); - return null; - } -} diff --git a/src/application/code/core/Wootook/Core/Block/Text.php b/src/application/code/core/Wootook/Core/Block/Text.php deleted file mode 100644 index dabe336..0000000 --- a/src/application/code/core/Wootook/Core/Block/Text.php +++ /dev/null @@ -1,28 +0,0 @@ -_content = $content; - - return $this; - } - - public function getContent() - { - return $this->_content; - } - - public function render() - { - $content = $this->getContent(); - if (empty($content)) { - return null; - } - return $content; - } -} diff --git a/src/application/code/core/Wootook/Core/Config/Adapter/Adapter.php b/src/application/code/core/Wootook/Core/Config/Adapter/Adapter.php deleted file mode 100644 index bec4430..0000000 --- a/src/application/code/core/Wootook/Core/Config/Adapter/Adapter.php +++ /dev/null @@ -1,6 +0,0 @@ -load($filename); - } - } - - public function load($filename) - { - if (!file_exists($filename)) { - throw new Wootook_Core_Exception_DataAccessException(sprintf('Could not load config file "%s"', $filename)); - } - $data = include $filename; - - if (!is_array($data)) { - throw new Wootook_Core_Exception_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; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Controller/ErrorController.php b/src/application/code/core/Wootook/Core/Controller/ErrorController.php deleted file mode 100644 index 0a2e348..0000000 --- a/src/application/code/core/Wootook/Core/Controller/ErrorController.php +++ /dev/null @@ -1,11 +0,0 @@ -loadLayout('no-route'); - $this->renderLayout(); - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Controller/IndexController.php b/src/application/code/core/Wootook/Core/Controller/IndexController.php deleted file mode 100644 index c77c6f0..0000000 --- a/src/application/code/core/Wootook/Core/Controller/IndexController.php +++ /dev/null @@ -1,11 +0,0 @@ -loadLayout('home'); - $this->renderLayout(); - } -} diff --git a/src/application/code/core/Wootook/Core/Database/Adapter/Adapter.php b/src/application/code/core/Wootook/Core/Database/Adapter/Adapter.php deleted file mode 100644 index 41d8bdb..0000000 --- a/src/application/code/core/Wootook/Core/Database/Adapter/Adapter.php +++ /dev/null @@ -1,199 +0,0 @@ -_handler; - } - - public function getDataMapper() - { - return new Wootook_Core_Database_Orm_DataMapper(); - } - - /** - * - * @param string $prefix - * @return Wootook_Core_Database_Adapter_Pdo_Mysql - */ - 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 Wootook_Core_Database_Sql_Select - */ - public function select() - { - return new Wootook_Core_Database_Sql_Select($this); - } - - /** - * @return Wootook_Core_Database_Sql_Insert - */ - public function insert() - { - return new Wootook_Core_Database_Sql_Insert($this); - } - - /** - * @return Wootook_Core_Database_Sql_Update - */ - public function update() - { - return new Wootook_Core_Database_Sql_Update($this); - } - - /** - * @return Wootook_Core_Database_Sql_Delete - */ - public function delete() - { - return new Wootook_Core_Database_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; - } - - /** - * @return Wootook_Core_Database_Statement_Statement - */ - public function query($sql, Array $params = null) - { - $statement = $this->prepare($sql, $params); - if (!$statement->execute()) { - $message = sprintf('[SQLSTATE %s] Could not execute query: %s', $statement->errorState(), $statement->errorMessage()); - throw new Wootook_Core_Exception_Database_StatementError($statement, $message); - } - - return $statement; - } - - /** - * @return bool - */ - public function execute($sql, Array $params = null) - { - $statement = $this->prepare($sql); - return $statement->execute($params); - } - - /** - * @return Wootook_Core_Database_Statement_Statement - */ - abstract public function prepare($sql, Array $params = null); - - /** - * @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(); -} diff --git a/src/application/code/core/Wootook/Core/Database/Adapter/Pdo/Mysql.php b/src/application/code/core/Wootook/Core/Database/Adapter/Pdo/Mysql.php deleted file mode 100644 index 5270cf2..0000000 --- a/src/application/code/core/Wootook/Core/Database/Adapter/Pdo/Mysql.php +++ /dev/null @@ -1,170 +0,0 @@ -hostname};dbname={$config->database}"; - if (is_numeric($config->port)) { - $dsn .= ";port={$config->database}"; - } - - if (!isset($options[Wootook_Core_Database_ConnectionManager::ATTR_ERRMODE])) { - $options[Wootook_Core_Database_ConnectionManager::ATTR_ERRMODE] = Wootook_Core_Database_ConnectionManager::ERRMODE_EXCEPTION; - } - - try { - $this->_handler = new PDO($dsn, $config->username, $config->password, $options); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_AdapterError($this, $e->getMessage(), null, $e); - } - } - - /** - * (non-PHPdoc) - * @see Wootook_Core_Database_Adapter_Adapter::quoteIdentifier() - */ - public function quoteIdentifier($identifier) - { - return "`$identifier`"; - } - - public function quote($data) - { - try { - return $this->_handler->quote($data); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_AdapterError($this, $e->getMessage(), null, $e); - } - return null; - } - - /** - * - * @param string $name - * @return string - */ - public function getTable($name) - { - return $this->getTablePrefix() . $name; - } - - /** - * @see Wootook_Core_Database_Adapter_Adapter::select() - */ - public function select($tableName = null) - { - return new Wootook_Core_Database_Sql_Mysql_Select($this, $tableName); - } - - /** - * @return Wootook_Core_Database_Statement_Statement - */ - public function prepare($sql, Array $params = null) - { - $statement = new Wootook_Core_Database_Statement_Pdo_Mysql($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 Wootook_Core_Exception_Database_AdapterError($this, $e->getMessage(), null, $e); - } - return false; - } - - /** - * @return bool - */ - public function commit() - { - try { - return $this->_handler->commit(); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_AdapterError($this, $e->getMessage(), null, $e); - } - return false; - } - - /** - * @return bool - */ - public function rollback() - { - try { - return $this->_handler->rollback(); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_AdapterError($this, $e->getMessage(), null, $e); - } - return false; - } - - /** - * @return int - */ - public function lastInsertId() - { - try { - return $this->_handler->lastInsertId(); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_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]; - } -} diff --git a/src/application/code/core/Wootook/Core/Database/Orm/DataMapper/Array.php b/src/application/code/core/Wootook/Core/Database/Orm/DataMapper/Array.php deleted file mode 100644 index f1db44d..0000000 --- a/src/application/code/core/Wootook/Core/Database/Orm/DataMapper/Array.php +++ /dev/null @@ -1,15 +0,0 @@ -toArray()); - } - - public function decode($value) - { - return new Wootook_Core_Config_Node(parent::decode($value)); - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Database/Orm/DataMapper/DateTime.php b/src/application/code/core/Wootook/Core/Database/Orm/DataMapper/DateTime.php deleted file mode 100644 index 1e37d12..0000000 --- a/src/application/code/core/Wootook/Core/Database/Orm/DataMapper/DateTime.php +++ /dev/null @@ -1,38 +0,0 @@ -_format = self::DATE_FORMAT_MYSQL; - } else { - $this->_format = $format; - } - return $this; - } - - public function getFormat() - { - return $this->_format; - } - - public function encode($value) - { - if (!$value instanceof Wootook_Core_DateTime) { - $value = new Wootook_Core_DateTime($value); - } - - return $value->toString($this->getFormat()); - } - - public function decode($value) - { - return new Wootook_Core_DateTime($value, $this->getFormat()); - } -} diff --git a/src/application/code/core/Wootook/Core/Database/Orm/DataMapper/FieldMapper.php b/src/application/code/core/Wootook/Core/Database/Orm/DataMapper/FieldMapper.php deleted file mode 100644 index a7e989c..0000000 --- a/src/application/code/core/Wootook/Core/Database/Orm/DataMapper/FieldMapper.php +++ /dev/null @@ -1,15 +0,0 @@ -_mapper = $mapper; - } - - abstract public function encode($value); - - abstract public function decode($value); -} diff --git a/src/application/code/core/Wootook/Core/Database/Orm/DataMapper/Object.php b/src/application/code/core/Wootook/Core/Database/Orm/DataMapper/Object.php deleted file mode 100644 index 7af245b..0000000 --- a/src/application/code/core/Wootook/Core/Database/Orm/DataMapper/Object.php +++ /dev/null @@ -1,43 +0,0 @@ -_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; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Database/Resource.php b/src/application/code/core/Wootook/Core/Database/Resource.php deleted file mode 100644 index 5501b32..0000000 --- a/src/application/code/core/Wootook/Core/Database/Resource.php +++ /dev/null @@ -1,89 +0,0 @@ -_dataMapper === null) { - $this->_dataMapper = new Wootook_Core_Database_Orm_DataMapper(); - } - return $this->_dataMapper; - } - - public function setTableName($tableName) - { - $this->_tableName = $tableName; - - return $this; - } - - public function getTableName() - { - return $this->_tableName; - } - - /** - * @return Wootook_Core_Database_Adapter_Adapter - */ - public function getReadConnection() - { - if ($this->_readConnection === null) { - $this->_readConnection = Wootook_Core_Database_ConnectionManager::getSingleton() - ->getConnection('core_read'); - } - - return $this->_readConnection; - } - - public function setReadConnection($connection) - { - if ($connection instanceof Wootook_Core_Database_Adapter_Pdo_Mysql) { - $this->_readConnection = $connection; - } else if (is_string($connection)) { - $this->_readConnection = $this->getConnection($connection); - } else { - throw new Wootook_Core_Exception_RuntimeException( - 'First parameter should be either a database connection object or a string identifier.'); - } - - return $this; - } - - /** - * @return Wootook_Core_Database_Adapter_Adapter - */ - public function getWriteConnection() - { - if ($this->_writeConnection === null) { - $this->_writeConnection = Wootook_Core_Database_ConnectionManager::getSingleton() - ->getConnection('core_write'); - } - return $this->_writeConnection; - } - - public function setWriteConnection($connection) - { - if ($connection instanceof Wootook_Core_Database_Adapter_Pdo_Mysql) { - $this->_readConnection = $connection; - } else if (is_string($connection)) { - $this->_readConnection = $this->getConnection($connection); - } else { - throw new Wootook_Core_Exception_RuntimeException( - 'First parameter should be either a database connection object or a string identifier.'); - } - - return $this; - } -} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Dml.php b/src/application/code/core/Wootook/Core/Database/Sql/Dml.php deleted file mode 100644 index de0c17b..0000000 --- a/src/application/code/core/Wootook/Core/Database/Sql/Dml.php +++ /dev/null @@ -1,24 +0,0 @@ -setConnection($connection); - - $this->reset(); - $this->_init($tableName); - } - - /** - * @return Wootook_Core_Database_Adapter_Adapter - */ - public function getConnection() - { - return $this->_connection; - } - - public function setConnection(Wootook_Core_Database_Adapter_Adapter $connection) - { - $this->_connection = $connection; - - return $this; - } - - protected function _init($param = null) - { - return $this; - } - - public function getPart($part = null) - { - if ($part === null) { - return $this->_parts; - } - if (isset($this->_parts[$part])) { - return $this->_parts[$part]; - } - - return null; - } - - public function quote($data) - { - return $this->getConnection()->quote($data); - } - - public function quoteIdentifier($identifier) - { - return $this->getConnection()->quoteIdentifier($identifier); - } - - public function beforePrepare(Wootook_Core_Database_Statement_Statement $statement) - { - foreach ($this->_placeholders as $placeholder) { - $placeholder->beforePrepare($statement); - } - - return $this; - } - - public function afterPrepare(Wootook_Core_Database_Statement_Statement $statement) - { - foreach ($this->_placeholders as $placeholder) { - $placeholder->afterPrepare($statement); - } - - return $this; - } - - public function beforeExecute(Wootook_Core_Database_Statement_Statement $statement) - { - foreach ($this->_placeholders as $placeholder) { - $placeholder->beforeExecute($statement); - } - - return $this; - } - - public function afterExecute(Wootook_Core_Database_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); - } -} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Mysql/Select.php b/src/application/code/core/Wootook/Core/Database/Sql/Mysql/Select.php deleted file mode 100644 index 5e8c80c..0000000 --- a/src/application/code/core/Wootook/Core/Database/Sql/Mysql/Select.php +++ /dev/null @@ -1,6 +0,0 @@ -_expression = (string) $expression; - $this->_params = $params; - } - - public function __toString() - { - return $this->_expression; - } - - public function beforeExecute(Wootook_Core_Database_Statement_Statement $statement) - { - parent::beforeExecute($statement); - - foreach ($this->_params as $paramName => $value) { - $statement->bindValue($paramName, $value, $statement->getParamType($value)); - } - - return $this; - } -} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Param.php b/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Param.php deleted file mode 100644 index 5a77287..0000000 --- a/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Param.php +++ /dev/null @@ -1,31 +0,0 @@ -_paramName = $paramName; - $this->_paramType = $type; - $this->_value = $value; - } - - public function __toString() - { - return ':' . $this->_paramName; - } - - public function beforeExecute(Wootook_Core_Database_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; - } -} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Placeholder.php b/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Placeholder.php deleted file mode 100644 index b601575..0000000 --- a/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Placeholder.php +++ /dev/null @@ -1,31 +0,0 @@ -__toString(); - } - - abstract public function __toString(); - - public function beforePrepare(Wootook_Core_Database_Statement_Statement $statement) - { - return $this; - } - - public function afterPrepare(Wootook_Core_Database_Statement_Statement $statement) - { - return $this; - } - - public function beforeExecute(Wootook_Core_Database_Statement_Statement $statement) - { - return $this; - } - - public function afterExecute(Wootook_Core_Database_Statement_Statement $statement) - { - return $this; - } -} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Variable.php b/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Variable.php deleted file mode 100644 index 04e4217..0000000 --- a/src/application/code/core/Wootook/Core/Database/Sql/Placeholder/Variable.php +++ /dev/null @@ -1,20 +0,0 @@ -_paramName = $paramName; - $this->_paramType = $type; - } - - public function __toString() - { - return ':' . $this->_paramName; - } -} diff --git a/src/application/code/core/Wootook/Core/Database/Statement/Pdo/Mysql.php b/src/application/code/core/Wootook/Core/Database/Statement/Pdo/Mysql.php deleted file mode 100644 index 33b243d..0000000 --- a/src/application/code/core/Wootook/Core/Database/Statement/Pdo/Mysql.php +++ /dev/null @@ -1,321 +0,0 @@ -_query = $query; - - if ($this->_query instanceof Wootook_Core_Database_Sql_Dml) { - $this->_query->beforePrepare($this); - } - - try { - $this->_handler = $this->_adapter->getDriverHandler()->prepare($this->_query); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e); - } - - if ($this->_query instanceof Wootook_Core_Database_Sql_Dml) { - $this->_query->afterPrepare($this); - } - - return $this; - } - - /** - * - * @param string|int $column - * @param mixed $param - * @param int $type - * @return Wootook_Core_Database_Statement_Statement - */ - public function bindColumn($column, &$param, $type = null) - { - try { - return $this->_handler->bindColumn($column, $param, $type); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e); - } - - return false; - } - - /** - * - * @param string|int $parameter - * @param mixed $variable - * @param int $type - * @param int $length - * @param unknown_type $options - * @return Wootook_Core_Database_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 Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e); - } - return false; - } - - /** - * - * @param string|int $parameter - * @param mixed $value - * @param int $type - * @return Wootook_Core_Database_Statement_Statement - */ - public function bindValue($parameter, $value, $type = null) - { - try { - return $this->_handler->bindValue($parameter, $value, $type); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e); - } - return false; - } - - /** - * - * @param array $params - * @return bool - */ - public function execute(Array $params = null) - { - if ($this->_query instanceof Wootook_Core_Database_Sql_Dml) { - $this->_query->beforeExecute($this); - } - - try { - $result = $this->_handler->execute($params); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e); - } - - if ($this->_query instanceof Wootook_Core_Database_Sql_Dml) { - $this->_query->afterExecute($this); - } - - 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 Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e); - } - return $result; - } - - /** - * - * @param int $col - * @return mixed - */ - public function fetchColumn($col = 0) - { - try { - return $this->_handler->fetchColumn($col); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e); - } - return null; - } - - /** - * - * @return Wootook_Core_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 Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e); - } - return null; - } - - /** - * - * @param string $key - * @param mixed $value - * @return Wootook_Core_Database_Statement_Statement - */ - public function setAttribute($key, $value) - { - try { - return $this->_handler->setAttribute($key, $value); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e); - } - return false; - } - - /** - * @param unknown_type $mode - * @return Wootook_Core_Database_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 Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e); - } - return false; - } - - /** - * @return int - */ - public function columnCount() - { - try { - return $this->_handler->columnCount(); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e); - } - return 0; - } - - /** - * @return int - */ - public function rowCount() - { - try { - return $this->_handler->rowCount(); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e); - } - return 0; - } - - /** - * @param int $col - * @return mixed - */ - public function fetch($style = null, $orientation = Wootook_Core_Database_ConnectionManager::FETCH_ORI_NEXT, $cursorOffset = 0) - { - try { - return $this->_handler->fetch($style, $orientation, $cursorOffset); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e); - } - return null; - } - - /** - * @param string $class - * @param array $config - * @return Wootook_Object - */ - public function fetchObject($class = 'Wootook_Object', Array $constructorArgs = array()) - { - try { - return $this->_handler->fetchObject($class, $constructorArgs); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e); - } - return null; - } - - /** - * @return bool - */ - public function closeCursor() - { - try { - return $this->_handler->closeCursor(); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_Database_AdapterError($this, $e->getMessage(), null, $e); - } - return false; - } - - /** - * @return bool - */ - public function nextRowset() - { - try { - return $this->_handler->nextRowset(); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_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]; - } -} diff --git a/src/application/code/core/Wootook/Core/Database/Statement/Statement.php b/src/application/code/core/Wootook/Core/Database/Statement/Statement.php deleted file mode 100644 index 9e8875f..0000000 --- a/src/application/code/core/Wootook/Core/Database/Statement/Statement.php +++ /dev/null @@ -1,215 +0,0 @@ -_adapter = $adapter; - - $this->_init($sql); - } - - abstract protected function _init($sql); - - /** - * - * @param string|int $column - * @param mixed $param - * @param int $type - * @return Wootook_Core_Database_Statement_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 Wootook_Core_Database_Statement_Statement - */ - abstract public function bindParam($parameter, &$variable, $type = null, $length = null, $options = null); - - /** - * - * @param string|int $parameter - * @param mixed $value - * @param int $type - * @return Wootook_Core_Database_Statement_Statement - */ - abstract public function bindValue($parameter, $value, $type = null); - - /** - * - * @param array $params - * @return bool - */ - abstract public function execute(Array $params = null); - - /** - * - * @param int $style - * @param int $col - * @return mixed - */ - abstract public function fetch($style = null, $orientation = Wootook_Core_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_Object - */ - abstract public function fetchObject($class = 'Wootook_Object', Array $constructorArgs = array()); - - /** - * - * @param string $class - * @param array $config - * @return Wootook_Object - */ - public function fetchEntity($class = 'Wootook_Core_Mvc_Model_Entity', Array $constructorArgs = array()) - { - $reflection = new ReflectionClass($class); - $object = $reflection->newInstanceArgs($constructorArgs); - - if (!$object instanceof Wootook_Object) { - throw new Wootook_Core_Exception_Database_StatementError($this, 'Destination object should be a Wootook_Core_Mvc_Model_Entity instance.'); - } - - $data = $this->fetch(Wootook_Core_Database_ConnectionManager::FETCH_ASSOC); - if ($data !== false) { - $object->getDataMapper()->decode($object, $data); - } - - return $object; - } - - /** - * - * @return Wootook_Core_Database_Adapter_Adapter - */ - abstract public function getAdapter(); - - /** - * - * @param string $key - */ - abstract public function getAttribute($key); - - /** - * - * @param string $key - * @param mixed $value - * @return Wootook_Core_Database_Statement_Statement - */ - abstract public function setAttribute($key, $value); - - /** - * @param unknown_type $mode - * @return Wootook_Core_Database_Statement_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(); - - public function getParamType($value) - { - if (is_numeric($value)) { - return Wootook_Core_Database_ConnectionManager::PARAM_INT; - } else if (is_bool($value)) { - return Wootook_Core_Database_ConnectionManager::PARAM_BOOL; - } else if (is_string($value)) { - return Wootook_Core_Database_ConnectionManager::PARAM_STR; - } - - return null; - } - - public function current() - { - return $this->_currentRow; - } - - public function next() - { - $this->_currentRow = $this->fetch(); - $this->_currentIndex++; - } - - public function key() - { - return $this->_currentIndex; - } - - public function rewind() - { - return $this->_currentIndex; - } - - public function valid() - { - $rows = $this->rowCount(); - return $rows > 0 && $this->_currentIndex <= $rows; - } -} diff --git a/src/application/code/core/Wootook/Core/Email.php b/src/application/code/core/Wootook/Core/Email.php deleted file mode 100644 index e94331e..0000000 --- a/src/application/code/core/Wootook/Core/Email.php +++ /dev/null @@ -1,51 +0,0 @@ -setTransport($transport); - } - - public function setTransport(Wootook_Core_Email_Transport_Transport $transport) - { - $this->_transport = $transport; - } - - /** - * @return Wootook_Core_Email_Transport_Transport - */ - public function getTransport() - { - return $this->_transport; - } - - public function send($to, $from, $subject, $body, Array $headers = array()) - { - try { - $this->_transport - ->addRecipient($to) - ->setFrom($from) - ->setSubject($subject) - ->addPart(new Wootook_Core_Email_Part_Part($body)) - ->addHeaders($headers) - ->connect() - ->send() - ; - } catch (Wootook_Core_Exception_RuntimeException $e) { - throw new Wootook_Core_Exception_RuntimeException('Could not send mail.', null, $e); - } - - $this->_transport->disconnect(); - - return $this; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Email/Part/Part.php b/src/application/code/core/Wootook/Core/Email/Part/Part.php deleted file mode 100644 index 563a051..0000000 --- a/src/application/code/core/Wootook/Core/Email/Part/Part.php +++ /dev/null @@ -1,16 +0,0 @@ -_content = $content; - } - - public function render() - { - return $this->_content; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Email/Transport/Transport.php b/src/application/code/core/Wootook/Core/Email/Transport/Transport.php deleted file mode 100644 index fed059e..0000000 --- a/src/application/code/core/Wootook/Core/Email/Transport/Transport.php +++ /dev/null @@ -1,22 +0,0 @@ -_adapter = $adapter; - } - - public function getAdapter() - { - return $this->_adapter; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Exception/Database/Error.php b/src/application/code/core/Wootook/Core/Exception/Database/Error.php deleted file mode 100644 index 6d485fa..0000000 --- a/src/application/code/core/Wootook/Core/Exception/Database/Error.php +++ /dev/null @@ -1,5 +0,0 @@ -_statement = $statement; - } - - public function getStatement() - { - return $this->_statement; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Exception/Deprecated.php b/src/application/code/core/Wootook/Core/Exception/Deprecated.php deleted file mode 100644 index 75cbf77..0000000 --- a/src/application/code/core/Wootook/Core/Exception/Deprecated.php +++ /dev/null @@ -1,7 +0,0 @@ -= 50300) { - parent::__construct($message, $code, $previous); - } else { - parent::__construct($message, $code); - $this->_previous = $previous; - } - } - - public function __call($method, $params) - { - if (strtolower($method) == 'getprevious') { - return $this->_previous; - } - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Exception/GameError.php b/src/application/code/core/Wootook/Core/Exception/GameError.php deleted file mode 100644 index ab228a8..0000000 --- a/src/application/code/core/Wootook/Core/Exception/GameError.php +++ /dev/null @@ -1,7 +0,0 @@ -= 50300) { - parent::__construct($message, $code, $previous); - } else { - parent::__construct($message, $code); - $this->_previous = $previous; - } - } - - public function __call($method, $params) - { - if (strtolower($method) == 'getprevious') { - return $this->_previous; - } - } - - public function __toString() - { - return <<_form = $form; - - foreach ($namespaces as $namespace => $path) { - if (is_int($namespace)) { - $this->registerNamespace($path); - } else { - $this->registerNamespace($namespace, $path); - } - } - } - - protected function _load($className, $useSingleton, Array $constructorParams = array()) - { - $reflection = new ReflectionClass($className); - if ($useSingleton && $reflection->implementsInterface('Wootook_Core_Singleton')) { - $method = $reflection->getMethod('getSingleton'); - return $method->invoke(null); - } - - try { - return $reflection->newInstance($this->_form); - } catch (ReflectionException $e) { - Wootook_Core_ErrorProfiler::getSingleton() - ->addException($e); - return null; - } - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Form/Validator/Alnum.php b/src/application/code/core/Wootook/Core/Form/Validator/Alnum.php deleted file mode 100644 index cdacc4f..0000000 --- a/src/application/code/core/Wootook/Core/Form/Validator/Alnum.php +++ /dev/null @@ -1,21 +0,0 @@ -_validate($element, $data)) { - $this->_getSession($element) - ->addError('Field "%s" should only contain alphanumeric characters.', $element->getName()); - - return false; - } - return true; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Form/Validator/Alpha.php b/src/application/code/core/Wootook/Core/Form/Validator/Alpha.php deleted file mode 100644 index fb091ce..0000000 --- a/src/application/code/core/Wootook/Core/Form/Validator/Alpha.php +++ /dev/null @@ -1,21 +0,0 @@ -_validate($element, $data)) { - $this->_getSession($element) - ->addError('Field "%s" should only contain alphabetic characters.', $element->getName()); - - return false; - } - return true; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Form/Validator/Email.php b/src/application/code/core/Wootook/Core/Form/Validator/Email.php deleted file mode 100644 index 3ec8e21..0000000 --- a/src/application/code/core/Wootook/Core/Form/Validator/Email.php +++ /dev/null @@ -1,21 +0,0 @@ -_validate($element, $data)) { - $this->_getSession($element) - ->addError('Field "%s" should contain an email.', $element->getName()); - - return false; - } - return true; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Form/Validator/FormKey.php b/src/application/code/core/Wootook/Core/Form/Validator/FormKey.php deleted file mode 100644 index 11f49d0..0000000 --- a/src/application/code/core/Wootook/Core/Form/Validator/FormKey.php +++ /dev/null @@ -1,20 +0,0 @@ -getForm(); - $session = $form->getSession(); - - if ($session->getFormKey(false) == $data) { - return true; - } - - $this->_getSession($field) - ->addError('CSRF token failure.', $field->getName()); - - return false; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Form/Validator/Hex.php b/src/application/code/core/Wootook/Core/Form/Validator/Hex.php deleted file mode 100644 index cbb2913..0000000 --- a/src/application/code/core/Wootook/Core/Form/Validator/Hex.php +++ /dev/null @@ -1,22 +0,0 @@ -_validate($element, $data)) { - $this->_getSession($element) - ->addError('Field "%s" should only contain numeric characters.', $element->getName()); - - return false; - } - return true; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Form/Validator/Host.php b/src/application/code/core/Wootook/Core/Form/Validator/Host.php deleted file mode 100644 index 4d1f7f5..0000000 --- a/src/application/code/core/Wootook/Core/Form/Validator/Host.php +++ /dev/null @@ -1,21 +0,0 @@ -_validate($element, $data)) { - $this->_getSession($element) - ->addError('Field "%s" should contain a host name.', $element->getName()); - - return false; - } - return true; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Form/Validator/Numeric.php b/src/application/code/core/Wootook/Core/Form/Validator/Numeric.php deleted file mode 100644 index 35f275d..0000000 --- a/src/application/code/core/Wootook/Core/Form/Validator/Numeric.php +++ /dev/null @@ -1,22 +0,0 @@ -_validate($element, $data)) { - $this->_getSession($element) - ->addError('Field "%s" should only contain numeric characters.', $element->getName()); - - return false; - } - return true; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Form/Validator/Regex.php b/src/application/code/core/Wootook/Core/Form/Validator/Regex.php deleted file mode 100644 index 172a787..0000000 --- a/src/application/code/core/Wootook/Core/Form/Validator/Regex.php +++ /dev/null @@ -1,28 +0,0 @@ -_expression = $expression; - } - - public function validate(Wootook_Core_Form_ElementAbstract $element, $data) - { - if (!$this->_validate($element, $data)) { - $this->_getSession($element) - ->addError('Field "%s" does not match the validation pattern.', $element->getName()); - - return false; - } - return true; - } - - protected function _validate(Wootook_Core_Form_ElementAbstract $element, $data) - { - return preg_match($this->_expression, $data); - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Form/ValidatorAbstract.php b/src/application/code/core/Wootook/Core/Form/ValidatorAbstract.php deleted file mode 100644 index d3f6da2..0000000 --- a/src/application/code/core/Wootook/Core/Form/ValidatorAbstract.php +++ /dev/null @@ -1,15 +0,0 @@ -getForm(); - if (!$form instanceof Wootook_Core_Form) { - return null; - } - return $element->getSession(); - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Form/ValidatorLoader.php b/src/application/code/core/Wootook/Core/Form/ValidatorLoader.php deleted file mode 100644 index 123bd64..0000000 --- a/src/application/code/core/Wootook/Core/Form/ValidatorLoader.php +++ /dev/null @@ -1,37 +0,0 @@ -_form = $form; - - foreach ($namespaces as $namespace => $path) { - if (is_int($namespace)) { - $this->registerNamespace($path); - } else { - $this->registerNamespace($namespace, $path); - } - } - } - - protected function _load($className, $useSingleton, Array $constructorParams = array()) - { - $reflection = new ReflectionClass($className); - if ($useSingleton && $reflection->implementsInterface('Wootook_Core_Singleton')) { - $method = $reflection->getMethod('getSingleton'); - return $method->invoke(null); - } - - try { - return $reflection->newInstance(); - } catch (ReflectionException $e) { - Wootook_Core_ErrorProfiler::getSingleton() - ->addException($e); - return null; - } - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Helper/Config/ConfigHandler.php b/src/application/code/core/Wootook/Core/Helper/Config/ConfigHandler.php deleted file mode 100644 index 7421bad..0000000 --- a/src/application/code/core/Wootook/Core/Helper/Config/ConfigHandler.php +++ /dev/null @@ -1,59 +0,0 @@ - 'default', - 'episode' => 'default' - ); - } else { - $config = $config->toArray(); - } - - $path = 'gamedata' . DIRECTORY_SEPARATOR . $config['universe'] . DIRECTORY_SEPARATOR - . $config['episode'] . DIRECTORY_SEPARATOR . $filename . '.php'; - - foreach (include APPLICATION_PATH . $path as $elementId => $fieldName) { - $this->setData($elementId, $fieldName); - } - - return $this; - } - - public function count() - { - return count($this->_data); - } - - public function current() - { - return current($this->_data); - } - - public function next() - { - return next($this->_data); - } - - public function key() - { - return key($this->_data); - } - - public function valid() - { - return $this->current() !== false; - } - - public function rewind() - { - reset($this->_data); - } -} diff --git a/src/application/code/core/Wootook/Core/Helper/Config/Events.php b/src/application/code/core/Wootook/Core/Helper/Config/Events.php deleted file mode 100644 index 30b0528..0000000 --- a/src/application/code/core/Wootook/Core/Helper/Config/Events.php +++ /dev/null @@ -1,56 +0,0 @@ - $listenerList) { - foreach ($listenerList as $listener) { - Wootook::registerListener($event, $listener); - } - } - } - - protected function _init() - { - $this->_initData('events'); - return $this; - } - - protected function _load() - { - // NOP - return $this; - } - - protected function _save() - { - // NOP - return $this; - } - - protected function _delete() - { - // NOP - return $this; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Helper/Config/Modules.php b/src/application/code/core/Wootook/Core/Helper/Config/Modules.php deleted file mode 100644 index 17d1a46..0000000 --- a/src/application/code/core/Wootook/Core/Helper/Config/Modules.php +++ /dev/null @@ -1,47 +0,0 @@ -_initData('modules'); - return $this; - } - - protected function _load() - { - // NOP - return $this; - } - - protected function _save() - { - // NOP - return $this; - } - - protected function _delete() - { - // NOP - return $this; - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Model/Config.php b/src/application/code/core/Wootook/Core/Model/Config.php deleted file mode 100644 index 5607ddf..0000000 --- a/src/application/code/core/Wootook/Core/Model/Config.php +++ /dev/null @@ -1,61 +0,0 @@ -_tableName = 'core_config'; - $this->_idFieldNames = array('config_path', 'website_id', 'game_id'); - } - - public function setWebsiteId($websiteId) - { - return $this->setData('website_id', $websiteId); - } - - public function getWebsiteId() - { - return $this->getData('website_id'); - } - - public function setGameId($gameId) - { - return $this->setData('game_id', $gameId); - } - - public function getGameId() - { - return $this->getData('game_id'); - } - - public function setPath($path) - { - return $this->setData('config_path', $path); - } - - public function getPath() - { - return $this->getData('config_path'); - } - - public function setValue($value) - { - return $this->setData('config_value', $value); - } - - public function getValue() - { - return $this->getData('config_value'); - } -} diff --git a/src/application/code/core/Wootook/Core/Model/Game.php b/src/application/code/core/Wootook/Core/Model/Game.php deleted file mode 100644 index bc4c234..0000000 --- a/src/application/code/core/Wootook/Core/Model/Game.php +++ /dev/null @@ -1,23 +0,0 @@ -_tableName = 'core_game'; - $this->_idFieldName = 'game_id'; - } -} diff --git a/src/application/code/core/Wootook/Core/Model/Translator.php b/src/application/code/core/Wootook/Core/Model/Translator.php deleted file mode 100644 index 6d81883..0000000 --- a/src/application/code/core/Wootook/Core/Model/Translator.php +++ /dev/null @@ -1,37 +0,0 @@ -= 2) { - $this->_translations[$line[0]] = $line[1]; - } - } - } - } - - public function translate($message, $_ = null) - { - $args = func_get_args(); - array_shift($args); - - return $this->translateArgs($message, $args); - } - - public function translateArgs($message, Array $args = array()) - { - if (isset($this->_translations[$message])) { - $message = $this->_translations[$message]; - } - - return vsprintf($message, $args); - } -} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Core/Model/Website.php b/src/application/code/core/Wootook/Core/Model/Website.php deleted file mode 100644 index 018edac..0000000 --- a/src/application/code/core/Wootook/Core/Model/Website.php +++ /dev/null @@ -1,23 +0,0 @@ -_tableName = 'core_website'; - $this->_idFieldName = 'website_id'; - } -} diff --git a/src/application/code/core/Wootook/Core/Mvc/Controller/Request/Request.php b/src/application/code/core/Wootook/Core/Mvc/Controller/Request/Request.php deleted file mode 100644 index 3a77073..0000000 --- a/src/application/code/core/Wootook/Core/Mvc/Controller/Request/Request.php +++ /dev/null @@ -1,35 +0,0 @@ -init(); - - parent::__construct($data); - } - - public function setParam($key, $value) - { - return $this->setData($key, $value); - } - - public function getParam($key, $default = null) - { - if ($this->hasData($key)) { - return $this->getData($key); - } - return $default; - } - - abstract public function init(); - - abstract public function getModuleName(); - abstract public function getControllerName(); - abstract public function getActionName(); - - abstract public function setModuleName($name); - abstract public function setControllerName($name); - abstract public function setActionName($name); -} diff --git a/src/application/code/core/Wootook/Core/Mvc/Controller/Response/Response.php b/src/application/code/core/Wootook/Core/Mvc/Controller/Response/Response.php deleted file mode 100644 index a36048a..0000000 --- a/src/application/code/core/Wootook/Core/Mvc/Controller/Response/Response.php +++ /dev/null @@ -1,21 +0,0 @@ -_isDispatched = $dispatched; - - return $this; - } - - public function isDispatched() - { - return $this->_isDispatched; - } - - abstract public function render($send = true); -} diff --git a/src/application/code/core/Wootook/Core/Mvc/Model/Entity.php b/src/application/code/core/Wootook/Core/Mvc/Model/Entity.php deleted file mode 100644 index 2c19005..0000000 --- a/src/application/code/core/Wootook/Core/Mvc/Model/Entity.php +++ /dev/null @@ -1,142 +0,0 @@ -_idFieldName = $fieldName; - - return $this; - } - - public function getIdFieldName() - { - return $this->_idFieldName; - } - - public function setId($id) - { - $this->setData($this->getIdFieldName(), $id); - - return $this; - } - - public function getId() - { - return $this->getData($this->getIdFieldName()); - } - - protected function _load() - { - $id = func_get_arg(0); - - if (func_num_args() >= 2) { - $idFieldName = func_get_arg(1); - } else { - $idFieldName = $this->getIdFieldName(); - } - - $database = $this->getReadConnection(); - if ($database === null) { - throw new Wootook_Core_Exception_DataAccessException('Could not load data: no read connection configured.'); - } - - $select = $database->select() - ->from(array('main_table' => $database->getTable($this->getTableName()))) - ->where($idFieldName, new Wootook_Core_Database_Sql_Placeholder_Param('id', $id)) - ->limit(1); - - $statement = $select->prepare(); - $statement->execute(array( - 'id' => $id - )); - - $datas = $statement->fetch(PDO::FETCH_ASSOC); - if (!is_array($datas) || empty($datas)) { - throw new Wootook_Core_Exception_DataAccessException('Could not load data: this id could not be found.'); - } - $realId = $datas[$this->getIdFieldName()]; - unset($datas[$this->getIdFieldName()]); - - $this->_data = array(); - $this->getDataMapper()->decode($this, $datas); - $this->setId($realId); - - return $this; - } - - protected function _save() - { - $adapter = $this->getWriteConnection(); - - if ($adapter === null) { - throw new Wootook_Core_Exception_DataAccessException('Could not save data: no write connection configured.'); - } - - if ($this->getId() !== null) { - $update = $adapter->update() - ->into($adapter->getTable($this->getTableName())) - ->where(new Wootook_Core_Database_Sql_Placeholder_Expression("{$adapter->quoteIdentifier($this->getIdFieldName())}=:id", array('id' => $this->getId()))); - - foreach ($this->getDataMapper()->encode($this, $this->getChangedDatas()) as $field => $value) { - $update->set($field, new Wootook_Core_Database_Sql_Placeholder_Param($field, $value)); - } - try { - $statement = $update->prepare(); - $statement->execute(); - } catch (Wootook_Core_Exception_Database_AdapterError $e) { - throw new Wootook_Core_Exception_DataAccessException('Could not save data: ' . $e->getMessage(), null, $e); - } catch (Wootook_Core_Exception_Database_StatementError $e) { - throw new Wootook_Core_Exception_DataAccessException('Could not save data: ' . $e->getMessage(), null, $e); - } - } else { - $insert = $adapter->insert() - ->into($adapter->getTable($this->getTableName())); - - foreach ($this->getDataMapper()->encode($this, $this->getAllDatas()) as $field => $value) { - $insert->set($field, new Wootook_Core_Database_Sql_Placeholder_Param($field, $value)); - } - try { - $statement = $insert->prepare(); - $statement->execute(); - - $id = $adapter->lastInsertId($adapter->getTable($this->getTableName())); - $this->setId($id); - } catch (Wootook_Core_Exception_Database_AdapterError $e) { - throw new Wootook_Core_Exception_DataAccessException('Could not save data: ' . $e->getMessage(), null, $e); - } catch (Wootook_Core_Exception_Database_StatementError $e) { - throw new Wootook_Core_Exception_DataAccessException('Could not save data: ' . $e->getMessage(), null, $e); - } - } - - return $this; - } - - protected function _delete() - { - $adapter = $this->getWriteConnection(); - if ($adapter === null) { - throw new Wootook_Core_Exception_DataAccessException('Could not delete data: no write connection configured.'); - } - $delete = $adapter - ->delete() - ->from($adapter->getTable($this->getTableName())) - ->where($this->getIdFieldName(), $this->getId()) - ->limit(1); - - try { - $statement = $adapter->prepare($delete); - $statement->execute(); - } catch (Wootook_Core_Exception_Database_AdapterError $e) { - throw new Wootook_Core_Exception_DataAccessException('Could not delete data: ' . $e->getMessage(), null, $e); - } catch (Wootook_Core_Exception_Database_StatementError $e) { - throw new Wootook_Core_Exception_DataAccessException('Could not delete data: ' . $e->getMessage(), null, $e); - } - - return $this; - } -} diff --git a/src/application/code/core/Wootook/Core/Mvc/Model/Model.php b/src/application/code/core/Wootook/Core/Mvc/Model/Model.php deleted file mode 100644 index e91265f..0000000 --- a/src/application/code/core/Wootook/Core/Mvc/Model/Model.php +++ /dev/null @@ -1,205 +0,0 @@ - - * 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 . - * - * --> 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. - * - */ - -/** - * - * Enter description here ... - * @author Greg - * - */ -abstract class Wootook_Core_Mvc_Model_Model - extends Wootook_Object -{ - protected $_originalData = array(); - - protected $_eventPrefix = null; - protected $_eventObject = null; - - public function __construct(Array $data = array()) - { - $this->_data = $data; - - $this->_init(); - $this->_setOriginalData(); - } - - abstract protected function _init(); - - protected function _setOriginalData() - { - $this->_originalData = $this->_data; - } - - public function getChangedDatas() - { - return array_diff_assoc($this->_data, $this->_originalData); - } - - public function hasChangedDatas() - { - if (count($this->getChangedDatas()) > 0) { - return true; - } - return false; - } - - final public function save() - { - try { - $params = func_get_args(); - call_user_func_array(array($this, '_beforeSave'), $params); - call_user_func_array(array($this, '_save'), $params); - call_user_func_array(array($this, '_afterSave'), $params); - $this->_setOriginalData($this->_data); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_DataAccessException('Could not save data: ' . $e->getMessage(), 0); - } - return $this; - } - - abstract protected function _save(); - - protected function _beforeSave() - { - Wootook::dispatchEvent('model.before-save', array('model' => $this)); - - if ($this->_eventPrefix !== null && $this->_eventObject !== null) { - Wootook::dispatchEvent($this->_eventPrefix . '.before-save', array($this->_eventObject => $this)); - } - - return $this; - } - - protected function _afterSave() - { - Wootook::dispatchEvent('model.after-save', array('model' => $this)); - - if ($this->_eventPrefix !== null && $this->_eventObject !== null) { - Wootook::dispatchEvent($this->_eventPrefix . '.after-save', array($this->_eventObject => $this)); - } - - return $this; - } - - final public function load() - { - try { - $params = func_get_args(); - call_user_func_array(array($this, '_beforeLoad'), $params); - call_user_func_array(array($this, '_load'), $params); - call_user_func_array(array($this, '_afterLoad'), $params); - $this->_setOriginalData($this->_data); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_DataAccessException('Could not load data: ' . $e->getMessage(), 0, $e); - } - return $this; - } - - abstract protected function _load(); - - protected function _beforeLoad() - { - Wootook::dispatchEvent('model.before-load', array('model' => $this)); - - if ($this->_eventPrefix !== null && $this->_eventObject !== null) { - Wootook::dispatchEvent($this->_eventPrefix . '.before-load', array($this->_eventObject => $this)); - } - - return $this; - } - - protected function _afterLoad() - { - Wootook::dispatchEvent('model.after-load', array('model' => $this)); - - if ($this->_eventPrefix !== null && $this->_eventObject !== null) { - Wootook::dispatchEvent($this->_eventPrefix . '.after-load', array($this->_eventObject => $this)); - } - - return $this; - } - - final public function delete() - { - try { - $params = func_get_args(); - call_user_func_array(array($this, '_beforeDelete'), $params); - call_user_func_array(array($this, '_delete'), $params); - call_user_func_array(array($this, '_afterDelete'), $params); - } catch (PDOException $e) { - throw new Wootook_Core_Exception_DataAccessException('Could not delete entity: ' . $e->getMessage(), 0); - } - return $this; - } - - abstract protected function _delete(); - - protected function _beforeDelete() - { - Wootook::dispatchEvent('model.before-delete', array('model' => $this)); - - if ($this->_eventPrefix !== null && $this->_eventObject !== null) { - Wootook::dispatchEvent($this->_eventPrefix . '.before-delete', array($this->_eventObject => $this)); - } - - return $this; - } - - protected function _afterDelete() - { - Wootook::dispatchEvent('model.after-delete', array('model' => $this)); - - if ($this->_eventPrefix !== null && $this->_eventObject !== null) { - Wootook::dispatchEvent($this->_eventPrefix . '.after-delete', array($this->_eventObject => $this)); - } - - return $this; - } - - public function __set($key, $value) - { - return $this->setData($key, $value); - } - - public function __get($key) - { - return $this->getData($key); - } - - public function __unset($key) - { - return $this->unsetData($key); - } - - public function __isset($key) - { - return $this->hasData($key); - } -} diff --git a/src/application/code/core/Wootook/Core/Setup/Exception/RuntimeException.php b/src/application/code/core/Wootook/Core/Setup/Exception/RuntimeException.php deleted file mode 100644 index 29a8002..0000000 --- a/src/application/code/core/Wootook/Core/Setup/Exception/RuntimeException.php +++ /dev/null @@ -1,7 +0,0 @@ -_setupConnection = Wootook_Core_Database_ConnectionManager::getSingleton() - ->getConnection($connection); - } else { - $this->_setupConnection = $connection; - } - - return $this; - } - - /** - * - * Enter description here ... - * @return Wootook_Core_Database_Adapter_Pdo_Mysql - */ - public function getSetupConnection() - { - if ($this->_setupConnection === null) { - $this->setSetupConnection('default'); - } - return $this->_setupConnection; - } - - public function getTableName($tableName) - { - return $this->getSetupConnection()->getTable($tableName); - } - - public function query($statement) - { - try { - if (!$this->getSetupConnection()->query($statement)) { - $info = $this->getSetupConnection()->errorInfo(); - throw new Wootook_Core_Setup_Exception_RuntimeException( - Wootook::__('Query failed: SQLSTATE %s: %s.', $info[1], $info[2])); - } - } catch (PDOException $e) { - Wootook_Core_ErrorProfiler::getSingleton()->exceptionManager($e); - throw new Wootook_Core_Setup_Exception_RuntimeException($e->getMessage(), null, $e); - } - } - - public function grant($tableName, $connectionName, $perms = null) - { - $hostname = Wootook::getConfig("database/{$connectionName}/params/hostname"); - $username = Wootook::getConfig("database/{$connectionName}/params/username"); - $database = Wootook::getConfig("database/{$connectionName}/params/database"); - $password = Wootook::getConfig("database/{$connectionName}/params/password"); - - if ($perms === null) { - $perms = 'ALL PRIVILEGES'; - } else if (is_array($perms)) { - $perms = implode(' ', $perms); - } - - $sql =<<getTable($tableName)} -TO '{$username}@{$hostname}' IDENTIFIED BY '$password' -SQL_EOF; - - $this->getSetupConnection()->query($sql); - - return $this; - } - - public function revoke($tableName, $connectionName, $perms = null) - { - $hostname = Wootook::getConfig("database/{$connectionName}/params/hostname"); - $username = Wootook::getConfig("database/{$connectionName}/params/username"); - $database = Wootook::getConfig("database/{$connectionName}/params/database"); - $password = Wootook::getConfig("database/{$connectionName}/params/password"); - - if ($perms === null) { - $perms = 'ALL PRIVILEGES'; - } else if (is_array($perms)) { - $perms = implode(' ', $perms); - } - - $sql =<<getTable($tableName)} -FROM '{$username}@{$hostname}' -SQL_EOF; - - $this->getSetupConnection()->query($sql); - - return $this; - } - - public function run($script) - { - include $script; - } - - public function getConfig($path = null) - { - return Wootook::getConfig($path); - } - - public function getWebsiteConfig($path = null, $websiteId = null) - { - return Wootook::getWebsiteConfig($path, $websiteId); - } - - public function getGameConfig($path = null, $gameId = null) - { - return Wootook::getGameConfig($path, $gameId); - } -} diff --git a/src/application/code/core/Wootook/Empire/Block/Overview/DestroyPlanet.php b/src/application/code/core/Wootook/Empire/Block/Overview/DestroyPlanet.php index 8d78612..a780d30 100644 --- a/src/application/code/core/Wootook/Empire/Block/Overview/DestroyPlanet.php +++ b/src/application/code/core/Wootook/Empire/Block/Overview/DestroyPlanet.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Block_Overview_DestroyPlanet extends Wootook_Core_Block_Html_Form diff --git a/src/application/code/core/Wootook/Empire/Block/Overview/Fleet/List.php b/src/application/code/core/Wootook/Empire/Block/Overview/Fleet/List.php index 770fcbb..dd2c30a 100644 --- a/src/application/code/core/Wootook/Empire/Block/Overview/Fleet/List.php +++ b/src/application/code/core/Wootook/Empire/Block/Overview/Fleet/List.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Block_Overview_Fleet_List extends Wootook_Core_Block_Template diff --git a/src/application/code/core/Wootook/Empire/Block/Overview/Fleet/List/Item.php b/src/application/code/core/Wootook/Empire/Block/Overview/Fleet/List/Item.php index cd1cffc..0a8fbc1 100644 --- a/src/application/code/core/Wootook/Empire/Block/Overview/Fleet/List/Item.php +++ b/src/application/code/core/Wootook/Empire/Block/Overview/Fleet/List/Item.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Block_Overview_Fleet_List_Item extends Wootook_Core_Block_Template @@ -103,12 +131,12 @@ class Wootook_Empire_Block_Overview_Fleet_List_Item public function getOriginPlanetName() { - return $this->getOriginPlanetName(); + return $this->getFleetItem()->getOriginPlanetName(); } public function getOriginPlanetCoords() { - return $this->getOriginPlanetCoords(); + return $this->getFleetItem()->getOriginPlanetCoords(); } public function getDestinationPlanet() @@ -133,12 +161,12 @@ class Wootook_Empire_Block_Overview_Fleet_List_Item public function getDestinationPlanetName() { - return $this->getDestinationPlanetName(); + return $this->getFleetItem()->getDestinationPlanetName(); } public function getDestinationPlanetCoords() { - return $this->getDestinationPlanetCoords(); + return $this->getFleetItem()->getDestinationPlanetCoords(); } public function getMissionLabel() diff --git a/src/application/code/core/Wootook/Empire/Block/Overview/RenamePlanet.php b/src/application/code/core/Wootook/Empire/Block/Overview/RenamePlanet.php index 24ece3e..8aebc64 100644 --- a/src/application/code/core/Wootook/Empire/Block/Overview/RenamePlanet.php +++ b/src/application/code/core/Wootook/Empire/Block/Overview/RenamePlanet.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Block_Overview_RenamePlanet extends Wootook_Core_Block_Html_Form diff --git a/src/application/code/core/Wootook/Empire/Block/Planet/Builder/ItemAbstract.php b/src/application/code/core/Wootook/Empire/Block/Planet/Builder/ItemAbstract.php index dfffacd..eb65634 100644 --- a/src/application/code/core/Wootook/Empire/Block/Planet/Builder/ItemAbstract.php +++ b/src/application/code/core/Wootook/Empire/Block/Planet/Builder/ItemAbstract.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ abstract class Wootook_Empire_Block_Planet_Builder_ItemAbstract extends Wootook_Core_Block_Template diff --git a/src/application/code/core/Wootook/Empire/Block/Planet/Builder/Queue/ItemAbstract.php b/src/application/code/core/Wootook/Empire/Block/Planet/Builder/Queue/ItemAbstract.php index 962783a..38d33a9 100644 --- a/src/application/code/core/Wootook/Empire/Block/Planet/Builder/Queue/ItemAbstract.php +++ b/src/application/code/core/Wootook/Empire/Block/Planet/Builder/Queue/ItemAbstract.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ abstract class Wootook_Empire_Block_Planet_Builder_Queue_ItemAbstract extends Wootook_Empire_Block_Planet_Builder_ItemAbstract diff --git a/src/application/code/core/Wootook/Empire/Block/Planet/Builder/QueueAbstract.php b/src/application/code/core/Wootook/Empire/Block/Planet/Builder/QueueAbstract.php index baf9c71..93167af 100644 --- a/src/application/code/core/Wootook/Empire/Block/Planet/Builder/QueueAbstract.php +++ b/src/application/code/core/Wootook/Empire/Block/Planet/Builder/QueueAbstract.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ abstract class Wootook_Empire_Block_Planet_Builder_QueueAbstract extends Wootook_Core_Block_Template diff --git a/src/application/code/core/Wootook/Empire/Block/Planet/BuilderAbstract.php b/src/application/code/core/Wootook/Empire/Block/Planet/BuilderAbstract.php index 9cc98f2..c3a7ef9 100644 --- a/src/application/code/core/Wootook/Empire/Block/Planet/BuilderAbstract.php +++ b/src/application/code/core/Wootook/Empire/Block/Planet/BuilderAbstract.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ abstract class Wootook_Empire_Block_Planet_BuilderAbstract extends Wootook_Core_Block_Template diff --git a/src/application/code/core/Wootook/Empire/Block/Planet/Buildings.php b/src/application/code/core/Wootook/Empire/Block/Planet/Buildings.php index 77d4a86..5cbc9e4 100644 --- a/src/application/code/core/Wootook/Empire/Block/Planet/Buildings.php +++ b/src/application/code/core/Wootook/Empire/Block/Planet/Buildings.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Block_Planet_Buildings extends Wootook_Empire_Block_Planet_BuilderAbstract diff --git a/src/application/code/core/Wootook/Empire/Block/Planet/Buildings/Item.php b/src/application/code/core/Wootook/Empire/Block/Planet/Buildings/Item.php index 1c4a970..3abe561 100644 --- a/src/application/code/core/Wootook/Empire/Block/Planet/Buildings/Item.php +++ b/src/application/code/core/Wootook/Empire/Block/Planet/Buildings/Item.php @@ -1,7 +1,40 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Empire_Block_Planet_Buildings_Item - extends Wootook_Empire_Block_Planet_Builder_ItemAbstract +namespace Wootook\Empire\Block\Planet\Buildings; + +use Wootook\Core, + Wootook\Empire\Block\Planet\Builder; + +class Item + extends Builder\ItemAbstract { public function getLevel() { @@ -45,7 +78,7 @@ class Wootook_Empire_Block_Planet_Buildings_Item $resourceConfig = array(); foreach ($resources as $resourceId => $resourceValue) { - $resourceConfig[$resourceId] = new Wootook_Object(array( + $resourceConfig[$resourceId] = new Core\BaseObject($this->app(), array( 'resource_id' => $resourceId, 'value' => $resourceValue )); @@ -69,4 +102,4 @@ class Wootook_Empire_Block_Planet_Buildings_Item { return $this->getBuildingTime($this->getNextLevel()); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Empire/Block/Planet/Buildings/Queue.php b/src/application/code/core/Wootook/Empire/Block/Planet/Buildings/Queue.php index b1c3f55..cb9664a 100644 --- a/src/application/code/core/Wootook/Empire/Block/Planet/Buildings/Queue.php +++ b/src/application/code/core/Wootook/Empire/Block/Planet/Buildings/Queue.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Block_Planet_Buildings_Queue extends Wootook_Empire_Block_Planet_Builder_QueueAbstract diff --git a/src/application/code/core/Wootook/Empire/Block/Planet/Buildings/Queue/Item.php b/src/application/code/core/Wootook/Empire/Block/Planet/Buildings/Queue/Item.php index 6941b62..196814a 100644 --- a/src/application/code/core/Wootook/Empire/Block/Planet/Buildings/Queue/Item.php +++ b/src/application/code/core/Wootook/Empire/Block/Planet/Buildings/Queue/Item.php @@ -28,14 +28,19 @@ * */ +namespace Wootook\Empire\Block\Planet\Buildings\Queue; + +use Wootook\Core, +Wootook\Empire\Block\Planet\Builder\Queue; + /** * * Enter description here ... * @author Greg * */ -class Wootook_Empire_Block_Planet_Buildings_Queue_Item - extends Wootook_Empire_Block_Planet_Builder_Queue_ItemAbstract +class Item + extends Queue\ItemAbstract { protected $_itemIdField = 'building_id'; @@ -78,7 +83,7 @@ class Wootook_Empire_Block_Planet_Buildings_Queue_Item $resourceConfig = array(); foreach ($resources as $resourceId => $resourceValue) { - $resourceConfig[$resourceId] = new Wootook_Object(array( + $resourceConfig[$resourceId] = new Core\BaseObject($this->app(), array( 'resource_id' => $resourceId, 'value' => $resourceValue )); @@ -102,4 +107,4 @@ class Wootook_Empire_Block_Planet_Buildings_Queue_Item { return $this->getBuildingTime($this->getNextLevel()); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Empire/Block/Planet/Overview.php b/src/application/code/core/Wootook/Empire/Block/Planet/Overview.php index f24f5dc..603e910 100644 --- a/src/application/code/core/Wootook/Empire/Block/Planet/Overview.php +++ b/src/application/code/core/Wootook/Empire/Block/Planet/Overview.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Block_Planet_Overview extends Wootook_Core_Block_Template diff --git a/src/application/code/core/Wootook/Empire/Block/PlanetList.php b/src/application/code/core/Wootook/Empire/Block/PlanetList.php index 4d1decf..4b54f75 100644 --- a/src/application/code/core/Wootook/Empire/Block/PlanetList.php +++ b/src/application/code/core/Wootook/Empire/Block/PlanetList.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Block_PlanetList extends Wootook_Core_Block_Template diff --git a/src/application/code/core/Wootook/Empire/Block/Topnav.php b/src/application/code/core/Wootook/Empire/Block/Topnav.php index 72a6d5b..1b31d84 100644 --- a/src/application/code/core/Wootook/Empire/Block/Topnav.php +++ b/src/application/code/core/Wootook/Empire/Block/Topnav.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Block_Topnav extends Wootook_Core_Block_Template diff --git a/src/application/code/core/Wootook/Empire/Controller/BuildingsController.php b/src/application/code/core/Wootook/Empire/Controller/BuildingsController.php index 6a5234b..777ac8c 100644 --- a/src/application/code/core/Wootook/Empire/Controller/BuildingsController.php +++ b/src/application/code/core/Wootook/Empire/Controller/BuildingsController.php @@ -1,10 +1,31 @@ + * 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 . + * + * --> 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. + * */ class Wootook_Empire_Controller_BuildingsController extends Wootook_Player_Mvc_Controller_Registered diff --git a/src/application/code/core/Wootook/Empire/Exception.php b/src/application/code/core/Wootook/Empire/Exception.php index e2bd909..9633dca 100644 --- a/src/application/code/core/Wootook/Empire/Exception.php +++ b/src/application/code/core/Wootook/Empire/Exception.php @@ -1,3 +1,31 @@ + * 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 . + * + * --> 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. + * + */ interface Wootook_Empire_Exception extends Wootook_Exception {} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Empire/Exception/Exception.php b/src/application/code/core/Wootook/Empire/Exception/Exception.php index b3154b8..fb0647b 100644 --- a/src/application/code/core/Wootook/Empire/Exception/Exception.php +++ b/src/application/code/core/Wootook/Empire/Exception/Exception.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Exception_Exception extends Exception diff --git a/src/application/code/core/Wootook/Empire/Exception/Planet.php b/src/application/code/core/Wootook/Empire/Exception/Planet.php index 36c2cf2..9a4f00b 100644 --- a/src/application/code/core/Wootook/Empire/Exception/Planet.php +++ b/src/application/code/core/Wootook/Empire/Exception/Planet.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Exception_Planet extends Wootook_Empire_Exception_RuntimeException diff --git a/src/application/code/core/Wootook/Empire/Exception/RuntimeException.php b/src/application/code/core/Wootook/Empire/Exception/RuntimeException.php index c4dcb32..7e03d1e 100644 --- a/src/application/code/core/Wootook/Empire/Exception/RuntimeException.php +++ b/src/application/code/core/Wootook/Empire/Exception/RuntimeException.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Exception_RuntimeException extends RuntimeException diff --git a/src/application/code/core/Wootook/Empire/Helper/Config/Combat.php b/src/application/code/core/Wootook/Empire/Helper/Config/Combat.php index 26a1bc8..f89db25 100644 --- a/src/application/code/core/Wootook/Empire/Helper/Config/Combat.php +++ b/src/application/code/core/Wootook/Empire/Helper/Config/Combat.php @@ -1,10 +1,38 @@ + * 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 . + * + * --> 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. + * + */ /** * * Enter description here ... * - * @uses Wootook_Object + * @uses Wootook\Core\BaseObject * @uses Legacies_Empire */ class Wootook_Empire_Helper_Config_Combat @@ -44,4 +72,4 @@ class Wootook_Empire_Helper_Config_Combat // NOP return $this; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Empire/Helper/Config/FieldsAlias.php b/src/application/code/core/Wootook/Empire/Helper/Config/FieldsAlias.php index 101bc5f..f171de0 100644 --- a/src/application/code/core/Wootook/Empire/Helper/Config/FieldsAlias.php +++ b/src/application/code/core/Wootook/Empire/Helper/Config/FieldsAlias.php @@ -1,10 +1,38 @@ + * 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 . + * + * --> 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. + * + */ /** * * Enter description here ... * - * @uses Wootook_Object + * @uses Wootook\Core\BaseObject * @uses Legacies_Empire */ class Wootook_Empire_Helper_Config_FieldsAlias @@ -44,4 +72,4 @@ class Wootook_Empire_Helper_Config_FieldsAlias // NOP return $this; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Empire/Helper/Config/Labels.php b/src/application/code/core/Wootook/Empire/Helper/Config/Labels.php index 94297a2..1e0b860 100644 --- a/src/application/code/core/Wootook/Empire/Helper/Config/Labels.php +++ b/src/application/code/core/Wootook/Empire/Helper/Config/Labels.php @@ -1,10 +1,38 @@ + * 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 . + * + * --> 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. + * + */ /** * * Enter description here ... * - * @uses Wootook_Object + * @uses Wootook\Core\BaseObject * @uses Legacies_Empire */ class Wootook_Empire_Helper_Config_Labels diff --git a/src/application/code/core/Wootook/Empire/Helper/Config/Prices.php b/src/application/code/core/Wootook/Empire/Helper/Config/Prices.php index 1a328de..889e506 100644 --- a/src/application/code/core/Wootook/Empire/Helper/Config/Prices.php +++ b/src/application/code/core/Wootook/Empire/Helper/Config/Prices.php @@ -1,10 +1,38 @@ + * 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 . + * + * --> 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. + * + */ /** * * Enter description here ... * - * @uses Wootook_Object + * @uses Wootook\Core\BaseObject * @uses Legacies_Empire */ class Wootook_Empire_Helper_Config_Prices @@ -44,4 +72,4 @@ class Wootook_Empire_Helper_Config_Prices // NOP return $this; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Empire/Helper/Config/Production.php b/src/application/code/core/Wootook/Empire/Helper/Config/Production.php index d4539fc..11be14e 100644 --- a/src/application/code/core/Wootook/Empire/Helper/Config/Production.php +++ b/src/application/code/core/Wootook/Empire/Helper/Config/Production.php @@ -1,10 +1,38 @@ + * 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 . + * + * --> 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. + * + */ /** * * Enter description here ... * - * @uses Wootook_Object + * @uses Wootook\Core\BaseObject * @uses Legacies_Empire */ class Wootook_Empire_Helper_Config_Production @@ -44,4 +72,4 @@ class Wootook_Empire_Helper_Config_Production // NOP return $this; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Empire/Helper/Config/Requirements.php b/src/application/code/core/Wootook/Empire/Helper/Config/Requirements.php index 04ea042..3a7c544 100644 --- a/src/application/code/core/Wootook/Empire/Helper/Config/Requirements.php +++ b/src/application/code/core/Wootook/Empire/Helper/Config/Requirements.php @@ -1,10 +1,38 @@ + * 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 . + * + * --> 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. + * + */ /** * * Enter description here ... * - * @uses Wootook_Object + * @uses Wootook\Core\BaseObject * @uses Legacies_Empire */ class Wootook_Empire_Helper_Config_Requirements @@ -44,4 +72,4 @@ class Wootook_Empire_Helper_Config_Requirements // NOP return $this; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Empire/Helper/Config/Resources.php b/src/application/code/core/Wootook/Empire/Helper/Config/Resources.php index 8ce2483..212ebaa 100644 --- a/src/application/code/core/Wootook/Empire/Helper/Config/Resources.php +++ b/src/application/code/core/Wootook/Empire/Helper/Config/Resources.php @@ -1,10 +1,38 @@ + * 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 . + * + * --> 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. + * + */ /** * * Enter description here ... * - * @uses Wootook_Object + * @uses Wootook\Core\BaseObject * @uses Legacies_Empire */ class Wootook_Empire_Helper_Config_Resources @@ -44,4 +72,4 @@ class Wootook_Empire_Helper_Config_Resources // NOP return $this; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Empire/Helper/Config/Types.php b/src/application/code/core/Wootook/Empire/Helper/Config/Types.php index 9ef029d..ac3feaa 100644 --- a/src/application/code/core/Wootook/Empire/Helper/Config/Types.php +++ b/src/application/code/core/Wootook/Empire/Helper/Config/Types.php @@ -1,10 +1,38 @@ + * 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 . + * + * --> 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. + * + */ /** * * Enter description here ... * - * @uses Wootook_Object + * @uses Wootook\Core\BaseObject * @uses Legacies_Empire */ class Wootook_Empire_Helper_Config_Types @@ -52,4 +80,4 @@ class Wootook_Empire_Helper_Config_Types } return in_array($element, $this->getData($type)); } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Empire/Model/Builder/Break.php b/src/application/code/core/Wootook/Empire/Model/Builder/Break.php index a1bfc75..af6d5f7 100644 --- a/src/application/code/core/Wootook/Empire/Model/Builder/Break.php +++ b/src/application/code/core/Wootook/Empire/Model/Builder/Break.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Model_Builder_Break extends Exception diff --git a/src/application/code/core/Wootook/Empire/Model/Builder/Item.php b/src/application/code/core/Wootook/Empire/Model/Builder/Item.php index d590b81..0817b55 100644 --- a/src/application/code/core/Wootook/Empire/Model/Builder/Item.php +++ b/src/application/code/core/Wootook/Empire/Model/Builder/Item.php @@ -1,7 +1,39 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Empire_Model_Builder_Item - extends Wootook_Object +namespace Wootook\Empire\Model\Builder; + +use Wootook\Core; + +class Item + extends Core\BaseObject { protected $_index = null; @@ -16,4 +48,4 @@ class Wootook_Empire_Model_Builder_Item return $this; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Empire/Model/BuilderAbstract.php b/src/application/code/core/Wootook/Empire/Model/BuilderAbstract.php index dc0899e..05e3306 100644 --- a/src/application/code/core/Wootook/Empire/Model/BuilderAbstract.php +++ b/src/application/code/core/Wootook/Empire/Model/BuilderAbstract.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ abstract class Wootook_Empire_Model_BuilderAbstract implements Countable, Serializable, Iterator diff --git a/src/application/code/core/Wootook/Empire/Model/Fleet.php b/src/application/code/core/Wootook/Empire/Model/Fleet.php index e622226..010c2b7 100644 --- a/src/application/code/core/Wootook/Empire/Model/Fleet.php +++ b/src/application/code/core/Wootook/Empire/Model/Fleet.php @@ -1,9 +1,37 @@ + * 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 . + * + * --> 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. + * + */ /** * * Enter description here ... * - * @uses Wootook_Object + * @uses Wootook\Core\BaseObject * @uses Legacies_Empire */ class Wootook_Empire_Model_Fleet diff --git a/src/application/code/core/Wootook/Empire/Model/Galaxy/Position.php b/src/application/code/core/Wootook/Empire/Model/Galaxy/Position.php index 2ce4b24..c2567c7 100644 --- a/src/application/code/core/Wootook/Empire/Model/Galaxy/Position.php +++ b/src/application/code/core/Wootook/Empire/Model/Galaxy/Position.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Model_Galaxy_Position extends Wootook_Core_Mvc_Model_Entity_SubTable diff --git a/src/application/code/core/Wootook/Empire/Model/Planet.php b/src/application/code/core/Wootook/Empire/Model/Planet.php index 980524f..1f099e5 100644 --- a/src/application/code/core/Wootook/Empire/Model/Planet.php +++ b/src/application/code/core/Wootook/Empire/Model/Planet.php @@ -1,8 +1,36 @@ + * 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 . + * + * --> 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. + * + */ /** * - * @uses Wootook_Object + * @uses Wootook\Core\BaseObject * @uses Legacies_Empire * @uses Wootook_Player_Model_Entity */ @@ -164,7 +192,7 @@ class Wootook_Empire_Model_Planet break; } - throw new Wootook_Core_Exception_RuntimeException(Wootook::__('Undefined method %s::%s.', get_class($this), $method)); + throw new Wootook_Core_Exception_RuntimeException(\Wootook::__('Undefined method %s::%s.', get_class($this), $method)); } /** @@ -220,7 +248,7 @@ class Wootook_Empire_Model_Planet $storageSize = Math::add(BASE_STORAGE_SIZE, $storageEnhancement); - $event = Wootook::dispatchEvent($this->_eventPrefix . 'update-storage.resource', array( + $event = \Wootook::dispatchEvent($this->_eventPrefix . 'update-storage.resource', array( 'resource_id' => $resource, 'resource_data' => $resourceData, 'default_size' => $storageSize, @@ -269,7 +297,7 @@ class Wootook_Empire_Model_Planet } if ($this->getPlayer()->isVacation()) { - $resourceConfig = Wootook::getGameConfig('resource/base-income'); + $resourceConfig = \Wootook::app()->getDefaultGame()->getConfig('resource/base-income'); foreach ($resources->getAllDatas() as $resource => $resourceData) { $this->setData($resourceData['production_field'], $resourceConfig[$resource]); } @@ -362,7 +390,7 @@ class Wootook_Empire_Model_Planet } // Dispatch 'planet.update-production.before' event - Wootook::dispatchEvent($this->_eventPrefix . '.update-production.before', array( + \Wootook::dispatchEvent($this->_eventPrefix . '.update-production.before', array( $this->_eventObject => $this, 'player' => $this->getPlayer(), 'productions' => $actualProduction @@ -378,7 +406,7 @@ class Wootook_Empire_Model_Planet } // Dispatch 'planet.update-production.after' event - Wootook::dispatchEvent($this->_eventPrefix . '.update-production.after', array( + \Wootook::dispatchEvent($this->_eventPrefix . '.update-production.after', array( $this->_eventObject => $this, 'player' => $this->getPlayer() )); @@ -616,16 +644,16 @@ class Wootook_Empire_Model_Planet } if ($this->isDestroyed()) { - throw new Wootook_Empire_Exception_Planet(Wootook::__('Planet is already destroyed.')); + throw new Wootook_Empire_Exception_Planet(\Wootook::__('Planet is already destroyed.')); } if ($this->getFleetCollection()->count() > 0) { - throw new Wootook_Empire_Exception_Planet(Wootook::__("Could not delete planet until fleets aten't retuned.")); + throw new Wootook_Empire_Exception_Planet(\Wootook::__("Could not delete planet until fleets aten't retuned.")); } $player = $this->getPlayer(); if ($player->getHomePlanet()->getId() == $this->getId()) { - throw new Wootook_Empire_Exception_Planet(Wootook::__("You can't destroy your home planet.")); + throw new Wootook_Empire_Exception_Planet(\Wootook::__("You can't destroy your home planet.")); } if ($player->getCurrentPlanet()->getId() == $this->getId()) { @@ -695,7 +723,7 @@ class Wootook_Empire_Model_Planet } // Dispatch 'planet.building.append-queue.before' event - Wootook::dispatchEvent($this->_eventPrefix . '.building.append-queue.before', array( + \Wootook::dispatchEvent($this->_eventPrefix . '.building.append-queue.before', array( 'bulding_id' => $buildingId, 'level' => $this->getElement($buildingId), $this->_eventObject => $this, @@ -712,7 +740,7 @@ class Wootook_Empire_Model_Planet $this->getBuildingQueue()->appendQueue($buildingId, $level, $time); // Dispatch 'planet.shipyard.append-queue.after' event - Wootook::dispatchEvent($this->_eventPrefix . '.building.append-queue.after', array( + \Wootook::dispatchEvent($this->_eventPrefix . '.building.append-queue.after', array( 'bulding_id' => $buildingId, 'level' => $this->getElement($buildingId), $this->_eventObject => $this, @@ -730,7 +758,7 @@ class Wootook_Empire_Model_Planet } // Dispatch event - Wootook::dispatchEvent($this->_eventPrefix . '.update-queue.before', array( + \Wootook::dispatchEvent($this->_eventPrefix . '.update-queue.before', array( 'time' => &$time, $this->_eventObject => $this, 'player' => $this->getPlayer() @@ -739,7 +767,7 @@ class Wootook_Empire_Model_Planet $this->getBuildingQueue()->updateQueue($time); // Dispatch event - Wootook::dispatchEvent($this->_eventPrefix . '.update-queue.after', array( + \Wootook::dispatchEvent($this->_eventPrefix . '.update-queue.after', array( 'time' => $time, $this->_eventObject => $this, 'player' => $this->getPlayer() @@ -815,7 +843,7 @@ class Wootook_Empire_Model_Planet try { // Dispatch event. Throw an exception to break the avaliability. - Wootook::dispatchEvent($this->_eventPrefix . '.check-availability', array( + \Wootook::dispatchEvent($this->_eventPrefix . '.check-availability', array( 'ship_id' => $buildingId, 'shipyard' => $this, $this->_eventObject => $this, @@ -865,8 +893,8 @@ class Wootook_Empire_Model_Planet ->group('galaxy.system') ; - if ($galaxyList === null && Wootook::getGameConfig('user/registration/galaxy_list')) { - $galaxyList = explode(',', Wootook::getGameConfig('user/registration/galaxy_list')); + if ($galaxyList === null && \Wootook::app()->getDefaultGame()->getConfig('user/registration/galaxy_list')) { + $galaxyList = explode(',', \Wootook::app()->getDefaultGame()->getConfig('user/registration/galaxy_list')); } if ($galaxyList !== null) { @@ -874,8 +902,8 @@ class Wootook_Empire_Model_Planet $select->where('galaxy', array(array(Wootook_Core_Database_Sql_Select::OPERATOR_IN => $galaxyList))); } - if ($systemList === null && Wootook::getGameConfig('user/registration/system_list')) { - $systemList = explode(',', Wootook::getGameConfig('user/registration/system_list')); + if ($systemList === null && \Wootook::app()->getDefaultGame()->getConfig('user/registration/system_list')) { + $systemList = explode(',', \Wootook::app()->getDefaultGame()->getConfig('user/registration/system_list')); } if ($systemList !== null) { @@ -884,15 +912,15 @@ class Wootook_Empire_Model_Planet } $orders = array( - "COUNT(*) / {$adapter->quote(Wootook::getGameConfig('engine/universe/positions'))}", - "1 + ABS(galaxy.galaxy - CEIL({$adapter->quote(Wootook::getGameConfig('engine/universe/galaxies'))} / 2))", - "1 + 2 * ABS(galaxy.system - CEIL({$adapter->quote(Wootook::getGameConfig('engine/universe/systems'))} / 2))", + "COUNT(*) / {$adapter->quote(\Wootook::app()->getDefaultGame()->getConfig('engine/universe/positions'))}", + "1 + ABS(galaxy.galaxy - CEIL({$adapter->quote(\\Wootook::app()->getDefaultGame()->getConfig('engine/universe/galaxies'))} / 2))", + "1 + 2 * ABS(galaxy.system - CEIL({$adapter->quote(\\Wootook::app()->getDefaultGame()->getConfig('engine/universe/systems'))} / 2))", "RAND() / 1000", ); $select ->order(new Wootook_Core_Database_Sql_Placeholder_Expression('((' . implode(') * (', $orders) . '))'), 'ASC') - //->order("ABS(galaxy.system - CEIL({$collection->quote(Wootook::getGameConfig('engine/universe/systems'))} / 2))", 'ASC') - //->order("ABS(galaxy.galaxy - CEIL({$collection->quote(Wootook::getGameConfig('engine/universe/galaxies'))} / 2))", 'ASC') + //->order("ABS(galaxy.system - CEIL({$collection->quote(\\Wootook::app()->getDefaultGame()->getConfig('engine/universe/systems'))} / 2))", 'ASC') + //->order("ABS(galaxy.galaxy - CEIL({$collection->quote(\\Wootook::app()->getDefaultGame()->getConfig('engine/universe/galaxies'))} / 2))", 'ASC') //->order("1.5 / COUNT(*)", 'ASC') ->order('RAND()', 'ASC'); diff --git a/src/application/code/core/Wootook/Empire/Model/Planet/Builder/Item.php b/src/application/code/core/Wootook/Empire/Model/Planet/Builder/Item.php index 2e40fd2..7980561 100644 --- a/src/application/code/core/Wootook/Empire/Model/Planet/Builder/Item.php +++ b/src/application/code/core/Wootook/Empire/Model/Planet/Builder/Item.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Model_Planet_Builder_Item extends Wootook_Empire_Model_Builder_Item diff --git a/src/application/code/core/Wootook/Empire/Model/Planet/BuildingInterface.php b/src/application/code/core/Wootook/Empire/Model/Planet/BuildingInterface.php index d9d694b..9434aa3 100644 --- a/src/application/code/core/Wootook/Empire/Model/Planet/BuildingInterface.php +++ b/src/application/code/core/Wootook/Empire/Model/Planet/BuildingInterface.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ interface Wootook_Empire_Model_Planet_BuildingInterface { diff --git a/src/application/code/core/Wootook/Empire/Model/Planet/PluginLoader.php b/src/application/code/core/Wootook/Empire/Model/Planet/PluginLoader.php index d3cc37b..04da029 100644 --- a/src/application/code/core/Wootook/Empire/Model/Planet/PluginLoader.php +++ b/src/application/code/core/Wootook/Empire/Model/Planet/PluginLoader.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Model_Planet_PluginLoader extends Wootook_Core_PluginLoader_PluginLoader diff --git a/src/application/code/core/Wootook/Empire/Model/Planet/QueueInterface.php b/src/application/code/core/Wootook/Empire/Model/Planet/QueueInterface.php index 7bd2c42..2d1380a 100644 --- a/src/application/code/core/Wootook/Empire/Model/Planet/QueueInterface.php +++ b/src/application/code/core/Wootook/Empire/Model/Planet/QueueInterface.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ interface Wootook_Empire_Model_Planet_QueueInterface { diff --git a/src/application/code/core/Wootook/Empire/Model/Planet/ResourceProductionInterface.php b/src/application/code/core/Wootook/Empire/Model/Planet/ResourceProductionInterface.php index 9556195..604cab1 100644 --- a/src/application/code/core/Wootook/Empire/Model/Planet/ResourceProductionInterface.php +++ b/src/application/code/core/Wootook/Empire/Model/Planet/ResourceProductionInterface.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ interface Wootook_Empire_Model_Planet_ResourceProductionInterface { diff --git a/src/application/code/core/Wootook/Empire/Model/Planet/ShipAbstract.php b/src/application/code/core/Wootook/Empire/Model/Planet/ShipAbstract.php index d108099..722dbb7 100644 --- a/src/application/code/core/Wootook/Empire/Model/Planet/ShipAbstract.php +++ b/src/application/code/core/Wootook/Empire/Model/Planet/ShipAbstract.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ abstract class Wootook_Empire_Model_Planet_ShipAbstract implements Wootook_Empire_Model_Planet_ShipInterface diff --git a/src/application/code/core/Wootook/Empire/Model/Planet/ShipInterface.php b/src/application/code/core/Wootook/Empire/Model/Planet/ShipInterface.php index dc9863a..999cff4 100644 --- a/src/application/code/core/Wootook/Empire/Model/Planet/ShipInterface.php +++ b/src/application/code/core/Wootook/Empire/Model/Planet/ShipInterface.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ interface Wootook_Empire_Model_Planet_ShipInterface { diff --git a/src/application/code/core/Wootook/Empire/Model/Player/TechnologyInterface.php b/src/application/code/core/Wootook/Empire/Model/Player/TechnologyInterface.php index 589914b..0fdb57f 100644 --- a/src/application/code/core/Wootook/Empire/Model/Player/TechnologyInterface.php +++ b/src/application/code/core/Wootook/Empire/Model/Player/TechnologyInterface.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ interface Wootook_Empire_Model_Player_TechnologyInterface { diff --git a/src/application/code/core/Wootook/Empire/Resource/Fleet/Collection.php b/src/application/code/core/Wootook/Empire/Resource/Fleet/Collection.php index ea399f3..1ecde5e 100644 --- a/src/application/code/core/Wootook/Empire/Resource/Fleet/Collection.php +++ b/src/application/code/core/Wootook/Empire/Resource/Fleet/Collection.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Resource_Fleet_Collection extends Wootook_Core_Resource_EntityCollection diff --git a/src/application/code/core/Wootook/Empire/Resource/Planet/Collection.php b/src/application/code/core/Wootook/Empire/Resource/Planet/Collection.php index fc3e8ee..dbf7999 100644 --- a/src/application/code/core/Wootook/Empire/Resource/Planet/Collection.php +++ b/src/application/code/core/Wootook/Empire/Resource/Planet/Collection.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Empire_Resource_Planet_Collection extends Wootook_Core_Resource_EntityCollection diff --git a/src/application/code/core/Wootook/Exception.php b/src/application/code/core/Wootook/Exception.php index c3b339a..80d3b8e 100644 --- a/src/application/code/core/Wootook/Exception.php +++ b/src/application/code/core/Wootook/Exception.php @@ -28,10 +28,12 @@ * */ +namespace Wootook; + /** * * Enter description here ... * @author Greg * */ -interface Wootook_Exception {} \ No newline at end of file +interface Exception {} diff --git a/src/application/code/core/Wootook/Player/Block/Overview.php b/src/application/code/core/Wootook/Player/Block/Overview.php index bf689f0..374e168 100644 --- a/src/application/code/core/Wootook/Player/Block/Overview.php +++ b/src/application/code/core/Wootook/Player/Block/Overview.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Player_Block_Overview extends Wootook_Core_Block_Template diff --git a/src/application/code/core/Wootook/Player/Block/TopBar.php b/src/application/code/core/Wootook/Player/Block/TopBar.php index 9b7adaf..ecf19b3 100644 --- a/src/application/code/core/Wootook/Player/Block/TopBar.php +++ b/src/application/code/core/Wootook/Player/Block/TopBar.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Player_Block_TopBar extends Wootook_Core_Block_Template diff --git a/src/application/code/core/Wootook/Player/Controller/OverviewController.php b/src/application/code/core/Wootook/Player/Controller/OverviewController.php index 97db0cf..a167551 100644 --- a/src/application/code/core/Wootook/Player/Controller/OverviewController.php +++ b/src/application/code/core/Wootook/Player/Controller/OverviewController.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Player_Controller_OverviewController extends Wootook_Player_Mvc_Controller_Registered diff --git a/src/application/code/core/Wootook/Player/Exception.php b/src/application/code/core/Wootook/Player/Exception.php index 6a51351..9004d66 100644 --- a/src/application/code/core/Wootook/Player/Exception.php +++ b/src/application/code/core/Wootook/Player/Exception.php @@ -1,3 +1,31 @@ + * 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 . + * + * --> 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. + * + */ interface Wootook_Player_Exception extends Wootook_Exception {} \ No newline at end of file diff --git a/src/application/code/core/Wootook/Player/Exception/Exception.php b/src/application/code/core/Wootook/Player/Exception/Exception.php index 5e50e0a..7d5b9b1 100644 --- a/src/application/code/core/Wootook/Player/Exception/Exception.php +++ b/src/application/code/core/Wootook/Player/Exception/Exception.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Player_Exception_Exception extends Exception diff --git a/src/application/code/core/Wootook/Player/Exception/Session.php b/src/application/code/core/Wootook/Player/Exception/Session.php index b546e5d..f6ae97f 100644 --- a/src/application/code/core/Wootook/Player/Exception/Session.php +++ b/src/application/code/core/Wootook/Player/Exception/Session.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Player_Exception_Session extends Wootook_Player_Exception_RuntimeException diff --git a/src/application/code/core/Wootook/Player/Model/Entity.php b/src/application/code/core/Wootook/Player/Model/Entity.php index 389b8ba..4bfc6be 100644 --- a/src/application/code/core/Wootook/Player/Model/Entity.php +++ b/src/application/code/core/Wootook/Player/Model/Entity.php @@ -1,10 +1,38 @@ + * 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 . + * + * --> 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. + * + */ /** * * Enter description here ... * - * @uses Wootook_Object + * @uses Wootook\Core\BaseObject * @uses Legacies_Empire */ class Wootook_Player_Model_Entity @@ -627,11 +655,6 @@ class Wootook_Player_Model_Entity return $this->getData('urlaubs_until'); } - public function getLastLoginDate() - { - return $this->getData('onlinetime'); - } - public function setVacation($active = true) { $this->setData('urlaubs_modus', $active); diff --git a/src/application/code/core/Wootook/Player/Model/Message.php b/src/application/code/core/Wootook/Player/Model/Message.php index 0002d94..129f0f3 100644 --- a/src/application/code/core/Wootook/Player/Model/Message.php +++ b/src/application/code/core/Wootook/Player/Model/Message.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Player_Model_Message extends Wootook_Core_Mvc_Model_Entity_SubTable diff --git a/src/application/code/core/Wootook/Player/Model/Session.php b/src/application/code/core/Wootook/Player/Model/Session.php index 9ae226c..85c463e 100644 --- a/src/application/code/core/Wootook/Player/Model/Session.php +++ b/src/application/code/core/Wootook/Player/Model/Session.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Player_Model_Session extends Wootook_Core_Model_Session diff --git a/src/application/code/core/Wootook/Player/Mvc/Controller/Registered.php b/src/application/code/core/Wootook/Player/Mvc/Controller/Registered.php index 3374acf..9282caa 100644 --- a/src/application/code/core/Wootook/Player/Mvc/Controller/Registered.php +++ b/src/application/code/core/Wootook/Player/Mvc/Controller/Registered.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Player_Mvc_Controller_Registered extends Wootook_Core_Mvc_Controller_Action diff --git a/src/application/code/core/Wootook/Player/Resource/Entity/Collection.php b/src/application/code/core/Wootook/Player/Resource/Entity/Collection.php index 3e2c1bc..e2288ad 100644 --- a/src/application/code/core/Wootook/Player/Resource/Entity/Collection.php +++ b/src/application/code/core/Wootook/Player/Resource/Entity/Collection.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Player_Resource_Entity_Collection extends Wootook_Core_Resource_EntityCollection diff --git a/src/application/code/core/Wootook/Player/Resource/Message/Collection.php b/src/application/code/core/Wootook/Player/Resource/Message/Collection.php index e6d9198..0a0921c 100644 --- a/src/application/code/core/Wootook/Player/Resource/Message/Collection.php +++ b/src/application/code/core/Wootook/Player/Resource/Message/Collection.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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. + * + */ class Wootook_Player_Resource_Message_Collection extends Wootook_Core_Resource_EntityCollection diff --git a/src/application/code/libraries/Wildfire/Stream.php b/src/application/code/libraries/Wildfire/Stream.php deleted file mode 100644 index 9966a44..0000000 --- a/src/application/code/libraries/Wildfire/Stream.php +++ /dev/null @@ -1,1753 +0,0 @@ - - * @license http://www.opensource.org/licenses/bsd-license.php - * @package FirePHPCore - */ - - -/** - * Sends the given data to the FirePHP Firefox Extension. - * The data can be displayed in the Firebug Console or in the - * "Server" request tab. - * - * For more information see: http://www.firephp.org/ - * - * @copyright Copyright (C) 2007-2009 Christoph Dorn - * @author Christoph Dorn - * @license http://www.opensource.org/licenses/bsd-license.php - * @package FirePHPCore - */ -class Wildfire_Stream { - - /** - * FirePHP version - * - * @var string - */ - const VERSION = '0.3'; // @pinf replace '0.3' with '%%package.version%%' - - /** - * Firebug LOG level - * - * Logs a message to firebug console. - * - * @var string - */ - const LOG = 'LOG'; - - /** - * Firebug INFO level - * - * Logs a message to firebug console and displays an info icon before the message. - * - * @var string - */ - const INFO = 'INFO'; - - /** - * Firebug WARN level - * - * Logs a message to firebug console, displays an warning icon before the message and colors the line turquoise. - * - * @var string - */ - const WARN = 'WARN'; - - /** - * Firebug ERROR level - * - * Logs a message to firebug console, displays an error icon before the message and colors the line yellow. Also increments the firebug error count. - * - * @var string - */ - const ERROR = 'ERROR'; - - /** - * Dumps a variable to firebug's server panel - * - * @var string - */ - const DUMP = 'DUMP'; - - /** - * Displays a stack trace in firebug console - * - * @var string - */ - const TRACE = 'TRACE'; - - /** - * Displays an exception in firebug console - * - * Increments the firebug error count. - * - * @var string - */ - const EXCEPTION = 'EXCEPTION'; - - /** - * Displays an table in firebug console - * - * @var string - */ - const TABLE = 'TABLE'; - - /** - * Starts a group in firebug console - * - * @var string - */ - const GROUP_START = 'GROUP_START'; - - /** - * Ends a group in firebug console - * - * @var string - */ - const GROUP_END = 'GROUP_END'; - - /** - * Singleton instance of FirePHP - * - * @var FirePHP - */ - protected static $instance = null; - - /** - * Flag whether we are logging from within the exception handler - * - * @var boolean - */ - protected $inExceptionHandler = false; - - /** - * Flag whether to throw PHP errors that have been converted to ErrorExceptions - * - * @var boolean - */ - protected $throwErrorExceptions = true; - - /** - * Flag whether to convert PHP assertion errors to Exceptions - * - * @var boolean - */ - protected $convertAssertionErrorsToExceptions = true; - - /** - * Flag whether to throw PHP assertion errors that have been converted to Exceptions - * - * @var boolean - */ - protected $throwAssertionExceptions = false; - - /** - * Wildfire protocol message index - * - * @var int - */ - protected $messageIndex = 1; - - /** - * Options for the library - * - * @var array - */ - protected $options = array('maxDepth' => 10, - 'maxObjectDepth' => 5, - 'maxArrayDepth' => 5, - 'useNativeJsonEncode' => true, - 'includeLineNumbers' => true); - - /** - * Filters used to exclude object members when encoding - * - * @var array - */ - protected $objectFilters = array( - 'firephp' => array('objectStack', 'instance', 'json_objectStack'), - 'firephp_test_class' => array('objectStack', 'instance', 'json_objectStack') - ); - - /** - * A stack of objects used to detect recursion during object encoding - * - * @var object - */ - protected $objectStack = array(); - - /** - * Flag to enable/disable logging - * - * @var boolean - */ - protected $enabled = true; - - /** - * The insight console to log to if applicable - * - * @var object - */ - protected $logToInsightConsole = null; - - /** - * When the object gets serialized only include specific object members. - * - * @return array - */ - public function __sleep() - { - return array('options','objectFilters','enabled'); - } - - /** - * Gets singleton instance of FirePHP - * - * @param boolean $AutoCreate - * @return FirePHP - */ - public static function getInstance($AutoCreate = false) - { - if ($AutoCreate===true && !self::$instance) { - self::init(); - } - return self::$instance; - } - - /** - * Creates FirePHP object and stores it for singleton access - * - * @return FirePHP - */ - public static function init() - { - return self::setInstance(new self()); - } - - /** - * Set the instance of the FirePHP singleton - * - * @param FirePHP $instance The FirePHP object instance - * @return FirePHP - */ - public static function setInstance($instance) - { - return self::$instance = $instance; - } - - /** - * Set an Insight console to direct all logging calls to - * - * @param object $console The console object to log to - * @return void - */ - public function setLogToInsightConsole($console) - { - if(is_string($console)) { - if(get_class($this)!='FirePHP_Insight' && !is_subclass_of($this, 'FirePHP_Insight')) { - throw new Exception('FirePHP instance not an instance or subclass of FirePHP_Insight!'); - } - $this->logToInsightConsole = $this->to('request')->console($console); - } else { - $this->logToInsightConsole = $console; - } - } - - /** - * Enable and disable logging to Firebug - * - * @param boolean $Enabled TRUE to enable, FALSE to disable - * @return void - */ - public function setEnabled($Enabled) - { - $this->enabled = $Enabled; - } - - /** - * Check if logging is enabled - * - * @return boolean TRUE if enabled - */ - public function getEnabled() - { - return $this->enabled; - } - - /** - * Specify a filter to be used when encoding an object - * - * Filters are used to exclude object members. - * - * @param string $Class The class name of the object - * @param array $Filter An array of members to exclude - * @return void - */ - public function setObjectFilter($Class, $Filter) - { - $this->objectFilters[strtolower($Class)] = $Filter; - } - - /** - * Set some options for the library - * - * Options: - * - maxDepth: The maximum depth to traverse (default: 10) - * - maxObjectDepth: The maximum depth to traverse objects (default: 5) - * - maxArrayDepth: The maximum depth to traverse arrays (default: 5) - * - useNativeJsonEncode: If true will use json_encode() (default: true) - * - includeLineNumbers: If true will include line numbers and filenames (default: true) - * - * @param array $Options The options to be set - * @return void - */ - public function setOptions($Options) - { - $this->options = array_merge($this->options,$Options); - } - - /** - * Get options from the library - * - * @return array The currently set options - */ - public function getOptions() - { - return $this->options; - } - - /** - * Set an option for the library - * - * @param string $Name - * @param mixed $Value - * @throws Exception - * @return void - */ - public function setOption($Name, $Value) - { - if (!isset($this->options[$Name])) { - throw $this->newException('Unknown option: ' . $Name); - } - $this->options[$Name] = $Value; - } - - /** - * Get an option from the library - * - * @param string $Name - * @throws Exception - * @return mixed - */ - public function getOption($Name) - { - if (!isset($this->options[$Name])) { - throw $this->newException('Unknown option: ' . $Name); - } - return $this->options[$Name]; - } - - /** - * Register FirePHP as your error handler - * - * Will throw exceptions for each php error. - * - * @return mixed Returns a string containing the previously defined error handler (if any) - */ - public function registerErrorHandler($throwErrorExceptions = false) - { - //NOTE: The following errors will not be caught by this error handler: - // E_ERROR, E_PARSE, E_CORE_ERROR, - // E_CORE_WARNING, E_COMPILE_ERROR, - // E_COMPILE_WARNING, E_STRICT - - $this->throwErrorExceptions = $throwErrorExceptions; - - return set_error_handler(array($this,'errorHandler')); - } - - /** - * FirePHP's error handler - * - * Throws exception for each php error that will occur. - * - * @param int $errno - * @param string $errstr - * @param string $errfile - * @param int $errline - * @param array $errcontext - */ - public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) - { - // Don't throw exception if error reporting is switched off - if (error_reporting() == 0) { - return; - } - // Only throw exceptions for errors we are asking for - if (error_reporting() & $errno) { - - $exception = new ErrorException($errstr, 0, $errno, $errfile, $errline); - if ($this->throwErrorExceptions) { - throw $exception; - } else { - $this->fb($exception); - } - } - } - - /** - * Register FirePHP as your exception handler - * - * @return mixed Returns the name of the previously defined exception handler, - * or NULL on error. - * If no previous handler was defined, NULL is also returned. - */ - public function registerExceptionHandler() - { - return set_exception_handler(array($this,'exceptionHandler')); - } - - /** - * FirePHP's exception handler - * - * Logs all exceptions to your firebug console and then stops the script. - * - * @param Exception $Exception - * @throws Exception - */ - function exceptionHandler($Exception) - { - - $this->inExceptionHandler = true; - - header('HTTP/1.1 500 Internal Server Error'); - - try { - $this->fb($Exception); - } catch (Exception $e) { - echo 'We had an exception: ' . $e; - } - $this->inExceptionHandler = false; - } - - /** - * Register FirePHP driver as your assert callback - * - * @param boolean $convertAssertionErrorsToExceptions - * @param boolean $throwAssertionExceptions - * @return mixed Returns the original setting or FALSE on errors - */ - public function registerAssertionHandler($convertAssertionErrorsToExceptions = true, $throwAssertionExceptions = false) - { - $this->convertAssertionErrorsToExceptions = $convertAssertionErrorsToExceptions; - $this->throwAssertionExceptions = $throwAssertionExceptions; - - if ($throwAssertionExceptions && !$convertAssertionErrorsToExceptions) { - throw $this->newException('Cannot throw assertion exceptions as assertion errors are not being converted to exceptions!'); - } - - return assert_options(ASSERT_CALLBACK, array($this, 'assertionHandler')); - } - - /** - * FirePHP's assertion handler - * - * Logs all assertions to your firebug console and then stops the script. - * - * @param string $file File source of assertion - * @param int $line Line source of assertion - * @param mixed $code Assertion code - */ - public function assertionHandler($file, $line, $code) - { - if ($this->convertAssertionErrorsToExceptions) { - - $exception = new ErrorException('Assertion Failed - Code[ '.$code.' ]', 0, null, $file, $line); - - if ($this->throwAssertionExceptions) { - throw $exception; - } else { - $this->fb($exception); - } - - } else { - $this->fb($code, 'Assertion Failed', FirePHP::ERROR, array('File'=>$file,'Line'=>$line)); - } - } - - /** - * Start a group for following messages. - * - * Options: - * Collapsed: [true|false] - * Color: [#RRGGBB|ColorName] - * - * @param string $Name - * @param array $Options OPTIONAL Instructions on how to log the group - * @return true - * @throws Exception - */ - public function group($Name, $Options = null) - { - - if (!$Name) { - throw $this->newException('You must specify a label for the group!'); - } - - if ($Options) { - if (!is_array($Options)) { - throw $this->newException('Options must be defined as an array!'); - } - if (array_key_exists('Collapsed', $Options)) { - $Options['Collapsed'] = ($Options['Collapsed'])?'true':'false'; - } - } - - return $this->fb(null, $Name, FirePHP::GROUP_START, $Options); - } - - /** - * Ends a group you have started before - * - * @return true - * @throws Exception - */ - public function groupEnd() - { - return $this->fb(null, null, FirePHP::GROUP_END); - } - - /** - * Log object with label to firebug console - * - * @see FirePHP::LOG - * @param mixes $Object - * @param string $Label - * @return true - * @throws Exception - */ - public function log($Object, $Label = null, $Options = array()) - { - return $this->fb($Object, $Label, FirePHP::LOG, $Options); - } - - /** - * Log object with label to firebug console - * - * @see FirePHP::INFO - * @param mixes $Object - * @param string $Label - * @return true - * @throws Exception - */ - public function info($Object, $Label = null, $Options = array()) - { - return $this->fb($Object, $Label, FirePHP::INFO, $Options); - } - - /** - * Log object with label to firebug console - * - * @see FirePHP::WARN - * @param mixes $Object - * @param string $Label - * @return true - * @throws Exception - */ - public function warn($Object, $Label = null, $Options = array()) - { - return $this->fb($Object, $Label, FirePHP::WARN, $Options); - } - - /** - * Log object with label to firebug console - * - * @see FirePHP::ERROR - * @param mixes $Object - * @param string $Label - * @return true - * @throws Exception - */ - public function error($Object, $Label = null, $Options = array()) - { - return $this->fb($Object, $Label, FirePHP::ERROR, $Options); - } - - /** - * Dumps key and variable to firebug server panel - * - * @see FirePHP::DUMP - * @param string $Key - * @param mixed $Variable - * @return true - * @throws Exception - */ - public function dump($Key, $Variable, $Options = array()) - { - if (!is_string($Key)) { - throw $this->newException('Key passed to dump() is not a string'); - } - if (strlen($Key)>100) { - throw $this->newException('Key passed to dump() is longer than 100 characters'); - } - if (!preg_match_all('/^[a-zA-Z0-9-_\.:]*$/', $Key, $m)) { - throw $this->newException('Key passed to dump() contains invalid characters [a-zA-Z0-9-_\.:]'); - } - return $this->fb($Variable, $Key, FirePHP::DUMP, $Options); - } - - /** - * Log a trace in the firebug console - * - * @see FirePHP::TRACE - * @param string $Label - * @return true - * @throws Exception - */ - public function trace($Label) - { - return $this->fb($Label, FirePHP::TRACE); - } - - /** - * Log a table in the firebug console - * - * @see FirePHP::TABLE - * @param string $Label - * @param string $Table - * @return true - * @throws Exception - */ - public function table($Label, $Table, $Options = array()) - { - return $this->fb($Table, $Label, FirePHP::TABLE, $Options); - } - - /** - * Insight API wrapper - * - * @see Insight_Helper::to() - */ - public static function to() - { - $instance = self::getInstance(); - if (!method_exists($instance, "_to")) { - throw new Exception("FirePHP::to() implementation not loaded"); - } - $args = func_get_args(); - return call_user_func_array(array($instance, '_to'), $args); - } - - /** - * Insight API wrapper - * - * @see Insight_Helper::plugin() - */ - public static function plugin() - { - $instance = self::getInstance(); - if (!method_exists($instance, "_plugin")) { - throw new Exception("FirePHP::plugin() implementation not loaded"); - } - $args = func_get_args(); - return call_user_func_array(array($instance, '_plugin'), $args); - } - - /** - * Check if FirePHP is installed on client - * - * @return boolean - */ - public function detectClientExtension() - { - // Check if FirePHP is installed on client via User-Agent header - if (@preg_match_all('/\sFirePHP\/([\.\d]*)\s?/si',$this->getUserAgent(),$m) && - version_compare($m[1][0],'0.0.6','>=')) { - return true; - } else - // Check if FirePHP is installed on client via X-FirePHP-Version header - if (@preg_match_all('/^([\.\d]*)$/si',$this->getRequestHeader("X-FirePHP-Version"),$m) && - version_compare($m[1][0],'0.0.6','>=')) { - return true; - } - return false; - } - - /** - * Log varible to Firebug - * - * @see http://www.firephp.org/Wiki/Reference/Fb - * @param mixed $Object The variable to be logged - * @return true Return TRUE if message was added to headers, FALSE otherwise - * @throws Exception - */ - public function fb($Object) - { - if($this instanceof FirePHP_Insight && method_exists($this, '_logUpgradeClientMessage')) { - if(!FirePHP_Insight::$upgradeClientMessageLogged) { // avoid infinite recursion as _logUpgradeClientMessage() logs a message - $this->_logUpgradeClientMessage(); - } - } - - static $insightGroupStack = array(); - - if (!$this->getEnabled()) { - return false; - } - - if ($this->headersSent($filename, $linenum)) { - // If we are logging from within the exception handler we cannot throw another exception - if ($this->inExceptionHandler) { - // Simply echo the error out to the page - echo '
FirePHP ERROR: Headers already sent in '.$filename.' on line '.$linenum.'. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.
'; - } else { - throw $this->newException('Headers already sent in '.$filename.' on line '.$linenum.'. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.'); - } - } - - $Type = null; - $Label = null; - $Options = array(); - - if (func_num_args()==1) { - } else - if (func_num_args()==2) { - switch(func_get_arg(1)) { - case self::LOG: - case self::INFO: - case self::WARN: - case self::ERROR: - case self::DUMP: - case self::TRACE: - case self::EXCEPTION: - case self::TABLE: - case self::GROUP_START: - case self::GROUP_END: - $Type = func_get_arg(1); - break; - default: - $Label = func_get_arg(1); - break; - } - } else - if (func_num_args()==3) { - $Type = func_get_arg(2); - $Label = func_get_arg(1); - } else - if (func_num_args()==4) { - $Type = func_get_arg(2); - $Label = func_get_arg(1); - $Options = func_get_arg(3); - } else { - throw $this->newException('Wrong number of arguments to fb() function!'); - } - - if($this->logToInsightConsole!==null && (get_class($this)=='FirePHP_Insight' || is_subclass_of($this, 'FirePHP_Insight'))) { - $msg = $this->logToInsightConsole; - if ($Object instanceof Exception) { - $Type = self::EXCEPTION; - } - if($Label && $Type!=self::TABLE && $Type!=self::GROUP_START) { - $msg = $msg->label($Label); - } - switch($Type) { - case self::DUMP: - case self::LOG: - return $msg->log($Object); - case self::INFO: - return $msg->info($Object); - case self::WARN: - return $msg->warn($Object); - case self::ERROR: - return $msg->error($Object); - case self::TRACE: - return $msg->trace($Object); - case self::EXCEPTION: - return $this->plugin('engine')->handleException($Object, $msg); - case self::TABLE: - if (isset($Object[0]) && !is_string($Object[0]) && $Label) { - $Object = array($Label, $Object); - } - return $msg->table($Object[0], array_slice($Object[1],1), $Object[1][0]); - case self::GROUP_START: - $insightGroupStack[] = $msg->group(md5($Label))->open(); - return $msg->log($Label); - case self::GROUP_END: - if(count($insightGroupStack)==0) { - throw new Error('Too many groupEnd() as opposed to group() calls!'); - } - $group = array_pop($insightGroupStack); - return $group->close(); - default: - return $msg->log($Object); - } - } - - if (!$this->detectClientExtension()) { - return false; - } - - $meta = array(); - $skipFinalObjectEncode = false; - - if ($Object instanceof Exception) { - - $meta['file'] = $this->_escapeTraceFile($Object->getFile()); - $meta['line'] = $Object->getLine(); - - $trace = $Object->getTrace(); - if ($Object instanceof ErrorException - && isset($trace[0]['function']) - && $trace[0]['function']=='errorHandler' - && isset($trace[0]['class']) - && $trace[0]['class']=='FirePHP') { - - $severity = false; - switch($Object->getSeverity()) { - case E_WARNING: $severity = 'E_WARNING'; break; - case E_NOTICE: $severity = 'E_NOTICE'; break; - case E_USER_ERROR: $severity = 'E_USER_ERROR'; break; - case E_USER_WARNING: $severity = 'E_USER_WARNING'; break; - case E_USER_NOTICE: $severity = 'E_USER_NOTICE'; break; - case E_STRICT: $severity = 'E_STRICT'; break; - case E_RECOVERABLE_ERROR: $severity = 'E_RECOVERABLE_ERROR'; break; - case E_DEPRECATED: $severity = 'E_DEPRECATED'; break; - case E_USER_DEPRECATED: $severity = 'E_USER_DEPRECATED'; break; - } - - $Object = array('Class'=>get_class($Object), - 'Message'=>$severity.': '.$Object->getMessage(), - 'File'=>$this->_escapeTraceFile($Object->getFile()), - 'Line'=>$Object->getLine(), - 'Type'=>'trigger', - 'Trace'=>$this->_escapeTrace(array_splice($trace,2))); - $skipFinalObjectEncode = true; - } else { - $Object = array('Class'=>get_class($Object), - 'Message'=>$Object->getMessage(), - 'File'=>$this->_escapeTraceFile($Object->getFile()), - 'Line'=>$Object->getLine(), - 'Type'=>'throw', - 'Trace'=>$this->_escapeTrace($trace)); - $skipFinalObjectEncode = true; - } - $Type = self::EXCEPTION; - - } else - if ($Type==self::TRACE) { - - $trace = debug_backtrace(); - if (!$trace) return false; - for( $i=0 ; $i_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php' - || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) { - /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ - } else - if (isset($trace[$i]['class']) - && isset($trace[$i+1]['file']) - && $trace[$i]['class']=='FirePHP' - && substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') { - /* Skip fb() */ - } else - if ($trace[$i]['function']=='fb' - || $trace[$i]['function']=='trace' - || $trace[$i]['function']=='send') { - - $Object = array('Class'=>isset($trace[$i]['class'])?$trace[$i]['class']:'', - 'Type'=>isset($trace[$i]['type'])?$trace[$i]['type']:'', - 'Function'=>isset($trace[$i]['function'])?$trace[$i]['function']:'', - 'Message'=>$trace[$i]['args'][0], - 'File'=>isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):'', - 'Line'=>isset($trace[$i]['line'])?$trace[$i]['line']:'', - 'Args'=>isset($trace[$i]['args'])?$this->encodeObject($trace[$i]['args']):'', - 'Trace'=>$this->_escapeTrace(array_splice($trace,$i+1))); - - $skipFinalObjectEncode = true; - $meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):''; - $meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:''; - break; - } - } - - } else - if ($Type==self::TABLE) { - - if (isset($Object[0]) && is_string($Object[0])) { - $Object[1] = $this->encodeTable($Object[1]); - } else { - $Object = $this->encodeTable($Object); - } - - $skipFinalObjectEncode = true; - - } else - if ($Type==self::GROUP_START) { - - if (!$Label) { - throw $this->newException('You must specify a label for the group!'); - } - - } else { - if ($Type===null) { - $Type = self::LOG; - } - } - - if ($this->options['includeLineNumbers']) { - if (!isset($meta['file']) || !isset($meta['line'])) { - - $trace = debug_backtrace(); - for( $i=0 ; $trace && $i_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php' - || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) { - /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ - } else - if (isset($trace[$i]['class']) - && isset($trace[$i+1]['file']) - && $trace[$i]['class']=='FirePHP' - && substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') { - /* Skip fb() */ - } else - if (isset($trace[$i]['file']) - && substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php') { - /* Skip FB::fb() */ - } else { - $meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):''; - $meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:''; - break; - } - } - } - } else { - unset($meta['file']); - unset($meta['line']); - } - - $this->setHeader('X-Wf-Protocol-1','http://meta.wildfirehq.org/Protocol/JsonStream/0.2'); - $this->setHeader('X-Wf-1-Plugin-1','http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/'.self::VERSION); - - $structure_index = 1; - if ($Type==self::DUMP) { - $structure_index = 2; - $this->setHeader('X-Wf-1-Structure-2','http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1'); - } else { - $this->setHeader('X-Wf-1-Structure-1','http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1'); - } - - if ($Type==self::DUMP) { - $msg = '{"'.$Label.'":'.$this->jsonEncode($Object, $skipFinalObjectEncode).'}'; - } else { - $msg_meta = $Options; - $msg_meta['Type'] = $Type; - if ($Label!==null) { - $msg_meta['Label'] = $Label; - } - if (isset($meta['file']) && !isset($msg_meta['File'])) { - $msg_meta['File'] = $meta['file']; - } - if (isset($meta['line']) && !isset($msg_meta['Line'])) { - $msg_meta['Line'] = $meta['line']; - } - $msg = '['.$this->jsonEncode($msg_meta).','.$this->jsonEncode($Object, $skipFinalObjectEncode).']'; - } - - $parts = explode("\n",chunk_split($msg, 5000, "\n")); - - for( $i=0 ; $i2) { - // Message needs to be split into multiple parts - $this->setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex, - (($i==0)?strlen($msg):'') - . '|' . $part . '|' - . (($isetHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex, - strlen($part) . '|' . $part . '|'); - } - - $this->messageIndex++; - - if ($this->messageIndex > 99999) { - throw $this->newException('Maximum number (99,999) of messages reached!'); - } - } - } - - $this->setHeader('X-Wf-1-Index',$this->messageIndex-1); - - return true; - } - - /** - * Standardizes path for windows systems. - * - * @param string $Path - * @return string - */ - protected function _standardizePath($Path) - { - return preg_replace('/\\\\+/','/',$Path); - } - - /** - * Escape trace path for windows systems - * - * @param array $Trace - * @return array - */ - protected function _escapeTrace($Trace) - { - if (!$Trace) return $Trace; - for( $i=0 ; $i_escapeTraceFile($Trace[$i]['file']); - } - if (isset($Trace[$i]['args'])) { - $Trace[$i]['args'] = $this->encodeObject($Trace[$i]['args']); - } - } - return $Trace; - } - - /** - * Escape file information of trace for windows systems - * - * @param string $File - * @return string - */ - protected function _escapeTraceFile($File) - { - /* Check if we have a windows filepath */ - if (strpos($File,'\\')) { - /* First strip down to single \ */ - - $file = preg_replace('/\\\\+/','\\',$File); - - return $file; - } - return $File; - } - - /** - * Check if headers have already been sent - * - * @param string $Filename - * @param integer $Linenum - */ - protected function headersSent(&$Filename, &$Linenum) - { - return headers_sent($Filename, $Linenum); - } - - /** - * Send header - * - * @param string $Name - * @param string $Value - */ - protected function setHeader($Name, $Value) - { - return header($Name.': '.$Value); - } - - /** - * Get user agent - * - * @return string|false - */ - protected function getUserAgent() - { - if (!isset($_SERVER['HTTP_USER_AGENT'])) return false; - return $_SERVER['HTTP_USER_AGENT']; - } - - /** - * Get all request headers - * - * @return array - */ - public static function getAllRequestHeaders() { - static $_cached_headers = false; - if($_cached_headers!==false) { - return $_cached_headers; - } - $headers = array(); - if(function_exists('getallheaders')) { - foreach( getallheaders() as $name => $value ) { - $headers[strtolower($name)] = $value; - } - } else { - foreach($_SERVER as $name => $value) { - if(substr($name, 0, 5) == 'HTTP_') { - $headers[strtolower(str_replace(' ', '-', str_replace('_', ' ', substr($name, 5))))] = $value; - } - } - } - return $_cached_headers = $headers; - } - - /** - * Get a request header - * - * @return string|false - */ - protected function getRequestHeader($Name) - { - $headers = self::getAllRequestHeaders(); - if (isset($headers[strtolower($Name)])) { - return $headers[strtolower($Name)]; - } - return false; - } - - /** - * Returns a new exception - * - * @param string $Message - * @return Exception - */ - protected function newException($Message) - { - return new Exception($Message); - } - - /** - * Encode an object into a JSON string - * - * Uses PHP's jeson_encode() if available - * - * @param object $Object The object to be encoded - * @return string The JSON string - */ - public function jsonEncode($Object, $skipObjectEncode = false) - { - if (!$skipObjectEncode) { - $Object = $this->encodeObject($Object); - } - - if (function_exists('json_encode') - && $this->options['useNativeJsonEncode']!=false) { - - return json_encode($Object); - } else { - return $this->json_encode($Object); - } - } - - /** - * Encodes a table by encoding each row and column with encodeObject() - * - * @param array $Table The table to be encoded - * @return array - */ - protected function encodeTable($Table) - { - - if (!$Table) return $Table; - - $new_table = array(); - foreach($Table as $row) { - - if (is_array($row)) { - $new_row = array(); - - foreach($row as $item) { - $new_row[] = $this->encodeObject($item); - } - - $new_table[] = $new_row; - } - } - - return $new_table; - } - - /** - * Encodes an object including members with - * protected and private visibility - * - * @param Object $Object The object to be encoded - * @param int $Depth The current traversal depth - * @return array All members of the object - */ - protected function encodeObject($Object, $ObjectDepth = 1, $ArrayDepth = 1, $MaxDepth = 1) - { - if ($MaxDepth > $this->options['maxDepth']) { - return '** Max Depth ('.$this->options['maxDepth'].') **'; - } - - $return = array(); - - if (is_resource($Object)) { - - return '** '.(string)$Object.' **'; - - } else - if (is_object($Object)) { - - if ($ObjectDepth > $this->options['maxObjectDepth']) { - return '** Max Object Depth ('.$this->options['maxObjectDepth'].') **'; - } - - foreach ($this->objectStack as $refVal) { - if ($refVal === $Object) { - return '** Recursion ('.get_class($Object).') **'; - } - } - array_push($this->objectStack, $Object); - - $return['__className'] = $class = get_class($Object); - $class_lower = strtolower($class); - - $reflectionClass = new ReflectionClass($class); - $properties = array(); - foreach( $reflectionClass->getProperties() as $property) { - $properties[$property->getName()] = $property; - } - - $members = (array)$Object; - - foreach( $properties as $plain_name => $property ) { - - $name = $raw_name = $plain_name; - if ($property->isStatic()) { - $name = 'static:'.$name; - } - if ($property->isPublic()) { - $name = 'public:'.$name; - } else - if ($property->isPrivate()) { - $name = 'private:'.$name; - $raw_name = "\0".$class."\0".$raw_name; - } else - if ($property->isProtected()) { - $name = 'protected:'.$name; - $raw_name = "\0".'*'."\0".$raw_name; - } - - if (!(isset($this->objectFilters[$class_lower]) - && is_array($this->objectFilters[$class_lower]) - && in_array($plain_name,$this->objectFilters[$class_lower]))) { - - if (array_key_exists($raw_name,$members) - && !$property->isStatic()) { - - $return[$name] = $this->encodeObject($members[$raw_name], $ObjectDepth + 1, 1, $MaxDepth + 1); - - } else { - if (method_exists($property,'setAccessible')) { - $property->setAccessible(true); - $return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1, $MaxDepth + 1); - } else - if ($property->isPublic()) { - $return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1, $MaxDepth + 1); - } else { - $return[$name] = '** Need PHP 5.3 to get value **'; - } - } - } else { - $return[$name] = '** Excluded by Filter **'; - } - } - - // Include all members that are not defined in the class - // but exist in the object - foreach( $members as $raw_name => $value ) { - - $name = $raw_name; - - if ($name{0} == "\0") { - $parts = explode("\0", $name); - $name = $parts[2]; - } - - $plain_name = $name; - - if (!isset($properties[$name])) { - $name = 'undeclared:'.$name; - - if (!(isset($this->objectFilters[$class_lower]) - && is_array($this->objectFilters[$class_lower]) - && in_array($plain_name,$this->objectFilters[$class_lower]))) { - - $return[$name] = $this->encodeObject($value, $ObjectDepth + 1, 1, $MaxDepth + 1); - } else { - $return[$name] = '** Excluded by Filter **'; - } - } - } - - array_pop($this->objectStack); - - } elseif (is_array($Object)) { - - if ($ArrayDepth > $this->options['maxArrayDepth']) { - return '** Max Array Depth ('.$this->options['maxArrayDepth'].') **'; - } - - foreach ($Object as $key => $val) { - - // Encoding the $GLOBALS PHP array causes an infinite loop - // if the recursion is not reset here as it contains - // a reference to itself. This is the only way I have come up - // with to stop infinite recursion in this case. - if ($key=='GLOBALS' - && is_array($val) - && array_key_exists('GLOBALS',$val)) { - $val['GLOBALS'] = '** Recursion (GLOBALS) **'; - } - - $return[$key] = $this->encodeObject($val, 1, $ArrayDepth + 1, $MaxDepth + 1); - } - } else { - if (self::is_utf8($Object)) { - return $Object; - } else { - return utf8_encode($Object); - } - } - return $return; - } - - /** - * Returns true if $string is valid UTF-8 and false otherwise. - * - * @param mixed $str String to be tested - * @return boolean - */ - protected static function is_utf8($str) - { - if(function_exists('mb_detect_encoding')) { - return (mb_detect_encoding($str) == 'UTF-8'); - } - $c=0; $b=0; - $bits=0; - $len=strlen($str); - for($i=0; $i<$len; $i++){ - $c=ord($str[$i]); - if ($c > 128){ - if (($c >= 254)) return false; - elseif ($c >= 252) $bits=6; - elseif ($c >= 248) $bits=5; - elseif ($c >= 240) $bits=4; - elseif ($c >= 224) $bits=3; - elseif ($c >= 192) $bits=2; - else return false; - if (($i+$bits) > $len) return false; - while($bits > 1){ - $i++; - $b=ord($str[$i]); - if ($b < 128 || $b > 191) return false; - $bits--; - } - } - } - return true; - } - - /** - * Converts to and from JSON format. - * - * JSON (JavaScript Object Notation) is a lightweight data-interchange - * format. It is easy for humans to read and write. It is easy for machines - * to parse and generate. It is based on a subset of the JavaScript - * Programming Language, Standard ECMA-262 3rd Edition - December 1999. - * This feature can also be found in Python. JSON is a text format that is - * completely language independent but uses conventions that are familiar - * to programmers of the C-family of languages, including C, C++, C#, Java, - * JavaScript, Perl, TCL, and many others. These properties make JSON an - * ideal data-interchange language. - * - * This package provides a simple encoder and decoder for JSON notation. It - * is intended for use with client-side Javascript applications that make - * use of HTTPRequest to perform server communication functions - data can - * be encoded into JSON notation for use in a client-side javascript, or - * decoded from incoming Javascript requests. JSON format is native to - * Javascript, and can be directly eval()'ed with no further parsing - * overhead - * - * All strings should be in ASCII or UTF-8 format! - * - * LICENSE: 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. - * - * THIS SOFTWARE IS PROVIDED ``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 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. - * - * @category - * @package Services_JSON - * @author Michal Migurski - * @author Matt Knapp - * @author Brett Stimmerman - * @author Christoph Dorn - * @copyright 2005 Michal Migurski - * @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $ - * @license http://www.opensource.org/licenses/bsd-license.php - * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198 - */ - - - /** - * Keep a list of objects as we descend into the array so we can detect recursion. - */ - private $json_objectStack = array(); - - - /** - * convert a string from one UTF-8 char to one UTF-16 char - * - * Normally should be handled by mb_convert_encoding, but - * provides a slower PHP-only method for installations - * that lack the multibye string extension. - * - * @param string $utf8 UTF-8 character - * @return string UTF-16 character - * @access private - */ - private function json_utf82utf16($utf8) - { - // oh please oh please oh please oh please oh please - if (function_exists('mb_convert_encoding')) { - return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); - } - - switch(strlen($utf8)) { - case 1: - // this case should never be reached, because we are in ASCII range - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - return $utf8; - - case 2: - // return a UTF-16 character from a 2-byte UTF-8 char - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - return chr(0x07 & (ord($utf8{0}) >> 2)) - . chr((0xC0 & (ord($utf8{0}) << 6)) - | (0x3F & ord($utf8{1}))); - - case 3: - // return a UTF-16 character from a 3-byte UTF-8 char - // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - return chr((0xF0 & (ord($utf8{0}) << 4)) - | (0x0F & (ord($utf8{1}) >> 2))) - . chr((0xC0 & (ord($utf8{1}) << 6)) - | (0x7F & ord($utf8{2}))); - } - - // ignoring UTF-32 for now, sorry - return ''; - } - - /** - * encodes an arbitrary variable into JSON format - * - * @param mixed $var any number, boolean, string, array, or object to be encoded. - * see argument 1 to Services_JSON() above for array-parsing behavior. - * if var is a strng, note that encode() always expects it - * to be in ASCII or UTF-8 format! - * - * @return mixed JSON string representation of input var or an error if a problem occurs - * @access public - */ - private function json_encode($var) - { - - if (is_object($var)) { - if (in_array($var,$this->json_objectStack)) { - return '"** Recursion **"'; - } - } - - switch (gettype($var)) { - case 'boolean': - return $var ? 'true' : 'false'; - - case 'NULL': - return 'null'; - - case 'integer': - return (int) $var; - - case 'double': - case 'float': - return (float) $var; - - case 'string': - // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT - $ascii = ''; - $strlen_var = strlen($var); - - /* - * Iterate over every character in the string, - * escaping with a slash or encoding to UTF-8 where necessary - */ - for ($c = 0; $c < $strlen_var; ++$c) { - - $ord_var_c = ord($var{$c}); - - switch (true) { - case $ord_var_c == 0x08: - $ascii .= '\b'; - break; - case $ord_var_c == 0x09: - $ascii .= '\t'; - break; - case $ord_var_c == 0x0A: - $ascii .= '\n'; - break; - case $ord_var_c == 0x0C: - $ascii .= '\f'; - break; - case $ord_var_c == 0x0D: - $ascii .= '\r'; - break; - - case $ord_var_c == 0x22: - case $ord_var_c == 0x2F: - case $ord_var_c == 0x5C: - // double quote, slash, slosh - $ascii .= '\\'.$var{$c}; - break; - - case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): - // characters U-00000000 - U-0000007F (same as ASCII) - $ascii .= $var{$c}; - break; - - case (($ord_var_c & 0xE0) == 0xC0): - // characters U-00000080 - U-000007FF, mask 110XXXXX - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, ord($var{$c + 1})); - $c += 1; - $utf16 = $this->json_utf82utf16($char); - $ascii .= sprintf('\u%04s', bin2hex($utf16)); - break; - - case (($ord_var_c & 0xF0) == 0xE0): - // characters U-00000800 - U-0000FFFF, mask 1110XXXX - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, - ord($var{$c + 1}), - ord($var{$c + 2})); - $c += 2; - $utf16 = $this->json_utf82utf16($char); - $ascii .= sprintf('\u%04s', bin2hex($utf16)); - break; - - case (($ord_var_c & 0xF8) == 0xF0): - // characters U-00010000 - U-001FFFFF, mask 11110XXX - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, - ord($var{$c + 1}), - ord($var{$c + 2}), - ord($var{$c + 3})); - $c += 3; - $utf16 = $this->json_utf82utf16($char); - $ascii .= sprintf('\u%04s', bin2hex($utf16)); - break; - - case (($ord_var_c & 0xFC) == 0xF8): - // characters U-00200000 - U-03FFFFFF, mask 111110XX - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, - ord($var{$c + 1}), - ord($var{$c + 2}), - ord($var{$c + 3}), - ord($var{$c + 4})); - $c += 4; - $utf16 = $this->json_utf82utf16($char); - $ascii .= sprintf('\u%04s', bin2hex($utf16)); - break; - - case (($ord_var_c & 0xFE) == 0xFC): - // characters U-04000000 - U-7FFFFFFF, mask 1111110X - // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, - ord($var{$c + 1}), - ord($var{$c + 2}), - ord($var{$c + 3}), - ord($var{$c + 4}), - ord($var{$c + 5})); - $c += 5; - $utf16 = $this->json_utf82utf16($char); - $ascii .= sprintf('\u%04s', bin2hex($utf16)); - break; - } - } - - return '"'.$ascii.'"'; - - case 'array': - /* - * As per JSON spec if any array key is not an integer - * we must treat the the whole array as an object. We - * also try to catch a sparsely populated associative - * array with numeric keys here because some JS engines - * will create an array with empty indexes up to - * max_index which can cause memory issues and because - * the keys, which may be relevant, will be remapped - * otherwise. - * - * As per the ECMA and JSON specification an object may - * have any string as a property. Unfortunately due to - * a hole in the ECMA specification if the key is a - * ECMA reserved word or starts with a digit the - * parameter is only accessible using ECMAScript's - * bracket notation. - */ - - // treat as a JSON object - if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) { - - $this->json_objectStack[] = $var; - - $properties = array_map(array($this, 'json_name_value'), - array_keys($var), - array_values($var)); - - array_pop($this->json_objectStack); - - foreach($properties as $property) { - if ($property instanceof Exception) { - return $property; - } - } - - return '{' . join(',', $properties) . '}'; - } - - $this->json_objectStack[] = $var; - - // treat it like a regular array - $elements = array_map(array($this, 'json_encode'), $var); - - array_pop($this->json_objectStack); - - foreach($elements as $element) { - if ($element instanceof Exception) { - return $element; - } - } - - return '[' . join(',', $elements) . ']'; - - case 'object': - $vars = self::encodeObject($var); - - $this->json_objectStack[] = $var; - - $properties = array_map(array($this, 'json_name_value'), - array_keys($vars), - array_values($vars)); - - array_pop($this->json_objectStack); - - foreach($properties as $property) { - if ($property instanceof Exception) { - return $property; - } - } - - return '{' . join(',', $properties) . '}'; - - default: - return null; - } - } - - /** - * array-walking function for use in generating JSON-formatted name-value pairs - * - * @param string $name name of key to use - * @param mixed $value reference to an array element to be encoded - * - * @return string JSON-formatted name-value pair, like '"name":value' - * @access private - */ - private function json_name_value($name, $value) - { - // Encoding the $GLOBALS PHP array causes an infinite loop - // if the recursion is not reset here as it contains - // a reference to itself. This is the only way I have come up - // with to stop infinite recursion in this case. - if ($name=='GLOBALS' - && is_array($value) - && array_key_exists('GLOBALS',$value)) { - $value['GLOBALS'] = '** Recursion **'; - } - - $encoded_value = $this->json_encode($value); - - if ($encoded_value instanceof Exception) { - return $encoded_value; - } - - return $this->json_encode(strval($name)) . ':' . $encoded_value; - } -} diff --git a/src/application/configs/modules/Wootook.php b/src/application/configs/modules/Wootook.php new file mode 100644 index 0000000..c94c9e0 --- /dev/null +++ b/src/application/configs/modules/Wootook.php @@ -0,0 +1,17 @@ + array( + 'modules' => array( + 'WootookCore' => array( + 'active' => true, + 'code-pool' => 'core' + ), + 'WootookPlayer' => array( + 'active' => false, + 'code-pool' => 'core', + 'dependencies' => array( + 'WootookCore' => '1.5.0' + ) + ) + ) + ) + ); diff --git a/src/application/configs/system.php b/src/application/configs/system.php index 8246cb4..033ef82 100644 --- a/src/application/configs/system.php +++ b/src/application/configs/system.php @@ -52,7 +52,7 @@ ), 'home' => array( 'title' => 'Welcome on Wootook!', - 'formated-welcome-text' => '

Wootook make you an emperor.

Conquer outer space and master other players on Wootook.

' + 'formatted-welcome-text' => '

Wootook make you an emperor.

Conquer outer space and master other players on Wootook.

' ) ) ), diff --git a/src/application/design/backend/base/default/layouts/admin.php b/src/application/design/backend/base/default/layouts/admin.php index ddac4e8..1507a49 100644 --- a/src/application/design/backend/base/default/layouts/admin.php +++ b/src/application/design/backend/base/default/layouts/admin.php @@ -5,7 +5,7 @@ 'header' => array( 'children' => array( 'navigation' => array( - 'type' => 'core/html.navigation', + 'type' => 'core/html.navigation.menu', 'template' => 'page/html/navigation.phtml', 'actions' => array( array( diff --git a/src/application/design/backend/base/default/layouts/admin.xml b/src/application/design/backend/base/default/layouts/admin.xml index 18fde20..16f98f1 100644 --- a/src/application/design/backend/base/default/layouts/admin.xml +++ b/src/application/design/backend/base/default/layouts/admin.xml @@ -4,7 +4,7 @@ - + system System diff --git a/src/application/design/frontend/base/default/layouts/empire.xml b/src/application/design/frontend/base/default/layouts/empire.xml index f18da5b..f82def1 100644 --- a/src/application/design/frontend/base/default/layouts/empire.xml +++ b/src/application/design/frontend/base/default/layouts/empire.xml @@ -2,7 +2,7 @@ - + planet Planet diff --git a/src/application/design/frontend/base/default/scripts/page/html/home.phtml b/src/application/design/frontend/base/default/scripts/page/html/home.phtml index 2970804..1007da5 100644 --- a/src/application/design/frontend/base/default/scripts/page/html/home.phtml +++ b/src/application/design/frontend/base/default/scripts/page/html/home.phtml @@ -2,6 +2,6 @@ getLayout()->getMessagesBlock()->renderGroupedHtml()?>

getTitle()?>

-

getFormatedWelcomeText()?>

+

getFormattedWelcomeText()?>

diff --git a/src/application/gamedata/legacies/default/events.php b/src/application/gamedata/legacies/default/events.php index 09af7ec..e3af345 100644 --- a/src/application/gamedata/legacies/default/events.php +++ b/src/application/gamedata/legacies/default/events.php @@ -10,9 +10,7 @@ 'register.failure' => array(), 'register.success' => array(), 'user.init' => array(), - 'planet.init' => array( - array('Wootook_Empire_Model_Galaxy_Position', 'initPlanetListerner') - ), + 'planet.init' => array(), 'planet.update' => array( array('Wootook_Empire_Model_Planet', 'planetUpdateListener'), array('Legacies_Empire_Model_Planet_Building_Shipyard', 'planetUpdateListener'), diff --git a/src/application/gamedata/legacies/default/locale/fr_FR/labels.php b/src/application/gamedata/legacies/default/locale/fr_FR/labels.php index ab43b0a..c8945a7 100644 --- a/src/application/gamedata/legacies/default/locale/fr_FR/labels.php +++ b/src/application/gamedata/legacies/default/locale/fr_FR/labels.php @@ -22,13 +22,13 @@ Legacies_Empire::ID_BUILDING_SOLAR_PLANT => array( 'name' => 'Centrale électrique solaire', - 'description' => "

La centrale électrique solaire est la source d'énergie la plus abordable.

", + 'description' => "

La centrale électrique solaire est la source d'énergie la plus abordable.

Elle puise sa source des étoiles les plus proches de la planète sur laquelle elle est implantée. De ce fait, les planètes les plus proches du centre du système solaires produiront une plus grande quantité d'énergie que les planètes les plus éloignées.

", 'image' => 'medias/klore/images/building/solar-plant.jpg' ), Legacies_Empire::ID_BUILDING_FUSION_REACTOR => array( 'name' => 'Réacteur à fusion nucléaire', - 'description' => "

Fruit de longues décénnies de recherche, le réacteur à fusion nucléaire est désormais une source d'énergie rentable.

Nourrie par l'énergie engendrée par la fusion des isotopes d'hydrogène, cette centrale génère plus d'énergie que toutes les autres sources d'énergie. La contrepartie à cette surgénération d'énergie, est son côut en deutérium.

", + 'description' => "

Fruit de longues décénnies de recherche, le réacteur à fusion nucléaire est désormais une source d'énergie rentable.

Nourrie par l'énergie engendrée par la fusion des isotopes d'hydrogène, cette centrale génère plus d'énergie que toutes les autres sources d'énergie disponibles aujourd'hui. La contrepartie à cette surgénération d'énergie est son côut en deutérium.

", 'image' => 'medias/klore/images/building/fusion-reactor.jpg' ), diff --git a/src/application/modules/WootookCore/autoload_classmap.php b/src/application/modules/WootookCore/autoload_classmap.php new file mode 100644 index 0000000..1a3400c --- /dev/null +++ b/src/application/modules/WootookCore/autoload_classmap.php @@ -0,0 +1,167 @@ + __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', +); diff --git a/src/application/modules/WootookCore/autoload_function.php b/src/application/modules/WootookCore/autoload_function.php new file mode 100644 index 0000000..3cce3b6 --- /dev/null +++ b/src/application/modules/WootookCore/autoload_function.php @@ -0,0 +1,11 @@ + 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', + ), + ), +); diff --git a/src/application/code/core/Wootook/Core/configs/module.php b/src/application/modules/WootookCore/config/module.php similarity index 65% rename from src/application/code/core/Wootook/Core/configs/module.php rename to src/application/modules/WootookCore/config/module.php index 9b01f6a..0ab6e23 100644 --- a/src/application/code/core/Wootook/Core/configs/module.php +++ b/src/application/modules/WootookCore/config/module.php @@ -1,13 +1,13 @@ array( - 'Wootook_Core' => array( - 'version' => '1.5.0' + 'global' => array( + 'modules' => array( + 'WootookCore' => array( + 'version' => '1.5.0' ) ), - 'global' => array( 'models' => array( 'core' => array( - 'namespace' => 'Warner_Core_Model_', + 'namespace' => 'Wootook\\Core\\Model', 'connection' => array( 'read' => 'core_read', 'write' => 'core_write', @@ -17,17 +17,17 @@ ), 'blocks' => array( 'core' => array( - 'namespace' => 'Warner_Core_Block_' + 'namespace' => 'Wootook\\Core\\Block' ) ) ), 'frontend' => array( 'routes' => array( 'core' => array( - 'modules' => array( - 'core' => 'Wootook_Core' + 'controllers' => array( + 'core' => 'Wootook\\Core\\Controller' ) ) ) ) - ); \ No newline at end of file + ); diff --git a/src/application/code/core/Wootook/Core/install/mysql5/install-1.5.0.php b/src/application/modules/WootookCore/install/mysql5/install-1.5.0.beta2.php similarity index 100% rename from src/application/code/core/Wootook/Core/install/mysql5/install-1.5.0.php rename to src/application/modules/WootookCore/install/mysql5/install-1.5.0.beta2.php diff --git a/src/application/code/core/Wootook/Core/install/mysql5/uninstall-1.5.0.php b/src/application/modules/WootookCore/install/mysql5/uninstall-1.5.0.beta2.php similarity index 100% rename from src/application/code/core/Wootook/Core/install/mysql5/uninstall-1.5.0.php rename to src/application/modules/WootookCore/install/mysql5/uninstall-1.5.0.beta2.php diff --git a/src/application/modules/WootookCore/src/Wootook/Core/App/App.php b/src/application/modules/WootookCore/src/Wootook/Core/App/App.php new file mode 100644 index 0000000..898527a --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/App/App.php @@ -0,0 +1,498 @@ + + * 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 . + * + * --> 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]; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Base/BaseObject.php b/src/application/modules/WootookCore/src/Wootook/Core/Base/BaseObject.php new file mode 100644 index 0000000..db1e7c1 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Base/BaseObject.php @@ -0,0 +1,68 @@ + + * 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 . + * + * --> 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); + } +} diff --git a/src/application/code/core/Wootook/Object.php b/src/application/modules/WootookCore/src/Wootook/Core/Base/DataContainer.php similarity index 77% rename from src/application/code/core/Wootook/Object.php rename to src/application/modules/WootookCore/src/Wootook/Core/Base/DataContainer.php index d3271ee..1399ba1 100644 --- a/src/application/code/core/Wootook/Object.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Base/DataContainer.php @@ -28,22 +28,12 @@ * */ -/** - * - * Enter description here ... - * @author Greg - * - */ -class Wootook_Object - implements ArrayAccess +namespace Wootook\Core\Base; + +trait DataContainer { protected $_data = array(); - public function __construct(Array $data = array()) - { - $this->_data = $data; - } - public function getData($key) { if ($this->hasData($key)) { @@ -93,24 +83,4 @@ class Wootook_Object return $this; } - - 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); - } } diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Base/Service/App.php b/src/application/modules/WootookCore/src/Wootook/Core/Base/Service/App.php new file mode 100644 index 0000000..d2c142e --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Base/Service/App.php @@ -0,0 +1,67 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/code/core/Wootook/Core/Singleton.php b/src/application/modules/WootookCore/src/Wootook/Core/Base/Singleton.php similarity index 96% rename from src/application/code/core/Wootook/Core/Singleton.php rename to src/application/modules/WootookCore/src/Wootook/Core/Base/Singleton.php index c136e82..c8a1cf2 100644 --- a/src/application/code/core/Wootook/Core/Singleton.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Base/Singleton.php @@ -28,13 +28,15 @@ * */ +namespace Wootook\Core\Base; + /** * * Enter description here ... * @author Greg * */ -interface Wootook_Core_Singleton +interface Singleton { public static function getSingleton(); -} \ No newline at end of file +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Block/Concat.php b/src/application/modules/WootookCore/src/Wootook/Core/Block/Concat.php new file mode 100644 index 0000000..9eaeae8 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Block/Concat.php @@ -0,0 +1,46 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Block/Deprecated.php b/src/application/modules/WootookCore/src/Wootook/Core/Block/Deprecated.php new file mode 100644 index 0000000..b3f9edb --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Block/Deprecated.php @@ -0,0 +1,40 @@ + + * 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 . + * + * --> 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(); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Form.php b/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Form.php new file mode 100644 index 0000000..d98e023 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Form.php @@ -0,0 +1,41 @@ + + * 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 . + * + * --> 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); + } +} diff --git a/src/application/code/core/Wootook/Core/Block/Html/Head.php b/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Head.php similarity index 86% rename from src/application/code/core/Wootook/Core/Block/Html/Head.php rename to src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Head.php index c404045..9b6312c 100644 --- a/src/application/code/core/Wootook/Core/Block/Html/Head.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Head.php @@ -1,7 +1,37 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Block_Html_Head - extends Wootook_Core_Block_Template +namespace Wootook\Core\Block; + +class Head + extends Template { const TYPE_GLOBAL_CSS = 'global_css'; const TYPE_GLOBAL_JS = 'global_js'; @@ -284,4 +314,4 @@ HTML_EOF; } return $render; } -} \ No newline at end of file +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Home.php b/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Home.php new file mode 100644 index 0000000..6634cd7 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Home.php @@ -0,0 +1,45 @@ + + * 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 . + * + * --> 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'); + } +} diff --git a/src/application/code/core/Wootook/Core/Block/Html/Navigation/Link.php b/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Navigation/Link.php similarity index 79% rename from src/application/code/core/Wootook/Core/Block/Html/Navigation/Link.php rename to src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Navigation/Link.php index 82a09fa..94c4771 100644 --- a/src/application/code/core/Wootook/Core/Block/Html/Navigation/Link.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Navigation/Link.php @@ -1,7 +1,39 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Block_Html_Navigation_Link - extends Wootook_Core_Block_Template +namespace Wootook\Core\Block\Html\Navigation; + +use Wootook\Core\Block; + +class Link + extends Block\Template { protected $_label = ''; protected $_title = ''; diff --git a/src/application/code/core/Wootook/Core/Block/Html/Navigation.php b/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Navigation/Menu.php similarity index 73% rename from src/application/code/core/Wootook/Core/Block/Html/Navigation.php rename to src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Navigation/Menu.php index efbcd35..7d6ebbf 100644 --- a/src/application/code/core/Wootook/Core/Block/Html/Navigation.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Navigation/Menu.php @@ -1,7 +1,40 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Block_Html_Navigation - extends Wootook_Core_Block_Template +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()) { @@ -115,8 +148,8 @@ class Wootook_Core_Block_Html_Navigation $this->setPartial($name, $child); } - if ($child instanceof Wootook_Core_Block_Html_Navigation_Link) { - throw new Wootook_Core_Exception_RuntimeException('Node is a link. Could not append a child node to a link node.'); + 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) { diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Navigation/Node.php b/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Navigation/Node.php new file mode 100644 index 0000000..e60a391 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Navigation/Node.php @@ -0,0 +1,57 @@ + + * 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 . + * + * --> 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'; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Page.php b/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Page.php new file mode 100644 index 0000000..0d4135b --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Block/Html/Page.php @@ -0,0 +1,51 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Block/Messages.php b/src/application/modules/WootookCore/src/Wootook/Core/Block/Messages.php new file mode 100644 index 0000000..e483a09 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Block/Messages.php @@ -0,0 +1,77 @@ + + * 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 . + * + * --> 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 = '
'; + foreach ($messages as $messageLevel => $messageList) { + $output .= "
    "; + foreach ($messageList as $message) { + $output .= "
  • {$message}
  • "; + } + $output .= '
'; + } + $output .= '
'; + + return $output; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Block/Template.php b/src/application/modules/WootookCore/src/Wootook/Core/Block/Template.php new file mode 100644 index 0000000..6e4fe80 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Block/Template.php @@ -0,0 +1,81 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Block/Text.php b/src/application/modules/WootookCore/src/Wootook/Core/Block/Text.php new file mode 100644 index 0000000..a28e04d --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Block/Text.php @@ -0,0 +1,60 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Bootstrap/Module.php b/src/application/modules/WootookCore/src/Wootook/Core/Bootstrap/Module.php new file mode 100644 index 0000000..d1f460d --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Bootstrap/Module.php @@ -0,0 +1,55 @@ + + * 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 . + * + * --> 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; + } + + + } + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/Adapter.php b/src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/Adapter.php new file mode 100644 index 0000000..e688136 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/Adapter.php @@ -0,0 +1,38 @@ + + * 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 . + * + * --> 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 +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/PhpArray.php b/src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/PhpArray.php new file mode 100644 index 0000000..18e158a --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/PhpArray.php @@ -0,0 +1,68 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/code/core/Wootook/Core/Config/Node.php b/src/application/modules/WootookCore/src/Wootook/Core/Config/Node.php similarity index 75% rename from src/application/code/core/Wootook/Core/Config/Node.php rename to src/application/modules/WootookCore/src/Wootook/Core/Config/Node.php index 309c1cf..007cea1 100644 --- a/src/application/code/core/Wootook/Core/Config/Node.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Config/Node.php @@ -1,7 +1,39 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Config_Node - implements ArrayAccess, Iterator, Countable +namespace Wootook\Core\Config; + +use Wootook\Core\Exception as CoreException; + +class Node + implements \ArrayAccess, \Iterator, \Countable { protected $_children = array(); @@ -54,7 +86,7 @@ class Wootook_Core_Config_Node for ($i = 0; $i < $length; $i++) { if ($i < ($length - 1)) { if (!$currentNode->offsetExists($explodedPath[$i])) { - $newNode = new Wootook_Core_Config_Node(array(), $currentNode); + $newNode = new Node(array(), $currentNode); $currentNode->offsetSet($explodedPath[$i], $newNode); } } else if (is_array($value)) { @@ -67,8 +99,8 @@ class Wootook_Core_Config_Node $currentNode = $currentNode->offsetGet($explodedPath[$i]); - if (!$currentNode instanceof Wootook_Core_Config_Node) { - throw new Wootook_Core_Exception_RuntimeException(); + if (!$currentNode instanceof Node) { + throw new CoreException\RuntimeException(); } } @@ -82,8 +114,8 @@ class Wootook_Core_Config_Node $length = count($explodedPath); $currentNode = $this; for ($i = 0; $i < $length; $i++) { - if (!$currentNode instanceof Wootook_Core_Config_Node) { - throw new Wootook_Core_Exception_RuntimeException(); + if (!$currentNode instanceof Node) { + throw new CoreException\RuntimeException(); } if (!$currentNode->offsetExists($explodedPath[$i])) { return null; @@ -101,7 +133,7 @@ class Wootook_Core_Config_Node foreach ($this->_children as $key => $child) { if ($child instanceof self) { $result[$key] = $child->toArray(); - } else if ($child instanceof Wootook_Core_Config_Leaf) { + } else if ($child instanceof Leaf) { $result[$key] = $child->getValue(); } else { $result[$key] = $child; @@ -215,31 +247,31 @@ class Wootook_Core_Config_Node } } - public function valid() - { - return key($this->_children); - } - - public function next() - { - next($this->_children); - } - public function current() { return current($this->_children); } - public function rewind() - { - reset($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); diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Controller/ErrorController.php b/src/application/modules/WootookCore/src/Wootook/Core/Controller/ErrorController.php new file mode 100644 index 0000000..17ecba0 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Controller/ErrorController.php @@ -0,0 +1,43 @@ + + * 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 . + * + * --> 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(); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Controller/IndexController.php b/src/application/modules/WootookCore/src/Wootook/Core/Controller/IndexController.php new file mode 100644 index 0000000..4a1993a --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Controller/IndexController.php @@ -0,0 +1,43 @@ + + * 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 . + * + * --> 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(); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Adapter.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Adapter.php new file mode 100644 index 0000000..09ff943 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Adapter.php @@ -0,0 +1,281 @@ + + * 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 . + * + * --> 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(); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Mysql.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Mysql.php new file mode 100644 index 0000000..9596466 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Mysql.php @@ -0,0 +1,178 @@ + + * 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 . + * + * --> 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]; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Pdo.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Pdo.php new file mode 100644 index 0000000..c9bc397 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Pdo.php @@ -0,0 +1,180 @@ + + * 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 . + * + * --> 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]; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Pdo/Mysql.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Pdo/Mysql.php new file mode 100644 index 0000000..3cc0e0f --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Pdo/Mysql.php @@ -0,0 +1,63 @@ + + * 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 . + * + * --> 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`"; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Pdo/Sqlite.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Pdo/Sqlite.php new file mode 100644 index 0000000..8a24958 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Adapter/Pdo/Sqlite.php @@ -0,0 +1,60 @@ + + * 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 . + * + * --> 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\""; + } +} diff --git a/src/application/code/core/Wootook/Core/Database/ConnectionManager.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/ConnectionManager.php similarity index 65% rename from src/application/code/core/Wootook/Core/Database/ConnectionManager.php rename to src/application/modules/WootookCore/src/Wootook/Core/Database/ConnectionManager.php index 4ba8289..f7af92e 100644 --- a/src/application/code/core/Wootook/Core/Database/ConnectionManager.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/ConnectionManager.php @@ -1,9 +1,48 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Database_ConnectionManager - extends Wootook_Core_PluginLoader_PluginLoader - implements Wootook_Core_Singleton +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'; @@ -99,20 +138,20 @@ class Wootook_Core_Database_ConnectionManager protected static $_singleton = null; - public function __construct() + protected function _construct() { - $this->registerNamespace('Wootook_Core_Database_Adapter_'); + $this->registerNamespace('Wootook\\Core\\Database\\Adapter'); } /** - * @return Wootook_Core_Database_ConnectionManager + * @return ConnectionManager */ public static function getSingleton() { - if (self::$_singleton === null) { - self::$_singleton = new self(); - } - return self::$_singleton; + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); + + return \Wootook::app()->getConnectionManager(); } protected $_defaultOptions = array( @@ -121,7 +160,7 @@ class Wootook_Core_Database_ConnectionManager /** * @param $connectionName - * @return Wootook_Core_Database_Adapter_Adapter + * @return Adapter\Adapter */ public function getConnection($connectionName) { @@ -134,7 +173,7 @@ class Wootook_Core_Database_ConnectionManager return $this->_connectionAliases[$connectionName]; } - $connectionConfig = Wootook::getConfig("resource/database/{$connectionName}"); + $connectionConfig = \Wootook::app()->getGlobalConfig("resource/database/{$connectionName}"); if ($connectionConfig === null) { return null; } @@ -154,12 +193,12 @@ class Wootook_Core_Database_ConnectionManager private function _initConnection($connectionName, $engine, $params, $options = array()) { if (is_array($params)) { - $params = new Wootook_Core_Config_Node($params); - } else if (!$params instanceof Wootook_Core_Config_Node) { - $params = new Wootook_Core_Config_Node(array()); + $params = new Config\Node($params); + } else if (!$params instanceof Config\Node) { + $params = new Config\Node(array()); } - if ($options instanceof Wootook_Core_Config_Node) { + if ($options instanceof Config\Node) { $options = $options->toArray(); } else if (!is_array($options)) { $options = array(); @@ -169,24 +208,28 @@ class Wootook_Core_Database_ConnectionManager return null; } - $event = Wootook::dispatchEvent('database.prepare-options', array( + $event = \Wootook::dispatchEvent('database.prepare-options', array( 'name' => $connectionName, 'options' => array_merge($this->_defaultOptions, $options) )); $options = $event->getData('options'); - $connection = $this->load($engine, false, array($params, $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 Wootook_Core_Exception_Database_AdapterError('Could not find data connection handler.'); + throw new CoreException\DataAccessException('Could not find data connection handler.'); } - if (($prefix = Wootook::getConfig("resource/database/{$connectionName}/table_prefix")) !== null) { + if (($prefix = \Wootook::app()->getGlobalConfig("resource/database/{$connectionName}/table_prefix")) !== null) { $connection->setTablePrefix($prefix); } - Wootook::dispatchEvent('database.init', array( + \Wootook::dispatchEvent('database.init', array( 'name' => $connectionName, 'handler' => $connection )); @@ -196,7 +239,7 @@ class Wootook_Core_Database_ConnectionManager protected function _load($className, $useSingleton, Array $constructorParams = array()) { - $reflection = new ReflectionClass($className); + $reflection = new \ReflectionClass($className); return $reflection->newInstanceArgs($constructorParams); } } diff --git a/src/application/code/core/Wootook/Core/Database/Orm/DataMapper.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper.php similarity index 56% rename from src/application/code/core/Wootook/Core/Database/Orm/DataMapper.php rename to src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper.php index d4dc61f..437426c 100644 --- a/src/application/code/core/Wootook/Core/Database/Orm/DataMapper.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper.php @@ -1,7 +1,43 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Database_Orm_DataMapper - extends Wootook_Core_PluginLoader_PluginLoader +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(); @@ -9,9 +45,9 @@ class Wootook_Core_Database_Orm_DataMapper public function __construct($config = array()) { - $this->registerNamespace('Wootook_Core_Database_Orm_DataMapper_'); + $this->registerNamespace('Wootook\\Core\\Database\\Orm\\DataMapper'); - if (!is_array($config) || !$config instanceof Wootook_Core_Config_Node) { + if (!is_array($config) || !$config instanceof Config\Node) { return; } @@ -53,16 +89,16 @@ class Wootook_Core_Database_Orm_DataMapper protected function _load($className, $useSingleton, Array $constructorParams = array()) { - $reflection = new ReflectionClass($className); - if ($useSingleton && $reflection->implementsInterface('Wootook_Core_Singleton')) { + $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) { - Wootook_Core_ErrorProfiler::getSingleton() + } catch (\ReflectionException $e) { + Profiler\ErrorProfiler::getSingleton() ->addException($e); return null; } @@ -70,11 +106,11 @@ class Wootook_Core_Database_Orm_DataMapper /** * - * @param Wootook_Core_Database_Resource $entity + * @param Database\Resource $entity * @param Array $datas * @return Array */ - public function encode(Wootook_Core_Database_Resource $entity, Array $datas = array()) + public function encode(Model\Entity $entity, Array $datas = array()) { $aliasTable = array_flip($this->_alias); foreach ($entity->getAllDatas() as $aliasedField => $decodedValue) { @@ -96,11 +132,11 @@ class Wootook_Core_Database_Orm_DataMapper /** * - * @param Wootook_Core_Database_Resource $entity + * @param Database\Resource $entity * @param Array $datas - * @return Wootook_Core_Database_Resource + * @return Database\Resource */ - public function decode(Wootook_Core_Database_Resource $entity, Array $datas = array()) + public function decode(Model\Entity $entity, Array $datas = array()) { foreach ($datas as $field => $encodedValue) { if (isset($this->_rules[$field])) { @@ -112,4 +148,4 @@ class Wootook_Core_Database_Orm_DataMapper return $entity; } -} \ No newline at end of file +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/Config.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/Config.php new file mode 100644 index 0000000..dbb88ff --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/Config.php @@ -0,0 +1,47 @@ + + * 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 . + * + * --> 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)); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/DateTime.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/DateTime.php new file mode 100644 index 0000000..b8e624f --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/DateTime.php @@ -0,0 +1,70 @@ + + * 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 . + * + * --> 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()); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/FieldMapper.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/FieldMapper.php new file mode 100644 index 0000000..7399fed --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/FieldMapper.php @@ -0,0 +1,47 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/PhpArray.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/PhpArray.php new file mode 100644 index 0000000..aa25a02 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/PhpArray.php @@ -0,0 +1,45 @@ + + * 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 . + * + * --> 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); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/PhpObject.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/PhpObject.php new file mode 100644 index 0000000..8e52740 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Orm/DataMapper/PhpObject.php @@ -0,0 +1,73 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Resource/DataMapper.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Resource/DataMapper.php new file mode 100644 index 0000000..db0e086 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Resource/DataMapper.php @@ -0,0 +1,61 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Resource/ReadConnection.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Resource/ReadConnection.php new file mode 100644 index 0000000..4dfea06 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Resource/ReadConnection.php @@ -0,0 +1,72 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Resource/WriteConnection.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Resource/WriteConnection.php new file mode 100644 index 0000000..61b0dc5 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Resource/WriteConnection.php @@ -0,0 +1,70 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Condition.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Condition.php new file mode 100644 index 0000000..64e94c2 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Condition.php @@ -0,0 +1,123 @@ + + * 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 . + * + * --> 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; + } + +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/InListOperator.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/InListOperator.php new file mode 100644 index 0000000..fb289e5 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/InListOperator.php @@ -0,0 +1,127 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/LogicalOperator.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/LogicalOperator.php new file mode 100644 index 0000000..c7f8c15 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/LogicalOperator.php @@ -0,0 +1,264 @@ + + * 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 . + * + * --> 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]); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/MathOperator.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/MathOperator.php new file mode 100644 index 0000000..95fe6a6 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/MathOperator.php @@ -0,0 +1,136 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Placeholder.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Placeholder.php new file mode 100644 index 0000000..58d3ea7 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Placeholder.php @@ -0,0 +1,72 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Delete.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Delete.php similarity index 62% rename from src/application/code/core/Wootook/Core/Database/Sql/Delete.php rename to src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Delete.php index 84d8e37..025cd52 100644 --- a/src/application/code/core/Wootook/Core/Database/Sql/Delete.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Delete.php @@ -1,7 +1,37 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Database_Sql_Delete - extends Wootook_Core_Database_Sql_DmlFilterableQuery +namespace Wootook\Core\Database\Sql; + +class Delete + extends DmlFilterableQuery { const FROM = 'FROM'; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Dml.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Dml.php new file mode 100644 index 0000000..3e2f22c --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Dml.php @@ -0,0 +1,63 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/DmlQuery.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/DmlQuery.php new file mode 100644 index 0000000..146be4d --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/DmlQuery.php @@ -0,0 +1,162 @@ + + * 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 . + * + * --> 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); + } +} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Insert.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Insert.php similarity index 71% rename from src/application/code/core/Wootook/Core/Database/Sql/Insert.php rename to src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Insert.php index cccbcc8..c262915 100644 --- a/src/application/code/core/Wootook/Core/Database/Sql/Insert.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Insert.php @@ -1,7 +1,39 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Database_Sql_Insert - extends Wootook_Core_Database_Sql_DmlQuery +namespace Wootook\Core\Database\Sql; + +use Wootook\Core\Database\Sql\Placeholder; + +class Insert + extends DmlQuery { const SET = 'SET'; const INTO = 'INTO'; @@ -40,7 +72,7 @@ class Wootook_Core_Database_Sql_Insert } foreach ($column as $field => $value) { - if ($value instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { + if ($value instanceof Placeholder\Placeholder) { $this->_placeholders[] = $value; } @@ -102,7 +134,7 @@ class Wootook_Core_Database_Sql_Insert { $fields = array(); foreach ($this->_parts[self::SET] as $field) { - if ($field['value'] instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { + 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'])}"; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Renderer.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Renderer.php new file mode 100644 index 0000000..c8b6a6d --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Renderer.php @@ -0,0 +1,44 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Column.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Column.php new file mode 100644 index 0000000..2326d56 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Column.php @@ -0,0 +1,72 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/ColumnAware.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/ColumnAware.php new file mode 100644 index 0000000..a75f0be --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/ColumnAware.php @@ -0,0 +1,38 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/From.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/From.php new file mode 100644 index 0000000..414c40f --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/From.php @@ -0,0 +1,61 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/FromAware.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/FromAware.php new file mode 100644 index 0000000..1c16e2b --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/FromAware.php @@ -0,0 +1,38 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Into.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Into.php new file mode 100644 index 0000000..7b70980 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Into.php @@ -0,0 +1,44 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/IntoAware.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/IntoAware.php new file mode 100644 index 0000000..d0c3d7e --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/IntoAware.php @@ -0,0 +1,38 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Limit.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Limit.php new file mode 100644 index 0000000..54ed5d7 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Limit.php @@ -0,0 +1,42 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/LimitAware.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/LimitAware.php new file mode 100644 index 0000000..586d4be --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/LimitAware.php @@ -0,0 +1,39 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Column.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Column.php new file mode 100644 index 0000000..3920de5 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Column.php @@ -0,0 +1,73 @@ + + * 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 . + * + * --> 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 '*'; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/ColumnAware.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/ColumnAware.php new file mode 100644 index 0000000..dfaf4c2 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/ColumnAware.php @@ -0,0 +1,38 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/From.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/From.php new file mode 100644 index 0000000..a57f6a1 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/From.php @@ -0,0 +1,68 @@ + + * 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 . + * + * --> 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); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/FromAware.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/FromAware.php new file mode 100644 index 0000000..52e6ab6 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/FromAware.php @@ -0,0 +1,38 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Into.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Into.php new file mode 100644 index 0000000..f5d6cfb --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Into.php @@ -0,0 +1,48 @@ + + * 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 . + * + * --> 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'])}"; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/IntoAware.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/IntoAware.php new file mode 100644 index 0000000..05be8b2 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/IntoAware.php @@ -0,0 +1,38 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Limit.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Limit.php new file mode 100644 index 0000000..4b7efdd --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Limit.php @@ -0,0 +1,47 @@ + + * 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 . + * + * --> 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); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/LimitAware.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/LimitAware.php new file mode 100644 index 0000000..b4a4c8d --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/LimitAware.php @@ -0,0 +1,38 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Set.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Set.php new file mode 100644 index 0000000..cc14251 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Set.php @@ -0,0 +1,60 @@ + + * 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 . + * + * --> 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 ''; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/SetAware.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/SetAware.php new file mode 100644 index 0000000..f072e75 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/SetAware.php @@ -0,0 +1,38 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/DmlFilterableQuery.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Where.php similarity index 81% rename from src/application/code/core/Wootook/Core/Database/Sql/DmlFilterableQuery.php rename to src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Where.php index 6ca3730..1807256 100644 --- a/src/application/code/core/Wootook/Core/Database/Sql/DmlFilterableQuery.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Where.php @@ -1,11 +1,43 @@ + * 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 . + * + * --> 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. + * + */ -abstract class Wootook_Core_Database_Sql_DmlFilterableQuery - extends Wootook_Core_Database_Sql_DmlQuery +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 LIMIT = 'LIMIT'; - const OFFSET = 'OFFSET'; const OPERATOR_AND = 'AND'; const OPERATOR_OR = 'OR'; @@ -25,7 +57,7 @@ abstract class Wootook_Core_Database_Sql_DmlFilterableQuery public function where($condition, $value = null) { - if ($condition instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { + if ($condition instanceof Placeholder\Placeholder) { $this->_placeholders[] = $condition; $this->_parts[self::WHERE][] = $condition; } else if (is_array($value)) { @@ -33,7 +65,7 @@ abstract class Wootook_Core_Database_Sql_DmlFilterableQuery if ($where !== null) { $this->_parts[self::WHERE][] = $where; } - } else if ($value instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { + } 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); @@ -42,14 +74,6 @@ abstract class Wootook_Core_Database_Sql_DmlFilterableQuery return $this; } - public function limit($limit, $offset = null) - { - $this->_parts[self::LIMIT] = intval($limit); - $this->_parts[self::OFFSET] = intval($offset); - - return $this; - } - public function renderWhere() { if (count($this->_parts[self::WHERE]) <= 0) { @@ -59,17 +83,6 @@ abstract class Wootook_Core_Database_Sql_DmlFilterableQuery return " WHERE (" . implode(")\n AND (", $this->_parts[self::WHERE]) . ')'; } - public function renderLimit() - { - if (!$this->_parts[self::LIMIT]) { - return ''; - } - if (!$this->_parts[self::OFFSET]) { - return sprintf(" LIMIT %d", $this->_parts[self::LIMIT]); - } - return sprintf(" LIMIT %d,%d", $this->_parts[self::LIMIT], $this->_parts[self::OFFSET]); - } - protected function _translateSqlWhere($field, $operator, $value) { if ($value === null) { @@ -94,7 +107,7 @@ abstract class Wootook_Core_Database_Sql_DmlFilterableQuery 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 Wootook_Core_Database_Sql_Placeholder_Placeholder) { + } else if ($value instanceof Placeholder\Placeholder) { $this->_placeholders[] = $value; return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%s", $adapter->quote($value->toString())); } else { @@ -182,7 +195,7 @@ abstract class Wootook_Core_Database_Sql_DmlFilterableQuery case self::OPERATOR_DATE: $dateValues = array(); if (isset($value['from'])) { - if ($value['from'] instanceof Wootook_Core_DateTime) { + 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'])}"; @@ -191,7 +204,7 @@ abstract class Wootook_Core_Database_Sql_DmlFilterableQuery } } if (isset($value['to'])) { - if ($value['to'] instanceof Wootook_Core_DateTime) { + 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'])}"; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/WhereAware.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/WhereAware.php new file mode 100644 index 0000000..063a748 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/WhereAware.php @@ -0,0 +1,38 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Set.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Set.php new file mode 100644 index 0000000..14d75c9 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Set.php @@ -0,0 +1,63 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/SetAware.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/SetAware.php new file mode 100644 index 0000000..28c4996 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/SetAware.php @@ -0,0 +1,38 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Where.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Where.php new file mode 100644 index 0000000..f3bebbb --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Where.php @@ -0,0 +1,204 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/WhereAware.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/WhereAware.php new file mode 100644 index 0000000..a45b415 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/WhereAware.php @@ -0,0 +1,58 @@ + + * 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 . + * + * --> 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); +} diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Select.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Select.php similarity index 85% rename from src/application/code/core/Wootook/Core/Database/Sql/Select.php rename to src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Select.php index 3c67203..e18e588 100644 --- a/src/application/code/core/Wootook/Core/Database/Sql/Select.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Select.php @@ -1,10 +1,44 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Database_Sql_Select - extends Wootook_Core_Database_Sql_DmlFilterableQuery +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 FROM = 'FROM'; const JOIN = 'JOIN'; const ORDER = 'ORDER'; const UNION = 'UNION'; @@ -68,7 +102,7 @@ class Wootook_Core_Database_Sql_Select } } } else { - if ($column instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { + if ($column instanceof Placeholder\Placeholder) { $this->_placeholders[] = $column; } @@ -211,13 +245,13 @@ class Wootook_Core_Database_Sql_Select { $fields = array(); foreach ($this->_parts[self::COLUMNS] as $field) { - if ($field['field'] instanceof Wootook_Core_Database_Sql_Dml) { + if ($field['field'] instanceof Dml) { if ($field['alias'] !== null) { $fields[] = "({$field['field']}) AS {$field['alias']}"; } else { $fields[] = "({$field['field']})"; } - } else if ($field['field'] instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { + } else if ($field['field'] instanceof Placeholder\Placeholder) { if ($field['alias'] !== null) { $fields[] = "({$field['field']}) AS {$field['alias']}"; } else { @@ -246,7 +280,7 @@ class Wootook_Core_Database_Sql_Select { $tables = array(); foreach ($this->_parts[self::FROM] as $table) { - if ($table['table'] instanceof Wootook_Core_Database_Sql_Dml) { + if ($table['table'] instanceof Dml) { if ($table['alias'] !== null) { $tables[] = "({$table['table']}) AS {$this->_connection->quoteIdentifier($table['alias'])}"; } else { diff --git a/src/application/code/core/Wootook/Core/Database/Sql/Update.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Update.php similarity index 60% rename from src/application/code/core/Wootook/Core/Database/Sql/Update.php rename to src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Update.php index 5cd83b8..018d80e 100644 --- a/src/application/code/core/Wootook/Core/Database/Sql/Update.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Update.php @@ -1,10 +1,43 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Database_Sql_Update - extends Wootook_Core_Database_Sql_DmlFilterableQuery +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 { - const SET = 'SET'; - const INTO = 'INTO'; + use Section\Set, Section\Into, Section\Where, Section\Limit; protected function _init($tableName = null) { @@ -34,36 +67,6 @@ class Wootook_Core_Database_Sql_Update return $this; } - public function set($column, $value = null) - { - if (!is_array($column)) { - $column = array($column => $value); - } - - foreach ($column as $field => $value) { - if ($value instanceof Wootook_Core_Database_Sql_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 __toString() { return $this->render(); @@ -91,7 +94,7 @@ class Wootook_Core_Database_Sql_Update { $fields = array(); foreach ($this->_parts[self::SET] as $field) { - if ($field['value'] instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) { + 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'])}"; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Expression.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Expression.php new file mode 100644 index 0000000..796fc9f --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Expression.php @@ -0,0 +1,62 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Param.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Param.php new file mode 100644 index 0000000..18155c0 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Param.php @@ -0,0 +1,63 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Placeholder.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Placeholder.php new file mode 100644 index 0000000..188cd03 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Placeholder.php @@ -0,0 +1,63 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Variable.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Variable.php new file mode 100644 index 0000000..ef1bfdc --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Placeholder/Variable.php @@ -0,0 +1,52 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/QueryBuilder/QueryBuilder.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/QueryBuilder/QueryBuilder.php new file mode 100644 index 0000000..dbda08e --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/QueryBuilder/QueryBuilder.php @@ -0,0 +1,8 @@ + + * 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 . + * + * --> 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]; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Pdo.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Pdo.php new file mode 100644 index 0000000..492c409 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Pdo.php @@ -0,0 +1,387 @@ + + * 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 . + * + * --> 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]; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Statement.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Statement.php new file mode 100644 index 0000000..150901e --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Statement.php @@ -0,0 +1,275 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateInterval.php b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateInterval.php new file mode 100644 index 0000000..0a9babb --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateInterval.php @@ -0,0 +1,39 @@ + + * 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 . + * + * --> 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 +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DateTime/DatePeriod.php b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/DatePeriod.php new file mode 100644 index 0000000..1b2701c --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/DatePeriod.php @@ -0,0 +1,39 @@ + + * 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 . + * + * --> 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 +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateTime.php b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateTime.php new file mode 100644 index 0000000..db2d3fe --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateTime.php @@ -0,0 +1,226 @@ + + * 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 . + * + * --> 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(); + } +} diff --git a/src/application/code/core/Wootook/Core/DateTime.php b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateTime.php.old similarity index 83% rename from src/application/code/core/Wootook/Core/DateTime.php rename to src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateTime.php.old index 06a6d79..934c6d3 100644 --- a/src/application/code/core/Wootook/Core/DateTime.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateTime.php.old @@ -1,7 +1,40 @@ + * 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 . + * + * --> 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; -class Wootook_Core_DateTime +/** + * Date and time management class + * @todo : refactor to be compatible with \DateTime + */ +class DateTime { const ISO_8601 = 'c'; @@ -71,16 +104,18 @@ class Wootook_Core_DateTime 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::getConfig('system/date/timezone'); + //$timezone = \Wootook::app()->getGlobalConfig('system/date/timezone'); } if ($timezone === null) { - $timezone = 'GMT'; + $timezone = 'UTC'; } date_default_timezone_set($timezone); @@ -88,7 +123,11 @@ class Wootook_Core_DateTime } } - public function __construct($timestamp = null, $format = null) + /** + * @param null|string|int $timestamp + * @param string $format + */ + public function __construct($timestamp = null, $format = null, $timezone = 'UTC') { self::init(); @@ -99,6 +138,8 @@ class Wootook_Core_DateTime } else { $this->_datetime = $this->_parse($timestamp, $format); } + + $this->_timezone = $timezone; } public function getIso($useTimezone = false) @@ -222,18 +263,12 @@ class Wootook_Core_DateTime protected function _parseShortMonth($match) { - if ($key = array_search(strtolower($match), array('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'))) { - return $key + 1; - } - return false; + return 1 + array_search(strtolower($match), array('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec')); } protected function _parseShortWeekday($match) { - if ($key = array_search(strtolower($match), array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'))) { - return $key; - } - return false; + return array_search(strtolower($match), array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')); } protected function _parseWeekday($match) @@ -243,10 +278,7 @@ class Wootook_Core_DateTime protected function _parseMeridiem($match) { - if (in_array(strtolower($match), array(self::MERIDIEM_AM, self::MERIDIEM_PM))) { - return strtolower($match); - } - return false; + return strtolower($match); } protected function _parse($datetime, $format) diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateTimeZone.php b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateTimeZone.php new file mode 100644 index 0000000..08b2a7c --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/DateTimeZone.php @@ -0,0 +1,39 @@ + + * 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 . + * + * --> 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 +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DateTime/Formatter.php b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/Formatter.php new file mode 100644 index 0000000..c1f4954 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/Formatter.php @@ -0,0 +1,39 @@ + + * 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 . + * + * --> 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 +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php new file mode 100644 index 0000000..4336845 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php @@ -0,0 +1,129 @@ +_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); + } + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ClassDefinition.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ClassDefinition.php new file mode 100644 index 0000000..8adc5ce --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ClassDefinition.php @@ -0,0 +1,121 @@ +_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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php new file mode 100644 index 0000000..6cdd5e5 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php @@ -0,0 +1,197 @@ +_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'); + } + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Factory.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Factory.php new file mode 100644 index 0000000..f4218de --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Factory.php @@ -0,0 +1,91 @@ +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); + } + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Registry.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Registry.php new file mode 100644 index 0000000..df4c3fb --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Registry.php @@ -0,0 +1,60 @@ +_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]); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Email/Email.php b/src/application/modules/WootookCore/src/Wootook/Core/Email/Email.php new file mode 100644 index 0000000..df01526 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Email/Email.php @@ -0,0 +1,104 @@ + + * 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 . + * + * --> 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\Email; + +use Wootook\Core, + Wootook\Core\Exception as CoreException, + Wootook\Core\Email\Transport, + Wootook\Core\Email\Part; + +/** + * Email management class + */ +class Email +{ + /** + * @var Transport\Transport + */ + protected $_transport = null; + + /** + * @param null|Transport\Transport $transport + */ + public function __construct(Transport\Transport $transport = null) + { + if ($transport === null) { + $transport = new Transport\Sendmail(); + } + $this->setTransport($transport); + } + + /** + * @param Transport\Transport $transport + */ + public function setTransport(Transport\Transport $transport) + { + $this->_transport = $transport; + } + + /** + * @return Transport\Transport + */ + public function getTransport() + { + return $this->_transport; + } + + /** + * @param string|array $to + * @param string|array $from + * @param string $subject + * @param $body + * @param array $headers + * @return Core\Email + * @throws CoreException\RuntimeException + */ + public function send($to, $from, $subject, $body, Array $headers = array()) + { + try { + $this->_transport + ->addRecipient($to) + ->setFrom($from) + ->setSubject($subject) + ->addPart(new Part\Part($body)) + ->addHeaders($headers) + ->connect() + ->send() + ; + } catch (CoreException\RuntimeException $e) { + throw new CoreException\RuntimeException('Could not send mail.', null, $e); + } + + $this->_transport->disconnect(); + + return $this; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Email/Part/Part.php b/src/application/modules/WootookCore/src/Wootook/Core/Email/Part/Part.php new file mode 100644 index 0000000..ea8d79e --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Email/Part/Part.php @@ -0,0 +1,46 @@ + + * 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 . + * + * --> 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\Email\Part; + +class Part +{ + protected $_content = null; + + public function __construct($content, $mime = 'text/plain') + { + $this->_content = $content; + } + + public function render() + { + return $this->_content; + } +} diff --git a/src/application/code/core/Wootook/Core/Email/Transport/Sendmail.php b/src/application/modules/WootookCore/src/Wootook/Core/Email/Transport/Sendmail.php similarity index 69% rename from src/application/code/core/Wootook/Core/Email/Transport/Sendmail.php rename to src/application/modules/WootookCore/src/Wootook/Core/Email/Transport/Sendmail.php index 165247a..4a7f066 100644 --- a/src/application/code/core/Wootook/Core/Email/Transport/Sendmail.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Email/Transport/Sendmail.php @@ -1,7 +1,40 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Email_Transport_Sendmail - implements Wootook_Core_Email_Transport_Transport +namespace Wootook\Core\Email\Transport; + +use Wootook\Core\Email\Part, + Wootook\Core\Exception as CoreException; + +class Sendmail + implements Transport { protected static $_defaultHeaders = array(); @@ -89,7 +122,7 @@ class Wootook_Core_Email_Transport_Sendmail return $this; } - public function addPart(Wootook_Core_Email_Part_Part $part) + public function addPart(Part\Part $part) { $this->_parts[] = $part; @@ -154,9 +187,9 @@ class Wootook_Core_Email_Transport_Sendmail $this->addHeader('To', implode(',', $this->_recipients)); if (!mail(implode(',', $this->_recipients), $this->_subject, $content, implode("\r\n", $this->_headers))) { - throw new Wootook_Core_Exception_RuntimeException('Could not send mail.'); + throw new CoreException\RuntimeException('Could not send mail.'); } return $this; } -} \ No newline at end of file +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Email/Transport/Transport.php b/src/application/modules/WootookCore/src/Wootook/Core/Email/Transport/Transport.php new file mode 100644 index 0000000..371f40a --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Email/Transport/Transport.php @@ -0,0 +1,54 @@ + + * 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 . + * + * --> 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\Email\Transport; + +use Wootook\Core\Email\Part; + +interface Transport +{ + public function setFrom($from); + public function addRecipient($recipient); + public function setSubject($subject); + public function addHeader($name, $value); + public function addPart(Part\Part $part); + + public function reset(); + public function clearFrom(); + public function clearHeaders(); + public function clearRecipients(); + public function clearSubject(); + public function clearParts(); + + public function connect(); + public function disconnect(); + + public function send(); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Event/Break.php b/src/application/modules/WootookCore/src/Wootook/Core/Event/Break.php new file mode 100644 index 0000000..4ca10bb --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Event/Break.php @@ -0,0 +1,38 @@ + + * 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 . + * + * --> 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\Event; + +use Wootook\Core\Exception as CoreException; + +class EventBreak + extends CoreException\Exception +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Event/Event.php b/src/application/modules/WootookCore/src/Wootook/Core/Event/Event.php new file mode 100644 index 0000000..3d37596 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Event/Event.php @@ -0,0 +1,117 @@ + + * 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 . + * + * --> 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\Event; + +use Wootook\Core, + Wootook\Core\Exception as CoreException; + +/** + * Event + */ +class Event + extends Core\Base\BaseObject +{ + protected $_propagationStopped = false; + + public function __call($method, $params) + { + $prefix = substr($method, 0, 3); + $dataKey = substr($method, 3); + + $dataKey = str_replace(' ', '', ucwords(str_replace('-', ' ', $dataKey))); + $dataKey = str_replace(' ', '_', ucwords(str_replace('.', ' ', $dataKey))); + + switch ($prefix) { + case 'get': + return $this->getData($dataKey); + case 'set': + return $this->setData($dataKey, isset($params[0]) ? $params[0] : null); + case 'uns': + return $this->unsetData($dataKey); + case 'has': + return $this->hasData($dataKey); + } + + throw new CoreException\RuntimeException(sprintf('Method %d does not exist.', $method)); + } + + public function setType($type) + { + return $this->setData('type', $type); + } + + public function getType() + { + return $this->getData('type'); + } + + public function hasType() + { + return $this->hasData('type'); + } + + public function unsType() + { + return $this->unsetData('type'); + } + + public function setTarget($target) + { + return $this->setData('target', $target); + } + + public function getTarget() + { + return $this->getData('target'); + } + + public function hasTarget() + { + return $this->hasData('target'); + } + + public function unsTarget() + { + return $this->unsetData('target'); + } + + public function stopPropagation() + { + $this->_propagationStopped = true; + + return $this; + } + + public function isPropagationStopped() + { + return $this->_propagationStopped; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Event/EventTarget.php b/src/application/modules/WootookCore/src/Wootook/Core/Event/EventTarget.php new file mode 100644 index 0000000..0808e9e --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Event/EventTarget.php @@ -0,0 +1,94 @@ + + * 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 . + * + * --> 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\Event; + +/** + * EventTarget + */ +trait EventTarget +{ + protected $_eventListeners = array(); + + /** + * @param $type + * @param Closure $listener + * @return EventTarget + */ + public function registerEventListener($type, Closure $listener) + { + if (!isset($this->_eventListeners[$type])) { + $this->_eventListeners[$type] = array(); + } + $this->_eventListeners[$type][] = $listener; + + return $this; + } + + /** + * @param $type + * @param Closure $listener + * @return EventTarget + */ + public function unregisterEventListener($type, Closure $listener) + { + if (!isset($this->_eventListeners[$type])) { + return $this; + } + $key = array_search($listener, $this->_eventListeners[$type]); + unset($this->_eventListeners[$type][$key]); + + return $this; + } + + /** + * @param $type + * @return Event + */ + public function dispatchEvent($type, Array $datas = array()) + { + if (!isset($this->_eventListeners[$type])) { + return $this; + } + + $event = new Event($datas); + $event->setType($type); + $event->setTarget($this); + + foreach ($this->_eventListeners[$type] as $eventListener) { + $eventListener($event); + if ($event->isPropagationStopped()) { + break; + } + } + + return $event; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/BadMethodCallException.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/BadMethodCallException.php new file mode 100644 index 0000000..0dacf2f --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/BadMethodCallException.php @@ -0,0 +1,37 @@ + + * 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 . + * + * --> 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\Exception; + +class BadMethodCallException + extends \BadMethodCallException + implements CoreException +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/CoreException.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/CoreException.php new file mode 100644 index 0000000..ef691e2 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/CoreException.php @@ -0,0 +1,40 @@ + + * 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 . + * + * --> 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\Exception; + +use Wootook; + +/** + * Base exception identifier for the Core module + */ +interface CoreException +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/DataAccessException.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/DataAccessException.php new file mode 100644 index 0000000..b7fc6da --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/DataAccessException.php @@ -0,0 +1,36 @@ + + * 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 . + * + * --> 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\Exception; + +class DataAccessException + extends RuntimeException +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/Database/AdapterError.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/Database/AdapterError.php new file mode 100644 index 0000000..90e41c7 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/Database/AdapterError.php @@ -0,0 +1,53 @@ + + * 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 . + * + * --> 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\Exception\Database; + +use Wootook\Core\Database\Adapter, + Wootook\Core\Exception as CoreException; + +class AdapterError + extends CoreException\RuntimeException + implements Error +{ + protected $_adapter = null; + + public function __construct(Adapter\Adapter $adapter, $message = null, $code = null, $previous = null) + { + parent::__construct($message, null, $previous); + + $this->_adapter = $adapter; + } + + public function getAdapter() + { + return $this->_adapter; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/Database/Error.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/Database/Error.php new file mode 100644 index 0000000..c1c30b1 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/Database/Error.php @@ -0,0 +1,35 @@ + + * 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 . + * + * --> 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\Exception\Database; + +interface Error +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/Database/StatementError.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/Database/StatementError.php new file mode 100644 index 0000000..7876465 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/Database/StatementError.php @@ -0,0 +1,53 @@ + + * 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 . + * + * --> 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\Exception\Database; + +use Wootook\Core\Database\Statement, + Wootook\Core\Exception as CoreException; + +class StatementError + extends CoreException\RuntimeException + implements Error +{ + protected $_statement = null; + + public function __construct(Statement\Statement $statement, $message = null, $code = null, $previous = null) + { + parent::__construct($message, $code, $previous); + + $this->_statement = $statement; + } + + public function getStatement() + { + return $this->_statement; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/DependencyInjection/BadMethodCallException.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/DependencyInjection/BadMethodCallException.php new file mode 100644 index 0000000..4b19b85 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/DependencyInjection/BadMethodCallException.php @@ -0,0 +1,39 @@ + + * 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 . + * + * --> 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\Exception\DependencyInjection; + +use Wootook\Core\Exception; + +class BadMethodCallException + extends \BadMethodCallException + implements Exception\CoreException +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/DependencyInjection/InvalidArgumentException.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/DependencyInjection/InvalidArgumentException.php new file mode 100644 index 0000000..d24998d --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/DependencyInjection/InvalidArgumentException.php @@ -0,0 +1,39 @@ + + * 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 . + * + * --> 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\Exception\DependencyInjection; + +use Wootook\Core\Exception; + +class InvalidArgumentException + extends \InvalidArgumentException + implements Exception\CoreException +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/DependencyInjection/RuntimeException.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/DependencyInjection/RuntimeException.php new file mode 100644 index 0000000..1185dad --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/DependencyInjection/RuntimeException.php @@ -0,0 +1,39 @@ + + * 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 . + * + * --> 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\Exception\DependencyInjection; + +use Wootook\Core\Exception; + +class RuntimeException + extends \RuntimeException + implements Exception\CoreException +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/Deprecated.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/Deprecated.php new file mode 100644 index 0000000..138c74e --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/Deprecated.php @@ -0,0 +1,37 @@ + + * 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 . + * + * --> 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\Exception; + +class Deprecated + extends RuntimeException +{ + +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/Exception.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/Exception.php new file mode 100644 index 0000000..1c594e0 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/Exception.php @@ -0,0 +1,37 @@ + + * 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 . + * + * --> 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\Exception; + +class Exception + extends \Exception + implements CoreException +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/GameError.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/GameError.php new file mode 100644 index 0000000..6738dc9 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/GameError.php @@ -0,0 +1,37 @@ + + * 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 . + * + * --> 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\Exception; + +class GameError + extends RuntimeException +{ + +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/InvalidArgumentException.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/InvalidArgumentException.php new file mode 100644 index 0000000..d1d5838 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/InvalidArgumentException.php @@ -0,0 +1,37 @@ + + * 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 . + * + * --> 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\Exception; + +class InvalidArgumentException + extends \InvalidArgumentException + implements CoreException +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/LayoutException.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/LayoutException.php new file mode 100644 index 0000000..81d9822 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/LayoutException.php @@ -0,0 +1,36 @@ + + * 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 . + * + * --> 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\Exception; + +class LayoutException + extends RuntimeException +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/RuntimeException.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/RuntimeException.php new file mode 100644 index 0000000..4dd710f --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/RuntimeException.php @@ -0,0 +1,37 @@ + + * 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 . + * + * --> 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\Exception; + +class RuntimeException + extends \RuntimeException + implements CoreException +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Exception/WebsiteError.php b/src/application/modules/WootookCore/src/Wootook/Core/Exception/WebsiteError.php new file mode 100644 index 0000000..00d4292 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Exception/WebsiteError.php @@ -0,0 +1,37 @@ + + * 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 . + * + * --> 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\Exception; + +class WebsiteError + extends RuntimeException +{ + +} diff --git a/src/application/code/core/Wootook/Core/Form/ElementAbstract.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/Element/BaseElement.php similarity index 61% rename from src/application/code/core/Wootook/Core/Form/ElementAbstract.php rename to src/application/modules/WootookCore/src/Wootook/Core/Form/Element/BaseElement.php index f718c34..bf04160 100644 --- a/src/application/code/core/Wootook/Core/Form/ElementAbstract.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/Element/BaseElement.php @@ -1,6 +1,39 @@ + * 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 . + * + * --> 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. + * + */ -abstract class Wootook_Core_Form_ElementAbstract +namespace Wootook\Core\Form\Element; + +use Wootook\Core\Form, + Wootook\Core\Form\Validator; + +abstract class BaseElement { protected $_name = null; protected $_form = null; @@ -10,7 +43,7 @@ abstract class Wootook_Core_Form_ElementAbstract protected $_validators = array(); - public function __construct($name, $params = array(), Wootook_Core_Form $form = null) + public function __construct($name, $params = array(), Form\Form $form = null) { if ($form !== null) { $this->setForm($form); @@ -82,7 +115,7 @@ abstract class Wootook_Core_Form_ElementAbstract return $this; } - public function setForm(Wootook_Core_Form $form) + public function setForm(Form\Form $form) { $this->_form = $form; @@ -106,7 +139,7 @@ abstract class Wootook_Core_Form_ElementAbstract return $this; } - public function addValidator(Wootook_Core_Form_ValidatorAbstract $validator, $name = null) + public function addValidator(Validator\BaseValidator $validator, $name = null) { if ($name === null) { $this->_validators = array(); @@ -142,4 +175,4 @@ abstract class Wootook_Core_Form_ElementAbstract return $this; } -} \ No newline at end of file +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Form/Element/Button.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/Element/Button.php new file mode 100644 index 0000000..d573d52 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/Element/Button.php @@ -0,0 +1,40 @@ + + * 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 . + * + * --> 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\Form\Element; + +class Button + extends BaseElement +{ + public function getType() + { + return 'button'; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Form/Element/Text.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/Element/Text.php new file mode 100644 index 0000000..2df3e25 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/Element/Text.php @@ -0,0 +1,40 @@ + + * 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 . + * + * --> 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\Form\Element; + +class Text + extends BaseElement +{ + public function getType() + { + return 'text'; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Form/ElementLoader.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/ElementLoader.php new file mode 100644 index 0000000..63a7b25 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/ElementLoader.php @@ -0,0 +1,70 @@ + + * 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 . + * + * --> 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\Form; + +use Wootook\Core\Profiler, + Wootook\Core\PluginLoader; + +class ElementLoader + extends PluginLoader\PluginLoader +{ + protected $_form = null; + + public function __construct(Form $form, Array $namespaces = array()) + { + $this->_form = $form; + + foreach ($namespaces as $namespace => $path) { + if (is_int($namespace)) { + $this->registerNamespace($path); + } else { + $this->registerNamespace($namespace, $path); + } + } + } + + 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->_form); + } catch (\ReflectionException $e) { + Profiler\ErrorProfiler::getSingleton() + ->addException($e); + return null; + } + } +} diff --git a/src/application/code/core/Wootook/Core/Form.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/Form.php similarity index 65% rename from src/application/code/core/Wootook/Core/Form.php rename to src/application/modules/WootookCore/src/Wootook/Core/Form/Form.php index 75137de..5ee6929 100644 --- a/src/application/code/core/Wootook/Core/Form.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/Form.php @@ -28,49 +28,73 @@ * */ +namespace Wootook\Core\Form; + +use Wootook\Core\Exception as CoreException, + Wootook\Core\Model, + Wootook\Core\Form\Element, + Wootook\Core\Mvc\Controller\Response, + Wootook\Core\Mvc\Controller\Request, + Wootook\Core\Profiler; + + /** * * Enter description here ... * @author Greg * */ -class Wootook_Core_Form +class Form { + /** + * Form elements container + * + * @var array + */ protected $_elements = array(); + /** + * current MVC request management instance + * + * @var Request\Http + */ protected $_request = null; /** + * Form element instance loader * - * Element class loader - * @var Wootook_Core_Form_ElementLoader + * @var ElementLoader */ protected $_elementLoader = null; /** + * Form field validator instance loader * - * Validator class loader - * @var Wootook_Core_Form_ValidatorLoader + * @var ValidatorLoader */ protected $_validatorLoader = null; /** + * Session storage instance, used for messaging purposes * - * Enter description here ... - * @var Wootook_Core_Model_Session + * @var Model\Session */ protected $_session = null; - public function __construct(Wootook_Core_Model_Session $session, Array $elements = array()) + /** + * @param Model\Session $session + * @param array $elements + */ + public function __construct(Model\Session $session, Array $elements = array()) { $this->_session = $session; - $this->_elementLoader = new Wootook_Core_Form_ElementLoader($this, array( - 'Wootook_Core_Form_Element_' => 'Wootook/Core/Form/Element' + $this->_elementLoader = new ElementLoader($this, array( + 'Wootook\\Core\\Form\\Element' => 'Wootook/Core/Form/Element' )); - $this->_validatorLoader = new Wootook_Core_Form_ValidatorLoader($this, array( - 'Wootook_Core_Form_Validator_' => 'Wootook/Core/Form/Validator' + $this->_validatorLoader = new ValidatorLoader($this, array( + 'Wootook\\Core\\Form\\Validator' => 'Wootook/Core/Form/Validator' )); $this->addElement('__formkey', 'text', array('form_key' => 'formKey')); @@ -78,7 +102,7 @@ class Wootook_Core_Form foreach ($elements as $elementName => $elementConfig) { if (is_string($elementConfig)) { $this->addElement($elementName, $elementConfig); - } else if ($elementConfig instanceof Wootook_Core_Form_ElementAbstract) { + } else if ($elementConfig instanceof Element\BaseElement) { $this->addElement($elementName, $elementConfig); } else { if (isset($elementConfig['validators'])) { @@ -90,6 +114,11 @@ class Wootook_Core_Form } } + /** + * Validated the form field values + * + * @return bool + */ public function validate() { foreach ($this->_elements as $element) { @@ -101,23 +130,23 @@ class Wootook_Core_Form } /** + * Add a field element to the current form * - * Enter description here ... * @param string $name - * @param string|Wootook_Core_Form_ElementAbstract $type - * @return Wootook_Core_Form + * @param string|Element\BaseElement $type + * @return Form */ public function addElement($name, $type = 'text', Array $validators = array()) { - if ($type instanceof Wootook_Core_Form_ElementAbstract) { + if ($type instanceof Element\BaseElement) { $this->_elements[$name] = $type; $this->_elements[$name]->setForm($this); } else { $element = $this->_elementLoader->load($type); if ($element === null) { - Wootook_Core_ErrorProfiler::getSingleton() - ->addException(new Wootook_Core_Exception_RuntimeException(sprintf('Element %1$s (type: %2$s) could not be created.', $name, $type))); + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException(sprintf('Element %1$s (type: %2$s) could not be created.', $name, $type))); return $this; } $element->setForm($this); @@ -126,14 +155,14 @@ class Wootook_Core_Form $this->_elements[$name]->setName($name); foreach ($validators as $validatorName => $validatorType) { - if ($validatorType instanceof Wootook_Core_Form_ElementAbstract) { + if ($validatorType instanceof Element\BaseElement) { $this->_elements[$name]->addValidator($validatorType, $validatorName); } else { $validator = $this->_validatorLoader->load($validatorType); if ($validator === null) { - Wootook_Core_ErrorProfiler::getSingleton() - ->addException(new Wootook_Core_Exception_RuntimeException(sprintf('Validator %1$s (type: %2$s) could not be created.', $validatorName, $validatorType))); + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\RuntimeException(sprintf('Validator %1$s (type: %2$s) could not be created.', $validatorName, $validatorType))); return $this; } $this->_elements[$name]->addValidator($validator, $validatorName); @@ -144,10 +173,10 @@ class Wootook_Core_Form } /** + * Returns the form field element instance * - * Enter description here ... * @param string $name - * @return Wootook_Core_Form_ElementAbstract + * @return Element\BaseElement */ public function getElement($name) { @@ -159,17 +188,22 @@ class Wootook_Core_Form } /** + * Get the currently used session instance * - * Enter description here ... - * @param string $name - * @return Wootook_Core_Model_Session + * @return Model\Session */ public function getSession() { return $this->_session; } - public function setRequest(Wootook_Core_Mvc_Controller_Request_Http $request) + /** + * Use a new MVC request handler instance + * + * @param Request\Http $request + * @return Form + */ + public function setRequest(Request\Http $request) { $this->_request = $request; @@ -177,15 +211,20 @@ class Wootook_Core_Form } /** + * Get the currently used MVC request handler * - * Enter description here ... - * @return Wootook_Core_Mvc_Controller_Request_Http + * @return Request\Http */ public function getRequest() { return $this->_request; } + /** + * Return the validated and filtered form data + * + * @return array + */ public function getData() { $request = $this->getRequest(); @@ -198,6 +237,11 @@ class Wootook_Core_Form return $request->getAllQueryData(); } + /** + * Populates form fields using the data provided. + * + * @param array $datas + */ public function populate(Array $datas = array()) { $request = $this->getRequest(); @@ -212,4 +256,4 @@ class Wootook_Core_Form } } } -} \ No newline at end of file +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Alnum.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Alnum.php new file mode 100644 index 0000000..459dbb7 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Alnum.php @@ -0,0 +1,53 @@ + + * 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 . + * + * --> 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\Form\Validator; + +use Wootook\Core\Form\Element; + +class Alnum + extends Regex +{ + public function __construct() + { + parent::__construct('#[^[:alnum:]]#'); + } + + public function validate(Element\BaseElement $element, $data) + { + if ($this->_validate($element, $data)) { + $this->_getSession($element) + ->addError('Field "%s" should only contain alphanumeric characters.', $element->getName()); + + return false; + } + return true; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Alpha.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Alpha.php new file mode 100644 index 0000000..98eb3cf --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Alpha.php @@ -0,0 +1,53 @@ + + * 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 . + * + * --> 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\Form\Validator; + +use Wootook\Core\Form\Element; + +class Alpha + extends Regex +{ + public function __construct() + { + parent::__construct('#[^[:alpha:]]#'); + } + + public function validate(Element\BaseElement $element, $data) + { + if ($this->_validate($element, $data)) { + $this->_getSession($element) + ->addError('Field "%s" should only contain alphabetic characters.', $element->getName()); + + return false; + } + return true; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/BaseValidator.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/BaseValidator.php new file mode 100644 index 0000000..3307b02 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/BaseValidator.php @@ -0,0 +1,48 @@ + + * 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 . + * + * --> 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\Form\Validator; + +use Wootook\Core\Form, + Wootook\Core\Form\Element; + +abstract class BaseValidator +{ + abstract public function validate(Element\BaseElement $element, $data); + + protected function _getSession(Element\BaseElement $element) + { + $form = $element->getForm(); + if (!$form instanceof Form\Form) { + return null; + } + return $element->getSession(); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Email.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Email.php new file mode 100644 index 0000000..8e36960 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Email.php @@ -0,0 +1,53 @@ + + * 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 . + * + * --> 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\Form\Validator; + +use Wootook\Core\Form\Element; + +class Email + extends Regex +{ + public function __construct() + { + parent::__construct('#^[[:alnum:]\._\-]@[[:alnum:]\._\-]\.[a-z]{2,}$#'); + } + + public function validate(Element\BaseElement $element, $data) + { + if (!$this->_validate($element, $data)) { + $this->_getSession($element) + ->addError('Field "%s" should contain an email.', $element->getName()); + + return false; + } + return true; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/FormKey.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/FormKey.php new file mode 100644 index 0000000..32d54bd --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/FormKey.php @@ -0,0 +1,52 @@ + + * 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 . + * + * --> 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\Form\Validator; + +use Wootook\Core\Form\Element; + +class FormKey + extends BaseValidator +{ + public function validate(Element\BaseElement $element, $data) + { + $form = $element->getForm(); + $session = $form->getSession(); + + if ($session->getFormKey(false) == $data) { + return true; + } + + $this->_getSession($field) + ->addError('CSRF token failure.', $field->getName()); + + return false; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Hex.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Hex.php new file mode 100644 index 0000000..2009a54 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Hex.php @@ -0,0 +1,54 @@ + + * 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 . + * + * --> 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\Form\Validator; + +use Wootook\Core\Form\Element; + +class Hex + extends Regex +{ + + public function __construct() + { + parent::__construct('#(?:0x)?[^0-9a-f]#i'); + } + + public function validate(Element\BaseElement $element, $data) + { + if ($this->_validate($element, $data)) { + $this->_getSession($element) + ->addError('Field "%s" should only contain numeric characters.', $element->getName()); + + return false; + } + return true; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Host.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Host.php new file mode 100644 index 0000000..f8df82f --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Host.php @@ -0,0 +1,53 @@ + + * 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 . + * + * --> 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\Form\Validator; + +use Wootook\Core\Form\Element; + +class Host + extends Regex +{ + public function __construct() + { + parent::__construct('#^[[:alnum:]\._\-]\.[a-z]{2,}$#'); + } + + public function validate(Element\BaseElement $element, $data) + { + if (!$this->_validate($element, $data)) { + $this->_getSession($element) + ->addError('Field "%s" should contain a host name.', $element->getName()); + + return false; + } + return true; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Numeric.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Numeric.php new file mode 100644 index 0000000..b3ed15b --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Numeric.php @@ -0,0 +1,54 @@ + + * 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 . + * + * --> 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\Form\Validator; + +use Wootook\Core\Form\Element; + +class Numeric + extends Regex +{ + + public function __construct() + { + parent::__construct('#[^[:digit:]]#'); + } + + public function validate(Element\BaseElement $element, $data) + { + if ($this->_validate($element, $data)) { + $this->_getSession($element) + ->addError('Field "%s" should only contain numeric characters.', $element->getName()); + + return false; + } + return true; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Regex.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Regex.php new file mode 100644 index 0000000..c692ec0 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/Validator/Regex.php @@ -0,0 +1,60 @@ + + * 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 . + * + * --> 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\Form\Validator; + +use Wootook\Core\Form\Element; + +class Regex + extends BaseValidator +{ + protected $_expression = null; + + public function __construct($expression) + { + $this->_expression = $expression; + } + + public function validate(Element\BaseElement $element, $data) + { + if (!$this->_validate($element, $data)) { + $this->_getSession($element) + ->addError('Field "%s" does not match the validation pattern.', $element->getName()); + + return false; + } + return true; + } + + protected function _validate(Element\BaseElement $element, $data) + { + return preg_match($this->_expression, $data); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Form/ValidatorLoader.php b/src/application/modules/WootookCore/src/Wootook/Core/Form/ValidatorLoader.php new file mode 100644 index 0000000..8acc4b4 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Form/ValidatorLoader.php @@ -0,0 +1,70 @@ + + * 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 . + * + * --> 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\Form; + +use Wootook\Core\Profiler, + Wootook\Core\PluginLoader; + +class ValidatorLoader + extends PluginLoader\PluginLoader +{ + protected $_form = null; + + public function __construct(Form $form, Array $namespaces = array()) + { + $this->_form = $form; + + foreach ($namespaces as $namespace => $path) { + if (is_int($namespace)) { + $this->registerNamespace($path); + } else { + $this->registerNamespace($namespace, $path); + } + } + } + + 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(); + } catch (\ReflectionException $e) { + Profiler\ErrorProfiler::getSingleton() + ->addException($e); + return null; + } + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Helper/Config/ConfigHandler.php b/src/application/modules/WootookCore/src/Wootook/Core/Helper/Config/ConfigHandler.php new file mode 100644 index 0000000..6fb1cae --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Helper/Config/ConfigHandler.php @@ -0,0 +1,93 @@ + + * 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 . + * + * --> 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\Helper\Config; + +use Wootook\Core\Mvc\Model\Type, + Wootook\Core\Mvc\Model\Action; + +abstract class ConfigHandler + implements \Iterator, \Countable +{ + protected $_data = array(); + + protected function _initData($filename) + { + $config = \Wootook::app()->getDefaultGame()->getConfig('engine/storyline'); + + if ($config === null) { + $config = array( + 'universe' => 'default', + 'episode' => 'default' + ); + } else { + $config = $config->toArray(); + } + + $path = 'gamedata' . DIRECTORY_SEPARATOR . $config['universe'] . DIRECTORY_SEPARATOR + . $config['episode'] . DIRECTORY_SEPARATOR . $filename . '.php'; + + foreach (include APPLICATION_PATH . $path as $elementId => $fieldName) { + $this->setData($elementId, $fieldName); + } + + return $this; + } + + public function count() + { + return count($this->_data); + } + + public function current() + { + return current($this->_data); + } + + public function next() + { + return next($this->_data); + } + + public function key() + { + return key($this->_data); + } + + public function valid() + { + return $this->current() !== false; + } + + public function rewind() + { + reset($this->_data); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Helper/Config/Events.php b/src/application/modules/WootookCore/src/Wootook/Core/Helper/Config/Events.php new file mode 100644 index 0000000..9809eed --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Helper/Config/Events.php @@ -0,0 +1,71 @@ + + * 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 . + * + * --> 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\Helper\Config; + +use Wootook\Core, + Wootook\Core\Config; + +/** + * + * Enter description here ... + * + * @uses Wootook\Core\BaseObject + * @uses Legacies_Empire + */ +class Events + extends ConfigHandler + implements Core\Base\Singleton +{ + private static $_singleton = null; + + public static function getSingleton() + { + if (self::$_singleton === null) { + self::$_singleton = new self(); + } + return self::$_singleton; + } + + public static function registerEvents() + { + foreach (self::getSingleton() as $event => $listenerList) { + foreach ($listenerList as $listener) { + \Wootook::registerListener($event, $listener); + } + } + } + + protected function _init() + { + $this->_initData('events'); + return $this; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Helper/Config/Modules.php b/src/application/modules/WootookCore/src/Wootook/Core/Helper/Config/Modules.php new file mode 100644 index 0000000..cfad504 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Helper/Config/Modules.php @@ -0,0 +1,79 @@ + + * 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 . + * + * --> 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\Helper\Config; + +use Wootook\Core; + +/** + * + * Enter description here ... + * + * @uses Wootook\Core\BaseObject + * @uses Legacies_Empire + */ +class Modules + extends ConfigHandler + implements Core\Base\Singleton +{ + private static $_singleton = null; + + public static function getSingleton() + { + if (self::$_singleton === null) { + self::$_singleton = new self(); + } + return self::$_singleton; + } + + protected function _init() + { + $this->_initData('modules'); + return $this; + } + + protected function _load() + { + // NOP + return $this; + } + + protected function _save() + { + // NOP + return $this; + } + + protected function _delete() + { + // NOP + return $this; + } +} diff --git a/src/application/code/core/Wootook/Core/Model/Layout.php b/src/application/modules/WootookCore/src/Wootook/Core/Layout/Manager.php similarity index 84% rename from src/application/code/core/Wootook/Core/Model/Layout.php rename to src/application/modules/WootookCore/src/Wootook/Core/Layout/Manager.php index d15057f..b3a95e0 100644 --- a/src/application/code/core/Wootook/Core/Model/Layout.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Layout/Manager.php @@ -28,6 +28,19 @@ * */ +namespace Wootook\Core\Layout; + +use Wootook\Core, + Wootook\Core\Base, + Wootook\Core\Block, + Wootook\Core\Config, + Wootook\Core\Exception as CoreException, + Wootook\Core\Helper\Config as ConfigHelper, + Wootook\Core\Model\Layout, + Wootook\Core\Mvc\Model, + Wootook\Core\Mvc\View, + Wootook\Core\Profiler; + /** * Page layout class utility. * Builds page structures from flexible layout declaration files, written in a @@ -36,12 +49,14 @@ * @author Greg * @since 1.5.0 * @package Wootook - * @subpackage Wootook_Core + * @subpackage WootookCore * @category layout */ -class Wootook_Core_Model_Layout - extends Wootook_Core_Mvc_Model_Model +class Manager + //extends Core\BaseObject { + use Base\Service\App, Base\DataContainer; + const DEFAULT_PACKAGE = 'base'; const DEFAULT_THEME = 'default'; @@ -51,10 +66,10 @@ class Wootook_Core_Model_Layout /** @var array */ protected $_blocks = array(); - /** @var Wootook_Core_Mvc_View_View */ + /** @var View\View */ protected $_messageBlock = null; - /** @var Wootook_Core_Mvc_View_View */ + /** @var View\View */ protected $_rootView = null; /** @var string */ @@ -75,7 +90,7 @@ class Wootook_Core_Model_Layout /** @var array */ protected $_namespaces = array( 'core' => array( - 'Wootook_Core_Block_' => 'Wootook/Core/Block' + 'Wootook\\Core\\Block' => 'Wootook/Core/Block' ) ); @@ -87,10 +102,10 @@ class Wootook_Core_Model_Layout * @param string $theme * @param array $data */ - public function __construct($domain = null, $package = null, $theme = null, Array $data = array()) + protected function _construct($domain = null, $package = null, $theme = null, Array $data = array()) { if ($domain === null) { - if (Wootook::getDefaultWebsite()->getId() == 0) { + if (\Wootook::app()->getDefaultWebsiteId() == 0) { $this->_domain = self::DOMAIN_BACKEND; } else { $this->_domain = self::DOMAIN_FRONTEND; @@ -104,13 +119,12 @@ class Wootook_Core_Model_Layout if ($theme !== null) { $this->setTheme($theme); } - - parent::__construct($data); + $this->addData($data); } public function _init() { - $modules = Wootook_Core_Helper_Config_Modules::getSingleton(); + $modules = ConfigHelper\Modules::getSingleton(); foreach ($modules['block'] as $module => $moduleNamespaces) { foreach ($moduleNamespaces as $namespace => $path) { @@ -118,8 +132,8 @@ class Wootook_Core_Model_Layout } } - $fileList = Wootook::getGameConfig('layout'); - if ($fileList instanceof Wootook_Core_Config_Node) { + $fileList = \Wootook::app()->getDefaultGame()->getConfig('layout'); + if ($fileList instanceof Config\Node) { $fileList = $fileList->toArray(); } if (!is_array($fileList) || empty($fileList)) { @@ -127,10 +141,10 @@ class Wootook_Core_Model_Layout } $this->_data = array(); - $this->setPackage(Wootook::getWebsiteConfig('package')); - $this->setTheme(Wootook::getGameConfig('theme')); + $this->setPackage(\Wootook::app()->getDefaultWebsite()->getConfig('package')); + $this->setTheme(\Wootook::app()->getDefaultGame()->getConfig('theme')); - $parser = new Wootook_Core_Model_Layout_Parser(); + $parser = new Layout\Parser(); foreach ($fileList as $layoutFile) { try { if (preg_match('#\.php$#', $layoutFile)) { @@ -138,8 +152,8 @@ class Wootook_Core_Model_Layout } else { $layoutData = $parser->parse($this->_getLayoutPath($layoutFile), $this->_getLayoutCachePath($layoutFile), 3600); } - } catch (Wootook_Core_Exception_LayoutException $e) { - Wootook_Core_ErrorProfiler::getSingleton()->addException($e); + } catch (CoreException\LayoutException $e) { + Profiler\ErrorProfiler::getSingleton()->addException($e); continue; } @@ -186,10 +200,8 @@ class Wootook_Core_Model_Layout } } - protected function _load() + public function load($layoutId) { - $layoutId = func_get_arg(0); - if (!$this->hasData($layoutId)) { return $this; } @@ -258,7 +270,7 @@ class Wootook_Core_Model_Layout } } - Wootook::dispatchEvent($this->_eventPrefix . '.prepare.before', array( + \Wootook::dispatchEvent($this->_eventPrefix . '.prepare.before', array( $this->_eventObject => $this )); @@ -266,19 +278,19 @@ class Wootook_Core_Model_Layout $block->prepareLayout(); } - Wootook::dispatchEvent($this->_eventPrefix . '.prepare.after', array( + \Wootook::dispatchEvent($this->_eventPrefix . '.prepare.after', array( $this->_eventObject => $this )); } protected function _save() { - throw new Wootook_Core_Exception_LayoutException('Save not permitted for the layout manager.'); + throw new CoreException\LayoutException('Save not permitted for the layout manager.'); } protected function _delete() { - throw new Wootook_Core_Exception_LayoutException('Delete not permitted for the layout manager.'); + throw new CoreException\LayoutException('Delete not permitted for the layout manager.'); } protected function _resolveBlockClassType($type) @@ -303,12 +315,12 @@ class Wootook_Core_Model_Layout $className = $namespace . $block; $fileName = $path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $block) . '.php'; - Wootook_Core_ErrorProfiler::getSingleton()->sleep(); + Profiler\ErrorProfiler::getSingleton()->sleep(); if (!($fp = @fopen($fileName, 'r', true))) { - Wootook_Core_ErrorProfiler::getSingleton()->wakeup(); + Profiler\ErrorProfiler::getSingleton()->wakeup(); continue; } - Wootook_Core_ErrorProfiler::getSingleton()->wakeup(); + Profiler\ErrorProfiler::getSingleton()->wakeup(); fclose($fp); if (!class_exists($className, true)) { @@ -319,8 +331,8 @@ class Wootook_Core_Model_Layout } } - Wootook_Core_ErrorProfiler::getSingleton() - ->addException(new Wootook_Core_Exception_LayoutException(sprintf('Class type "%s" could not be resolved.', $type))); + Profiler\ErrorProfiler::getSingleton() + ->addException(new CoreException\LayoutException(sprintf('Class type "%s" could not be resolved.', $type))); return null; } @@ -331,7 +343,7 @@ class Wootook_Core_Model_Layout * @param string $module * @param string $namespace * @param string|null $path - * @return Wootook_Core_Model_Layout + * @return Layout */ public function registerBlockNamespace($module, $namespace, $path = null) { @@ -352,7 +364,7 @@ class Wootook_Core_Model_Layout * @since 1.5.0 * @param string $module * @param string $namespace - * @return Wootook_Core_Model_Layout + * @return Layout */ public function unregisterBlockNamespace($module, $namespace) { @@ -369,7 +381,7 @@ class Wootook_Core_Model_Layout * @param string $type * @param string $name * @param array $config - * @return Wootook_Core_Mvc_View_View + * @return View\View */ public function createBlock($type, $name, $config = array()) { @@ -419,7 +431,7 @@ class Wootook_Core_Model_Layout } if (!isset($config['type'])) { - $instance->$alias = new Wootook_Core_Mvc_View_View($config); + $instance->$alias = new View\View($config); } else { $child = $this->_createBlock($config['type'], $name, $config); if ($child !== null) { @@ -427,8 +439,8 @@ class Wootook_Core_Model_Layout } } } - } catch (ReflectionException $e) { - Wootook_Core_ErrorProfiler::getSingleton() + } catch (\ReflectionException $e) { + Profiler\ErrorProfiler::getSingleton() ->addException($e); return null; } @@ -467,18 +479,18 @@ class Wootook_Core_Model_Layout $callParamaters[$paramterPosition] = $parameter->getDefaultValue(); //} else if (!$parameter->isOptionnal()) { } else if ($paramterPosition <= $requiredParameterCount) { - throw new Wootook_Core_Exception_LayoutException(Wootook::__('Method %s requires parameter %d ($%s) to be defined.', + throw new CoreException\LayoutException(\Wootook::__('Method %s requires parameter %d ($%s) to be defined.', $reflectionMethod->getName(), $paramterPosition + 1, $paramterName)); } } $reflectionMethod->invokeArgs($block, $callParamaters); - } catch (ReflectionException $e) { - Wootook_Core_ErrorProfiler::getSingleton() + } catch (\ReflectionException $e) { + Profiler\ErrorProfiler::getSingleton() ->addException($e); continue; - } catch (RuntimeException $e) { - Wootook_Core_ErrorProfiler::getSingleton() + } catch (\RuntimeException $e) { + Profiler\ErrorProfiler::getSingleton() ->addException($e); continue; } @@ -501,7 +513,7 @@ class Wootook_Core_Model_Layout * * @since 1.5.0 * @param string $domain - * @return Wootook_Core_Model_Layout + * @return Layout */ public function setDomain($domain) { @@ -543,7 +555,7 @@ class Wootook_Core_Model_Layout public function getScriptPath() { - return Wootook::getBasePath('design') . DIRECTORY_SEPARATOR . $this->getDomain(); + return \Wootook::getBasePath('design') . DIRECTORY_SEPARATOR . $this->getDomain(); } public function getAllBlocks() @@ -561,13 +573,13 @@ class Wootook_Core_Model_Layout public function render() { - if (!$this->_rootView instanceof Wootook_Core_Mvc_View_View) { - throw new Wootook_Core_Exception_LayoutException(Wootook::__('No root view declared.')); + if (!$this->_rootView instanceof View\View) { + throw new CoreException\LayoutException(\Wootook::__('No root view declared.')); } $scriptPath = $this->getScriptPath(); foreach ($this->_blocks as $block) { - if ($block instanceof Wootook_Core_Block_Template) { + if ($block instanceof Block\Template) { $block->setScriptPath($scriptPath); } $block->beforeToHtml(); @@ -601,29 +613,29 @@ class Wootook_Core_Model_Layout if ($package !== null && $theme !== null) { $path = sprintf($pattern, $package, $theme); - if (Wootook::fileExists($path)) { + if (\Wootook::fileExists($path)) { return $path; } } if ($package !== null) { $path = sprintf($pattern, $package, self::DEFAULT_THEME); - if (Wootook::fileExists($path)) { + if (\Wootook::fileExists($path)) { return $path; } } $path = sprintf($pattern, self::DEFAULT_PACKAGE, self::DEFAULT_THEME); - if (Wootook::fileExists($path)) { + if (\Wootook::fileExists($path)) { return $path; } - throw new Wootook_Core_Exception_LayoutException(sprintf("Layout file '%s' does not exist.", $file)); + throw new CoreException\LayoutException(sprintf("Layout file '%s' does not exist.", $file)); } /** * - * @return Wootook_Core_Block_Messages + * @return Block\Messages */ public function getMessagesBlock() { diff --git a/src/application/code/core/Wootook/Core/Model/Layout/Parser.php b/src/application/modules/WootookCore/src/Wootook/Core/Layout/Parser.php similarity index 63% rename from src/application/code/core/Wootook/Core/Model/Layout/Parser.php rename to src/application/modules/WootookCore/src/Wootook/Core/Layout/Parser.php index 1e07ae8..b0a5bf2 100644 --- a/src/application/code/core/Wootook/Core/Model/Layout/Parser.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Layout/Parser.php @@ -1,15 +1,47 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Model_Layout_Parser +namespace Wootook\Core\Model\Layout; + +use Wootook\Core\Config; + +class Parser { /** * * Enter description here ... - * @param unknown_type $filename + * @param string $filename */ public function parse($filename, $cachePath = null, $cacheLifetime = 86400) { - if ($cachePath !== null && Wootook::fileExists($cachePath) && $cacheLifetime > 0 && (time() - filemtime($cachePath) <= $cacheLifetime)) { + if ($cachePath !== null && \Wootook::fileExists($cachePath) && $cacheLifetime > 0 && (time() - filemtime($cachePath) <= $cacheLifetime)) { return include $cachePath; } @@ -30,18 +62,18 @@ class Wootook_Core_Model_Layout_Parser return array(); } - $result = new Wootook_Core_Config_Adapter_Array(); + $result = new Config\Adapter\PhpArray(); foreach ($layout->handle as $handle) { $name = (string) $handle['name']; if (empty($name)) { continue; } - $handleNode = new Wootook_Core_Config_Node(array(), $result); + $handleNode = new Config\Node(array(), $result); $result->$name = $handleNode; if (isset($handle->update)) { - $updateListNode = new Wootook_Core_Config_Node(array(), $handleNode); + $updateListNode = new Config\Node(array(), $handleNode); $handleNode->update = $updateListNode; foreach ($handle->update as $update) { @@ -56,7 +88,7 @@ class Wootook_Core_Model_Layout_Parser } if (isset($handle->reference)) { - $referenceListNode = new Wootook_Core_Config_Node(array(), $handleNode); + $referenceListNode = new Config\Node(array(), $handleNode); $handleNode->reference = $referenceListNode; foreach ($handle->reference as $reference) { @@ -65,7 +97,7 @@ class Wootook_Core_Model_Layout_Parser continue; } - $referenceNode = new Wootook_Core_Config_Node(array(), $referenceListNode); + $referenceNode = new Config\Node(array(), $referenceListNode); $referenceListNode->$referenceName = $referenceNode; $this->_parseBlockBody($reference, $referenceNode); @@ -76,7 +108,7 @@ class Wootook_Core_Model_Layout_Parser return $result; } - protected function _parseBlock(SimpleXMLElement $handle, Wootook_Core_Config_Node $blockNode) + protected function _parseBlock(\SimpleXMLElement $handle, Config\Node $blockNode) { foreach ($handle->attributes() as $attributeName => $attributeValue) { $blockNode->$attributeName = (string) $attributeValue; @@ -85,10 +117,10 @@ class Wootook_Core_Model_Layout_Parser $this->_parseBlockBody($handle, $blockNode); } - protected function _parseBlockBody(SimpleXMLElement $handle, Wootook_Core_Config_Node $blockNode) + protected function _parseBlockBody(\SimpleXMLElement $handle, Config\Node $blockNode) { if (isset($handle->block)) { - $childrenNode = new Wootook_Core_Config_Node(array(), $blockNode); + $childrenNode = new Config\Node(array(), $blockNode); $blockNode->children = $childrenNode; foreach ($handle->block as $block) { @@ -97,7 +129,7 @@ class Wootook_Core_Model_Layout_Parser continue; } - $childNode = new Wootook_Core_Config_Node(array(), $childrenNode); + $childNode = new Config\Node(array(), $childrenNode); $childrenNode->$blockName = $childNode; $this->_parseBlock($block, $childNode); @@ -105,7 +137,7 @@ class Wootook_Core_Model_Layout_Parser } if (isset($handle->action)) { - $actionListNode = new Wootook_Core_Config_Node(array(), $blockNode); + $actionListNode = new Config\Node(array(), $blockNode); $blockNode->actions = $actionListNode; foreach ($handle->action as $action) { @@ -114,7 +146,7 @@ class Wootook_Core_Model_Layout_Parser continue; } - $actionNode = new Wootook_Core_Config_Node(array( + $actionNode = new Config\Node(array( 'method' => $methodName, 'params' => array() ), $actionListNode); @@ -134,7 +166,7 @@ class Wootook_Core_Model_Layout_Parser if (isset($param->const) && isset($param->const['name']) && defined((string) $param->const['name'])) { $paramsNode->$paramName = constant((string) $param->const['name']); } else { - $paramArrayNode = new Wootook_Core_Config_Node(array(), $paramsNode); + $paramArrayNode = new Config\Node(array(), $paramsNode); $paramsNode->$paramName = $paramArrayNode; $this->_parseArrayParam($param, $paramArrayNode); @@ -148,11 +180,11 @@ class Wootook_Core_Model_Layout_Parser } } - protected function _parseArrayParam(SimpleXMLElement $element, Wootook_Core_Config_Node $parentNode) + protected function _parseArrayParam(\SimpleXMLElement $element, Config\Node $parentNode) { foreach ($element->children() as $child) { if (count($child)) { - $childNode = new Wootook_Core_Config_Node(array(), $parentNode); + $childNode = new Config\Node(array(), $parentNode); $parentNode->{$child->getName()} = $childNode; $this->_parseArrayParam($child, $childNode); diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Model/Config.php b/src/application/modules/WootookCore/src/Wootook/Core/Model/Config.php new file mode 100644 index 0000000..81d2095 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Model/Config.php @@ -0,0 +1,93 @@ + + * 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 . + * + * --> 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\Model; + +use Wootook\Core\Mvc\Model; + +/** + * + * Enter description here ... + * + * @uses Wootook\Core\BaseObject + * @uses Legacies_Empire + */ +class Config + extends Model\SubTable +{ + protected $_eventPrefix = 'core.config'; + protected $_eventObject = 'config'; + + protected function _init() + { + $this->_tableName = 'core_config'; + $this->_idFieldNames = array('config_path', 'website_id', 'game_id'); + } + + public function setWebsiteId($websiteId) + { + return $this->setData('website_id', $websiteId); + } + + public function getWebsiteId() + { + return $this->getData('website_id'); + } + + public function setGameId($gameId) + { + return $this->setData('game_id', $gameId); + } + + public function getGameId() + { + return $this->getData('game_id'); + } + + public function setPath($path) + { + return $this->setData('config_path', $path); + } + + public function getPath() + { + return $this->getData('config_path'); + } + + public function setValue($value) + { + return $this->setData('config_value', $value); + } + + public function getValue() + { + return $this->getData('config_value'); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Model/Game.php b/src/application/modules/WootookCore/src/Wootook/Core/Model/Game.php new file mode 100644 index 0000000..4453274 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Model/Game.php @@ -0,0 +1,139 @@ + + * 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 . + * + * --> 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\Model; + +use Wootook\Core, + Wootook\Core\Mvc\Model, + Wootook\Core\Mvc\Model\Type; + +/** + * + * Enter description here ... + * + * @uses Wootook\Core\BaseObject + * @uses Legacies_Empire + */ +class Game + extends Model\Entity +{ + use Type\Full; + + const DEFAULT_CODE = 'default'; + + protected $_website = null; + + protected function _construct(Array $data = array()) + { + $this->_eventPrefix = 'core.game'; + $this->_eventObject = 'game'; + + parent::_construct($data); + + $this->_tableName = 'core_game'; + $this->_idFieldName = 'game_id'; + } + + public function getWebsiteId() + { + return $this->getData('website_id'); + } + + public function setWebsiteId($websiteId) + { + $this->_website = $this->app()->getWebsite($websiteId); + return $this->setData('website_id', $websiteId); + } + + /** + * @return Website + */ + public function getWebsite() + { + if ($this->_website === null) { + $this->_website = $this->app()->getWebsite($this->getWebsiteId()); + } + + return $this->_website; + } + + /** + * @param Website $website + * @return Game + */ + public function setWebsite(Website $website) + { + $this->_website = $website; + $this->setWebsiteId($website->getId()); + + return $this; + } + + /** + * @return string + */ + public function getCode() + { + return $this->getData('code'); + } + + /** + * @param string $code + * @return Game + */ + public function setCode($code) + { + return $this->setData('code', $code); + } + + /** + * @return Core\Config\Node + */ + public function getConfig($path = null) + { + if ($this->_config === null) { + $this->_config = clone $this->getWebsite()->getConfig(); + + $this->app()->appendEnvironmentConfig($this->_config, $this->getCode()); + $this->app()->appendDatabaseConfig($this->_config, Core\App\App::SCOPE_GAME, $this->getId()); + } + + if ($path !== null) { + return $this->_config->getConfig($path); + } + + return $this->_config; + } + + public function getBaseUrl() + { + return $this->getConfig('web/url/base'); + } +} diff --git a/src/application/code/core/Wootook/Core/Model/Image/Png.php b/src/application/modules/WootookCore/src/Wootook/Core/Model/Image/Png.php similarity index 79% rename from src/application/code/core/Wootook/Core/Model/Image/Png.php rename to src/application/modules/WootookCore/src/Wootook/Core/Model/Image/Png.php index 0b3f5f9..1d4303a 100644 --- a/src/application/code/core/Wootook/Core/Model/Image/Png.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Model/Image/Png.php @@ -1,4 +1,34 @@ + * 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 . + * + * --> 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\Model\Image; /** * @@ -6,7 +36,7 @@ * @author Greg * */ -class Wootook_Core_Model_Image_Png +class Png { private $_format = NULL; private $_mime = NULL; @@ -191,4 +221,4 @@ class Wootook_Core_Model_Image_Png return $imageData; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/Model/Session.php b/src/application/modules/WootookCore/src/Wootook/Core/Model/Session.php similarity index 76% rename from src/application/code/core/Wootook/Core/Model/Session.php rename to src/application/modules/WootookCore/src/Wootook/Core/Model/Session.php index 2306f03..a378f28 100644 --- a/src/application/code/core/Wootook/Core/Model/Session.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Model/Session.php @@ -1,15 +1,49 @@ + * 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 . + * + * --> 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\Model; + +use Wootook\Core, + Wootook\Core\Base; /** * * Enter description here ... * - * @uses Wootook_Object + * @uses Wootook\Core\BaseObject * @uses Legacies_Empire */ -class Wootook_Core_Model_Session - extends Wootook_Object +class Session { + use Base\Service\App, Base\DataContainer; + const CRIT = 0x80; const ERR = 0x40; const WARN = 0x20; @@ -51,7 +85,7 @@ class Wootook_Core_Model_Session session_destroy(); } - public function __construct($namespace) + public function _construct($namespace) { if (session_id() == '') { session_set_cookie_params($this->getCookieLifetime(), $this->getCookiePath(), $this->getCookieDomain(), false, true); @@ -80,7 +114,7 @@ class Wootook_Core_Model_Session public function getCookieLifetime() { - $lifetime = Wootook::getWebsiteConfig(self::COOKIE_LIFETIME_CONFIG_KEY); + $lifetime = \Wootook::app()->getDefaultWebsite()->getConfig(self::COOKIE_LIFETIME_CONFIG_KEY); if (!is_numeric($lifetime) || $lifetime <= 0) { return 900; } @@ -90,7 +124,7 @@ class Wootook_Core_Model_Session public function getCookieDomain() { - $domain = Wootook::getWebsiteConfig(self::COOKIE_DOMAIN_CONFIG_KEY); + $domain = \Wootook::app()->getDefaultWebsite()->getConfig(self::COOKIE_DOMAIN_CONFIG_KEY); if ($domain === null) { return $_SERVER['SERVER_NAME']; } @@ -99,7 +133,7 @@ class Wootook_Core_Model_Session public function getCookiePath() { - $path = Wootook::getWebsiteConfig(self::COOKIE_PATH_CONFIG_KEY); + $path = \Wootook::app()->getDefaultWebsite()->getConfig(self::COOKIE_PATH_CONFIG_KEY); if ($path === null) { return '/'; } diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Model/Translator.php b/src/application/modules/WootookCore/src/Wootook/Core/Model/Translator.php new file mode 100644 index 0000000..3e2bf53 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Model/Translator.php @@ -0,0 +1,67 @@ + + * 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 . + * + * --> 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\Model; + +class Translator +{ + protected $_translations = array(); + + public function __construct($path, $locale) + { + $fileList = glob($path . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . '*.csv'); + foreach ($fileList as $file) { + $fp = fopen($file, 'r'); + while (!feof($fp)) { + $line = fgetcsv($fp); + if (count($line) >= 2) { + $this->_translations[$line[0]] = $line[1]; + } + } + } + } + + public function translate($message, $_ = null) + { + $args = func_get_args(); + array_shift($args); + + return $this->translateArgs($message, $args); + } + + public function translateArgs($message, Array $args = array()) + { + if (isset($this->_translations[$message])) { + $message = $this->_translations[$message]; + } + + return vsprintf($message, $args); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Model/Website.php b/src/application/modules/WootookCore/src/Wootook/Core/Model/Website.php new file mode 100644 index 0000000..3a1552f --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Model/Website.php @@ -0,0 +1,96 @@ + + * 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 . + * + * --> 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\Model; + +use Wootook\Core, + Wootook\Core\Mvc\Model, + Wootook\Core\Mvc\Model\Type; + +/** + * + * Enter description here ... + * + * @uses Wootook\Core\BaseObject + * @uses Legacies_Empire + */ +class Website + extends Model\Entity +{ + use Type\Full; + + const DEFAULT_CODE = 'default'; + + protected $_config = null; + + protected function _construct(Array $data = array()) + { + $this->_eventPrefix = 'core.website'; + $this->_eventObject = 'website'; + + parent::_construct($data); + + $this->_tableName = 'core_website'; + $this->_idFieldName = 'website_id'; + } + + public function getCode() + { + return $this->getData('code'); + } + + public function setCode($code) + { + return $this->setData('code', $code); + } + + /** + * @return Core\Config\Node + */ + public function getConfig($path = null) + { + if ($this->_config === null) { + $this->_config = clone $this->app()->getGlobalConfig(); + + $this->app()->appendEnvironmentConfig($this->_config, $this->getCode()); + $this->app()->appendDatabaseConfig($this->_config, Core\App\App::SCOPE_WEBSITE, $this->getId()); + } + + if ($path !== null) { + return $this->_config->getConfig($path); + } + return $this->_config; + } + + public function getBaseUrl() + { + return $this->getConfig('web/url/base'); + } +} diff --git a/src/application/code/core/Wootook/Core/Mvc/Controller/Action.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Action.php similarity index 57% rename from src/application/code/core/Wootook/Core/Mvc/Controller/Action.php rename to src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Action.php index e6230ba..3a530c3 100644 --- a/src/application/code/core/Wootook/Core/Mvc/Controller/Action.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Action.php @@ -1,14 +1,54 @@ + * 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 . + * + * --> 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. + * + */ -abstract class Wootook_Core_Mvc_Controller_Action +namespace Wootook\Core\Mvc\Controller; + +use Wootook\Core, + Wootook\Core\Exception as CoreException, + Wootook\Core\Layout, + Wootook\Core\Model, + Wootook\Core\Profiler; + +abstract class Action { + protected $_app = null; + private $_request = null; private $_response = null; private $_layout = null; - public function __construct(Wootook_Core_Mvc_Controller_Request_Http $request, Wootook_Core_Mvc_Controller_Response_Http $response) + public function __construct(Core\App\App $app, Request\Request $request, Response\Response $response) { + $this->_app = $app; + $this->setRequest($request); $this->setResponse($response); } @@ -17,6 +57,11 @@ abstract class Wootook_Core_Mvc_Controller_Action { } + public function app() + { + return $this->_app; + } + public function preDispatch() { } @@ -25,14 +70,14 @@ abstract class Wootook_Core_Mvc_Controller_Action { } - public function setRequest(Wootook_Core_Mvc_Controller_Request_Http $request) + public function setRequest(Request\Request $request) { $this->_request = $request; return $this; } - public function setResponse(Wootook_Core_Mvc_Controller_Response_Http $response) + public function setResponse(Response\Response $response) { $this->_response = $response; @@ -41,7 +86,7 @@ abstract class Wootook_Core_Mvc_Controller_Action /** * - * @return Wootook_Core_Mvc_Controller_Request_Http + * @return Request\Request */ public function getRequest() { @@ -50,7 +95,7 @@ abstract class Wootook_Core_Mvc_Controller_Action /** * - * @return Wootook_Core_Mvc_Controller_Response_Http + * @return Response\Response */ public function getResponse() { @@ -71,7 +116,7 @@ abstract class Wootook_Core_Mvc_Controller_Action $this->getResponse()->setIsDispatched(false); } - protected function _redirect($uri, Array $params = array(), $code = Wootook_Core_Mvc_Controller_Response_Http::REDIRECT_FOUND) + protected function _redirect($uri, Array $params = array(), $code = Response\Response::REDIRECT_FOUND) { $parts = explode('/', $uri); $partsCount = count($parts); @@ -87,14 +132,14 @@ abstract class Wootook_Core_Mvc_Controller_Action $uri = implode('/', array_slice($parts, 0, 3)); $this->getResponse() - ->setRedirect(Wootook::getUrl($uri, $params), $code); + ->setRedirect(\Wootook::getUrl($uri, $params), $code); - Wootook_Core_ErrorProfiler::unregister(true); + Profiler\ErrorProfiler::unregister(true); return $this; } - protected function _redirectUrl($url, $code = Wootook_Core_Mvc_Controller_Response_Http::REDIRECT_FOUND) + protected function _redirectUrl($url, $code = Response\Response::REDIRECT_FOUND) { $this->getResponse()->setRedirect($url, $code); @@ -128,12 +173,12 @@ abstract class Wootook_Core_Mvc_Controller_Action protected function _initLayout() { - return new Wootook_Core_Model_Layout(Wootook_Core_Model_Layout::DOMAIN_FRONTEND); + return new Layout\Manager($this->app(), Layout\Manager::DOMAIN_FRONTEND); } /** * - * @return Wootook_Core_Model_Layout + * @return Layout\Manager */ public function getLayout() { @@ -144,8 +189,8 @@ abstract class Wootook_Core_Mvc_Controller_Action { try { $content = $this->getLayout()->render(); - } catch (Wootook_Core_Exception_LayoutException $e) { - Wootook_Core_ErrorProfiler::getSingleton()->addException($e); + } catch (CoreException\LayoutException $e) { + Profiler\ErrorProfiler::getSingleton()->addException($e); return $this; } $this->getResponse()->setBody($content); diff --git a/src/application/code/core/Wootook/Core/Mvc/Controller/Front.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Front.php similarity index 62% rename from src/application/code/core/Wootook/Core/Mvc/Controller/Front.php rename to src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Front.php index 6c6b20f..a95ce7d 100644 --- a/src/application/code/core/Wootook/Core/Mvc/Controller/Front.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Front.php @@ -1,7 +1,41 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Mvc_Controller_Front +namespace Wootook\Core\Mvc\Controller; + +use Wootook\Core\Base\Service; + +class Front { + use Service\App; + const ROUTE_DEFAULT = 'default'; const ROUTE_ERROR = 'error'; @@ -10,8 +44,7 @@ class Wootook_Core_Mvc_Controller_Front self::ROUTE_ERROR => array( 'modules' => array( 'core' => array( - 'class' => 'Wootook_Core_Controller_', - 'path' => 'Wootook/Core/Controller' + 100 => 'Wootook\\Core\\Controller' ) ), 'defaults' => array( @@ -34,11 +67,50 @@ class Wootook_Core_Mvc_Controller_Front protected $_request = null; protected $_response = null; - public function __construct(Wootook_Core_Mvc_Controller_Request_Request $request, - Wootook_Core_Mvc_Controller_Response_Response $response) + protected function _construct(Request\Request $request = null, Response\Response $response = null) + { + if ($request !== null) { + $this->setRequest($request); + } + if ($response !== null) { + $this->setResponse($response); + } + } + + /** + * @return Request\Request + */ + public function getRequest() + { + if ($this->_request === null) { + $this->_request = new Request\Http($this->app()); + } + return $this->_request; + } + + public function setRequest(Request\Request $request) { $this->_request = $request; + + return $this; + } + + /** + * @return Response\Response + */ + public function getResponse() + { + if ($this->_response === null) { + $this->_response = new Response\Http($this->app()); + } + return $this->_response; + } + + public function setResponse(Response\Response $response) + { $this->_response = $response; + + return $this; } protected function _setNoRouteAction(&$route, &$moduleKey, &$controllerKey, &$actionKey) @@ -64,14 +136,7 @@ class Wootook_Core_Mvc_Controller_Front protected function _camelizeClass($string) { $string = strtolower($string); - $string = str_replace(' ', '_', ucwords(str_replace('.', ' ', $string))); - return str_replace(' ', '', ucwords(str_replace('-', ' ', $string))); - } - - protected function _camelizePath($string) - { - $string = strtolower($string); - $string = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('.', ' ', $string))); + $string = str_replace(' ', '\\', ucwords(str_replace('.', ' ', $string))); return str_replace(' ', '', ucwords(str_replace('-', ' ', $string))); } @@ -88,21 +153,8 @@ class Wootook_Core_Mvc_Controller_Front if (!isset($this->_routes[$route]['modules'][$module])) { return null; } - $modulePrefix = $this->_routes[$route]['modules'][$module]['class']; - return $modulePrefix . $this->_camelizeClass($controllerKey) . 'Controller'; - } - - protected function _getControllerFilename($route, $module, $controllerKey) - { - if (!isset($this->_routes[$route])) { - return null; - } - if (!isset($this->_routes[$route]['modules'][$module])) { - return null; - } - $modulePath = $this->_routes[$route]['modules'][$module]['path']; - - return $modulePath . DIRECTORY_SEPARATOR . $this->_camelizePath($controllerKey) . 'Controller.php'; + $modulePrefix = current($this->_routes[$route]['modules'][$module]); + return $modulePrefix . '\\' . $this->_camelizeClass($controllerKey) . 'Controller'; } protected function _getActionMethod($actionKey) @@ -112,14 +164,14 @@ class Wootook_Core_Mvc_Controller_Front protected function _forward($action, $controller = null, $module = null) { - $this->_request->setActionName($action); + $this->getRequest()->setActionName($action); if ($controller !== null) { - $this->_request->setControllerName($controller); + $this->getRequest()->setControllerName($controller); if ($module != null) { - $this->_request->setModuleName($module); + $this->getRequest()->setModuleName($module); } } - $this->_response->setIsDispatched(false); + $this->getResponse()->setIsDispatched(false); } public function dispatch($route = null) @@ -134,7 +186,7 @@ class Wootook_Core_Mvc_Controller_Front $loop = 0; while ($loop++ < 100) { - $moduleKey = $this->_request->getModuleName(); + $moduleKey = $this->getRequest()->getModuleName(); if (empty($moduleKey)) { $this->_forward( $this->_routes[$route]['defaults']['action'], @@ -154,19 +206,14 @@ class Wootook_Core_Mvc_Controller_Front continue; } - $controllerKey = $this->_request->getControllerName(); + $controllerKey = $this->getRequest()->getControllerName(); if (empty($controllerKey)) { $controllerKey = $this->_routes[$route]['defaults']['controller']; } $controllerClass = $this->_getControllerClass($route, $moduleKey, $controllerKey); - $controllerPath = $this->_getControllerFilename($route, $moduleKey, $controllerKey); - if (!class_exists($controllerClass, false) && Wootook::fileExists($controllerPath)) { - include_once $controllerPath; - } - - if (!class_exists($controllerClass, false)) { + if (!class_exists($controllerClass, true)) { $this->_forward( $this->_routes[self::ROUTE_ERROR]['defaults']['action'], $this->_routes[self::ROUTE_ERROR]['defaults']['controller'], @@ -176,7 +223,7 @@ class Wootook_Core_Mvc_Controller_Front continue; } - $actionKey = $this->_request->getActionName(); + $actionKey = $this->getRequest()->getActionName(); if (empty($actionKey)) { $actionKey = $this->_routes[$route]['defaults']['action']; } @@ -192,30 +239,30 @@ class Wootook_Core_Mvc_Controller_Front continue; } - $controller = new $controllerClass($this->_request, $this->_response); + $controller = new $controllerClass($this->app(), $this->getRequest(), $this->getResponse()); $controller->init(); - $this->_response->setIsDispatched(); + $this->getResponse()->setIsDispatched(); $this->preDispatch(); $controller->preDispatch(); - if (!$this->_response->isDispatched()) { + if (!$this->getResponse()->isDispatched()) { continue; } - if ($this->_response->isRedirect()) { + if ($this->getResponse()->isRedirect()) { break; } $controller->$actionMethod(); - if (!$this->_response->isDispatched()) { + if (!$this->getResponse()->isDispatched()) { continue; } $controller->postDispatch(); $this->postDispatch(); - if ($this->_response->isDispatched() || $this->_response->isRedirect()) { + if ($this->getResponse()->isDispatched() || $this->getResponse()->isRedirect()) { break; } } @@ -225,7 +272,7 @@ class Wootook_Core_Mvc_Controller_Front public function send() { - $this->_response->render(); + $this->getResponse()->render(); } public function addModule($frontName, $namespace, $path) @@ -251,9 +298,9 @@ class Wootook_Core_Mvc_Controller_Front public function preDispatch() { - Wootook::dispatchEvent('core.mvc.controller.front.pre-dispatch', array( - 'request' => $this->_request, - 'response' => $this->_response + \Wootook::dispatchEvent('core.mvc.controller.front.pre-dispatch', array( + 'request' => $this->getRequest(), + 'response' => $this->getResponse() )); return $this; @@ -261,9 +308,9 @@ class Wootook_Core_Mvc_Controller_Front public function postDispatch() { - Wootook::dispatchEvent('core.mvc.controller.front.post-dispatch', array( - 'request' => $this->_request, - 'response' => $this->_response + \Wootook::dispatchEvent('core.mvc.controller.front.post-dispatch', array( + 'request' => $this->getRequest(), + 'response' => $this->getResponse() )); return $this; diff --git a/src/application/code/core/Wootook/Core/Mvc/Controller/Request/Http.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Request/Http.php similarity index 86% rename from src/application/code/core/Wootook/Core/Mvc/Controller/Request/Http.php rename to src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Request/Http.php index 3780a37..71b0f63 100644 --- a/src/application/code/core/Wootook/Core/Mvc/Controller/Request/Http.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Request/Http.php @@ -1,7 +1,37 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Mvc_Controller_Request_Http - extends Wootook_Core_Mvc_Controller_Request_Request +namespace Wootook\Core\Mvc\Controller\Request; + +class Http + extends Request { protected $_baseUrl = null; @@ -15,11 +45,11 @@ class Wootook_Core_Mvc_Controller_Request_Http protected $_serverVars = array(); protected $_postFiles = array(); - public function __construct(Array $options = array()) + protected function _construct(Array $options = array()) { - parent::__construct($options); + parent::_construct($options); - $this->_baseUrl = Wootook::getBaseUrl('link'); + $this->_baseUrl = \Wootook::getBaseUrl('link'); if ($this->_baseUrl === null) { $this->_baseUrl = 'http://' . $this->getServer('HTTP_HOST') . $this->getServer('REQUEST_URI'); } diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Request/Request.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Request/Request.php new file mode 100644 index 0000000..3eb24ca --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Request/Request.php @@ -0,0 +1,67 @@ + + * 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 . + * + * --> 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\Mvc\Controller\Request; + +use Wootook\Core; + +abstract class Request + extends Core\Base\BaseObject +{ + protected function _construct(Array $data = array()) + { + $this->init(); + + parent::_construct($data); + } + + public function setParam($key, $value) + { + return $this->setData($key, $value); + } + + public function getParam($key, $default = null) + { + if ($this->hasData($key)) { + return $this->getData($key); + } + return $default; + } + + abstract public function init(); + + abstract public function getModuleName(); + abstract public function getControllerName(); + abstract public function getActionName(); + + abstract public function setModuleName($name); + abstract public function setControllerName($name); + abstract public function setActionName($name); +} diff --git a/src/application/code/core/Wootook/Core/Mvc/Controller/Response/Http.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Response/Http.php similarity index 75% rename from src/application/code/core/Wootook/Core/Mvc/Controller/Response/Http.php rename to src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Response/Http.php index 3025249..74fbd71 100644 --- a/src/application/code/core/Wootook/Core/Mvc/Controller/Response/Http.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Response/Http.php @@ -1,7 +1,39 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Mvc_Controller_Response_Http - extends Wootook_Core_Mvc_Controller_Response_Response +namespace Wootook\Core\Mvc\Controller\Response; + +use Wootook\Core; + +class Http + extends Response { const STATUS_OK = 200; @@ -127,7 +159,7 @@ class Wootook_Core_Mvc_Controller_Response_Http public function setRawCookie($name, $value, $lifetime = null, $path = null, $domain = null) { - $date = new Wootook_Core_DateTime(); + $date = new Core\DateTime(); $date->add($lifetime); setcookie($name, $value, $date->getTimestamp(), $path, $domain); diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Response/Response.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Response/Response.php new file mode 100644 index 0000000..1afa0af --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Controller/Response/Response.php @@ -0,0 +1,53 @@ + + * 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 . + * + * --> 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\Mvc\Controller\Response; + +use Wootook\Core; + +abstract class Response + extends Core\Base\BaseObject +{ + protected $_isDispatched = false; + + public function setIsDispatched($dispatched = true) + { + $this->_isDispatched = $dispatched; + + return $this; + } + + public function isDispatched() + { + return $this->_isDispatched; + } + + abstract public function render($send = true); +} diff --git a/src/application/code/core/Wootook/Core/Event.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Deletable.php similarity index 92% rename from src/application/code/core/Wootook/Core/Event.php rename to src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Deletable.php index 42b4de7..123eea7 100644 --- a/src/application/code/core/Wootook/Core/Event.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Deletable.php @@ -28,13 +28,12 @@ * */ +namespace Wootook\Core\Mvc\Model\Action; + /** - * - * Enter description here ... - * @author Greg * */ -class Wootook_Core_Event - extends Wootook_Object +interface Deletable { -} \ No newline at end of file + public function save(); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Delete.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Delete.php new file mode 100644 index 0000000..76c577d --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Delete.php @@ -0,0 +1,75 @@ + + * 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 . + * + * --> 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\Mvc\Model\Action; + +use Wootook\Core\Exception as CoreException; + +/** + * + */ +trait Delete +{ + public function delete() + { + try { + $this->_beforeDelete(); + $this->_delete(); + $this->_afterDelete(); + } catch (\PDOException $e) { + throw new CoreException\DataAccessException('Could not delete entity: ' . $e->getMessage(), 0); + } + return $this; + } + + abstract protected function _delete(); + + protected function _beforeDelete() + { + \Wootook::dispatchEvent('model.before-delete', array('model' => $this)); + + if ($this->_eventPrefix !== null && $this->_eventObject !== null) { + \Wootook::dispatchEvent($this->_eventPrefix . '.before-delete', array($this->_eventObject => $this)); + } + + return $this; + } + + protected function _afterDelete() + { + \Wootook::dispatchEvent('model.after-delete', array('model' => $this)); + + if ($this->_eventPrefix !== null && $this->_eventObject !== null) { + \Wootook::dispatchEvent($this->_eventPrefix . '.after-delete', array($this->_eventObject => $this)); + } + + return $this; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Load.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Load.php new file mode 100644 index 0000000..1d39b9b --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Load.php @@ -0,0 +1,77 @@ + + * 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 . + * + * --> 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\Mvc\Model\Action; + +use Wootook\Core\Exception as CoreException; + +/** + * + */ +trait Load +{ + public function load($entityId, $field = null, $_ = null) + { + try { + $this->_beforeLoad(); + $this->_load($entityId, $field); + $this->_afterLoad(); + + $this->_setOriginalData($this->_data); + } catch (\PDOException $e) { + throw new CoreException\DataAccessException('Could not load data: ' . $e->getMessage(), 0, $e); + } + return $this; + } + + abstract protected function _load(); + + protected function _beforeLoad() + { + \Wootook::dispatchEvent('model.before-load', array('model' => $this)); + + if ($this->_eventPrefix !== null && $this->_eventObject !== null) { + \Wootook::dispatchEvent($this->_eventPrefix . '.before-load', array($this->_eventObject => $this)); + } + + return $this; + } + + protected function _afterLoad() + { + \Wootook::dispatchEvent('model.after-load', array('model' => $this)); + + if ($this->_eventPrefix !== null && $this->_eventObject !== null) { + \Wootook::dispatchEvent($this->_eventPrefix . '.after-load', array($this->_eventObject => $this)); + } + + return $this; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Loadable.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Loadable.php new file mode 100644 index 0000000..d809788 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Loadable.php @@ -0,0 +1,39 @@ + + * 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 . + * + * --> 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\Mvc\Model\Action; + +/** + * + */ +interface Loadable +{ + public function load($entityId, $field = null, $_ = null); +} diff --git a/src/application/code/core/Wootook/Core/Exception.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Savable.php similarity index 91% rename from src/application/code/core/Wootook/Core/Exception.php rename to src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Savable.php index 7a9030d..d933687 100644 --- a/src/application/code/core/Wootook/Core/Exception.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Savable.php @@ -28,10 +28,12 @@ * */ +namespace Wootook\Core\Mvc\Model\Action; + /** - * - * Enter description here ... - * @author Greg * */ -interface Wootook_Core_Exception extends Wootook_Exception {} \ No newline at end of file +interface Savable +{ + public function save(); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Save.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Save.php new file mode 100644 index 0000000..9089e37 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Action/Save.php @@ -0,0 +1,77 @@ + + * 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 . + * + * --> 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\Mvc\Model\Action; + +use Wootook\Core\Exception as CoreException; + +/** + * + */ +trait Save +{ + public function save() + { + try { + $this->_beforeSave(); + $this->_save(); + $this->_afterSave(); + + $this->_setOriginalData($this->_data); + } catch (PDOException $e) { + throw new CoreException\DataAccessException('Could not save data: ' . $e->getMessage(), 0); + } + return $this; + } + + abstract protected function _save(); + + protected function _beforeSave() + { + \Wootook::dispatchEvent('model.before-save', array('model' => $this)); + + if ($this->_eventPrefix !== null && $this->_eventObject !== null) { + \Wootook::dispatchEvent($this->_eventPrefix . '.before-save', array($this->_eventObject => $this)); + } + + return $this; + } + + protected function _afterSave() + { + \Wootook::dispatchEvent('model.after-save', array('model' => $this)); + + if ($this->_eventPrefix !== null && $this->_eventObject !== null) { + \Wootook::dispatchEvent($this->_eventPrefix . '.after-save', array($this->_eventObject => $this)); + } + + return $this; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Entity.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Entity.php new file mode 100644 index 0000000..dc4891b --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Entity.php @@ -0,0 +1,193 @@ + + * 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 . + * + * --> 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\Mvc\Model; + +use Wootook\Core, + Wootook\Core\Database, + Wootook\Core\Database\Sql, + Wootook\Core\Exception as CoreException; + +abstract class Entity + extends Core\Base\BaseObject + implements EntityInterface +{ + protected $_tableName = null; + + protected $_idFieldName = null; + + public function setIdFieldName($fieldName) + { + $this->_idFieldName = $fieldName; + + return $this; + } + + public function getIdFieldName() + { + return $this->_idFieldName; + } + + public function setId($id) + { + $this->setData($this->getIdFieldName(), $id); + + return $this; + } + + public function getId() + { + return $this->getData($this->getIdFieldName()); + } + + protected function _load() + { + $id = func_get_arg(0); + + $idFieldName = null; + if (func_num_args() >= 2) { + $idFieldName = func_get_arg(1); + } + if ($idFieldName === null) { + $idFieldName = $this->getIdFieldName(); + } + + $database = $this->getReadConnection(); + if ($database === null) { + throw new CoreException\DataAccessException('Could not load data: no read connection configured.'); + } + + $select = $database->select() + ->from(array('main_table' => $database->getTable($this->getTableName()))) + ->where($idFieldName, new Sql\Placeholder\Param('id', $id)) + ->limit(1); + + $statement = $select->prepare(); + $statement->execute(array( + 'id' => $id + )); + + $datas = $statement->fetch(Database\ConnectionManager::FETCH_ASSOC); + if (!is_array($datas) || empty($datas)) { + throw new CoreException\DataAccessException('Could not load data: this id could not be found.'); + } + $realId = $datas[$this->getIdFieldName()]; + unset($datas[$this->getIdFieldName()]); + + $this->_data = array(); + $this->getDataMapper()->decode($this, $datas); + $this->setId($realId); + + return $this; + } + + protected function _save() + { + $adapter = $this->getWriteConnection(); + + if ($adapter === null) { + throw new CoreException\DataAccessException('Could not save data: no write connection configured.'); + } + + if ($this->getId() !== null) { + $update = $adapter->update() + ->into($adapter->getTable($this->getTableName())) + ->where(new Sql\Placeholder\Expression("{$adapter->quoteIdentifier($this->getIdFieldName())}=:id", array('id' => $this->getId()))); + + foreach ($this->getDataMapper()->encode($this, $this->getChangedDatas()) as $field => $value) { + $update->set($field, new Sql\Placeholder\Param($field, $value)); + } + try { + $statement = $update->prepare(); + $statement->execute(); + } catch (CoreException\Database\AdapterError $e) { + throw new CoreException\DataAccessException('Could not save data: ' . $e->getMessage(), null, $e); + } catch (CoreException\Database\StatementError $e) { + throw new CoreException\DataAccessException('Could not save data: ' . $e->getMessage(), null, $e); + } + } else { + $insert = $adapter->insert() + ->into($adapter->getTable($this->getTableName())); + + foreach ($this->getDataMapper()->encode($this, $this->getAllDatas()) as $field => $value) { + $insert->set($field, new Sql\Placeholder\Param($field, $value)); + } + try { + $statement = $insert->prepare(); + $statement->execute(); + + $id = $adapter->lastInsertId($adapter->getTable($this->getTableName())); + $this->setId($id); + } catch (CoreException\Database\AdapterError $e) { + throw new CoreException\DataAccessException('Could not save data: ' . $e->getMessage(), null, $e); + } catch (CoreException\Database\StatementError $e) { + throw new CoreException\DataAccessException('Could not save data: ' . $e->getMessage(), null, $e); + } + } + + return $this; + } + + protected function _delete() + { + $adapter = $this->getWriteConnection(); + if ($adapter === null) { + throw new CoreException\DataAccessException('Could not delete data: no write connection configured.'); + } + $delete = $adapter + ->delete() + ->from($adapter->getTable($this->getTableName())) + ->where($this->getIdFieldName(), $this->getId()) + ->limit(1); + + try { + $statement = $adapter->prepare($delete); + $statement->execute(); + } catch (CoreException\Database\AdapterError $e) { + throw new CoreException\DataAccessException('Could not delete data: ' . $e->getMessage(), null, $e); + } catch (CoreException\Database\StatementError $e) { + throw new CoreException\DataAccessException('Could not delete data: ' . $e->getMessage(), null, $e); + } + + return $this; + } + + public function setTableName($tableName) + { + $this->_tableName = $tableName; + + return $this; + } + + public function getTableName() + { + return $this->_tableName; + } +} diff --git a/src/application/code/core/Wootook/Core/Mvc/Model/EntityInterface.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/EntityInterface.php similarity index 96% rename from src/application/code/core/Wootook/Core/Mvc/Model/EntityInterface.php rename to src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/EntityInterface.php index e512a5d..da60043 100644 --- a/src/application/code/core/Wootook/Core/Mvc/Model/EntityInterface.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/EntityInterface.php @@ -28,13 +28,15 @@ * */ +namespace Wootook\Core\Mvc\Model; + /** * * Enter description here ... * @author Greg * */ -interface Wootook_Core_Mvc_Model_EntityInterface +interface EntityInterface { public function getId(); public function setId($id); diff --git a/src/application/code/core/Wootook/Core/Mvc/Model/Entity/SubTable.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/SubTable.php similarity index 67% rename from src/application/code/core/Wootook/Core/Mvc/Model/Entity/SubTable.php rename to src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/SubTable.php index 791d481..faa3cc5 100644 --- a/src/application/code/core/Wootook/Core/Mvc/Model/Entity/SubTable.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/SubTable.php @@ -1,13 +1,44 @@ + * 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 . + * + * --> 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\Mvc\Model; + +use Wootook\Core, + Wootook\Core\Database, + Wootook\Core\Exception as CoreException; /** * - * @uses Wootook_Object - * @uses Legacies_Empire - * @uses Wootook_Player_Model_Entity + * @uses Wootook\Core\BaseObject */ -abstract class Wootook_Core_Mvc_Model_Entity_SubTable - extends Wootook_Core_Database_Resource +abstract class SubTable + extends Core\Base\BaseObject { private $_isLoaded = false; protected $_idFieldNames = array(); @@ -81,7 +112,7 @@ SQL_EOF; $datas = $statement->fetch(PDO::FETCH_ASSOC); if (!is_array($datas) || empty($datas)) { - throw new Wootook_Core_Exception_DataAccessException('Could not load data: this id combination could not be found.'); + throw new CoreException\DataAccessException('Could not load data: this id combination could not be found.'); } $this->_data = array(); diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Type/Base.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Type/Base.php new file mode 100644 index 0000000..631bae3 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Type/Base.php @@ -0,0 +1,96 @@ + + * 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 . + * + * --> 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\Mvc\Model\Type; + +use Wootook\Core, + Wootook\Core\Database\Resource, + Wootook\Core\Exception as CoreException; + +/** + * Base model implementation, should be consumed by a Wootook\Core\BaseObject derived class + */ +trait Base +{ + protected $_originalData = array(); + + protected $_eventPrefix = null; + protected $_eventObject = null; + + public function _construct(Array $data = array()) + { + parent::_construct($data); + + $this->_init(); + $this->_setOriginalData(); + } + + protected function _init() + { + } + + protected function _setOriginalData() + { + $this->_originalData = $this->_data; + } + + public function getChangedDatas() + { + return array_diff_assoc($this->_data, $this->_originalData); + } + + public function hasChangedDatas() + { + if (count($this->getChangedDatas()) > 0) { + return true; + } + return false; + } + + public function __set($key, $value) + { + return $this->setData($key, $value); + } + + public function __get($key) + { + return $this->getData($key); + } + + public function __unset($key) + { + return $this->unsetData($key); + } + + public function __isset($key) + { + return $this->hasData($key); + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Type/Full.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Type/Full.php new file mode 100644 index 0000000..ef18229 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Type/Full.php @@ -0,0 +1,46 @@ + + * 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 . + * + * --> 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\Mvc\Model\Type; + +use Wootook\Core, + Wootook\Core\Database\Resource, + Wootook\Core\Mvc\Model\Action; + +/** + * + * Enter description here ... + * @author Greg + * + */ +trait Full +{ + use Base, Action\Load, Action\Save, Action\Delete, Resource\ReadConnection, Resource\WriteConnection, Resource\DataMapper; +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Type/Readonly.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Type/Readonly.php new file mode 100644 index 0000000..c210162 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/Model/Type/Readonly.php @@ -0,0 +1,46 @@ + + * 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 . + * + * --> 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\Mvc\Model\Type; + +use Wootook\Core, + Wootook\Core\Mvc\Model\Action, + Wootook\Core\Exception as CoreException; + +/** + * + * Enter description here ... + * @author Greg + * + */ +trait Readonly +{ + use Base, Action\Load; +} diff --git a/src/application/code/core/Wootook/Core/Mvc/View/View.php b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/View/View.php similarity index 85% rename from src/application/code/core/Wootook/Core/Mvc/View/View.php rename to src/application/modules/WootookCore/src/Wootook/Core/Mvc/View/View.php index 4847061..b95b941 100644 --- a/src/application/code/core/Wootook/Core/Mvc/View/View.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Mvc/View/View.php @@ -28,14 +28,20 @@ * */ +namespace Wootook\Core\Mvc\View; + +use Wootook\Core, + Wootook\Core\Model; +use Wootook_Player_Model_Session; + /** * * Enter description here ... * @author Greg * */ -class Wootook_Core_Mvc_View_View - extends Wootook_Object +class View + extends Core\Base\BaseObject { protected $_template = null; protected $_partials = array(); @@ -44,14 +50,14 @@ class Wootook_Core_Mvc_View_View protected $_scriptPath = null; - public function __construct(Array $data = array()) + public function _construct(Array $data = array()) { if (isset($data['template'])) { $this->_template = $data['template']; unset($data['template']); } - parent::__construct($data); + parent::_construct($data); } protected function _prepareRender() @@ -95,8 +101,8 @@ class Wootook_Core_Mvc_View_View if ($format === null) { $format = 'H:i:s'; } - if (!$dateTime instanceof Wootook_Core_DateTime) { - $dateTime = new Wootook_Core_DateTime($dateTime); + if (!$dateTime instanceof Core\DateTime) { + $dateTime = new Core\DateTime($dateTime); } return $dateTime->toString($format); } @@ -116,7 +122,7 @@ class Wootook_Core_Mvc_View_View $args = func_get_args(); array_shift($args); - return Wootook::translate(Wootook::getDefaultLocale(), $message, $args); + return \Wootook::translate(\Wootook::getDefaultLocale(), $message, $args); } public function translate($message, $_ = null) @@ -124,7 +130,7 @@ class Wootook_Core_Mvc_View_View $args = func_get_args(); array_shift($args); - return Wootook::translate(Wootook::getLocale(), $message, $args); + return \Wootook::translate(\Wootook::getLocale(), $message, $args); } public function renderScript($file) @@ -179,18 +185,19 @@ class Wootook_Core_Mvc_View_View public function getUrl($uri, Array $params = array()) { - return Wootook::getUrl($uri, $params); + return \Wootook::getUrl($uri, $params); } public function getStaticUrl($uri, Array $params = array()) { - return Wootook::getStaticUrl($uri, $params); + return \Wootook::getStaticUrl($uri, $params); } public function getSkinUrl($uri, Array $params = array(), $theme = null, $package = null) { - if (Wootook::$isInstalled) { - $player = Wootook_Player_Model_Session::getSingleton()->getPlayer(); + if (\Wootook::$isInstalled) { + // FIXME: External dependency should not exist + $player = \Wootook\Player\Model\Session::getSingleton()->getPlayer(); if ($player !== null && $player->getId()) { $theme = $player->getSkinPath(); } @@ -199,19 +206,19 @@ class Wootook_Core_Mvc_View_View $theme = $this->getLayout()->getTheme(); } if ($theme === null || empty($theme)) { - $theme = Wootook_Core_Model_Layout::DEFAULT_THEME; + $theme = Model\Layout::DEFAULT_THEME; } if ($package === null || empty($package)) { $package = $this->getLayout()->getPackage(); } if ($package === null || empty($package)) { - $package = Wootook_Core_Model_Layout::DEFAULT_PACKAGE; + $package = Model\Layout::DEFAULT_PACKAGE; } $domain = $this->getLayout()->getDomain(); - $baseUrl = Wootook::getBaseUrl('skin'); - $basePath = Wootook::getBasePath('skin'); + $baseUrl = \Wootook::getBaseUrl('skin'); + $basePath = \Wootook::getBasePath('skin'); $pathPattern = $basePath . "{$domain}/%s/%s/{$uri}"; $urlPattern = $baseUrl . "{$domain}/%s/%s/{$uri}"; @@ -226,14 +233,14 @@ class Wootook_Core_Mvc_View_View $urlPattern .= '?' . implode('&', $serializedParams); } - if (Wootook::fileExists(sprintf($pathPattern, $package, $theme))) { + if (\Wootook::fileExists(sprintf($pathPattern, $package, $theme))) { return sprintf($urlPattern, $package, $theme); } - if (Wootook::fileExists(sprintf($pathPattern, $package, Wootook_Core_Model_Layout::DEFAULT_THEME))) { - return sprintf($urlPattern, $package, Wootook_Core_Model_Layout::DEFAULT_THEME); + if (\Wootook::fileExists(sprintf($pathPattern, $package, Model\Layout::DEFAULT_THEME))) { + return sprintf($urlPattern, $package, Model\Layout::DEFAULT_THEME); } - return sprintf($urlPattern, Wootook_Core_Model_Layout::DEFAULT_PACKAGE, Wootook_Core_Model_Layout::DEFAULT_THEME); + return sprintf($urlPattern, Model\Layout::DEFAULT_PACKAGE, Model\Layout::DEFAULT_THEME); } public function setPartial($name, $content) @@ -305,7 +312,7 @@ class Wootook_Core_Mvc_View_View /** * - * @return Wootook_Core_Model_Layout + * @return Model\Layout */ public function getLayout() { diff --git a/src/application/code/core/Wootook/Core/PluginLoader/PluginLoader.php b/src/application/modules/WootookCore/src/Wootook/Core/PluginLoader/PluginLoader.php similarity index 53% rename from src/application/code/core/Wootook/Core/PluginLoader/PluginLoader.php rename to src/application/modules/WootookCore/src/Wootook/Core/PluginLoader/PluginLoader.php index eaaff7a..3d86696 100644 --- a/src/application/code/core/Wootook/Core/PluginLoader/PluginLoader.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/PluginLoader/PluginLoader.php @@ -1,6 +1,36 @@ + * 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 . + * + * --> 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. + * + */ -abstract class Wootook_Core_PluginLoader_PluginLoader +namespace Wootook\Core\PluginLoader; + +abstract class PluginLoader { protected $_pluginInstances = array(); protected $_namespaces = array(); @@ -11,17 +41,13 @@ abstract class Wootook_Core_PluginLoader_PluginLoader return $this->_pluginInstances[$pluginName]; } - $pluginName = str_replace(' ', '_', ucwords(str_replace('.', ' ', $pluginName))); + $pluginName = str_replace(' ', '\\', ucwords(str_replace('.', ' ', $pluginName))); $pluginName = str_replace(' ', '', ucwords(str_replace('-', ' ', $pluginName))); foreach ($this->_namespaces as $namespace => $path) { - $className = $namespace . $pluginName; + $className = $namespace . '\\' . $pluginName; $fileName = $path . DIRECTORY_SEPARATOR . - str_replace('_', DIRECTORY_SEPARATOR, $pluginName) . '.php'; - - if (!Wootook::fileExists($fileName)) { - continue; - } + str_replace('\\', DIRECTORY_SEPARATOR, $pluginName) . '.php'; if (!class_exists($className, true)) { continue; @@ -36,7 +62,7 @@ abstract class Wootook_Core_PluginLoader_PluginLoader public function registerNamespace($namespace, $path = null) { if ($path === null) { - $path = str_replace('_', DIRECTORY_SEPARATOR, $namespace); + $path = str_replace('\\', DIRECTORY_SEPARATOR, $namespace); } $this->_namespaces[$namespace] = $path; @@ -77,4 +103,4 @@ abstract class Wootook_Core_PluginLoader_PluginLoader return $this; } -} \ No newline at end of file +} diff --git a/src/application/code/core/Wootook/Core/ErrorProfiler.php b/src/application/modules/WootookCore/src/Wootook/Core/Profiler/ErrorProfiler.php similarity index 70% rename from src/application/code/core/Wootook/Core/ErrorProfiler.php rename to src/application/modules/WootookCore/src/Wootook/Core/Profiler/ErrorProfiler.php index a957b62..276e4f7 100644 --- a/src/application/code/core/Wootook/Core/ErrorProfiler.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Profiler/ErrorProfiler.php @@ -28,13 +28,15 @@ * */ +namespace Wootook\Core\Profiler; + +use Wootook\Core\Config, + Wootook\Core\Exception as CoreException; + /** - * - * Enter description here ... - * @author Greg - * + * Error profiler, displays details about PHP core errors and uncaught exceptions. */ -class Wootook_Core_ErrorProfiler +class ErrorProfiler { private static $_singleton = null; @@ -48,11 +50,11 @@ class Wootook_Core_ErrorProfiler private $_listen = true; - private $_mute = true; + private $_mute = false; /** * - * @return Wootook_Core_ErrorProfiler + * @return ErrorProfiler */ public static function getSingleton() { @@ -62,6 +64,14 @@ class Wootook_Core_ErrorProfiler return self::$_singleton; } + /** + * @param $errno + * @param $errstr + * @param null $errfile + * @param null $errline + * @param array $errcontext + * @return bool + */ public function errorManager($errno, $errstr, $errfile = null, $errline = null, Array $errcontext = array()) { if (!$this->_listen) { @@ -71,59 +81,59 @@ class Wootook_Core_ErrorProfiler $trace = debug_backtrace(); switch ($errno) { - case E_RECOVERABLE_ERROR: - case E_USER_ERROR: - case E_ERROR: - $this->_errors[] = array( - 'time' => explode(' ', microtime()), - 'code' => $errno, - 'message' => $errstr, - 'file' => $errfile, - 'line' => $errline, - 'context' => $errcontext, - 'trace' => $trace + case E_RECOVERABLE_ERROR: + case E_USER_ERROR: + case E_ERROR: + $this->_errors[] = array( + 'time' => explode(' ', microtime()), + 'code' => $errno, + 'message' => $errstr, + 'file' => $errfile, + 'line' => $errline, + 'context' => $errcontext, + 'trace' => $trace ); break; - case E_USER_WARNING: - case E_WARNING: - $this->_warnings[] = array( - 'time' => explode(' ', microtime()), - 'code' => $errno, - 'message' => $errstr, - 'file' => $errfile, - 'line' => $errline, - 'context' => $errcontext, - 'trace' => $trace + case E_USER_WARNING: + case E_WARNING: + $this->_warnings[] = array( + 'time' => explode(' ', microtime()), + 'code' => $errno, + 'message' => $errstr, + 'file' => $errfile, + 'line' => $errline, + 'context' => $errcontext, + 'trace' => $trace ); break; - case E_USER_NOTICE: - case E_NOTICE: - $this->_notices[] = array( - 'time' => explode(' ', microtime()), - 'code' => $errno, - 'message' => $errstr, - 'file' => $errfile, - 'line' => $errline, - 'context' => $errcontext, - 'trace' => $trace + case E_USER_NOTICE: + case E_NOTICE: + $this->_notices[] = array( + 'time' => explode(' ', microtime()), + 'code' => $errno, + 'message' => $errstr, + 'file' => $errfile, + 'line' => $errline, + 'context' => $errcontext, + 'trace' => $trace ); break; - default: - if (!isset($this->_otherErrors[$errno])) { - $this->_otherErrors[$errno] = array(); - } + default: + if (!isset($this->_otherErrors[$errno])) { + $this->_otherErrors[$errno] = array(); + } - $this->_otherErrors[$errno][] = array( - 'time' => explode(' ', microtime()), - 'code' => $errno, - 'message' => $errstr, - 'file' => $errfile, - 'line' => $errline, - 'context' => $errcontext, - 'trace' => $trace + $this->_otherErrors[$errno][] = array( + 'time' => explode(' ', microtime()), + 'code' => $errno, + 'message' => $errstr, + 'file' => $errfile, + 'line' => $errline, + 'context' => $errcontext, + 'trace' => $trace ); break; } @@ -131,19 +141,36 @@ class Wootook_Core_ErrorProfiler return true; } - public function addException($exception) + /** + * Add a caught exception to the error profiler + * + * @param \Exception $exception + * @return void + */ + public function addException(\Exception $exception) { $this->_exceptions[] = $exception; } - public function exceptionManager($exception) + /** + * Exception manager, fallback function for uncaught exceptions + * + * @param \Exception $exception + * @return void + */ + public function exceptionManager(\Exception $exception) { if (!$this->_listen) { return; } - $this->_exceptions[] = new Wootook_Core_Exception_Exception('Uncaught Exception: ' . $exception->getMessage(), null, $exception); + $this->_exceptions[] = new CoreException\Exception('Uncaught Exception: ' . $exception->getMessage(), null, $exception); } + /** + * @param $id + * @param $error + * @return string + */ protected function _renderError($id, $error) { $types = array( @@ -162,7 +189,7 @@ class Wootook_Core_ErrorProfiler 0x1000 => 'E_RECOVERABLE_ERROR', 0x2000 => 'E_DEPRECATED', 0x4000 => 'E_USER_DEPRECATED', - ); + ); if (isset($error['code']) && isset($types[$error['code']])) { $code = $types[$error['code']]; @@ -171,10 +198,10 @@ class Wootook_Core_ErrorProfiler } $date = date('Y-m-d H:i:s', (int) $error['time'][1]); - $microsec = (int) ($error['time'][0] * 1000000); + $microSec = (int) ($error['time'][0] * 1000000); return << $value) { $output .= sprintf('
  • ', $level); $output .= sprintf('%s', $key); - if ($value instanceof Wootook_Core_Config_Node) { + if ($value instanceof Config\Node) { if (count($value) > 0) { $output .= $this->_renderConfig($value, $level + 1); } else { @@ -266,6 +293,39 @@ ERROR_EOF; return; } + $jqueryUrl = 'scripts/jquery/jquery-1.6.4.js'; + echo <<< JS_EOF + +JS_EOF; + + $index = 0; echo '
    '; echo '

    Debug profiler

    '; @@ -334,12 +394,11 @@ ERROR_EOF; echo PHP_EOL; echo ''; } - echo '
    '; } echo ''; echo << -(function(){ +WootookProfilerCallback(function(){ var sections = jQuery('.error-profiler'); sections.each(function(){ var element = jQuery(this); @@ -357,32 +416,33 @@ jQuery('.error-profiler-link').click(function(e){ } }); }); -})(); +}); JS_EOF; echo '

    Configuration profiler

    '; - echo ''; - echo '
    '; - $config = clone Wootook::getConfig(); - foreach ($config->getConfig('resource/database') as $node) { - if ($node->params) { - $node->params->reset(); + $config = \Wootook::app()->getGlobalConfig(); + if ($config !== null) { + echo ''; + echo '
    '; + $config = clone $config; + foreach ($config->getConfig('resource/database') as $node) { + if ($node->params) { + $node->params->reset(); + } } - } - echo $this->_renderConfig(Wootook::getConfig(), 0); - echo '
    '; - echo ''; - echo '
    '; - echo $this->_renderConfig(Wootook::getWebsiteConfig()); - echo '
    '; - echo ''; - echo '
    '; - echo $this->_renderConfig(Wootook::getGameConfig()); - echo '
    '; - echo '
    '; - echo <<_renderConfig($config, 0); + echo ''; + echo ''; + echo '
    '; + echo $this->_renderConfig(\Wootook::app()->getDefaultWebsite()->getConfig()); + echo '
    '; + echo ''; + echo '
    '; + echo $this->_renderConfig(\Wootook::app()->getDefaultGame()->getConfig()); + echo '
    '; + echo << -(function(){ +WootookProfilerCallback(function(){ var sections = jQuery('.config-profiler'); sections.each(function(){ var element = jQuery(this); @@ -400,9 +460,13 @@ jQuery('.config-profiler-link').click(function(e){ } }); }); -})(); +}); JS_EOF; + } else { + echo 'Could not load application configuration.'; + } + echo ''; } public static function register() @@ -410,9 +474,7 @@ JS_EOF; set_error_handler(array(self::getSingleton(), 'errorManager')); set_exception_handler(array(self::getSingleton(), 'exceptionManager')); - if (defined('DEBUG')) { - self::getSingleton()->_mute = false; - } + self::getSingleton()->_mute = false; if (self::$_isTraceRegistered === false && defined('DEBUG')) { self::$_isTraceRegistered = true; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Resource/Entity.php b/src/application/modules/WootookCore/src/Wootook/Core/Resource/Entity.php new file mode 100644 index 0000000..57bdba7 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Resource/Entity.php @@ -0,0 +1,36 @@ + + * 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 . + * + * --> 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\Resource; + +class Entity +{ + +} diff --git a/src/application/code/core/Wootook/Core/Resource/EntityCollection.php b/src/application/modules/WootookCore/src/Wootook/Core/Resource/EntityCollection.php similarity index 50% rename from src/application/code/core/Wootook/Core/Resource/EntityCollection.php rename to src/application/modules/WootookCore/src/Wootook/Core/Resource/EntityCollection.php index 0f0d29b..6f1a1de 100644 --- a/src/application/code/core/Wootook/Core/Resource/EntityCollection.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Resource/EntityCollection.php @@ -1,12 +1,47 @@ + * 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 . + * + * --> 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. + * + */ -abstract class Wootook_Core_Resource_EntityCollection - implements Iterator, Countable +namespace Wootook\Core\Resource; + +use Wootook\Core\Database, + Wootook\Core\Database\Adapter, + Wootook\Core\Database\Orm, + Wootook\Core\Database\Sql, + Wootook\Core\Database\Sql\Placeholder, + Wootook\Core\Exception as CoreException; + +abstract class EntityCollection + implements \Iterator, \Countable { - protected $_connection = null; - - /** @var Wootook_Core_Database_Sql_Select */ - protected $_select = null; + use Database\Resource\DataMapper, + Database\Resource\ReadConnection; protected $_entityTable = null; protected $_entityClass = null; @@ -14,14 +49,12 @@ abstract class Wootook_Core_Resource_EntityCollection protected $_eventObject = null; protected $_eventPrefix = null; - protected $_dataMapper = null; - protected $_curPage = null; protected $_pageSize = null; protected $_items = array(); - public function __construct(Wootook_Core_Database_Adapter_Adapter $connection = null) + public function __construct(Adapter\Adapter $connection = null) { $this->setReadConnection($connection); @@ -36,59 +69,7 @@ abstract class Wootook_Core_Resource_EntityCollection $this->_entityClass = $entityClass; } - public function getSelect() - { - if ($this->_select === null) { - $this->_select = $this->getReadConnection() - ->select() - ->from(array('main_table' => $this->getReadConnection()->getTable($this->_entityTable))); - - $this->_prepareSelect($this->_select); - } - - return $this->_select; - } - - public function _prepareSelect(Wootook_Core_Database_Sql_Select $select) - { - } - - /** - * - * @return Wootook_Core_Database_Orm_DataMapper - */ - public function getDataMapper() - { - if ($this->_dataMapper === null) { - $this->_dataMapper = new Wootook_Core_Database_Orm_DataMapper(); - } - return $this->_dataMapper; - } - - /** - * @return Wootook_Core_Database_Adapter_Adapter - */ - public function getReadConnection() - { - return $this->_connection; - } - - public function setReadConnection($connection) - { - if ($connection instanceof Wootook_Core_Database_Adapter_Pdo_Mysql) { - $this->_connection = $connection; - } else if (is_string($connection)) { - $this->_connection = Wootook_Core_Database_ConnectionManager::getSingleton() - ->getConnection($connection); - } else { - throw new Wootook_Core_Exception_RuntimeException( - 'First parameter should be either a database connection object or a string identifier.'); - } - - return $this; - } - - final public function load() + public function load() { $this->_beforeLoad(); $this->_load(); @@ -99,10 +80,10 @@ abstract class Wootook_Core_Resource_EntityCollection protected function _beforeLoad() { - Wootook::dispatchEvent('resource.collection.before-load', array('model' => $this)); + \Wootook::dispatchEvent('resource.collection.before-load', array('model' => $this)); if ($this->_eventPrefix !== null && $this->_eventObject !== null) { - Wootook::dispatchEvent($this->_eventPrefix . '.before-load', array($this->_eventObject => $this)); + \Wootook::dispatchEvent($this->_eventPrefix . '.before-load', array($this->_eventObject => $this)); } return $this; @@ -110,10 +91,10 @@ abstract class Wootook_Core_Resource_EntityCollection protected function _afterLoad() { - Wootook::dispatchEvent('resource.collection.after-load', array('model' => $this)); + \Wootook::dispatchEvent('resource.collection.after-load', array('model' => $this)); if ($this->_eventPrefix !== null && $this->_eventObject !== null) { - Wootook::dispatchEvent($this->_eventPrefix . '.after-load', array($this->_eventObject => $this)); + \Wootook::dispatchEvent($this->_eventPrefix . '.after-load', array($this->_eventObject => $this)); } return $this; @@ -138,9 +119,9 @@ abstract class Wootook_Core_Resource_EntityCollection $this->_items = array(); if (func_num_args() > 1) { - $reflection = new ReflectionClass(array_shift($args)); + $reflection = new \ReflectionClass(array_shift($args)); } else { - $reflection = new ReflectionClass($this->_entityClass); + $reflection = new \ReflectionClass($this->_entityClass); } while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { @@ -153,33 +134,6 @@ abstract class Wootook_Core_Resource_EntityCollection return $this; } - public function getSize($maintainGrouping = array()) - { - $clone = clone $this->_select; - $clone->reset(Wootook_Core_Database_Sql_Select::COLUMNS); - if (empty($maintainGrouping)) { - $clone->reset(Wootook_Core_Database_Sql_Select::GROUP); - } else { - $groupingFields = $clone->getPart(Wootook_Core_Database_Sql_Select::GROUP); - $clone->reset(Wootook_Core_Database_Sql_Select::GROUP); - foreach ($groupingFields as $field) { - if (in_array($field, $maintainGrouping)) { - $clone->group($field); - } - } - } - $clone->column(new Wootook_Core_Database_Sql_Placeholder_Expression('COUNT(*)')); - - $database = $this->getReadConnection(); - $statement = $database->prepare($clone); - - $statement->execute(); - $count = $statement->fetchColumn(); - $statement->closeCursor(); - - return $count; - } - public function count() { return count($this->_items); diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Resource/EntityCollection/Action/Load.php b/src/application/modules/WootookCore/src/Wootook/Core/Resource/EntityCollection/Action/Load.php new file mode 100644 index 0000000..aa99624 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Resource/EntityCollection/Action/Load.php @@ -0,0 +1,144 @@ + + * 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 . + * + * --> 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\Resource\EntityCollection\Action; + +use Wootook\Core\Database\Sql, + Wootook\Core\Exception as CoreException; + +/** + * + */ +trait Load +{ + /** @var Sql\Select */ + protected $_select = null; + + public function getSelect() + { + if ($this->_select === null) { + $this->_select = $this->getReadConnection() + ->select() + ->from(array('main_table' => $this->getReadConnection()->getTable($this->_entityTable))); + + $this->_prepareSelect($this->_select); + } + + return $this->_select; + } + + /** + * @return Sql\Select + */ + public function getSelectCount(Array $maintainGrouping) + { + $clone = clone $this->getSelect(); + $clone->reset(Sql\Select::COLUMNS); + + if (empty($maintainGrouping)) { + $clone->reset(Sql\Select::GROUP); + } else { + $groupingFields = $clone->getPart(Sql\Select::GROUP); + $clone->reset(Sql\Select::GROUP); + foreach ($groupingFields as $field) { + if (!in_array($field, $maintainGrouping)) { + continue; + } + $clone->group($field); + } + } + + $clone->column(new Sql\Placeholder\Expression('COUNT(*)')); + } + + public function _prepareSelect(Sql\Select $select) + { + } + + public function _prepareSelectCount(Sql\Select $select) + { + } + + public function getSize(Array $maintainGrouping = array()) + { + $select = $this->_getSelectCount($maintainGrouping); + + $database = $this->getReadConnection(); + try { + $statement = $database->prepare($select); + + $statement->execute(); + $count = $statement->fetchColumn(); + $statement->closeCursor(); + } catch (\PDOException $e) { + throw new CoreException\DataAccessException('Could not load data: ' . $e->getMessage(), 0, $e); + } + + return $count; + } + + public function load() + { + try { + $this->_beforeLoad(); + $this->_load(); + $this->_afterLoad(); + + $this->_setOriginalData($this->_data); + } catch (\PDOException $e) { + throw new CoreException\DataAccessException('Could not load data: ' . $e->getMessage(), 0, $e); + } + return $this; + } + + abstract protected function _load(); + + protected function _beforeLoad() + { + \Wootook::dispatchEvent('model.before-load', array('model' => $this)); + + if ($this->_eventPrefix !== null && $this->_eventObject !== null) { + \Wootook::dispatchEvent($this->_eventPrefix . '.before-load', array($this->_eventObject => $this)); + } + + return $this; + } + + protected function _afterLoad() + { + \Wootook::dispatchEvent('model.after-load', array('model' => $this)); + + if ($this->_eventPrefix !== null && $this->_eventObject !== null) { + \Wootook::dispatchEvent($this->_eventPrefix . '.after-load', array($this->_eventObject => $this)); + } + + return $this; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Resource/EntityCollection/Action/Loadable.php b/src/application/modules/WootookCore/src/Wootook/Core/Resource/EntityCollection/Action/Loadable.php new file mode 100644 index 0000000..0a1eeec --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Resource/EntityCollection/Action/Loadable.php @@ -0,0 +1,39 @@ + + * 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 . + * + * --> 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\Resource\EntityCollection\Action; + +/** + * + */ +interface Loadable +{ + public function load($entityId, $field = null, $_ = null); +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Setup/Exception/RuntimeException.php b/src/application/modules/WootookCore/src/Wootook/Core/Setup/Exception/RuntimeException.php new file mode 100644 index 0000000..88e0ef9 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Setup/Exception/RuntimeException.php @@ -0,0 +1,40 @@ + + * 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 . + * + * --> 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\Setup\Exception; + +use Wootook\Core, + Wootook\Core\Exception as CoreException; + +class RuntimeException + extends CoreException\RuntimeException + implements Core\Exception\CoreException +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Setup/Exception/VersionStageError.php b/src/application/modules/WootookCore/src/Wootook/Core/Setup/Exception/VersionStageError.php new file mode 100644 index 0000000..f14909c --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Setup/Exception/VersionStageError.php @@ -0,0 +1,39 @@ + + * 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 . + * + * --> 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\Setup\Exception; + +use Wootook\Core; + +class VersionStageError + extends RuntimeException + implements Core\Exception\CoreException +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Setup/Exception/VersionValueError.php b/src/application/modules/WootookCore/src/Wootook/Core/Setup/Exception/VersionValueError.php new file mode 100644 index 0000000..95d8b39 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Setup/Exception/VersionValueError.php @@ -0,0 +1,42 @@ + + * 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 . + * + * --> 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\Setup\Exception; + +use Wootook\Core; + +/** + * + */ +class VersionValueError + extends \RuntimeException + implements Core\Exception\CoreException +{ +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Setup/Updater.php b/src/application/modules/WootookCore/src/Wootook/Core/Setup/Updater.php new file mode 100644 index 0000000..0cdd15b --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Setup/Updater.php @@ -0,0 +1,159 @@ + + * 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 . + * + * --> 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\Setup; + +use Wootook\Core\Profiler, + Wootook\Core\Database, + Wootook\Core\Database\Adapter as DatabaseAdapter, + Wootook\Core\Setup\Exception as SetupException; + +class Updater +{ + protected $_setupConnection = null; + + /** + * + * Enter description here ... + * @param unknown_type $connection + * @return Updater + */ + public function setSetupConnection($connection) + { + if (is_string($connection)) { + $this->_setupConnection = Database\ConnectionManager::getSingleton() + ->getConnection($connection); + } else { + $this->_setupConnection = $connection; + } + + return $this; + } + + /** + * + * Enter description here ... + * @return DatabaseAdapter\Adapter + */ + public function getSetupConnection() + { + if ($this->_setupConnection === null) { + $this->setSetupConnection('default'); + } + return $this->_setupConnection; + } + + public function getTableName($tableName) + { + return $this->getSetupConnection()->getTable($tableName); + } + + public function query($statement) + { + try { + if (!$this->getSetupConnection()->query($statement)) { + $info = $this->getSetupConnection()->errorInfo(); + throw new SetupException\RuntimeException( + \Wootook::__('Query failed: SQLSTATE %s: %s.', $info[1], $info[2])); + } + } catch (PDOException $e) { + Profiler\ErrorProfiler::getSingleton()->exceptionManager($e); + throw new SetupException\RuntimeException($e->getMessage(), null, $e); + } + } + + public function grant($tableName, $connectionName, $perms = null) + { + $hostname = \Wootook::app()->getGlobalConfig("database/{$connectionName}/params/hostname"); + $username = \Wootook::app()->getGlobalConfig("database/{$connectionName}/params/username"); + $database = \Wootook::app()->getGlobalConfig("database/{$connectionName}/params/database"); + $password = \Wootook::app()->getGlobalConfig("database/{$connectionName}/params/password"); + + if ($perms === null) { + $perms = 'ALL PRIVILEGES'; + } else if (is_array($perms)) { + $perms = implode(' ', $perms); + } + + $sql =<<getTable($tableName)} +TO '{$username}@{$hostname}' IDENTIFIED BY '$password' +SQL_EOF; + + $this->getSetupConnection()->query($sql); + + return $this; + } + + public function revoke($tableName, $connectionName, $perms = null) + { + $hostname = \Wootook::app()->getGlobalConfig("database/{$connectionName}/params/hostname"); + $username = \Wootook::app()->getGlobalConfig("database/{$connectionName}/params/username"); + $database = \Wootook::app()->getGlobalConfig("database/{$connectionName}/params/database"); + $password = \Wootook::app()->getGlobalConfig("database/{$connectionName}/params/password"); + + if ($perms === null) { + $perms = 'ALL PRIVILEGES'; + } else if (is_array($perms)) { + $perms = implode(' ', $perms); + } + + $sql =<<getTable($tableName)} +FROM '{$username}@{$hostname}' +SQL_EOF; + + $this->getSetupConnection()->query($sql); + + return $this; + } + + public function run($script) + { + include $script; + } + + public function getConfig($path = null) + { + return \Wootook::app()->getGlobalConfig($path); + } + + public function getWebsiteConfig($path = null, $websiteId = null) + { + return \Wootook::app()->getWebsite($websiteId)->getConfig($path); + } + + public function getGameConfig($path = null, $gameId = null) + { + return \Wootook::app()->getGame($gameId)->getConfig($path); + } +} diff --git a/src/application/code/core/Wootook/Core/Setup/Updater/ScriptQueue.php b/src/application/modules/WootookCore/src/Wootook/Core/Setup/Updater/ScriptQueue.php similarity index 89% rename from src/application/code/core/Wootook/Core/Setup/Updater/ScriptQueue.php rename to src/application/modules/WootookCore/src/Wootook/Core/Setup/Updater/ScriptQueue.php index e0ce1d5..3d8ff5e 100644 --- a/src/application/code/core/Wootook/Core/Setup/Updater/ScriptQueue.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Setup/Updater/ScriptQueue.php @@ -1,7 +1,43 @@ + * 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 . + * + * --> 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. + * + */ -class Wootook_Core_Setup_Updater_ScriptQueue - implements Iterator, Countable, ArrayAccess +namespace Wootook\Core\Setup\Updater; + +use Wootook\Core\Exception as CoreException, + Wootook\Core\Setup\Exception as SetupException; + +/** + * + */ +class ScriptQueue + implements \Iterator, \Countable, \ArrayAccess { const PCRE_FILE_PATTERN = '%^(?install|upgrade|uninstall|downgrade)-(?[0-9]+\.[0-9]+\.[0-9]+)(?:\.(?[a-z]+)(?[0-9]+))?(?:-(?[0-9]+\.[0-9]+\.[0-9]+)(?:\.(?[a-z]+)(?[0-9]+))?)?$%'; const PCRE_VERSION_PATTERN = '%^(?[0-9]+\.[0-9]+\.[0-9]+)(?:-(?[a-z]+)(?[0-9]+)?)?$%'; @@ -88,7 +124,7 @@ class Wootook_Core_Setup_Updater_ScriptQueue if ($fromVersion['level'] < $toVersion['level']) { $this->_upgradeToVersion($fromVersion, $toVersion); } else { -// throw new Wootook_Core_Exception_RuntimeException("Version already installed."); +// throw new CoreException\RuntimeException("Version already installed."); } } else { $this->_upgradeToVersion($fromVersion, $toVersion); @@ -100,7 +136,7 @@ class Wootook_Core_Setup_Updater_ScriptQueue if ($fromVersion['level'] < $toVersion['level']) { $this->_upgradeToVersion($fromVersion, $toVersion); } else { -// throw new Wootook_Core_Exception_RuntimeException("Version already installed."); +// throw new CoreException\RuntimeException("Version already installed."); } } else { $this->_upgradeToVersion($fromVersion, $toVersion); @@ -112,13 +148,13 @@ class Wootook_Core_Setup_Updater_ScriptQueue if ($fromVersion['level'] < $toVersion['level']) { $this->_upgradeToVersion($fromVersion, $toVersion); } else { -// throw new Wootook_Core_Exception_RuntimeException("Version already installed."); +// throw new CoreException\RuntimeException("Version already installed."); } } else { $this->_upgradeToVersion($fromVersion, $toVersion); } } else { - throw new Wootook_Core_Setup_Exception_VersionStageError("Invalid version stage."); + throw new SetupException\VersionStageError("Invalid version stage."); } break; } @@ -167,7 +203,7 @@ class Wootook_Core_Setup_Updater_ScriptQueue } else if (isset($this->_installVersions[$highestVersion][self::STAGE_ALPHA])) { $stage = self::STAGE_ALPHA; } else { - throw new Wootook_Core_Setup_Exception_VersionStageError("Invalid version stage."); + throw new SetupException\VersionStageError("Invalid version stage."); } $levelList = array_keys($this->_installVersions[$highestVersion][$stage]); @@ -192,7 +228,7 @@ class Wootook_Core_Setup_Updater_ScriptQueue protected function _downgradeToVersion($fromVersion, $toVersion) { - throw new Wootook_Core_Exception_RuntimeException("Downgrade isn't yet implemented."); + throw new CoreException\RuntimeException("Downgrade isn't yet implemented."); } protected function _upgradeToVersion($fromVersion, $toVersion) @@ -249,7 +285,7 @@ class Wootook_Core_Setup_Updater_ScriptQueue $level = max(array_keys($versionPointer[$highestVersion][$stage])); } else { - throw new Wootook_Core_Setup_Exception_VersionValueError("Invalid version value."); + throw new SetupException\VersionValueError("Invalid version value."); } $currentVersion = array( diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/App/AppTest.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/App/AppTest.php new file mode 100644 index 0000000..a478b68 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/App/AppTest.php @@ -0,0 +1,19 @@ +getMock('Wootook\\Core\\App\\App', $methods, $constructorArgs); + } + + public function testConfigurationLoadingWithEnvironments() + { + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Base/BaseObjectTest.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Base/BaseObjectTest.php new file mode 100644 index 0000000..f52f45e --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Base/BaseObjectTest.php @@ -0,0 +1,226 @@ +_app = $this->getMock('Wootook\\Core\\App\\App', array('__construct'), array('')); + } + + public function testAppMethod() + { + $object = new Wootook\Core\Base\BaseObject($this->_app); + + $this->assertAttributeSame($this->_app, '_app', $object); + + $this->assertSame($this->_app, $object->app()); + } + + public function testSetData() + { + $object = new Wootook\Core\Base\BaseObject($this->_app); + + $this->assertAttributeEmpty('_data', $object); + + $object->setData('test', true); + $expected = array('test' => true); + $this->assertAttributeEquals($expected, '_data', $object); + + $object->setData('test', 'testing'); + $expected = array('test' => 'testing'); + $this->assertAttributeEquals($expected, '_data', $object); + } + + /** + * @requires testSetData + */ + public function testGetData() + { + $object = new Wootook\Core\Base\BaseObject($this->_app); + + $object->setData('test', 'testing'); + + $this->assertEquals('testing', $object->getData('test')); + + $object->setData('test', true); + $this->assertTrue($object->getData('test')); + + $this->assertNull($object->getData('testing')); + } + + /** + * @requires testSetData + * @requires testGetData + */ + public function testGetAllDatas() + { + $object = new Wootook\Core\Base\BaseObject($this->_app); + + $object->setData('test', 'testing'); + + $expected = array('test' => 'testing'); + $this->assertEquals($expected, $object->getAllDatas()); + + $object->setData('test', true); + $expected = array('test' => true); + $this->assertEquals($expected, $object->getAllDatas()); + } + + /** + * @requires testSetData + * @requires testGetData + */ + public function testHasData() + { + $object = new Wootook\Core\Base\BaseObject($this->_app); + + $object->setData('test', 'testing'); + + $this->assertTrue($object->hasData('test')); + $this->assertFalse($object->hasData('testing')); + } + + /** + * @requires testSetData + */ + public function testAddData() + { + $object = new Wootook\Core\Base\BaseObject($this->_app); + + $object->setData('test', 'testing'); + + $expected = array( + 'test' => 'testing', + 'testing' => true, + 'legacies' => false + ); + + $object->addData(array( + 'testing' => true, + 'legacies' => false + )); + $this->assertAttributeEquals($expected, '_data', $object); + + $expected = array( + 'test' => 'legacies', + 'testing' => false, + 'legacies' => 'Wootook_Object' + ); + + $object->addData($expected); + $this->assertAttributeEquals($expected, '_data', $object); + } + + /** + * @requires testSetData + */ + public function testUnsetData() + { + $object = new Wootook\Core\Base\BaseObject($this->_app); + + $object->setData('test', 'testing'); + $object->setData('testing', true); + $object->setData('removed', 'me!'); + $object->setData('legacies', false); + + $expected = array( + 'test' => 'testing', + 'testing' => true, + 'legacies' => false + ); + + $object->unsetData('removed'); + $this->assertAttributeEquals($expected, '_data', $object); + } + + public function testClearData() + { + $object = new Wootook\Core\Base\BaseObject($this->_app); + + $object->setData('test', 'testing'); + $object->setData('testing', true); + $object->setData('removed', 'me!'); + $object->setData('legacies', false); + + $expected = array( + 'test' => 'testing', + 'testing' => true, + 'legacies' => false + ); + + $object->clearData(); + $this->assertAttributeEmpty('_data', $object); + } + + /** + * @requires testSetData + * @requires testHasData + */ + public function testOffsetExists() + { + $object = new Wootook\Core\Base\BaseObject($this->_app); + + $object->setData('test', 'testing'); + + $this->assertTrue(isset($object['test'])); + } + + /** + * @requires testSetData + * @requires testGetData + */ + public function testOffsetGet() + { + $object = new Wootook\Core\Base\BaseObject($this->_app); + + $object->setData('test', 'testing'); + + $this->assertEquals('testing', $object['test']); + } + + /** + * @requires testGetData + * @requires testSetData + */ + public function testOffsetSet() + { + $object = new Wootook\Core\Base\BaseObject($this->_app); + + $object['test'] = 'testing'; + + $this->assertEquals('testing', $object->getData('test')); + } + + /** + * @requires testSetData + * @requires testGetData + */ + public function testOffsetUnset() + { + $object = new Wootook\Core\Base\BaseObject($this->_app); + + $object->setData('test', 'testing'); + + unset($object['test']); + + $this->assertAttributeEmpty('_data', $object); + $this->assertNull($object->getData('test')); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Config/NodeTest.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Config/NodeTest.php new file mode 100644 index 0000000..026e8cd --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Config/NodeTest.php @@ -0,0 +1,517 @@ +assertAttributeEmpty('_children', $object); + $this->assertAttributeEquals(null, '_parent', $object); + } + + public function testCreateEmptyWithoutParentCheckInitMethodCallWithInitialData() + { + $dataItems = array( + 'first-child' => 1, + 'second-child' => 2, + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + + $mock = $this->getMock('Wootook\\Core\\Config\\Node', array('__construct', '_init'), array($dataItems), '', false); + + $mock->expects($this->once()) + ->method('_init') + ->with($this->equalTo($dataItems)) + ; + + $mock->__construct($dataItems); + $this->assertAttributeNotEmpty('_children', $mock); + } + + public function testCreateEmptyWithParent() + { + $parent = new Wootook\Core\Config\Node(); + $object = new Wootook\Core\Config\Node(array(), $parent); + + $this->assertAttributeEmpty('_children', $object); + $this->assertAttributeEquals($parent, '_parent', $object); + $this->assertEquals($parent, $object->getParent()); + } + + public function testDirectChildAccessWithObjectNotation() + { + $object = new Wootook\Core\Config\Node(); + + $object->testingAttribute = 'testing random data'; + $this->assertAttributeEquals(array('testing-attribute' => 'testing random data'), '_children', $object); + + $this->assertEquals('testing random data', $object->testingAttribute); + + $this->assertEquals(true, isset($object->testingAttribute)); + + unset($object->testingAttribute); + $this->assertAttributeEmpty('_children', $object); + } + + public function testDirectChildAccessWithArrayNotation() + { + $object = new Wootook\Core\Config\Node(); + + $object['testing-attribute'] = 'testing random data'; + $this->assertAttributeEquals(array('testing-attribute' => 'testing random data'), '_children', $object); + + $this->assertEquals('testing random data', $object['testing-attribute']); + + $this->assertEquals(true, isset($object['testing-attribute'])); + + unset($object['testing-attribute']); + $this->assertAttributeEmpty('_children', $object); + } + + public function testDirectChildSettingArrayNotationWithoutKey() + { + $object = new Wootook\Core\Config\Node(); + + $object[] = 'testing random data'; + $this->assertAttributeEquals(array('testing random data'), '_children', $object); + } + + public function testDirectChildGettingArrayNotationKeyNotExists() + { + $object = new Wootook\Core\Config\Node(); + + $this->assertEquals(null, $object['inexistent']); + } + + public function testSwitchingArrayNotationToObjectNotation() + { + $object = new Wootook\Core\Config\Node(); + + $object['testing-attribute'] = 'testing random data'; + $this->assertEquals('testing random data', $object->testingAttribute); + + $this->assertEquals(true, isset($object->testingAttribute)); + + unset($object->testingAttribute); + $this->assertAttributeEmpty('_children', $object); + } + + public function testSwitchingObjectNotationToArrayNotation() + { + $object = new Wootook\Core\Config\Node(); + + $object->testingAttribute = 'testing random data'; + $this->assertEquals('testing random data', $object['testing-attribute']); + + $this->assertEquals(true, isset($object['testing-attribute'])); + + unset($object['testing-attribute']); + $this->assertAttributeEmpty('_children', $object); + } + + public function testGetConfigByPath() + { + $parent = new Wootook\Core\Config\Node(); + $object = new Wootook\Core\Config\Node(array(), $parent); + + $parent->superChild = $object; + $object->testingAttribute = 'testing random data'; + + $this->assertEquals('testing random data', $parent->getConfig('super-child/testing-attribute')); + } + + public function testGetConfigAsArray() + { + $parent = new Wootook\Core\Config\Node(); + $object = new Wootook\Core\Config\Node(array(), $parent); + + $parent->superChild = $object; + $object->testingAttribute = 'testing random data'; + + $this->assertEquals(array('super-child' => array('testing-attribute' => 'testing random data')), $parent->toArray()); + } + + public function testCount() + { + $object = new Wootook\Core\Config\Node(array( + 'first-child' => 1, + 'second-child' => 2, + '3rd-child' => '3rd', + 'fourth-child' => '4th' + )); + + $this->assertCount(4, $object); + } + + protected function _getIteratorMock($class, $dataItems, $useKeys = false) + { + $mock = $this->getMock($class, array(), array($dataItems)); + + $callCounter = 0; + $mock->expects($this->at($callCounter++)) + ->method('rewind') + ; + foreach ($dataItems as $dataKey => $dataValue) { + $mock->expects($this->at($callCounter++)) + ->method('valid') + ->will($this->returnValue(true)) + ; + + $mock->expects($this->at($callCounter++)) + ->method('current') + ->will($this->returnValue($dataValue)) + ; + + if ($useKeys === true) { + $mock->expects($this->at($callCounter++)) + ->method('key') + ->will($this->returnValue($dataKey)) + ; + } + $mock->expects($this->at($callCounter++)) + ->method('next') + ; + } + $mock->expects($this->at($callCounter)) + ->method('valid') + ->will($this->returnValue(false)) + ; + + return $mock; + } + + /** + * @covers Wootook\Core\Config\Node::rewind + * @covers Wootook\Core\Config\Node::valid + * @covers Wootook\Core\Config\Node::current + * @covers Wootook\Core\Config\Node::next + */ + public function testIteratorOneItemWithoutKey() + { + $dataItems = array( + 'first-child' => 1, + ); + + $mock = $this->_getIteratorMock('Wootook\\Core\\Config\\Node', $dataItems); + + $counter = 0; + foreach ($mock as $value) { + $counter++; + } + + $this->assertEquals(1, $counter); + } + + /** + * @covers Wootook\Core\Config\Node::rewind + * @covers Wootook\Core\Config\Node::valid + * @covers Wootook\Core\Config\Node::key + * @covers Wootook\Core\Config\Node::current + * @covers Wootook\Core\Config\Node::next + */ + public function testIteratorOneItemWithKey() + { + $dataItems = array( + 'first-child' => 1, + ); + + $mock = $this->_getIteratorMock('Wootook\\Core\\Config\\Node', $dataItems, true); + + $counter = 0; + foreach ($mock as $key => $value) { + $counter++; + } + + $this->assertEquals(1, $counter); + } + + /** + * @covers Wootook\Core\Config\Node::rewind + * @covers Wootook\Core\Config\Node::valid + * @covers Wootook\Core\Config\Node::current + * @covers Wootook\Core\Config\Node::next + */ + public function testIteratorMultipleItemsWithoutKey() + { + $dataItems = array( + 'first-child' => 1, + 'second-child' => 2, + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + + $mock = $this->_getIteratorMock('Wootook\\Core\\Config\\Node', $dataItems); + + $counter = 0; + foreach ($mock as $value) { + $counter++; + } + + $this->assertEquals(4, $counter); + } + + /** + * @covers Wootook\Core\Config\Node::rewind + * @covers Wootook\Core\Config\Node::valid + * @covers Wootook\Core\Config\Node::key + * @covers Wootook\Core\Config\Node::current + * @covers Wootook\Core\Config\Node::next + */ + public function testIteratorMultipleItemsWithKey() + { + $dataItems = array( + 'first-child' => 1, + 'second-child' => 2, + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + + $mock = $this->_getIteratorMock('Wootook\\Core\\Config\\Node', $dataItems, true); + + $counter = 0; + foreach ($mock as $key => $value) { + $counter++; + } + + $this->assertEquals(4, $counter); + } + + /** + * @covers Wootook\Core\Config\Node::rewind + * @covers Wootook\Core\Config\Node::valid + * @covers Wootook\Core\Config\Node::key + * @covers Wootook\Core\Config\Node::current + * @covers Wootook\Core\Config\Node::next + */ + public function testIterator() + { + $dataItems = array( + 'first-child' => 1, + 'second-child' => 2, + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + + $mock = new Wootook\Core\Config\Node($dataItems); + + $counter = 0; + reset($dataItems); + foreach ($mock as $key => $value) { + $this->assertEquals(key($dataItems), $key); + $this->assertEquals(current($dataItems), $value); + next($dataItems); + $counter++; + } + + $this->assertEquals(4, $counter); + } + + public function testTwoLevelsHierarchyInitializationWithPathRequest() + { + $dataItems = array( + 'first-child' => 1, + 'second-child' => array( + 'first-sub-child' => 1, + 'second-sub-child' => 1, + ), + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + + $mock = new Wootook\Core\Config\Node($dataItems); + $this->assertInstanceOf('Wootook\\Core\\Config\\Node', $mock->getConfig('second-child')); + $this->assertEquals(1, $mock->getConfig('second-child/second-sub-child')); + } + + public function testTwoLevelsHierarchyInitializationWithInexistentPathRequest() + { + $dataItems = array( + 'first-child' => 1, + 'second-child' => array( + 'first-sub-child' => 1, + 'second-sub-child' => 1, + ), + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + + $mock = new Wootook\Core\Config\Node($dataItems); + $this->assertEquals(null, $mock->getConfig('second-child/third-inexisting-sub-child')); + } + + public function testTwoLevelsHierarchyInitializationTooDeepPathRequest() + { + $dataItems = array( + 'first-child' => 1, + 'second-child' => array( + 'first-sub-child' => 1, + 'second-sub-child' => 1, + ), + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + + $mock = new Wootook\Core\Config\Node($dataItems); + $this->setExpectedException('Wootook\\Core\\Exception\\RuntimeException'); + $mock->getConfig('second-child/second-sub-child/inexistent-depth-child'); + } + + public function testClone() + { + $dataItems = array( + 'first-child' => 1, + 'second-child' => array( + 'first-sub-child' => 1, + 'second-sub-child' => 1, + ), + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + + $object = new Wootook\Core\Config\Node($dataItems); + $clone = clone $object; + $this->assertEquals($dataItems, $clone->toArray()); + } + + public function testUseNumericAttribute() + { + $object = new Wootook\Core\Config\Node(); + $object->{1} = 'first-child'; + $this->assertEquals('first-child', $object->{1}); + $this->assertEquals(array(1 => 'first-child'), $object->toArray()); + } + + public function testMergeConfigs() + { + $rootDataItems = array( + 'first-child' => 1, + 'second-child' => array( + 'first-sub-child' => 1, + 'second-sub-child' => 2, + ), + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + $secondaryDataItems = array( + 'second-sub-child' => 3, + 'third-sub-child' => '72', + 'fourth-sub-child' => array( + 'random-level-child' => 54 + ), + ); + $expectedDataItems = array( + 'first-child' => 1, + 'second-child' => array( + 'first-sub-child' => 1, + 'second-sub-child' => 3, + 'third-sub-child' => '72', + 'fourth-sub-child' => array( + 'random-level-child' => 54 + ), + ), + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + + $root = new Wootook\Core\Config\Node($rootDataItems); + $secondary = new Wootook\Core\Config\Node($secondaryDataItems); + $root->secondChild->merge($secondary); + $this->assertEquals($expectedDataItems, $root->toArray()); + } + + public function testResetConfig() + { + $dataItems = array( + 'first-child' => 1, + 'second-child' => array( + 'first-sub-child' => 1, + 'second-sub-child' => 2, + ), + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + + $object = new Wootook\Core\Config\Node($dataItems); + $object->reset(); + $this->assertEmpty($object->toArray()); + } + + public function testSetConfig() + { + $dataItems = array( + 'first-child' => 1, + 'second-child' => array( + 'first-sub-child' => 1, + 'second-sub-child' => 3, + 'third-sub-child' => '72', + 'fourth-sub-child' => array( + 'random-level-child' => 54 + ), + ), + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + + $expected = array( + 'first-child' => 1, + 'second-child' => array( + 'first-sub-child' => 1, + 'second-sub-child' => 3, + 'third-sub-child' => '72', + 'fourth-sub-child' => array( + 'random-level-child' => 72 + ), + ), + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + + $object = new Wootook\Core\Config\Node($dataItems); + $object->setConfig('second-child/fourth-sub-child/random-level-child', 72); + $this->assertEquals($expected, $object->toArray()); + } + + public function testSetConfigExpectError() + { + $dataItems = array( + 'first-child' => 1, + 'second-child' => array( + 'first-sub-child' => 1, + 'second-sub-child' => 3, + 'third-sub-child' => '72', + 'fourth-sub-child' => array( + 'random-level-child' => 54 + ), + ), + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + + $expected = array( + 'first-child' => 1, + 'second-child' => array( + 'first-sub-child' => 1, + 'second-sub-child' => 3, + 'third-sub-child' => '72', + 'fourth-sub-child' => array( + 'random-level-child' => 72 + ), + ), + '3rd-child' => '3rd', + 'fourth-child' => '4th' + ); + + $object = new Wootook\Core\Config\Node($dataItems); + $this->setExpectedException('Wootook\\Core\\Exception\\RuntimeException'); + $object->setConfig('second-child/third-sub-child/random-inexisting-level-child', 72); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Condition/ConditionTest.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Condition/ConditionTest.php new file mode 100644 index 0000000..710fb05 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Condition/ConditionTest.php @@ -0,0 +1,205 @@ +_setUp(); + + $this->_conditionMockClassName = 'Wootook\\Core\\Database\\Sql\\Dml\\Condition\\Condition'; + } + + protected function _setUp() + { + $this->_adapterMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); + $this->_queryMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Dml\\DmlQuery', array($this->_adapterMock)); + $this->_statementMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Statement\\Statement', array($this->_adapterMock, $this->_queryMock)); + } + + protected function buildMock(Array $methods = array(), $callOriginalconstructor = true, $callOriginalClone = true) + { + return $this->getMockForAbstractClass($this->_conditionMockClassName, array(), '', $callOriginalconstructor, $callOriginalClone, true, $methods); + } + + public function callNonPublicMethod($object, $method, Array $params = array()) + { + $conditionMock = $this->buildMock(); + + $method = new \ReflectionMethod(get_class($object), $method); + $method->setAccessible(true); + + return $method->invokeArgs($conditionMock, $params); + } + + public function testMagicToString() + { + $conditionMock = $this->buildMock(array('render')); + $conditionMock->expects($this->once()) + ->method('render') + ->will($this->returnValue('foo')) + ; + + $this->assertInternalType('string', $conditionMock->__toString()); + } + + public function testMagicToStringWithRenderReturnsNull() + { + $conditionMock = $this->buildMock(array('render')); + $conditionMock->expects($this->once()) + ->method('render') + ->will($this->returnValue(null)) + ; + + $this->assertInternalType('string', $conditionMock->__toString()); + } + + public function testMagicToStringWithRenderReturnsInt() + { + $conditionMock = $this->buildMock(array('render')); + $conditionMock->expects($this->once()) + ->method('render') + ->will($this->returnValue(32)) + ; + + $this->assertInternalType('string', $conditionMock->__toString()); + } + + public function testMagicToStringWithRenderReturnsFloat() + { + $conditionMock = $this->buildMock(array('render')); + $conditionMock->expects($this->once()) + ->method('render') + ->will($this->returnValue(.1)) + ; + + $this->assertInternalType('string', $conditionMock->__toString()); + } + + public function testQueryAccessMethods() + { + $conditionMock = $this->buildMock(); + $adapter = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); + $query = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Dml\\DmlQuery', array($adapter)); + + $conditionMock->setQuery($query); + + $this->assertSame($query, $conditionMock->getQuery()); + } + + /** + * @expectedException \PHPUnit_Framework_Error + */ + public function testSetQueryWithInvalidParameter() + { + $conditionMock = $this->buildMock(); + $conditionMock->setQuery('SELECT * FROM my_table'); + } + + public function testPlaceholderAssignment() + { + $conditionMock = $this->buildMock(); + $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); + + $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + + $result = $this->callNonPublicMethod($conditionMock, '_getAllPlaceholders'); + $this->assertArrayHasKey(0, $result); + $this->assertSame($placeholderMock, $result[0]); + } + + public function testPlaceholderClearing() + { + $conditionMock = $this->buildMock(); + $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); + + $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + $this->callNonPublicMethod($conditionMock, '_clearPlaceholders'); + + $expected = array(); + $this->assertEquals($expected, $this->callNonPublicMethod($conditionMock, '_getAllPlaceholders')); + } + + public function testPlaceholderCallTrigger_beforePrepare() + { + $conditionMock = $this->buildMock(); + $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); + + $placeholderMock->expects($this->any()) + ->method('beforePrepare') + ->with($this->_statementMock) + ; + + $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + + $conditionMock->beforePrepare($this->_statementMock); + } + + public function testPlaceholderCallTrigger_afterPrepare() + { + $conditionMock = $this->buildMock(); + $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); + + $placeholderMock->expects($this->any()) + ->method('afterPrepare') + ->with($this->_statementMock) + ; + + $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + + $conditionMock->afterPrepare($this->_statementMock); + } + + public function testPlaceholderCallTrigger_beforeExecute() + { + $conditionMock = $this->buildMock(); + $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); + + $placeholderMock->expects($this->any()) + ->method('beforeExecute') + ->with($this->_statementMock) + ; + + $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + + $conditionMock->beforeExecute($this->_statementMock); + } + + public function testPlaceholderCallTrigger_afterExecute() + { + $conditionMock = $this->buildMock(); + $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); + + $placeholderMock->expects($this->any()) + ->method('afterExecute') + ->with($this->_statementMock) + ; + + $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + + $conditionMock->afterExecute($this->_statementMock); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Condition/LogicalOperatorTest.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Condition/LogicalOperatorTest.php new file mode 100644 index 0000000..5f71a77 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Condition/LogicalOperatorTest.php @@ -0,0 +1,67 @@ +_setUp(); + + $this->_conditionMockClassName = 'Wootook\\Core\\Database\\Sql\\Dml\\Condition\\LogicalOperator'; + } + + protected function buildMock(Array $methods = array(), $callOriginalconstructor = true, $callOriginalClone = true) + { + return $this->getMockForAbstractClass($this->_conditionMockClassName, array($this->_queryMock), '', $callOriginalconstructor, $callOriginalClone, true, $methods); + } + + public function testOperatorAccessMethods() + { + $conditionMock = $this->buildMock(array($this->_queryMock)); + + $conditionMock->setOperator(Dml\Section\WhereAware::OPERATOR_NOT); + $this->assertEquals(Dml\Section\WhereAware::OPERATOR_NOT, $conditionMock->getOperator()); + + $conditionMock->setOperator(Dml\Section\WhereAware::OPERATOR_AND); + $this->assertEquals(Dml\Section\WhereAware::OPERATOR_AND, $conditionMock->getOperator()); + + $conditionMock->setOperator(Dml\Section\WhereAware::OPERATOR_NAND); + $this->assertEquals(Dml\Section\WhereAware::OPERATOR_NAND, $conditionMock->getOperator()); + + $conditionMock->setOperator(Dml\Section\WhereAware::OPERATOR_OR); + $this->assertEquals(Dml\Section\WhereAware::OPERATOR_OR, $conditionMock->getOperator()); + + $conditionMock->setOperator(Dml\Section\WhereAware::OPERATOR_NOR); + $this->assertEquals(Dml\Section\WhereAware::OPERATOR_NOR, $conditionMock->getOperator()); + + $conditionMock->setOperator(Dml\Section\WhereAware::OPERATOR_XOR); + $this->assertEquals(Dml\Section\WhereAware::OPERATOR_XOR, $conditionMock->getOperator()); + + $conditionMock->setOperator(Dml\Section\WhereAware::OPERATOR_NXOR); + $this->assertEquals(Dml\Section\WhereAware::OPERATOR_NXOR, $conditionMock->getOperator()); + } + + public function testNewOperatorAssignment() + { + $conditionMock = $this->buildMock(array($this->_queryMock)); + $closure = function(\Wootook\Core\Database\Sql\Dml\Condition\LogicalOperator $conditions){ + return 'foo'; + }; + $conditionMock->addAllowedOperator('inexistent', $closure); + + $this->assertSame($closure, $conditionMock->getAllowedOperatorRenderer('inexistent')); + } + + /** + * @expectedException \Wootook\Core\Exception\InvalidArgumentException + */ + public function testInexistentOperatorAssignment() + { + $conditionMock = $this->buildMock(array($this->_queryMock)); + $conditionMock->setOperator('inexistent'); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/ColumnMock.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/ColumnMock.php new file mode 100644 index 0000000..d9e9321 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/ColumnMock.php @@ -0,0 +1,13 @@ +getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); + $this->_mock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\ColumnMock', array($adapter)); + } + + public function testAddColumnWithoutTableWithoutAlias() + { + $this->_mock->column('foo_column'); + + $expected = array( + array( + 'field' => 'foo_column', + 'alias' => null, + 'table' => null + ) + ); + $this->assertEquals($expected, $this->_mock->getPart(ColumnMock::COLUMNS)); + } + + public function testAddColumnWithTableWithoutAlias() + { + $this->_mock->column('foo_column', 'testing_table'); + + $expected = array( + array( + 'field' => 'foo_column', + 'alias' => null, + 'table' => 'testing_table' + ) + ); + + $this->assertEquals($expected, $this->_mock->getPart(ColumnMock::COLUMNS)); + } + + public function testAddOneTableWithoutTableWithAlias() + { + $this->_mock->column(array('my_alias' => 'foo_column')); + + $expected = array( + array( + 'field' => 'foo_column', + 'alias' => 'my_alias', + 'table' => null + ) + ); + $this->assertEquals($expected, $this->_mock->getPart(ColumnMock::COLUMNS)); + } + + public function testAddColumnWithTableWithAlias() + { + $this->_mock->column(array('my_alias' => 'foo_column'), 'testing_table'); + + $expected = array( + array( + 'field' => 'foo_column', + 'alias' => 'my_alias', + 'table' => 'testing_table' + ) + ); + + $this->assertEquals($expected, $this->_mock->getPart(ColumnMock::COLUMNS)); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/FromMock.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/FromMock.php new file mode 100644 index 0000000..ee9a1ec --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/FromMock.php @@ -0,0 +1,13 @@ +getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); + $this->_mock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\FromMock', array($adapter)); + } + + public function testSetOneTableWithoutSchemaWithoutAlias() + { + $this->_mock->from('foo_table'); + + $expected = array( + array( + 'table' => 'foo_table', + 'alias' => null, + 'schema' => null + ) + ); + $this->assertEquals($expected, $this->_mock->getPart(FromMock::FROM)); + } + + public function testSetTableWithSchemaWithoutAlias() + { + $this->_mock->from('foo_table', 'testing_schema'); + + $expected = array( + array( + 'table' => 'foo_table', + 'alias' => null, + 'schema' => 'testing_schema' + ) + ); + + $this->assertEquals($expected, $this->_mock->getPart(FromMock::FROM)); + } + + public function testSetOneTableWithoutSchemaWithAlias() + { + $this->_mock->from(array('my_alias' => 'foo_table')); + + $expected = array( + array( + 'table' => 'foo_table', + 'alias' => 'my_alias', + 'schema' => null + ) + ); + $this->assertEquals($expected, $this->_mock->getPart(FromMock::FROM)); + } + + public function testSetTableWithSchemaWithAlias() + { + $this->_mock->from(array('my_alias' => 'foo_table'), 'testing_schema'); + + $expected = array( + array( + 'table' => 'foo_table', + 'alias' => 'my_alias', + 'schema' => 'testing_schema' + ) + ); + + $this->assertEquals($expected, $this->_mock->getPart(FromMock::FROM)); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/IntoMock.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/IntoMock.php new file mode 100644 index 0000000..fe051ab --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/IntoMock.php @@ -0,0 +1,13 @@ +getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); + $this->_mock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\IntoMock', array($adapter)); + } + + public function testSetTableWithoutSchema() + { + $this->_mock->into('foo_table'); + + $expected = array( + 'table' => 'foo_table', + 'schema' => null + ); + $this->assertEquals($expected, $this->_mock->getPart(IntoMock::INTO)); + } + + public function testSetTableWithSchema() + { + $this->_mock->into('foo_table', 'testing_schema'); + + $expected = array( + 'table' => 'foo_table', + 'schema' => 'testing_schema' + ); + $this->assertEquals($expected, $this->_mock->getPart(IntoMock::INTO)); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/LimitMock.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/LimitMock.php new file mode 100644 index 0000000..9bd6c7c --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/LimitMock.php @@ -0,0 +1,13 @@ +getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); + $this->_mock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\LimitMock', array($adapter)); + } + + public function testSetLimitWithoutOffset() + { + $this->_mock->limit(100); + + $this->assertEquals(100, $this->_mock->getPart(LimitMock::LIMIT)); + $this->assertEquals(0, $this->_mock->getPart(LimitMock::OFFSET)); + } + + public function testSetLimitWithOffset() + { + $this->_mock->limit(100, 20); + + $this->assertEquals(100, $this->_mock->getPart(LimitMock::LIMIT)); + $this->assertEquals(20, $this->_mock->getPart(LimitMock::OFFSET)); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/ColumnMock.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/ColumnMock.php new file mode 100644 index 0000000..5d54b4b --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/ColumnMock.php @@ -0,0 +1,12 @@ +getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); + + $adapterMock->expects($this->any()) + ->method('quoteIdentifier') + ->will($this->returnArgument(0)) + ; + + $this->_queryMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\ColumnMock', array($adapterMock)); + $this->_rendererMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\ColumnMock'); + } + + public function testRenderColumnWithoutTableWithoutAlias() + { + $this->_queryMock->column('foo_column'); + + $this->assertRegExp('#\s*[a-zA-Z_][a-zA-Z0-9_]+\s*#', $this->_rendererMock->renderColumn($this->_queryMock)); + } + + public function testRenderColumnWithTableWithoutAlias() + { + $this->_queryMock->column('foo_column', 'testing_table'); + + $this->assertRegExp('#\s*[a-zA-Z_][a-zA-Z0-9_]+\.[a-zA-Z_][a-zA-Z0-9_]+\s*#', $this->_rendererMock->renderColumn($this->_queryMock)); + } + + public function testRenderOneTableWithoutTableWithAlias() + { + $this->_queryMock->column(array('my_alias' => 'foo_column')); + + $this->assertRegExp('#\s*[a-zA-Z_][a-zA-Z0-9_]+\s+AS\s+[a-zA-Z_][a-zA-Z0-9_]+\s*#', $this->_rendererMock->renderColumn($this->_queryMock)); + } + + public function testRenderColumnWithTableWithAlias() + { + $this->_queryMock->column(array('my_alias' => 'foo_column'), 'testing_table'); + + $this->assertRegExp('#\s*[a-zA-Z_][a-zA-Z0-9_]+\.[a-zA-Z_][a-zA-Z0-9_]+\s+AS\s+[a-zA-Z_][a-zA-Z0-9_]+\s*#', $this->_rendererMock->renderColumn($this->_queryMock)); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/FromMock.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/FromMock.php new file mode 100644 index 0000000..2ad922a --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/FromMock.php @@ -0,0 +1,12 @@ +getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); + + $adapterMock->expects($this->any()) + ->method('quoteIdentifier') + ->will($this->returnArgument(0)) + ; + + $this->_queryMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\FromMock', array($adapterMock)); + $this->_rendererMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\FromMock'); + } + + public function testRenderOneTableWithoutSchemaWithoutAlias() + { + $this->_queryMock->from('foo_table'); + + $this->assertRegExp('#\s*FROM\s*[a-zA-Z_][a-zA-Z0-9_]+\s*#', $this->_rendererMock->renderFrom($this->_queryMock)); + } + + public function testRenderTableWithSchemaWithoutAlias() + { + $this->_queryMock->from('foo_table', 'testing_schema'); + + $this->assertRegExp('#\s*FROM\s*[a-zA-Z_][a-zA-Z0-9_]+\.[a-zA-Z_][a-zA-Z0-9_]+\s*#', $this->_rendererMock->renderFrom($this->_queryMock)); + } + + public function testRenderOneTableWithoutSchemaWithAlias() + { + $this->_queryMock->from(array('my_alias' => 'foo_table')); + + $this->assertRegExp('#\s*FROM\s*[a-zA-Z_][a-zA-Z0-9_]+\s+AS\s+[a-zA-Z_][a-zA-Z0-9_]+\s*#', $this->_rendererMock->renderFrom($this->_queryMock)); + } + + public function testRenderTableWithSchemaWithAlias() + { + $this->_queryMock->from(array('my_alias' => 'foo_table'), 'testing_schema'); + + $this->assertRegExp('#\s*FROM\s*[a-zA-Z_][a-zA-Z0-9_]+\.[a-zA-Z_][a-zA-Z0-9_]+\s+AS\s+[a-zA-Z_][a-zA-Z0-9_]+\s*#', $this->_rendererMock->renderFrom($this->_queryMock)); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/IntoMock.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/IntoMock.php new file mode 100644 index 0000000..8f5b817 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/IntoMock.php @@ -0,0 +1,12 @@ +getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); + + $adapterMock->expects($this->any()) + ->method('quoteIdentifier') + ->will($this->returnArgument(0)) + ; + + $this->_queryMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\IntoMock', array($adapterMock)); + $this->_rendererMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\IntoMock'); + } + + public function testRenderTableWithoutSchema() + { + $this->_queryMock->into('foo_table'); + + $this->assertRegExp('#\s*foo_table\s*#', $this->_rendererMock->renderInto($this->_queryMock)); + } + + public function testRenderTableWithSchema() + { + $this->_queryMock->into('foo_table', 'testing_schema'); + + $this->assertRegExp('#\s*testing_schema\.foo_table\s*#', $this->_rendererMock->renderInto($this->_queryMock)); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/LimitMock.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/LimitMock.php new file mode 100644 index 0000000..c8d0c78 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/LimitMock.php @@ -0,0 +1,12 @@ +getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); + $this->_queryMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\LimitMock', array($adapter)); + $this->_rendererMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\LimitMock'); + } + + public function testRenderLimitWithoutOffset() + { + $this->_queryMock->limit(100); + + $this->assertRegExp('#\s*LIMIT\s+\d+\s*#', $this->_rendererMock->renderLimit($this->_queryMock)); + } + + public function testRenderLimitWithOffset() + { + $this->_queryMock->limit(100, 20); + + $this->assertRegExp('#\s*LIMIT\s+\d+\s*,\s*\d+\s*#', $this->_rendererMock->renderLimit($this->_queryMock)); + } + + public function testRenderNoLimit() + { + $this->assertEmpty($this->_rendererMock->renderLimit($this->_queryMock)); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/SetMock.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/SetMock.php new file mode 100644 index 0000000..29637c0 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/SetMock.php @@ -0,0 +1,12 @@ +getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); + + $adapterMock->expects($this->any()) + ->method('quoteIdentifier') + ->will($this->returnArgument(0)) + ; + + $adapterMock->expects($this->any()) + ->method('quote') + ->will($this->returnArgument(0)) + ; + + $this->_queryMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\SetMock', array($adapterMock)); + $this->_rendererMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\SetMock'); + } + + public function testRenderFieldAndValue() + { + $this->_queryMock->set('foo_field', 18); + + $this->assertRegExp('#\s*SET\s*foo_field=18\s*#', $this->_rendererMock->renderSet($this->_queryMock)); + } + + public function testRenderFieldAndValueWithPlaceholder() + { + $placeholder = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); + + $placeholder->expects($this->any()) + ->method('__toString') + ->will($this->returnValue('18')) + ; + + $this->_queryMock->set('foo_field', $placeholder); + + $this->assertRegExp('#\s*SET\s*foo_field=18\s*#', $this->_rendererMock->renderSet($this->_queryMock)); + } + + public function testRenderMultipleFieldAndValueAsArray() + { + $this->_queryMock->set(array( + 'id' => 18, + 'foo_field' => 'test', + 'example' => null + )); + + $this->assertRegExp('#\s*SET\s+[a-zA-Z_][a-zA-Z0-9_]*\s*=\s*[0-9]+\s*,\s*[a-zA-Z_][a-zA-Z0-9_]*\s*=\s*[a-zA-Z]+\s*,\s*[a-zA-Z_][a-zA-Z0-9_]*\s*=\s*NULL\s*#', $this->_rendererMock->renderSet($this->_queryMock)); + } + + public function testRenderNoField() + { + $this->assertEmpty($this->_rendererMock->renderSet($this->_queryMock)); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/SetMock.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/SetMock.php new file mode 100644 index 0000000..313fc09 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/SetMock.php @@ -0,0 +1,13 @@ +getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); + $this->_mock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\SetMock', array($adapter)); + } + + public function testSetFieldAndValue() + { + $this->_mock->set('foo_field', 18); + + $expected = array( + array( + 'value' => 18, + 'field' => 'foo_field' + ) + ); + + $this->assertEquals($expected, $this->_mock->getPart(SetMock::SET)); + } + + public function testSetFieldAndValueWithPlaceholder() + { + $placeholder = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); + + $this->_mock->set('foo_field', $placeholder); + + $expected = array( + array( + 'value' => $placeholder, + 'field' => 'foo_field' + ) + ); + + $this->assertEquals($expected, $this->_mock->getPart(SetMock::SET)); + } + + public function testSetMultipleFieldAndValueAsArray() + { + $this->_mock->set(array( + 'id' => 18, + 'foo_field' => 'test', + 'example' => null + )); + + $expected = array( + array( + 'value' => 18, + 'field' => 'id' + ), + array( + 'value' => 'test', + 'field' => 'foo_field' + ), + array( + 'value' => null, + 'field' => 'example' + ) + ); + + $this->assertEquals($expected, $this->_mock->getPart(SetMock::SET)); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/WhereMock.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/WhereMock.php new file mode 100644 index 0000000..7bf52ef --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/WhereMock.php @@ -0,0 +1,13 @@ +getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); + $this->_mock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\WhereMock', array($adapter)); + } + + public function testAddScalarCondition() + { + $this->markTestIncomplete(); + $this->_mock->where('testing_field', 23); + + $expected = array( + array( + 'field' => 'foo_column', + 'alias' => null, + 'table' => null + ) + ); + $this->assertEquals($expected, $this->_mock->getPart(WhereMock::WHERE)); + } + + public function testAddColumnWithTableWithoutAlias() + { + $this->markTestIncomplete(); + $this->_mock->where('testing_field', 23); + + $expected = array( + array( + 'field' => 'foo_column', + 'alias' => null, + 'table' => 'testing_table' + ) + ); + + $this->assertEquals($expected, $this->_mock->getPart(WhereMock::WHERE)); + } + + public function testAddOneTableWithoutTableWithAlias() + { + $this->markTestIncomplete(); + $this->_mock->where('testing_field', 23); + + $expected = array( + array( + 'field' => 'foo_column', + 'alias' => 'my_alias', + 'table' => null + ) + ); + $this->assertEquals($expected, $this->_mock->getPart(WhereMock::WHERE)); + } + + public function testAddColumnWithTableWithAlias() + { + $this->markTestIncomplete(); + $this->_mock->where('testing_field', 23); + + $expected = array( + array( + 'field' => 'foo_column', + 'alias' => 'my_alias', + 'table' => 'testing_table' + ) + ); + + $this->assertEquals($expected, $this->_mock->getPart(WhereMock::WHERE)); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DateTime/DateTimeTest.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DateTime/DateTimeTest.php new file mode 100644 index 0000000..4aa4576 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DateTime/DateTimeTest.php @@ -0,0 +1,42 @@ +add(new \DateInterval('P15D')); // Period of 15 Days + $this->assertEquals('2010-12-11', $date->format('Y-m-d')); + } + + public function testSupportsSubtractionOfMonths() + { + $date = new \DateTime('2010-11-26'); + $date->sub(new \DateInterval('P20M')); // Period of 15 Days + $this->assertEquals('2009-03-26', $date->format('Y-m-d')); + } + + // takes into account leap years, number of days of the month, etc. + public function testSupportsDifferenceOfDates() + { + $stopDate = new \DateTime('2010-11-26'); + $startDate = new \DateTime('2010-10-28'); + $duration = $stopDate->diff($startDate); + $this->assertEquals('29', $duration->format('%d')); + } + + // never use mktime() again + public function testSupportsAlsoTimeAndOperatorOverloading() + { + $datetime = new \DateTime('2010-11-26 12:00'); + $this->assertTrue($datetime > new \DateTime('2010-11-26 11:00')); + $this->assertTrue($datetime == new \DateTime('2010-11-26 12:00')); + $this->assertTrue($datetime < new \DateTime('2010-11-26 13:00')); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DateTime/DateTimeTest.php.old b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DateTime/DateTimeTest.php.old new file mode 100644 index 0000000..300a7f7 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DateTime/DateTimeTest.php.old @@ -0,0 +1,243 @@ +assertEquals(1338874542, $object->getTimestamp()); + + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('@1338906942'); + $this->assertEquals(1338906942, $object->getTimestamp()); + } + + public function testParseStringGeneralDatabaseMySqlDateTimeFormat() + { + // 2012-06-05 05:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('2012-06-05 05:35:42', 'Y-m-d H:i:s'); + $this->assertEquals(1338874542, $object->getTimestamp()); + + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('2012-06-05 14:35:42', 'Y-m-d H:i:s'); + $this->assertEquals(1338906942, $object->getTimestamp()); + + // 2012-06-05 00:00:00 +000 + $object = new Wootook\Core\DateTime\DateTime('2012-06-05 02:35:42', 'Y-m-d'); + $this->assertEquals(1338854400, $object->getTimestamp()); + } + + public function testParseStringGeneralDatabaseIsoDateTimeFormat() + { + // 2012-06-05 05:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('2012-06-05T05:35:42', 'Y-m-d\\TH:i:s'); + $this->assertEquals(1338874542, $object->getTimestamp()); + + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('2012-06-05T14:35:42', 'Y-m-d\\TH:i:s'); + $this->assertEquals(1338906942, $object->getTimestamp()); + + // 2012-06-05 00:00:00 +000 + $object = new Wootook\Core\DateTime\DateTime('2012-06-05 02:35:42', 'Y-m-d'); + $this->assertEquals(1338854400, $object->getTimestamp()); + } + + public function testParseStringAmPmWhenAm() + { + // 2012-06-05 05:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('2012-06-05 05:35:42 AM', 'Y-m-d h:i:s A'); + $this->assertEquals(1338874542, $object->getTimestamp()); + + // 2012-06-05 05:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('2012-06-05 05:35:42 am', 'Y-m-d h:i:s a'); + $this->assertEquals(1338874542, $object->getTimestamp()); + } + + public function testParseStringAmPmWhenPm() + { + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('2012-06-05 02:35:42 PM', 'Y-m-d h:i:s A'); + $this->assertEquals(1338906942, $object->getTimestamp()); + + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('2012-06-05 02:35:42 pm', 'Y-m-d h:i:s a'); + $this->assertEquals(1338906942, $object->getTimestamp()); + } + + public function testParseStringShortLiteralDaysMonths() + { + // 2012-06-05 00:00:00 +000 + $object = new Wootook\Core\DateTime\DateTime('Tue Jun 5, 2012', 'D M j, Y'); + $this->assertEquals(1338854400, $object->getTimestamp()); + } + + public function testParseStringLongLiteralDaysMonthsWithErrors() + { + // 2012-06-05 00:00:00 +000 + $object = new Wootook\Core\DateTime\DateTime('Tuesday June 5, 2012', 'D M j, Y'); + $this->assertEquals(1338854400, $object->getTimestamp()); + } + + public function testParseStringLongLiteralDaysMonthsWithTypoError() + { + // 2012-06-05 00:00:00 +000 + $object = new Wootook\Core\DateTime\DateTime('Tusday Jume 5, 2012', 'D M j, Y'); + $this->assertAttributeNotEquals(1338854400, '_datetime', $object); + } + + public function testParseStringLiteralDaysMonthsAmPm() + { + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('Tue Jun 5, 2012 02:35:42 pm', 'D M j, Y H:i:s a'); + $this->assertEquals(1338906942, $object->getTimestamp()); + } + + public function testToStringLiteralDaysMonths() + { + // 2012-06-05 02:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('@1338906942'); + $this->assertEquals('Tue Jun 5, 2012 02:35:42 pm', $object->toString('D M j, Y h:i:s a')); + } + + public function testToStringGeneral() + { + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('@1338906942'); + $this->assertEquals('2012-06-05 14:35:42', $object->toString('Y-m-d H:i:s')); + } + + public function testToStringIso8601() + { + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('@1338906942'); + $this->assertEquals('2012-06-05T14:35:42+0000', $object->getIso()); + } + + public function testDateOperations() + { + $this->markTestSkipped(); + return; + + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('@1338906942'); + $object->add(10, Wootook\Core\DateTime\DateTime::SECOND); + $this->assertEquals('2012-06-05 14:35:52', $object->toString('Y-m-d H:i:s')); + + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('@1338906942'); + $object->add(70, Wootook\Core\DateTime\DateTime::SECOND); + $this->assertEquals('2012-06-05 14:36:52', $object->toString('Y-m-d H:i:s')); + + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('@1338906942'); + $object->sub(10, Wootook\Core\DateTime\DateTime::MINUTE); + $this->assertEquals('2012-06-05 14:25:42', $object->toString('Y-m-d H:i:s')); + + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('@1338906942'); + $object->sub(70, Wootook\Core\DateTime\DateTime::MINUTE); + $this->assertEquals('2012-06-05 13:25:42', $object->toString('Y-m-d H:i:s')); + + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('@1338906942'); + $object->set(25, Wootook\Core\DateTime\DateTime::DAY); + $this->assertEquals('2012-06-25 14:35:42', $object->toString('Y-m-d H:i:s')); + + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('@1338906942'); + // 2012-06-05 00:00:00 +000 + $object->set(1338854400, Wootook\Core\DateTime\DateTime::TIMESTAMP); + $this->assertEquals('2012-06-05 00:00:00', $object->toString('Y-m-d H:i:s')); + + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('@1338906942'); + $object->add(3600, Wootook\Core\DateTime\DateTime::TIMESTAMP); + $this->assertEquals('2012-06-05 15:35:42', $object->toString('Y-m-d H:i:s')); + + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('@1338906942'); + $object->sub(3600, Wootook\Core\DateTime\DateTime::TIMESTAMP); + $this->assertEquals('2012-06-05 13:35:42', $object->toString('Y-m-d H:i:s')); + } + + public function testDateDifference() + { + // 2012-06-05 14:35:42 +000 + $objectOne = new Wootook\Core\DateTime\DateTime('@1338906942'); + // 2012-06-05 00:00:00 +000 + $objectTwo = new Wootook\Core\DateTime\DateTime('@1338854400'); + + $this->assertInstanceOf('DateInterval', $diff = $objectOne->diff($objectTwo)); + //$this->assertInstanceOf('Wootook\\Core\\DateTime\\DateInterval', $diff = $objectOne->diff($objectTwo)); + $this->assertEquals(0, $diff->y); + $this->assertEquals(0, $diff->m); + $this->assertEquals(0, $diff->d); + $this->assertEquals(14, $diff->h); + $this->assertEquals(35, $diff->i); + $this->assertEquals(42, $diff->s); + $this->assertEquals(1, $diff->invert); + $this->assertEquals(0, $diff->days); + /* + $this->assertEquals(52542, $objectOne->diff($objectTwo, true)); + $this->assertEquals(-52542, $objectTwo->diff($objectOne, true)); + $this->assertEquals(0, $objectOne->diff($objectOne, true)); + */ + } + + public function testParseStringErrorMeridiem() + { + // 2012-06-05 05:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('2012-06-05 05:35:42 DX', 'Y-m-d h:i:s A'); + $this->assertEquals('2012-06-05 05:35:42', $object->toString('Y-m-d H:i:s')); + } + + public function testParseStringShortYear() + { + // 2012-06-05 05:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('12-06-05 05:35:42', 'y-m-d h:i:s A'); + $this->assertEquals('2012-06-05 05:35:42', $object->toString('Y-m-d H:i:s')); + + // 1969-06-05 05:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('69-06-05 05:35:42', 'y-m-d h:i:s A'); + $this->assertEquals('1969-06-05 05:35:42', $object->toString('Y-m-d H:i:s')); + } + + public function testDateEarlierLater() + { + // 2012-06-05 14:35:42 +000 + $objectOne = new Wootook\Core\DateTime\DateTime('@1338906942'); + // 2012-06-05 00:00:00 +000 + $objectTwo = new Wootook\Core\DateTime\DateTime('@1338854400'); + + $this->assertFalse($objectOne->isEarlier($objectTwo)); + $this->assertFalse($objectTwo->isLater($objectOne)); + + $this->assertFalse($objectTwo->isLater()); + $this->assertTrue($objectTwo->isEarlier()); + } + + public function testGetTimestamp() + { + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('2012-06-05 14:35:42', 'Y-m-d H:i:s'); + + $this->assertEquals(1338906942, $object->getTimestamp()); + } + + public function testMagicMethodToString() + { + // 2012-06-05 14:35:42 +000 + $object = new Wootook\Core\DateTime\DateTime('@1338906942'); + + $this->assertEquals('2012-06-05T14:35:42+00:00', $object.''); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/ArgumentDefinitionTest.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/ArgumentDefinitionTest.php new file mode 100644 index 0000000..e3169e6 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/ArgumentDefinitionTest.php @@ -0,0 +1,186 @@ +_methodDefinitionMock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', + array(), array(), '', false); + } + + public function testBuildNewWithoutRegistryWithParameterId_bindValue() + { + $reflectionParameter = new \ReflectionParameter(array(__CLASS__, 'myTestingMethod'), 0); + + $this->_methodDefinitionMock->expects($this->any()) + ->method('getArgumentReflector') + ->with(0) + ->will($this->returnValue($reflectionParameter)) + ; + + $definition = new Definition\ArgumentDefinition($this->_methodDefinitionMock, 0); + + $definition->bindValue(36); + + $compiledArguments = array(); + $definition->compileInto($compiledArguments); + + $this->assertEquals(array(36), $compiledArguments); + } + + public function testBuildNewWithoutRegistryWithParameterName_bindValue() + { + $reflectionParameter = new \ReflectionParameter(array(__CLASS__, 'myTestingMethod'), 0); + + $this->_methodDefinitionMock->expects($this->any()) + ->method('getArgumentReflector') + ->with('param1') + ->will($this->returnValue($reflectionParameter)) + ; + + $definition = new Definition\ArgumentDefinition($this->_methodDefinitionMock, 'param1'); + + $definition->bindValue(36); + + $compiledArguments = array(); + $definition->compileInto($compiledArguments); + + $this->assertEquals(array(36), $compiledArguments); + } + + public function testBuildNewWithRegistryWithParameterId_bindValue() + { + $reflectionParameter = new \ReflectionParameter(array(__CLASS__, 'myTestingMethod'), 0); + + $this->_methodDefinitionMock->expects($this->any()) + ->method('getArgumentReflector') + ->with(0) + ->will($this->returnValue($reflectionParameter)) + ; + + $registry = $this->getMock('DependencyInjection\Registry'); + $definition = new Definition\ArgumentDefinition($this->_methodDefinitionMock, 0); + + $definition->bindValue(36); + + $compiledArguments = array(); + $definition->compileInto($compiledArguments); + + $this->assertEquals(array(36), $compiledArguments); + } + + public function testBuildNewWithRegistryWithParameterName_bindValue() + { + $reflectionParameter = new \ReflectionParameter(array(__CLASS__, 'myTestingMethod'), 0); + + $this->_methodDefinitionMock->expects($this->any()) + ->method('getArgumentReflector') + ->with('param1') + ->will($this->returnValue($reflectionParameter)) + ; + + $definition = new Definition\ArgumentDefinition($this->_methodDefinitionMock, 'param1'); + + $definition->bindValue(36); + + $compiledArguments = array(); + $definition->compileInto($compiledArguments); + + $this->assertEquals(array(36), $compiledArguments); + } + + public function testBuildNewWithoutRegistryWithParameterId_bindVariable() + { + $reflectionParameter = new \ReflectionParameter(array(__CLASS__, 'myTestingMethod'), 0); + + $this->_methodDefinitionMock->expects($this->any()) + ->method('getArgumentReflector') + ->with(0) + ->will($this->returnValue($reflectionParameter)) + ; + + $definition = new Definition\ArgumentDefinition($this->_methodDefinitionMock, 0); + + $var = 36; + $definition->bindVariable($var); + + $compiledArguments = array(); + $definition->compileInto($compiledArguments); + + $this->assertEquals(array(&$var), $compiledArguments); + } + + public function testBuildNewWithoutRegistryWithParameterName_bindVariable() + { + $reflectionParameter = new \ReflectionParameter(array(__CLASS__, 'myTestingMethod'), 0); + + $this->_methodDefinitionMock->expects($this->any()) + ->method('getArgumentReflector') + ->with('param1') + ->will($this->returnValue($reflectionParameter)) + ; + + $definition = new Definition\ArgumentDefinition($this->_methodDefinitionMock, 'param1'); + + $var = 36; + $definition->bindVariable($var); + + $compiledArguments = array(); + $definition->compileInto($compiledArguments); + + $this->assertEquals(array(&$var), $compiledArguments); + } + + public function testBuildNewWithoutRegistryWithParameterId_bindRegistryEntry() + { + $reflectionParameter = new \ReflectionParameter(array(__CLASS__, 'myTestingMethod'), 0); + + $this->_methodDefinitionMock->expects($this->any()) + ->method('getArgumentReflector') + ->with(0) + ->will($this->returnValue($reflectionParameter)) + ; + + $definition = new Definition\ArgumentDefinition($this->_methodDefinitionMock, 0); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\RuntimeException'); + $definition->bindRegistryEntry('testing'); + + $compiledArguments = array(); + $definition->compileInto($compiledArguments); + } + + public function testBuildNewWithoutRegistryWithParameterName_bindRegistryEntry() + { + $reflectionParameter = new \ReflectionParameter(array(__CLASS__, 'myTestingMethod'), 0); + + $this->_methodDefinitionMock->expects($this->any()) + ->method('getArgumentReflector') + ->with('param1') + ->will($this->returnValue($reflectionParameter)) + ; + + $definition = new Definition\ArgumentDefinition($this->_methodDefinitionMock, 'param1'); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\RuntimeException'); + $definition->bindRegistryEntry('testing'); + + $compiledArguments = array(); + $definition->compileInto($compiledArguments); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/ClassDefinitionTest.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/ClassDefinitionTest.php new file mode 100644 index 0000000..7d7fdd8 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/ClassDefinitionTest.php @@ -0,0 +1,202 @@ +setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\BadMethodCallException'); + new Definition\ClassDefinition('InexistentClass'); + } + + public function testClassDefinitionInstantiation_withSpecialMethodDefinitionClassName() + { + $methodDefinitionClassName = \uniqid('WootookTest_Core_DependencyInjection_Mock_MethodDefinition_TestNewInstance_'); + $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), $methodDefinitionClassName, false); + + $definition = new Definition\ClassDefinition(__CLASS__, $methodDefinitionClassName); + + $this->assertInstanceOf($methodDefinitionClassName, $definition->getMethodDefinition(__FUNCTION__)); + } + + public function testClassDefinitionInstantiation_assignNewMethodDefinitionInstance() + { + $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), '', false); + + $definition = new Definition\ClassDefinition(__CLASS__); + $definition->setMethodDefinition(__FUNCTION__, $mock); + + $this->assertSame($mock, $definition->getMethodDefinition(__FUNCTION__)); + } + + public function testGetMethodDefinition_withInvalidMethodName() + { + $definition = new Definition\ClassDefinition(__CLASS__); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); + $definition->getMethodDefinition(42); + } + + public function testSetMethodDefinition_withInvalidMethodName() + { + $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), '', false); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); + + $definition = new Definition\ClassDefinition(__CLASS__); + $definition->setMethodDefinition(42, $mock); + } + + public function testGetAllMethodDefinitions() + { + $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), '', false); + + $definition = new Definition\ClassDefinition(__CLASS__); + $definition->setMethodDefinition('fooMethod', $mock); + + $expected = array( + 'fooMethod' => $mock + ); + $this->assertEquals($expected, $definition->getAllMethodDefinitions()); + } + + public function testReset() + { + $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), '', false); + + $definition = new Definition\ClassDefinition(__CLASS__); + $definition->setMethodDefinition('fooMethod', $mock); + + $definition->reset(); + + $this->assertEquals(array(), $definition->getAllMethodDefinitions()); + } + + public function testClassDefinitionAccessors_getReflector() + { + $definition = new Definition\ClassDefinition(__CLASS__); + + $this->assertInstanceOf('\\ReflectionClass', $definition->getReflector()); + } + + public function testClassDefinitionMutators_setReflector() + { + $definition = new Definition\ClassDefinition(__CLASS__); + $reflector = new \ReflectionClass(__CLASS__); + $definition->setReflector($reflector); + + $this->assertSame($reflector, $definition->getReflector()); + } + + public function testNewInstance_hasNoConstructor() + { + $this->markTestSkipped("Method ReflectionClass::newInstance() couldn't be mocked due to API<->Reflection inconsistencies."); + + $reflectionClassMock = $this->getMock('ReflectionClass', array('hasMethod', 'newInstance'), array('stdClass')); + $reflectionClassMock->expects($this->once()) + ->method('hasMethod') + ->with('__construct') + ->will($this->returnValue(false)) + ; + $reflectionClassMock->expects($this->once()) + ->method('newInstance') + ->will($this->returnValue(new \stdClass())) + ; + + $classDefinition = new Definition\ClassDefinition(__CLASS__); + $classDefinition->setReflector($reflectionClassMock); + + $this->assertInstanceOf('stdClass', $classDefinition->newInstance()); + } + + public function testNewInstance_usingConstructor() + { + $expectedArguments = array(42); + + $reflectionClassMock = $this->getMock('ReflectionClass', array('hasMethod', 'newInstanceArgs'), array('stdClass')); + $reflectionClassMock->expects($this->once()) + ->method('hasMethod') + ->with('__construct') + ->will($this->returnValue(true)) + ; + $reflectionClassMock->expects($this->once()) + ->method('newInstanceArgs') + ->with($expectedArguments) + ->will($this->returnValue(new \stdClass())) + ; + + $classDefinition = new Definition\ClassDefinition(__CLASS__); + $classDefinition->setReflector($reflectionClassMock); + + $methodDefinitionMock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array('compileArgs'), array(), '', false); + $methodDefinitionMock->expects($this->once()) + ->method('compileArgs') + ->will($this->returnValue(array(42))) + ; + $classDefinition->setMethodDefinition('__construct', $methodDefinitionMock); + + $this->assertInstanceOf('stdClass', $classDefinition->newInstance()); + } + + public function testNewInstance_usingNonPublicConstructor() + { + $reflectionClassMock = $this->getMock('ReflectionClass', array('hasMethod', 'newInstanceArgs'), array('stdClass')); + $reflectionClassMock->expects($this->once()) + ->method('hasMethod') + ->with('__construct') + ->will($this->returnValue(true)) + ; + $reflectionClassMock->expects($this->once()) + ->method('newInstanceArgs') + ->will($this->throwException($this->getMock('ReflectionException'))) + ; + + $classDefinition = new Definition\ClassDefinition(__CLASS__); + $classDefinition->setReflector($reflectionClassMock); + + $methodDefinitionMock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array('compileArgs'), array(), '', false); + $methodDefinitionMock->expects($this->once()) + ->method('compileArgs') + ->will($this->returnValue(array(42))) + ; + $classDefinition->setMethodDefinition('__construct', $methodDefinitionMock); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\RuntimeException'); + + $this->assertInstanceOf('stdClass', $classDefinition->newInstance()); + } + + public function testNewInstanceWithoutConstructor() + { + $reflectionClassMock = $this->getMock('ReflectionClass', array('newInstanceWithoutConstructor'), array('stdClass')); + $reflectionClassMock->expects($this->once()) + ->method('newInstanceWithoutConstructor') + ->will($this->returnValue(new \stdClass())) + ; + + $classDefinition = new Definition\ClassDefinition(__CLASS__); + $classDefinition->setReflector($reflectionClassMock); + + $this->assertInstanceOf('stdClass', $classDefinition->newInstanceWithoutConstructor()); + } + + public function testNewInstanceWithoutConstructor_throwsException() + { + $reflectionClassMock = $this->getMock('ReflectionClass', array('newInstanceWithoutConstructor'), array('stdClass')); + $reflectionClassMock->expects($this->once()) + ->method('newInstanceWithoutConstructor') + ->will($this->throwException($this->getMock('ReflectionException'))) + ; + + $classDefinition = new Definition\ClassDefinition(__CLASS__); + $classDefinition->setReflector($reflectionClassMock); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\RuntimeException'); + + $this->assertInstanceOf('stdClass', $classDefinition->newInstanceWithoutConstructor()); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/MethodDefinitionTest.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/MethodDefinitionTest.php new file mode 100644 index 0000000..966a511 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/MethodDefinitionTest.php @@ -0,0 +1,113 @@ +getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array(), array(), '', false); + + $mock->expects($this->once()) + ->method('getReflector') + ->will($this->returnValue(new \ReflectionClass(__CLASS__))) + ; + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\BadMethodCallException'); + new Definition\MethodDefinition($mock, 'inexistentMethod'); + } + + public function testMethodDefinitionInstantiation_withoutRegistry_withSpecialArgumentDefinitionClassName() + { + $argumentDefinitionClassName = \uniqid('WootookTest_Core_DependencyInjection_Mock_ArgumentDefinition_TestNewInstance_'); + $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ArgumentDefinition', array(), array(), $argumentDefinitionClassName, false); + + $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array(), array(), '', false); + + $mock->expects($this->once()) + ->method('getReflector') + ->will($this->returnValue(new \ReflectionClass(__CLASS__))) + ; + + $definition = new Definition\MethodDefinition($mock, 'methodToTest', null, $argumentDefinitionClassName); + + $this->assertInstanceOf($argumentDefinitionClassName, $definition->getArgumentDefinition('fooArgumentOne')); + } + + public function testMethodDefinitionAccessors_getReflector() + { + $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array(), array(), '', false); + + $mock->expects($this->once()) + ->method('getReflector') + ->will($this->returnValue(new \ReflectionClass(__CLASS__))) + ; + + $definition = new Definition\MethodDefinition($mock, __FUNCTION__); + + $this->assertInstanceOf('\\ReflectionMethod', $definition->getReflector()); + } + + public function testMethodDefinitionMutators_setReflector() + { + $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array(), array(), '', false); + + $mock->expects($this->once()) + ->method('getReflector') + ->will($this->returnValue(new \ReflectionClass(__CLASS__))) + ; + + $definition = new Definition\MethodDefinition($mock, __FUNCTION__); + $reflector = new \ReflectionMethod(__CLASS__, __FUNCTION__); + $definition->setReflector($reflector); + + $this->assertSame($reflector, $definition->getReflector()); + } + /* + public function testBuildWithoutConstructorArguments_callBindConstructorArgumentValue() + { + $definition = new Definition\ClassDefinition('MyNamespace\\MyClass'); + + $definition->bindConstructorArgumentValue(0, 36); + $this->assertEquals(36, $definition->getConstructorArgument(0)); + } + + public function testBuildWithoutConstructorArguments_callBindConstructorArgumentVariable() + { + $definition = new Definition\ClassDefinition('MyNamespace\\MyClass'); + + $variable = 36; + $definition->bindConstructorArgumentVariable(0, $variable); + + $variable = 12; + $this->assertEquals(12, $definition->getConstructorArgument(0)); + $this->assertSame($variable, $definition->getConstructorArgument(0)); + } + + public function testBuildWithoutConstructorArguments_callBindConstructorArgumentRegistry() + { + $definition = new Definition\ClassDefinition('MyNamespace\\MyClass'); + $registry = $this->getMock('Wootook\\Core\\DependencyInjection\\Registry'); + + $object = new \StdClass(); + $registry->expects($this->once()) + ->method('get') + ->with('my_object') + ->will($this->returnValue($object)) + ; + + $definition->setRegistry($registry); + $definition->bindConstructorArgumentRegistry(0, 'my_object'); + + $this->assertSame($object, $definition->getConstructorArgument(0)); + } + */ +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/FactoryTest.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/FactoryTest.php new file mode 100644 index 0000000..6b01c79 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/FactoryTest.php @@ -0,0 +1,73 @@ +_app = $this->getMock('Wootook\\Core\\App\\App', array('__construct'), array('')); + $this->_registry = new \Wootook\Core\DependencyInjection\Registry($this->_app); + $this->_config = new \Wootook\Core\Config\Node(array( + 'Test\\Foo' => array( + 'app' => array('instance' => $this->_app), + 'std-class' => array('registry' => 'registry-stored-instance') + ), + 'Test\\Bar' => null, + 'Test\\Baz' => null + )); + } + + public function testGetRegistryWhilePassedToConstructor() + { + $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_config, $this->_registry); + + $this->assertAttributeSame($this->_registry, '_registry', $object); + $this->assertSame($object->getRegistry(), $this->_registry); + } + + public function testGetRegistryWhileNonePassedToConstructor() + { + $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_config); + + $this->assertInstanceOf('Wootook\\Core\\DependencyInjection\\Registry', $object->getRegistry()); + $this->assertAttributeNotEmpty('_registry', $object); + $this->assertAttributeNotSame($this->_registry, '_registry', $object); + + $object->setRegistry($this->_registry); + + $this->assertAttributeSame($this->_registry, '_registry', $object); + $this->assertSame($object->getRegistry(), $this->_registry); + } + + public function testGetDefinition() + { + $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_config, $this->_registry); + + $this->assertInstanceOf('Wootook\\Core\\DependencyInjection\\Definition', $object->getDefinition('Test\\Foo')); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/RegistryTest.php b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/RegistryTest.php new file mode 100644 index 0000000..3d484fa --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/RegistryTest.php @@ -0,0 +1,133 @@ +_app = $this->getMock('Wootook\\Core\\App\\App', array('__construct'), array('')); + } + + public function testAddInstance() + { + $object = new \Wootook\Core\DependencyInjection\Registry($this->_app); + + $this->assertAttributeEmpty('_instances', $object); + + $instance = new \StdClass(); + $object->add('testing-instance', $instance); + + $expected = array('testing-instance' => $instance); + $this->assertAttributeEquals($expected, '_instances', $object); + } + + public function testAddInstanceWhileAlreadyExists() + { + $object = new \Wootook\Core\DependencyInjection\Registry($this->_app); + + $this->assertAttributeEmpty('_instances', $object); + + $instanceOne = new \StdClass(); + $object->add('testing-instance', $instanceOne); + + $this->setExpectedException('Wootook\\Core\\Exception\\RuntimeException'); + $instanceTwo = new \StdClass(); + $object->add('testing-instance', $instanceTwo); + } + + public function testSetInstance() + { + $object = new \Wootook\Core\DependencyInjection\Registry($this->_app); + + $this->assertAttributeEmpty('_instances', $object); + + $instance = new \StdClass(); + $object->set('testing-instance', $instance); + + $expected = array('testing-instance' => $instance); + $this->assertAttributeEquals($expected, '_instances', $object); + } + + public function testSetInstanceWhileOneIsAlreadyExisting() + { + $object = new \Wootook\Core\DependencyInjection\Registry($this->_app); + + $this->assertAttributeEmpty('_instances', $object); + + $instanceOne = new \StdClass(); + $object->set('testing-instance', $instanceOne); + $expected = array('testing-instance' => $instanceOne); + $this->assertAttributeEquals($expected, '_instances', $object); + + $this->setExpectedException('Wootook\\Core\\Exception\\BadMethodCallException'); + $instanceTwo = new \StdClass(); + $object->set('testing-instance', $instanceTwo); + } + + public function testGetInstance() + { + $object = new \Wootook\Core\DependencyInjection\Registry($this->_app); + + $this->assertAttributeEmpty('_instances', $object); + + $instance = new \StdClass(); + $object->set('testing-instance', $instance); + + $this->assertSame($instance, $object->get('testing-instance')); + } + + public function testDeleteInstance() + { + $object = new \Wootook\Core\DependencyInjection\Registry($this->_app); + + $this->assertAttributeEmpty('_instances', $object); + + $instanceOne = new \StdClass(); + $object->set('testing-instance', $instanceOne); + + $instanceTwo = new \StdClass(); + $object->set('testing-instance2', $instanceTwo); + + $expected = array('testing-instance' => $instanceOne, 'testing-instance2' => $instanceTwo); + $this->assertAttributeEquals($expected, '_instances', $object); + + $object->delete('testing-instance2'); + + $expected = array('testing-instance' => $instanceOne); + $this->assertAttributeEquals($expected, '_instances', $object); + } + + public function testClearAllInstances() + { + $object = new \Wootook\Core\DependencyInjection\Registry($this->_app); + + $this->assertAttributeEmpty('_instances', $object); + + $instanceOne = new \StdClass(); + $object->set('testing-instance', $instanceOne); + + $instanceTwo = new \StdClass(); + $object->set('testing-instance2', $instanceTwo); + + $expected = array('testing-instance' => $instanceOne, 'testing-instance2' => $instanceTwo); + $this->assertAttributeEquals($expected, '_instances', $object); + + $object->clear(); + + $this->assertAttributeEquals(array(), '_instances', $object); + } +} diff --git a/src/application/modules/WootookCore/test/unit/php/bootstrap.php b/src/application/modules/WootookCore/test/unit/php/bootstrap.php new file mode 100644 index 0000000..d7fead5 --- /dev/null +++ b/src/application/modules/WootookCore/test/unit/php/bootstrap.php @@ -0,0 +1,14 @@ + __DIR__ . '/src/Wootook/Core/App.php', + 'Wootook\\Core\\Base\\Service\\App' => __DIR__ . '/src/Wootook/Core/Base/Service/App.php', + 'Wootook\\Core\\BaseObject' => __DIR__ . '/src/Wootook/Core/BaseObject.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\\Pdo\\Mysql' => __DIR__ . '/src/Wootook/Core/Database/Adapter/Pdo/Mysql.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\\Delete' => __DIR__ . '/src/Wootook/Core/Database/Sql/Delete.php', + 'Wootook\\Core\\Database\\Sql\\Dml' => __DIR__ . '/src/Wootook/Core/Database/Sql/Dml.php', + 'Wootook\\Core\\Database\\Sql\\DmlFilterableQuery' => __DIR__ . '/src/Wootook/Core/Database/Sql/DmlFilterableQuery.php', + 'Wootook\\Core\\Database\\Sql\\DmlQuery' => __DIR__ . '/src/Wootook/Core/Database/Sql/DmlQuery.php', + 'Wootook\\Core\\Database\\Sql\\Insert' => __DIR__ . '/src/Wootook/Core/Database/Sql/Insert.php', + 'Wootook\\Core\\Database\\Sql\\Mysql\\Select' => __DIR__ . '/src/Wootook/Core/Database/Sql/Mysql/Select.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\\Sql\\Select' => __DIR__ . '/src/Wootook/Core/Database/Sql/Select.php', + 'Wootook\\Core\\Database\\Sql\\Update' => __DIR__ . '/src/Wootook/Core/Database/Sql/Update.php', + 'Wootook\\Core\\Database\\Statement\\Pdo\\Mysql' => __DIR__ . '/src/Wootook/Core/Database/Statement/Pdo/Mysql.php', + 'Wootook\\Core\\Database\\Statement\\Statement' => __DIR__ . '/src/Wootook/Core/Database/Statement/Statement.php', + 'Wootook\\Core\\DateTime' => __DIR__ . '/src/Wootook/Core/DateTime.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' => __DIR__ . '/src/Wootook/Core/Event.php', + 'Wootook\\Core\\Exception\\CoreException' => __DIR__ . '/src/Wootook/Core/Exception/CoreException.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\\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\\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', + 'Wootook\\Core\\Singleton' => __DIR__ . '/src/Wootook/Core/Singleton.php', +); diff --git a/src/application/modules/WootookPlayer/autoload_function.php b/src/application/modules/WootookPlayer/autoload_function.php new file mode 100644 index 0000000..3cce3b6 --- /dev/null +++ b/src/application/modules/WootookPlayer/autoload_function.php @@ -0,0 +1,11 @@ +isDir()) { + export($fileList, instance($file->getPathname()), + ($baseNamespace === null ? $file->getBasename('.php') : $baseNamespace . "\\" . $file->getBasename('.php')), + ($basePath === null ? $file->getBasename() : $basePath . "/" . $file->getBasename())); + } else if (strtolower($file->getExtension()) !== 'php') { + continue; + } else { + $className = $baseNamespace . '\\' . $file->getBasename('.php'); + $fileList[$className] = $basePath . '/' . $file->getBasename(); + } + } +}; + +$directory = dirname(__DIR__) . '/code/core/WootookCore/src'; +$fileList = array(); + +export($fileList, instance($directory)); + +$longest = 0; +foreach ($fileList as $class => $file) { + $length = strlen($class); + if ($length > $longest) { + $longest = $length; + } +} +echo " $file) { + $pad = str_pad('', $longest - strlen($class), ' ', STR_PAD_RIGHT); + echo " '{$class}'{$pad} => __DIR__ . '/src/{$file}',\n"; +} +echo " );\n"; + diff --git a/src/banned.php b/src/banned.php index 7874d75..a90d418 100644 --- a/src/banned.php +++ b/src/banned.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('banned'); @@ -59,4 +59,4 @@ else display(parsetemplate(gettemplate('banned_body'), $parse),'Banned',true); -?> \ No newline at end of file +?> diff --git a/src/buddy.php b/src/buddy.php index edc72dc..213cdcc 100644 --- a/src/buddy.php +++ b/src/buddy.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('buddy'); diff --git a/src/changelog.php b/src/changelog.php index ff78373..106d5f5 100644 --- a/src/changelog.php +++ b/src/changelog.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('changelog'); $template = gettemplate('changelog_table'); @@ -53,4 +53,4 @@ $page .= parsetemplate(gettemplate('changelog_body'), $parse); display($page,"Change Log"); -?> \ No newline at end of file +?> diff --git a/src/chat.php b/src/chat.php index a10f64b..bab9077 100644 --- a/src/chat.php +++ b/src/chat.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('chat'); $BodyTPL = gettemplate('chat_body'); @@ -42,4 +42,4 @@ require_once dirname(__FILE__) .'/application/bootstrap.php'; display($page, $lang['Chat'], false); // Shoutbox by e-Zobar - Copyright Wootook Team 2008 -?> \ No newline at end of file +?> diff --git a/src/chat_add.php b/src/chat_add.php index 62381d4..cb9e8e0 100644 --- a/src/chat_add.php +++ b/src/chat_add.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; // On récupère les informations du message et de l'envoyeur if (isset($_POST["msg"]) && isset($user['username'])) { @@ -50,4 +50,4 @@ require_once dirname(__FILE__) .'/application/bootstrap.php'; } // Shoutbox by e-Zobar - Copyright Wootook Team 2008 -?> \ No newline at end of file +?> diff --git a/src/chat_msg.php b/src/chat_msg.php index 7228440..ce31199 100644 --- a/src/chat_msg.php +++ b/src/chat_msg.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; // On efface les anciens messages $timemoment=time(); @@ -70,4 +70,4 @@ while($v=mysql_fetch_object($query)){ } // Shoutbox by e-Zobar - Copyright Wootook Team 2008 -?> \ No newline at end of file +?> diff --git a/src/contact.php b/src/contact.php index 437950c..beac507 100644 --- a/src/contact.php +++ b/src/contact.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); define('DISABLE_IDENTITY_CHECK', true); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('contact'); diff --git a/src/fleet.php b/src/fleet.php index e43bc39..e2b5ebb 100644 --- a/src/fleet.php +++ b/src/fleet.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; $labels = Wootook_Empire_Helper_Config_Labels::getSingleton(); //Compteur de flotte en expéditions et nombre d'expédition maximum diff --git a/src/fleetback.php b/src/fleetback.php index 4075674..10c21fd 100644 --- a/src/fleetback.php +++ b/src/fleetback.php @@ -13,7 +13,7 @@ Last revision: 13/07/11 define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('fleet'); $BoxTitle = $lang['fl_error']; diff --git a/src/fleetshortcut.php b/src/fleetshortcut.php index 016de90..e309fb6 100644 --- a/src/fleetshortcut.php +++ b/src/fleetshortcut.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; $mode = isset($_GET['mode']) ? $_GET['mode'] : null; diff --git a/src/floten1.php b/src/floten1.php index 5c881a1..908729e 100644 --- a/src/floten1.php +++ b/src/floten1.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('fleet'); $speed = array( diff --git a/src/floten2.php b/src/floten2.php index 1563070..2e42657 100644 --- a/src/floten2.php +++ b/src/floten2.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('fleet'); $session = Wootook::getSession('fleet'); diff --git a/src/floten3.php b/src/floten3.php index 23f3985..a121e29 100644 --- a/src/floten3.php +++ b/src/floten3.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('fleet'); diff --git a/src/flotenajax.php b/src/flotenajax.php index 8101ab0..5a1e2b6 100644 --- a/src/flotenajax.php +++ b/src/flotenajax.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('galaxy'); includeLang('fleet'); @@ -275,4 +275,4 @@ require_once dirname(__FILE__) .'/application/bootstrap.php'; $ResultMessage .= $CurrentFlyingFleets ." ".$UserSpyProbes." ".$UserRecycles." ".$UserMissiles; die ( $ResultMessage ); -?> \ No newline at end of file +?> diff --git a/src/galaxy.php b/src/galaxy.php index b3f8cb5..19c83fd 100644 --- a/src/galaxy.php +++ b/src/galaxy.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('galaxy'); @@ -140,7 +140,7 @@ if ($mode == 2) { $page .= ShowGalaxyMISelector($galaxy, $system, $planet, $CurrentPlanet['id'], $CurrentMIP); } -$page .= ""; +$page .= '
    '; $page .= ShowGalaxyTitles($galaxy, $system); $page .= ShowGalaxyRows($galaxy, $system); @@ -156,4 +156,4 @@ display($page, $lang, false, '', false); // 1.1 - Modified by -MoF- (UGamela germany) // 1.2 - 1er Nettoyage Chlorel ... // 1.3 - 2eme Nettoyage Chlorel ... Mise en fonction et debuging complet -?> \ No newline at end of file +?> diff --git a/src/imperium.php b/src/imperium.php index fb89688..34c4307 100644 --- a/src/imperium.php +++ b/src/imperium.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('imperium'); diff --git a/src/includes/functions/GalaxyCheckFunctions.php b/src/includes/functions/GalaxyCheckFunctions.php index 505fc8f..d2431ba 100644 --- a/src/includes/functions/GalaxyCheckFunctions.php +++ b/src/includes/functions/GalaxyCheckFunctions.php @@ -31,27 +31,29 @@ /** * * @deprecated - * @param unknown_type $lunarow + * @param Wootook_Empire_Model_Planet $moon */ -function CheckAbandonMoonState ($lunarow) { - if (($lunarow['destruyed'] + 172800) <= time() && $lunarow['destruyed'] != 0) { - $query = doquery("DELETE FROM {{table}} WHERE id = '" . $lunarow['id'] . "'", "lunas"); - } +function CheckAbandonMoonState($moon) +{ + if ($moon->isErasable()) { + $moon->getGalaxyData()->setData('id_luna', 0)->save(); + $moon->delete(); + } } /** - * Suppression complete d'une planete + * Suppression complete d'une planète * + * @param Wootook_Empire_Model_Planet * @deprecated */ -function CheckAbandonPlanetState (&$planet) { - trigger_error(sprintf('%s is deprecated', __FUNCTION__), E_USER_DEPRECATED); - if ($planet['destruyed'] <= time()) { - $id = $planet['id']; - doquery("DELETE FROM {{table}} WHERE id={$id}", 'planets'); - doquery("DELETE FROM {{table}} WHERE id_planet={$id}", 'galaxy'); - } -} - - -?> \ No newline at end of file +function CheckAbandonPlanetState(Wootook_Empire_Model_Planet $planet) +{ + if ($planet->isErasable()) { + $planet->getGalaxyData()->delete(); + if ($moon = $planet->getMoon()) { + $moon->delete(); + } + $planet->delete(); + } +} \ No newline at end of file diff --git a/src/includes/functions/GalaxyRowPlanet.php b/src/includes/functions/GalaxyRowPlanet.php index 36301be..888f791 100644 --- a/src/includes/functions/GalaxyRowPlanet.php +++ b/src/includes/functions/GalaxyRowPlanet.php @@ -109,7 +109,7 @@ function GalaxyRowPlanet ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowUser, $Galaxy $Result .= ""; $Result .= ""; $Result .= ""; $Result .= ""; return $Result; } -?> +?> \ No newline at end of file diff --git a/src/includes/functions/GalaxyRowUser.php b/src/includes/functions/GalaxyRowUser.php index 6e4f460..581d8f4 100644 --- a/src/includes/functions/GalaxyRowUser.php +++ b/src/includes/functions/GalaxyRowUser.php @@ -80,12 +80,12 @@ function GalaxyRowUser($currentPlanet, $currentPlayer) { } $pastDate = new Wootook_Core_DateTime(); $pastDate->sub(8, Wootook_Core_DateTime::DAY); - if ($pastDate->isLater($currentPlayer->getLastLoginDate())) { + if ($currentPlayer->getData('onlinetime')->isEarlier($pastDate)) { $classes['inactive'] = 'i'; } $pastDate->sub(22, Wootook_Core_DateTime::DAY); - if ($pastDate->isLater($currentPlayer->getLastLoginDate())) { + if ($currentPlayer->getData('onlinetime')->isEarlier($pastDate)) { $classes['long-inactive'] = 'I'; } if ($currentPlayer->isAuthorized(LEVEL_ADMIN)) { @@ -133,4 +133,4 @@ HTML_EOF; $output .= ''; return $output; -} +} \ No newline at end of file diff --git a/src/includes/functions/MissionCaseColonisation.php b/src/includes/functions/MissionCaseColonisation.php index b736091..51fadcf 100644 --- a/src/includes/functions/MissionCaseColonisation.php +++ b/src/includes/functions/MissionCaseColonisation.php @@ -91,6 +91,8 @@ function MissionCaseColonisation($fleet) } if (mt_rand(0, 100) >= 75) { + $position = $fleet->getData('fleet_end_planet'); + $baseSize = Wootook::getGameConfig('planet/initial/fields'); $factor = 2 * $position / (1 + log($position)); $fuzz = 2 * $factor * pow(sin($factor), 2) / 2 + $factor / 4; diff --git a/src/index.php b/src/index.php index 7454dc0..5acd161 100644 --- a/src/index.php +++ b/src/index.php @@ -28,15 +28,21 @@ * */ -define('DISABLE_IDENTITY_CHECK', true); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +try { + require_once dirname(__FILE__) .'/application/bootstrap.php'; -$frontController = new Wootook_Core_Mvc_Controller_Front(Wootook::getRequest(), Wootook::getResponse()); + Wootook::app() + ->getFrontController() + ->getResponse() + ->setHeader('Cache-Control', 'no-cache; must-revalidate; proxy-revalidate'); -$frontController - ->addModule('core', 'Wootook_Core_Controller_', 'Wootook/Core/Controller') - ->addModule('player', 'Wootook_Player_Controller_', 'Wootook/Player/Controller') - ->addModule('empire', 'Wootook_Empire_Controller_', 'Wootook/Empire/Controller') - ->addModule('legacies-empire', 'Legacies_Empire_Controller_', 'Legacies/Empire/Controller') - ->dispatch() - ->send(); + Wootook::app()->getFrontController() + ->addModule('core', 'Wootook_Core_Controller_', 'Wootook/Core/Controller') + ->addModule('player', 'Wootook_Player_Controller_', 'Wootook/Player/Controller') + ->addModule('empire', 'Wootook_Empire_Controller_', 'Wootook/Empire/Controller') + ->addModule('legacies-empire', 'Legacies_Empire_Controller_', 'Legacies/Empire/Controller') + ->dispatch() + ->send(); +} catch (Exception $e) { + Wootook\Core\Profiler\ErrorProfiler::getSingleton()->addException($e); +} diff --git a/src/infos.php b/src/infos.php index 3c982a7..467fb19 100644 --- a/src/infos.php +++ b/src/infos.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; // ---------------------------------------------------------------------------------------------------------- // Creation de la Liste de flotte disponible sur la lune diff --git a/src/jumpgate.php b/src/jumpgate.php index d4da63e..655749d 100644 --- a/src/jumpgate.php +++ b/src/jumpgate.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; function DoFleetJump ( $CurrentUser, $CurrentPlanet ) { global $lang, $resource; @@ -122,4 +122,4 @@ function DoFleetJump ( $CurrentUser, $CurrentPlanet ) { // History version // 1.0 - Version from scrap .. y avait pas ... bin maintenant y a !! -?> \ No newline at end of file +?> diff --git a/src/lostpassword.php b/src/lostpassword.php index d27b146..3be772d 100644 --- a/src/lostpassword.php +++ b/src/lostpassword.php @@ -31,7 +31,7 @@ define('INSIDE', true); define('INSTALL', false); define('DISABLE_IDENTITY_CHECK', true); -require_once dirname(__FILE__) . '/application/bootstrap.php'; +require_once dirname(__FILE__) . '/application/bc.php'; $mailData = array( 'recipient' => NULL, diff --git a/src/marchand.php b/src/marchand.php index 6f6876e..f689567 100644 --- a/src/marchand.php +++ b/src/marchand.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; function ModuleMarchand ( $CurrentUser, &$CurrentPlanet ) { global $lang, $_POST; @@ -154,4 +154,4 @@ function ModuleMarchand ( $CurrentUser, &$CurrentPlanet ) { // 1.0 - Version originelle (Tom1991) // 1.1 - Version 2.0 de Tom1991 ajout java // 1.2 - R��criture Chlorel passage aux template, optimisation des appels et des requetes SQL -?> \ No newline at end of file +?> diff --git a/src/messages.php b/src/messages.php index bb8bb1d..d9085ec 100644 --- a/src/messages.php +++ b/src/messages.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; include(ROOT_PATH . 'includes/functions/BBcodeFunction.' . PHPEXT); if(!isset($user['authlevel'])) { @@ -341,4 +341,4 @@ $Message = trim ( nl2br ( strip_tags ( $_POST['text'], '
    ' ) ) ); } // 1.1 - Mise a plat, linearisation, suppression des doublons / triplons / 'n'gnions dans le code (Chlorel) // 1.2 - Regroupage des 2 fichiers vers 1 seul plus simple a mettre en oeuvre et a gerer ! -?> \ No newline at end of file +?> diff --git a/src/mipattack.php b/src/mipattack.php index aad59fb..3311e83 100644 --- a/src/mipattack.php +++ b/src/mipattack.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; // Recup des variables $Attaquant = $_GET['current']; $NbreMip = $_POST['SendMI']; @@ -78,4 +78,4 @@ if($MipRestant > 0){ MipAttack($NbreMip, $Id); } -?> \ No newline at end of file +?> diff --git a/src/multi.php b/src/multi.php index 633de79..93de8c3 100644 --- a/src/multi.php +++ b/src/multi.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('messages'); includeLang('system'); diff --git a/src/neusuw.php b/src/neusuw.php index 51f872c..332947a 100644 --- a/src/neusuw.php +++ b/src/neusuw.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('usuw'); @@ -204,4 +204,4 @@ else } // Created by Perberos. All rights reversed (C) 2006 -?> \ No newline at end of file +?> diff --git a/src/notes.php b/src/notes.php index 52d85d4..4335ded 100644 --- a/src/notes.php +++ b/src/notes.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; $dpath = (!$user["dpath"]) ? DEFAULT_SKINPATH : $user["dpath"]; diff --git a/src/options.php b/src/options.php index a33c7bb..6f47303 100644 --- a/src/options.php +++ b/src/options.php @@ -31,7 +31,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; $user = Wootook_Player_Model_Session::getSingleton()->getPlayer(); diff --git a/src/phalanx.php b/src/phalanx.php index e960ab2..4fb7490 100644 --- a/src/phalanx.php +++ b/src/phalanx.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('overview'); includeLang('phalanx'); diff --git a/src/quickfleet.php b/src/quickfleet.php index e845611..2a70f41 100644 --- a/src/quickfleet.php +++ b/src/quickfleet.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('fleet'); @@ -167,4 +167,4 @@ includeLang('fleet'); // Updated by Chlorel Jan 22 2008 (all code just hold the table and the idea) // Created by Perberos. All rights reversed (C) 2006 -?> \ No newline at end of file +?> diff --git a/src/raketenangriff.php b/src/raketenangriff.php index 58a6aba..84a71d6 100644 --- a/src/raketenangriff.php +++ b/src/raketenangriff.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; $planet = doquery("SELECT * FROM {{table}} WHERE `id` = '".$user['current_planet']."';", 'planets', true); $iraks = $planet['interplanetary_misil']; diff --git a/src/records.php b/src/records.php index b7d8079..7d88e4d 100644 --- a/src/records.php +++ b/src/records.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; $cacheFile = ROOT_PATH . '/cache/' . basename(__FILE__) . '.cache'; $timeDelay = 21600; // 21600s = 6h @@ -139,4 +139,4 @@ if(!file_exists($cacheFile) || (time() - filemtime($cacheFile)) > $timeDelay) else { echo file_get_contents($cacheFile); -} \ No newline at end of file +} diff --git a/src/resources.php b/src/resources.php index 222c86d..cc80e83 100644 --- a/src/resources.php +++ b/src/resources.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; function BuildRessourcePage($CurrentUser, $CurrentPlanet ) { global $lang; diff --git a/src/rules.php b/src/rules.php index 195682c..2eb1f66 100644 --- a/src/rules.php +++ b/src/rules.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('rules'); diff --git a/src/rw.php b/src/rw.php index 3e1603d..be34fac 100644 --- a/src/rw.php +++ b/src/rw.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; $open = true; diff --git a/src/scripts/createbanner.php b/src/scripts/createbanner.php index 3520f82..c93423d 100644 --- a/src/scripts/createbanner.php +++ b/src/scripts/createbanner.php @@ -40,7 +40,7 @@ * */ define('DISABLE_IDENTITY_CHECK', true); -require_once dirname(dirname(__FILE__)) . '/application/bootstrap.php'; +require_once dirname(dirname(__FILE__)) . '/application/bc.php'; define('FONT_FILE', dirname(__FILE__) . '/resources/fonts/visitor/visitor.ttf'); define('BACKGROUND_FILE', dirname(__FILE__) . '/resources/backgrounds/default.png'); diff --git a/src/search.php b/src/search.php index 7a90a53..01a1d65 100644 --- a/src/search.php +++ b/src/search.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; $searchtext = mysql_escape_string($_POST['searchtext']); $type = $_POST['type']; diff --git a/src/skin/frontend/base/default/css/base.css b/src/skin/frontend/base/default/css/base.css index 38b8445..02b8811 100644 --- a/src/skin/frontend/base/default/css/base.css +++ b/src/skin/frontend/base/default/css/base.css @@ -18,7 +18,7 @@ input[type=submit],input[type=button] {height:2em;border:#58939f 0 solid;border- .global {} -.global .header .navigation-container {width:100%;margin:0;height:60px;background-color:#58939f;background-image:linear-gradient(center top, #58939F 0, #78B3BF 55px);background-image:-moz-linear-gradient(center top, #58939F 0, #78B3BF 55px);background-image:-o-linear-gradient(center top, #58939F 0, #78B3BF 55px);background-image:-webkit-linear-gradient(center top, #58939F 0, #78B3BF 55px);background-image:-ie-linear-gradient(center top, #58939F 0, #78B3BF 55px);} +.global .header .navigation-container {width:100%;margin:0;height:60px;background-color:#58939f;background-image:-moz-linear-gradient(center top, #58939F 0, #78B3BF 55px);background-image:-o-linear-gradient(center top, #58939F 0, #78B3BF 55px);background-image:-webkit-linear-gradient(center top, #58939F 0, #78B3BF 55px);background-image:-ie-linear-gradient(center top, #58939F 0, #78B3BF 55px);background-image:linear-gradient(center top, #58939F 0, #78B3BF 55px);} .global .header .navigation {margin:0 auto;width:600px;height:60px;display:block;padding:0 30px;position:relative;} .global .header .navigation .last {float:left;width:100%;} .global .header .navigation .navigation-node {margin:0 0 5px;height:30px;width:120px;color:#FFF;float:left;border-radius:15px;} @@ -30,7 +30,7 @@ input[type=submit],input[type=button] {height:2em;border:#58939f 0 solid;border- .global .header .navigation .navigation-link a:hover {color:#000;background:#FFF;} .global .header .planet-carrousel {width:100%;height:110px;border:none;padding:0;color:#000;font-weight:bold;background:#FFF;} -.global .header .planet-carrousel .end {height:9px;border-bottom:1px solid #000;background-color:#58939F;background-image:linear-gradient(center top, #78B3BF 0, #58939F 5px);background-image:-moz-linear-gradient(center top, #78B3BF 0, #58939F 5px);background-image:-o-linear-gradient(center top, #78B3BF 0, #58939F 5px);background-image:-webkit-linear-gradient(center top, #78B3BF 0, #58939F 5px);background-image:-ie-linear-gradient(center top, #78B3BF 0, #58939F 5px);} +.global .header .planet-carrousel .end {height:9px;border-bottom:1px solid #000;background-color:#58939F;background-image:-moz-linear-gradient(center top, #78B3BF 0, #58939F 5px);background-image:-o-linear-gradient(center top, #78B3BF 0, #58939F 5px);background-image:-webkit-linear-gradient(center top, #78B3BF 0, #58939F 5px);background-image:-ie-linear-gradient(center top, #78B3BF 0, #58939F 5px);background-image:linear-gradient(center top, #78B3BF 0, #58939F 5px);} .global .header .planet-carrousel .items {width:900px;height:100px;overflow:hidden;margin:0 auto;} .global .header .planet-carrousel div.planet {color:#000;height:100px;width:100px;float:left;} .global .header .planet-carrousel .selected {background-color:#58939f;} @@ -118,29 +118,31 @@ input[type=submit],input[type=button] {height:2em;border:#58939f 0 solid;border- .overview .global .container .left .item-container {width:200px;} .overview .global .container .content .item-container {width:440px;} +.galaxy .details {padding:5px 10px;border-radius:5px;width:300px;background:#FFF;z-index:999;display:none;position:relative;left:-30px;top:-10px;border:3px solid #58939f;border-left-width:15px;} + /** * Public pages */ body.public-form {width:100%;height:100%;} -body.public-form .main-form {display:block;margin:0 auto;padding:0;width:300px;border-radius:5px;background:rgba(255,255,255,.8);border:5px solid #58939f;background-image:-moz-linear-gradient(top,#AAA 0,#FFF 100%);background-image:linear-gradient(top,#AAA 0,#FFF 100%);} +body.public-form .main-form {display:block;margin:0 auto;padding:0;width:300px;border-radius:5px;background:rgba(255,255,255,.8);border:5px solid #58939f;background-image:-moz-linear-gradient(top,#AAA 0,#FFF 100%);background-image:-o-linear-gradient(top,#AAA 0,#FFF 100%);background-image:-webkit-linear-gradient(top,#AAA 0,#FFF 100%);background-image:-ie-linear-gradient(top,#AAA 0,#FFF 100%);background-image:linear-gradient(top,#AAA 0,#FFF 100%);} body.public-form #login-form {height:230px;} body.public-form #lost-password-form {height:170px;} -body.public-form #register-form {height:390px;} +body.public-form #register-form {height:350px;} body.public-form .main-form fieldset {border:none;margin:0;padding:0;} body.public-form #login-form fieldset legend, body.public-form #lost-password-form fieldset legend {display:block;width:280px;height:30px;background:#58939f;color:#FFF;font-weight:bold;font-size:2em;padding:0 10px;margin-bottom:10px;} body.public-form #register-form h1 {display:block;width:280px;height:30px;background:#58939f;color:#FFF;font-weight:bold;font-size:2em;padding:0 10px;margin:0 0 10px;} -body.public-form #register-form fieldset legend {display:block;width:280px;height:15px;font-weight:bold;font-size:1.5em;padding:0 10px;margin:10px 0 5px;} +body.public-form #register-form fieldset legend {display:block;width:280px;height:15px;font-weight:bold;font-size:1.5em;padding:0 10px;} body.public-form .main-form input[type="button"], body.public-form .main-form input[type="text"], body.public-form .main-form input[type="password"] {border-width:1px;} -body.public-form .main-form p.form {margin:0;padding:0;height:30px;width:300px;float:left;} +body.public-form .main-form p.form {margin:10px 0 0;padding:0;height:20px;width:300px;float:left;} body.public-form .main-form p.lost-password {margin:0;padding:0;height:30px;width:300px;float:left;text-align:center;} body.public-form .main-form p.form label {margin:0;padding:0 10px;text-align:right;width:150px;height:30px;float:left;display:block;} body.public-form .main-form p.form input {margin:0;padding:0;width:120px;} body.public-form .main-form p.checkbox input {margin:0;padding:0;width:20px;} body.public-form .main-form p.submit input {margin:0 100px;padding:0;text-align:center;} -body.public-form #lost-password-form p.submit input {margin:0 75px;} +body.public-form #lost-password-form p.submit input {margin:0 15px;width:270px;} body.public .content .public-topbar {background:#FFF;border-bottom:5px solid #000;margin:0;height:30px;padding:0 10px;width:100%;background:rgba(0,0,0,.1);} body.public .content .public-topbar .container {margin:0 auto;width:780px;} diff --git a/src/skin/frontend/base/default/css/canvas.css b/src/skin/frontend/base/default/css/canvas.css new file mode 100644 index 0000000..b1a1967 --- /dev/null +++ b/src/skin/frontend/base/default/css/canvas.css @@ -0,0 +1,120 @@ + +.transform-h-x { + -webkit-transform: matrix(1.42,0,0,0.71,0,0) rotate(45deg); + -moz-transform: matrix(1.42,0,0,0.71,0,0) rotate(45deg); + transform: matrix(1.42,0,0,0.71,0,0) rotate(45deg); +} +.transform-v-z { + -webkit-transform: matrix(1,-0.5,0,1,0,0); + -moz-transform: matrix(1,-0.5,0,1,0,0); + transform: matrix(1,-0.5,0,1,0,0); +} +.transform-v-x { + -webkit-transform: matrix(1,0.5,0,1,0,0); + -moz-transform: matrix(1,0.5,0,1,0,0); + transform: matrix(1,0.5,0,1,0,0); +} +.block { + background: url("../testing/test/futurb.png"); + width: 16px; + height: 16px; + position: fixed; +} + +.background-far { + background: url("../testing/floor-pattern/background.jpg"); + width: 1024px; + height: 1024px; + position: fixed; + overflow: hidden; +} +.background-near { + background: url("../testing/floor-pattern/texture-cloud.png"); + width: 1024px; + height: 1024px; + position: fixed; + overflow: hidden; +} +.block-techno-purple-north-west { + background-position: -96px -144px; +} +.block-techno-purple-north { + background-position: -112px -144px; +} +.block-techno-purple-north-east { + background-position: -128px -144px; +} +.block-techno-purple-west { + background-position: -96px -160px; +} +.block-techno-purple-center { + background-position: -112px -160px; +} +.block-techno-purple-east { + background-position: -128px -160px; +} +.block-techno-purple-south-west { + background-position: -96px -176px; +} +.block-techno-purple-south { + background-position: -112px -176px; +} +.block-techno-purple-south-east { + background-position: -128px -176px; +} + +.block-techno-gray-north-west { + background-position: -144px -144px; +} +.block-techno-gray-north { + background-position: -160px -144px; +} +.block-techno-gray-north-east { + background-position: -176px -144px; +} +.block-techno-gray-west { + background-position: -144px -160px; +} +.block-techno-gray-center { + background-position: -160px -160px; +} +.block-techno-gray-east { + background-position: -176px -160px; +} +.block-techno-gray-south-west { + background-position: -144px -176px; +} +.block-techno-gray-south { + background-position: -160px -176px; +} +.block-techno-gray-south-east { + background-position: -176px -176px; +} + +.block-grass-north-west { + background-position: -0px -80px; +} +.block-grass-north { + background-position: -48px -80px; +} +.block-grass-north-east { + background-position: -96px -80px; +} +.block-grass-west { + background-position: -0px -144px; +} +.block-grass-center { + background-position: -48px -144px; +} +.block-grass-east { + background-position: -96px -144px; +} +.block-grass-south-west { + background-position: -0px -268px; +} +.block-grass-south { + background-position: -48px -268px; +} +.block-grass-south-east { + background-position: -96px -268px; +} diff --git a/src/stat.php b/src/stat.php index c623527..c877987 100644 --- a/src/stat.php +++ b/src/stat.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('stat'); diff --git a/src/techdetails.php b/src/techdetails.php index 62b92e2..4426611 100644 --- a/src/techdetails.php +++ b/src/techdetails.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; $Id = $_GET['techid']; @@ -54,4 +54,4 @@ $page = parsetemplate($PageTPL, $parse); display ($page, $lang['Tech'], false, '', false); -?> \ No newline at end of file +?> diff --git a/src/techtree.php b/src/techtree.php index 72920e9..8434df3 100644 --- a/src/techtree.php +++ b/src/techtree.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; $HeadTpl = gettemplate('techtree_head'); $RowTpl = gettemplate('techtree_row'); foreach($lang['tech'] as $Element => $ElementName) { diff --git a/src/verband.php b/src/verband.php index e6e1809..da253d7 100644 --- a/src/verband.php +++ b/src/verband.php @@ -30,7 +30,7 @@ define('INSIDE' , true); define('INSTALL' , false); -require_once dirname(__FILE__) .'/application/bootstrap.php'; +require_once dirname(__FILE__) .'/application/bc.php'; includeLang('fleet'); $fleetid = $_POST['fleetid']; @@ -371,4 +371,4 @@ require_once dirname(__FILE__) .'/application/bootstrap.php'; display($page, "Flotten"); -?> \ No newline at end of file +?> diff --git a/vendor/ZendFramework b/vendor/ZendFramework new file mode 160000 index 0000000..96750fd --- /dev/null +++ b/vendor/ZendFramework @@ -0,0 +1 @@ +Subproject commit 96750fd8e6e85ead7ca42e5cb6b890816e67cbcc From 7a55d6e026008da4327f57ea9e3d8725d28c45f2 Mon Sep 17 00:00:00 2001 From: Gregory PLANCHAT Date: Thu, 12 Jul 2012 03:28:28 +0200 Subject: [PATCH 02/14] Added Dependency Injection configurator Signed-off-by: Gregory PLANCHAT --- .../DependencyInjection/Config/Config.php | 23 ++++++ .../Core/DependencyInjection/Factory.php | 80 +++++++++---------- 2 files changed, 62 insertions(+), 41 deletions(-) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php new file mode 100644 index 0000000..3f04a2c --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php @@ -0,0 +1,23 @@ + $classConfig) { + $classDefinition = $factory->initClassDefinition($className); + $factory->registerClassDefinition($className, $classDefinition); + + if ($classConfig->methods instanceof Config\Node) { + foreach ($classConfig->methods as $methodName => $methodConfig) { + $classDefinition-> + } + } + } + } +} \ No newline at end of file diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Factory.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Factory.php index f4218de..018e3d7 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Factory.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Factory.php @@ -12,27 +12,15 @@ class Factory protected $_registry = null; - protected $_definitions = array(); + protected $_classDefinitions = array(); - protected function _construct(Config\Node $config, Registry $registry = null) + protected $_classDefinitionClassName = 'Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition'; + + protected function _construct(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) @@ -51,41 +39,51 @@ class Factory return $this->_registry; } - public function getDefinition($className) + public function getClassDefinition($className) { - if (!isset($this->_definitions[$className])) { - $this->_definitions[$className] = new Definition\ClassDefinition($className); + if (isset($this->_classDefinitions[$className])) { + return $this->_classDefinitions[$className]; } - return $this->_definitions[$className]; + return $this->initClassDefinition($className); } - public function get($className, Array $additionalArguments = array()) + public function initClassDefinition($className) { - $definition = $this->getDefinition($className); + $class = $this->getClassDefinitionClassName(); + return new $class($className); + } - try { - $reflectionClass = new \ReflectionClass($className); - } catch (\ReflectionException $e) { - throw new CoreException\RuntimeException(sprintf('Class "%s" not found', $className), null, $e); - } + public function registerClassDefinition($className, Definition\ClassDefinition $classDefinition) + { + $this->_classDefinitions[$className] = $classDefinition; - if (!$reflectionClass->hasMethod('__construct')) { - return $reflectionClass->newInstance(); - } + return $this; + } - try { - $reflectionMethod = $reflectionClass->getMethod('__construct'); - } catch (\ReflectionException $e) { - throw new CoreException\RuntimeException(sprintf('Class "%s" has no contructor', $className), null, $e); - } + public function addClassDefinition($className) + { + $this->registerClassDefinition($className, $this->initClassDefinition($className)); - $constructorArguments = $definition->prepareArguments($reflectionMethod, $this->getRegistry(), $additionalArguments); + return $this; + } - try { - return $reflectionClass->newInstanceArgs($constructorArguments); - } catch (\ReflectionException $e) { - throw new CoreException\RuntimeException(sprintf('Class "%s" could not be instanciated', $className), null, $e); - } + public function setClassDefinitionClassName($className) + { + $this->_classDefinitionClassName = $className; + + return $this; + } + + public function getClassDefinitionClassName() + { + return $this->_classDefinitionClassName; + } + + public function __invoke($className, Array $additionalArguments = array()) + { + $definition = $this->getClassDefinition($className); + + return $definition->newInstance($additionalArguments); } } From a8dff3d6d72d5a3718645d81de333cd15bb27b62 Mon Sep 17 00:00:00 2001 From: Gregory PLANCHAT Date: Thu, 12 Jul 2012 03:35:31 +0200 Subject: [PATCH 03/14] Updated integration to Travis-CI Signed-off-by: Gregory PLANCHAT --- .gitmodules | 3 - .travis.yml | 6 ++ build/build.sh | 10 ++++ .../Definition/MethodDefinition.php | 4 +- .../test/{unit/php => }/bootstrap.php | 0 .../WootookUnit}/Core/App/AppTest.php | 4 +- .../WootookUnit}/Core/Base/BaseObjectTest.php | 33 ++++++----- .../WootookUnit}/Core/Config/NodeTest.php | 59 ++++++++++--------- .../Sql/Dml/Condition/ConditionTest.php | 2 +- .../Sql/Dml/Condition/LogicalOperatorTest.php | 2 +- .../Database/Sql/Dml/Section/ColumnMock.php | 2 +- .../Database/Sql/Dml/Section/ColumnTest.php | 4 +- .../Database/Sql/Dml/Section/FromMock.php | 2 +- .../Database/Sql/Dml/Section/FromTest.php | 4 +- .../Database/Sql/Dml/Section/IntoMock.php | 2 +- .../Database/Sql/Dml/Section/IntoTest.php | 4 +- .../Database/Sql/Dml/Section/LimitMock.php | 2 +- .../Database/Sql/Dml/Section/LimitTest.php | 4 +- .../Sql/Dml/Section/Renderer/ColumnMock.php | 2 +- .../Sql/Dml/Section/Renderer/ColumnTest.php | 6 +- .../Sql/Dml/Section/Renderer/FromMock.php | 2 +- .../Sql/Dml/Section/Renderer/FromTest.php | 6 +- .../Sql/Dml/Section/Renderer/IntoMock.php | 2 +- .../Sql/Dml/Section/Renderer/IntoTest.php | 6 +- .../Sql/Dml/Section/Renderer/LimitMock.php | 2 +- .../Sql/Dml/Section/Renderer/LimitTest.php | 6 +- .../Sql/Dml/Section/Renderer/SetMock.php | 2 +- .../Sql/Dml/Section/Renderer/SetTest.php | 6 +- .../Core/Database/Sql/Dml/Section/SetMock.php | 2 +- .../Core/Database/Sql/Dml/Section/SetTest.php | 4 +- .../Database/Sql/Dml/Section/WhereMock.php | 2 +- .../Database/Sql/Dml/Section/WhereTest.php | 4 +- .../Core/DateTime/DateTimeTest.php | 0 .../Core/DateTime/DateTimeTest.php.old | 2 +- .../Definition/ArgumentDefinitionTest.php | 2 +- .../Definition/ClassDefinitionTest.php | 4 +- .../Definition/MethodDefinitionTest.php | 4 +- .../Core/DependencyInjection/FactoryTest.php | 2 +- .../Core/DependencyInjection/RegistryTest.php | 2 +- .../modules/WootookCore/test/phpunit.xml | 24 ++++++++ 40 files changed, 139 insertions(+), 100 deletions(-) delete mode 100644 .gitmodules create mode 100644 .travis.yml create mode 100644 build/build.sh rename src/application/modules/WootookCore/test/{unit/php => }/bootstrap.php (100%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/App/AppTest.php (75%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Base/BaseObjectTest.php (82%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Config/NodeTest.php (89%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Condition/ConditionTest.php (99%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Condition/LogicalOperatorTest.php (97%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/ColumnMock.php (79%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/ColumnTest.php (91%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/FromMock.php (78%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/FromTest.php (91%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/IntoMock.php (78%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/IntoTest.php (82%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/LimitMock.php (78%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/LimitTest.php (80%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/Renderer/ColumnMock.php (74%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/Renderer/ColumnTest.php (90%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/Renderer/FromMock.php (74%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/Renderer/FromTest.php (90%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/Renderer/IntoMock.php (74%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/Renderer/IntoTest.php (84%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/Renderer/LimitMock.php (74%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/Renderer/LimitTest.php (84%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/Renderer/SetMock.php (74%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/Renderer/SetTest.php (91%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/SetMock.php (78%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/SetTest.php (90%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/WhereMock.php (78%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/Database/Sql/Dml/Section/WhereTest.php (91%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/DateTime/DateTimeTest.php (100%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/DateTime/DateTimeTest.php.old (99%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/DependencyInjection/Definition/ArgumentDefinitionTest.php (99%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/DependencyInjection/Definition/ClassDefinitionTest.php (98%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/DependencyInjection/Definition/MethodDefinitionTest.php (97%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/DependencyInjection/FactoryTest.php (98%) rename src/application/modules/WootookCore/test/{unit/php/WootookTest => php/WootookUnit}/Core/DependencyInjection/RegistryTest.php (98%) create mode 100644 src/application/modules/WootookCore/test/phpunit.xml diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 8f630ff..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "vendor/ZendFramework"] - path = vendor/ZendFramework - url = git://github.com/zendframework/zf2.git diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a09e130 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: php + +php: + - 5.4 + +script: build/build.sh diff --git a/build/build.sh b/build/build.sh new file mode 100644 index 0000000..0b75c51 --- /dev/null +++ b/build/build.sh @@ -0,0 +1,10 @@ +echo " * Wootook unit testing" + +MODULES_DIR="`pwd`/../src/application/modules" + +for file in "$MODULES_DIR/*" +do + echo " * Running ${file} module tests" + phpunit --strict --configuration $MODULES_DIR/${file}/test/$phpunit.xml $MODULES_DIR/${file} +done + diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php index 6cdd5e5..142634e 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php @@ -108,13 +108,13 @@ class MethodDefinition if (is_object($argumentVariable)) { $this->_arguments[$argumentPosition] = $argumentVariable; } else { - $this->_arguments[$argumentPosition] = &$argumentVariable; + $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; + $this->_arguments[$this->_argumentIndex[$argumentPosition]] =& $argumentVariable; } } else { throw new CoreException\DependencyInjection\InvalidArgumentException('No such argument'); diff --git a/src/application/modules/WootookCore/test/unit/php/bootstrap.php b/src/application/modules/WootookCore/test/bootstrap.php similarity index 100% rename from src/application/modules/WootookCore/test/unit/php/bootstrap.php rename to src/application/modules/WootookCore/test/bootstrap.php diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/App/AppTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/App/AppTest.php similarity index 75% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/App/AppTest.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/App/AppTest.php index a478b68..f6bde51 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/App/AppTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/App/AppTest.php @@ -1,12 +1,12 @@ _app); + $object = new Base\BaseObject($this->_app); $this->assertAttributeSame($this->_app, '_app', $object); @@ -35,7 +36,7 @@ class WootookTest_Core_BaseObjectTest extends PHPUnit_Framework_TestCase public function testSetData() { - $object = new Wootook\Core\Base\BaseObject($this->_app); + $object = new Base\BaseObject($this->_app); $this->assertAttributeEmpty('_data', $object); @@ -53,7 +54,7 @@ class WootookTest_Core_BaseObjectTest extends PHPUnit_Framework_TestCase */ public function testGetData() { - $object = new Wootook\Core\Base\BaseObject($this->_app); + $object = new Base\BaseObject($this->_app); $object->setData('test', 'testing'); @@ -71,7 +72,7 @@ class WootookTest_Core_BaseObjectTest extends PHPUnit_Framework_TestCase */ public function testGetAllDatas() { - $object = new Wootook\Core\Base\BaseObject($this->_app); + $object = new Base\BaseObject($this->_app); $object->setData('test', 'testing'); @@ -89,7 +90,7 @@ class WootookTest_Core_BaseObjectTest extends PHPUnit_Framework_TestCase */ public function testHasData() { - $object = new Wootook\Core\Base\BaseObject($this->_app); + $object = new Base\BaseObject($this->_app); $object->setData('test', 'testing'); @@ -102,7 +103,7 @@ class WootookTest_Core_BaseObjectTest extends PHPUnit_Framework_TestCase */ public function testAddData() { - $object = new Wootook\Core\Base\BaseObject($this->_app); + $object = new Base\BaseObject($this->_app); $object->setData('test', 'testing'); @@ -133,7 +134,7 @@ class WootookTest_Core_BaseObjectTest extends PHPUnit_Framework_TestCase */ public function testUnsetData() { - $object = new Wootook\Core\Base\BaseObject($this->_app); + $object = new Base\BaseObject($this->_app); $object->setData('test', 'testing'); $object->setData('testing', true); @@ -152,7 +153,7 @@ class WootookTest_Core_BaseObjectTest extends PHPUnit_Framework_TestCase public function testClearData() { - $object = new Wootook\Core\Base\BaseObject($this->_app); + $object = new Base\BaseObject($this->_app); $object->setData('test', 'testing'); $object->setData('testing', true); @@ -175,7 +176,7 @@ class WootookTest_Core_BaseObjectTest extends PHPUnit_Framework_TestCase */ public function testOffsetExists() { - $object = new Wootook\Core\Base\BaseObject($this->_app); + $object = new Base\BaseObject($this->_app); $object->setData('test', 'testing'); @@ -188,7 +189,7 @@ class WootookTest_Core_BaseObjectTest extends PHPUnit_Framework_TestCase */ public function testOffsetGet() { - $object = new Wootook\Core\Base\BaseObject($this->_app); + $object = new Base\BaseObject($this->_app); $object->setData('test', 'testing'); @@ -201,7 +202,7 @@ class WootookTest_Core_BaseObjectTest extends PHPUnit_Framework_TestCase */ public function testOffsetSet() { - $object = new Wootook\Core\Base\BaseObject($this->_app); + $object = new Base\BaseObject($this->_app); $object['test'] = 'testing'; @@ -214,7 +215,7 @@ class WootookTest_Core_BaseObjectTest extends PHPUnit_Framework_TestCase */ public function testOffsetUnset() { - $object = new Wootook\Core\Base\BaseObject($this->_app); + $object = new Base\BaseObject($this->_app); $object->setData('test', 'testing'); diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Config/NodeTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Config/NodeTest.php similarity index 89% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Config/NodeTest.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/Config/NodeTest.php index 026e8cd..dcaa6d9 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Config/NodeTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Config/NodeTest.php @@ -1,18 +1,19 @@ assertAttributeEmpty('_children', $object); $this->assertAttributeEquals(null, '_parent', $object); } @@ -39,8 +40,8 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase public function testCreateEmptyWithParent() { - $parent = new Wootook\Core\Config\Node(); - $object = new Wootook\Core\Config\Node(array(), $parent); + $parent = new Config\Node(); + $object = new Config\Node(array(), $parent); $this->assertAttributeEmpty('_children', $object); $this->assertAttributeEquals($parent, '_parent', $object); @@ -49,7 +50,7 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase public function testDirectChildAccessWithObjectNotation() { - $object = new Wootook\Core\Config\Node(); + $object = new Config\Node(); $object->testingAttribute = 'testing random data'; $this->assertAttributeEquals(array('testing-attribute' => 'testing random data'), '_children', $object); @@ -64,7 +65,7 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase public function testDirectChildAccessWithArrayNotation() { - $object = new Wootook\Core\Config\Node(); + $object = new Config\Node(); $object['testing-attribute'] = 'testing random data'; $this->assertAttributeEquals(array('testing-attribute' => 'testing random data'), '_children', $object); @@ -79,7 +80,7 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase public function testDirectChildSettingArrayNotationWithoutKey() { - $object = new Wootook\Core\Config\Node(); + $object = new Config\Node(); $object[] = 'testing random data'; $this->assertAttributeEquals(array('testing random data'), '_children', $object); @@ -87,14 +88,14 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase public function testDirectChildGettingArrayNotationKeyNotExists() { - $object = new Wootook\Core\Config\Node(); + $object = new Config\Node(); $this->assertEquals(null, $object['inexistent']); } public function testSwitchingArrayNotationToObjectNotation() { - $object = new Wootook\Core\Config\Node(); + $object = new Config\Node(); $object['testing-attribute'] = 'testing random data'; $this->assertEquals('testing random data', $object->testingAttribute); @@ -107,7 +108,7 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase public function testSwitchingObjectNotationToArrayNotation() { - $object = new Wootook\Core\Config\Node(); + $object = new Config\Node(); $object->testingAttribute = 'testing random data'; $this->assertEquals('testing random data', $object['testing-attribute']); @@ -120,8 +121,8 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase public function testGetConfigByPath() { - $parent = new Wootook\Core\Config\Node(); - $object = new Wootook\Core\Config\Node(array(), $parent); + $parent = new Config\Node(); + $object = new Config\Node(array(), $parent); $parent->superChild = $object; $object->testingAttribute = 'testing random data'; @@ -131,8 +132,8 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase public function testGetConfigAsArray() { - $parent = new Wootook\Core\Config\Node(); - $object = new Wootook\Core\Config\Node(array(), $parent); + $parent = new Config\Node(); + $object = new Config\Node(array(), $parent); $parent->superChild = $object; $object->testingAttribute = 'testing random data'; @@ -142,7 +143,7 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase public function testCount() { - $object = new Wootook\Core\Config\Node(array( + $object = new Config\Node(array( 'first-child' => 1, 'second-child' => 2, '3rd-child' => '3rd', @@ -301,7 +302,7 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase 'fourth-child' => '4th' ); - $mock = new Wootook\Core\Config\Node($dataItems); + $mock = new Config\Node($dataItems); $counter = 0; reset($dataItems); @@ -327,7 +328,7 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase 'fourth-child' => '4th' ); - $mock = new Wootook\Core\Config\Node($dataItems); + $mock = new Config\Node($dataItems); $this->assertInstanceOf('Wootook\\Core\\Config\\Node', $mock->getConfig('second-child')); $this->assertEquals(1, $mock->getConfig('second-child/second-sub-child')); } @@ -344,7 +345,7 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase 'fourth-child' => '4th' ); - $mock = new Wootook\Core\Config\Node($dataItems); + $mock = new Config\Node($dataItems); $this->assertEquals(null, $mock->getConfig('second-child/third-inexisting-sub-child')); } @@ -360,7 +361,7 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase 'fourth-child' => '4th' ); - $mock = new Wootook\Core\Config\Node($dataItems); + $mock = new Config\Node($dataItems); $this->setExpectedException('Wootook\\Core\\Exception\\RuntimeException'); $mock->getConfig('second-child/second-sub-child/inexistent-depth-child'); } @@ -377,14 +378,14 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase 'fourth-child' => '4th' ); - $object = new Wootook\Core\Config\Node($dataItems); + $object = new Config\Node($dataItems); $clone = clone $object; $this->assertEquals($dataItems, $clone->toArray()); } public function testUseNumericAttribute() { - $object = new Wootook\Core\Config\Node(); + $object = new Config\Node(); $object->{1} = 'first-child'; $this->assertEquals('first-child', $object->{1}); $this->assertEquals(array(1 => 'first-child'), $object->toArray()); @@ -422,8 +423,8 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase 'fourth-child' => '4th' ); - $root = new Wootook\Core\Config\Node($rootDataItems); - $secondary = new Wootook\Core\Config\Node($secondaryDataItems); + $root = new Config\Node($rootDataItems); + $secondary = new Config\Node($secondaryDataItems); $root->secondChild->merge($secondary); $this->assertEquals($expectedDataItems, $root->toArray()); } @@ -440,7 +441,7 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase 'fourth-child' => '4th' ); - $object = new Wootook\Core\Config\Node($dataItems); + $object = new Config\Node($dataItems); $object->reset(); $this->assertEmpty($object->toArray()); } @@ -475,7 +476,7 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase 'fourth-child' => '4th' ); - $object = new Wootook\Core\Config\Node($dataItems); + $object = new Config\Node($dataItems); $object->setConfig('second-child/fourth-sub-child/random-level-child', 72); $this->assertEquals($expected, $object->toArray()); } @@ -510,7 +511,7 @@ class WootookTest_Core_Config_NodeTest extends PHPUnit_Framework_TestCase 'fourth-child' => '4th' ); - $object = new Wootook\Core\Config\Node($dataItems); + $object = new Config\Node($dataItems); $this->setExpectedException('Wootook\\Core\\Exception\\RuntimeException'); $object->setConfig('second-child/third-sub-child/random-inexisting-level-child', 72); } diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Condition/ConditionTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Condition/ConditionTest.php similarity index 99% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Condition/ConditionTest.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Condition/ConditionTest.php index 710fb05..21cc0c7 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Condition/ConditionTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Condition/ConditionTest.php @@ -1,6 +1,6 @@ getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); - $this->_mock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\ColumnMock', array($adapter)); + $this->_mock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\ColumnMock', array($adapter)); } public function testAddColumnWithoutTableWithoutAlias() diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/FromMock.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/FromMock.php similarity index 78% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/FromMock.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/FromMock.php index ee9a1ec..7d8354c 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/FromMock.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/FromMock.php @@ -1,6 +1,6 @@ getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); - $this->_mock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\FromMock', array($adapter)); + $this->_mock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\FromMock', array($adapter)); } public function testSetOneTableWithoutSchemaWithoutAlias() diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/IntoMock.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/IntoMock.php similarity index 78% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/IntoMock.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/IntoMock.php index fe051ab..0d39fb4 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/IntoMock.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/IntoMock.php @@ -1,6 +1,6 @@ getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); - $this->_mock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\IntoMock', array($adapter)); + $this->_mock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\IntoMock', array($adapter)); } public function testSetTableWithoutSchema() diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/LimitMock.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/LimitMock.php similarity index 78% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/LimitMock.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/LimitMock.php index 9bd6c7c..774461f 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/LimitMock.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/LimitMock.php @@ -1,6 +1,6 @@ getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); - $this->_mock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\LimitMock', array($adapter)); + $this->_mock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\LimitMock', array($adapter)); } public function testSetLimitWithoutOffset() diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/ColumnMock.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/ColumnMock.php similarity index 74% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/ColumnMock.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/ColumnMock.php index 5d54b4b..fe66d53 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/ColumnMock.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/ColumnMock.php @@ -1,6 +1,6 @@ will($this->returnArgument(0)) ; - $this->_queryMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\ColumnMock', array($adapterMock)); - $this->_rendererMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\ColumnMock'); + $this->_queryMock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\ColumnMock', array($adapterMock)); + $this->_rendererMock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\ColumnMock'); } public function testRenderColumnWithoutTableWithoutAlias() diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/FromMock.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/FromMock.php similarity index 74% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/FromMock.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/FromMock.php index 2ad922a..833908c 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/FromMock.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/FromMock.php @@ -1,6 +1,6 @@ will($this->returnArgument(0)) ; - $this->_queryMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\FromMock', array($adapterMock)); - $this->_rendererMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\FromMock'); + $this->_queryMock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\FromMock', array($adapterMock)); + $this->_rendererMock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\FromMock'); } public function testRenderOneTableWithoutSchemaWithoutAlias() diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/IntoMock.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/IntoMock.php similarity index 74% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/IntoMock.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/IntoMock.php index 8f5b817..5d2805c 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/IntoMock.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/IntoMock.php @@ -1,6 +1,6 @@ will($this->returnArgument(0)) ; - $this->_queryMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\IntoMock', array($adapterMock)); - $this->_rendererMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\IntoMock'); + $this->_queryMock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\IntoMock', array($adapterMock)); + $this->_rendererMock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\IntoMock'); } public function testRenderTableWithoutSchema() diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/LimitMock.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/LimitMock.php similarity index 74% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/LimitMock.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/LimitMock.php index c8d0c78..a47d70a 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/LimitMock.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/LimitMock.php @@ -1,6 +1,6 @@ getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); - $this->_queryMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\LimitMock', array($adapter)); - $this->_rendererMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\LimitMock'); + $this->_queryMock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\LimitMock', array($adapter)); + $this->_rendererMock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\LimitMock'); } public function testRenderLimitWithoutOffset() diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/SetMock.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/SetMock.php similarity index 74% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/SetMock.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/SetMock.php index 29637c0..5f34c99 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/Renderer/SetMock.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/Renderer/SetMock.php @@ -1,6 +1,6 @@ will($this->returnArgument(0)) ; - $this->_queryMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\SetMock', array($adapterMock)); - $this->_rendererMock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\SetMock'); + $this->_queryMock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\SetMock', array($adapterMock)); + $this->_rendererMock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\Renderer\\SetMock'); } public function testRenderFieldAndValue() diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/SetMock.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/SetMock.php similarity index 78% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/SetMock.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/SetMock.php index 313fc09..4cc42d5 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/SetMock.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/SetMock.php @@ -1,6 +1,6 @@ getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); - $this->_mock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\SetMock', array($adapter)); + $this->_mock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\SetMock', array($adapter)); } public function testSetFieldAndValue() diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/WhereMock.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/WhereMock.php similarity index 78% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/WhereMock.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/WhereMock.php index 7bf52ef..b5d78ed 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/Database/Sql/Dml/Section/WhereMock.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Section/WhereMock.php @@ -1,6 +1,6 @@ getMockForAbstractClass('Wootook\\Core\\Database\\Adapter\\Adapter'); - $this->_mock = $this->getMockForAbstractClass('WootookTest\\Core\\Database\\Sql\\Dml\\Section\\WhereMock', array($adapter)); + $this->_mock = $this->getMockForAbstractClass('WootookUnit\\Core\\Database\\Sql\\Dml\\Section\\WhereMock', array($adapter)); } public function testAddScalarCondition() diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DateTime/DateTimeTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DateTime/DateTimeTest.php similarity index 100% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DateTime/DateTimeTest.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/DateTime/DateTimeTest.php diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DateTime/DateTimeTest.php.old b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DateTime/DateTimeTest.php.old similarity index 99% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DateTime/DateTimeTest.php.old rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/DateTime/DateTimeTest.php.old index 300a7f7..1e1707a 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DateTime/DateTimeTest.php.old +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DateTime/DateTimeTest.php.old @@ -6,7 +6,7 @@ require_once 'Wootook/Core/DateTime/DateTime.php'; * Test class for Wootook\Core\DateTime\DateTime. * Generated by PHPUnit on 2011-09-01 at 11:24:52. */ -class WootookTest_Core_DateTime_DateTimeTest extends PHPUnit_Framework_TestCase +class WootookUnit_Core_DateTime_DateTimeTest extends PHPUnit_Framework_TestCase { public function testTimestamp() { diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/ArgumentDefinitionTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/ArgumentDefinitionTest.php similarity index 99% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/ArgumentDefinitionTest.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/ArgumentDefinitionTest.php index e3169e6..713b86c 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/ArgumentDefinitionTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/ArgumentDefinitionTest.php @@ -1,6 +1,6 @@ getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), $methodDefinitionClassName, false); $definition = new Definition\ClassDefinition(__CLASS__, $methodDefinitionClassName); diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/MethodDefinitionTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php similarity index 97% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/MethodDefinitionTest.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php index 966a511..a4dab1e 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/Definition/MethodDefinitionTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php @@ -1,6 +1,6 @@ getMock('Wootook\\Core\\DependencyInjection\\Definition\\ArgumentDefinition', array(), array(), $argumentDefinitionClassName, false); $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array(), array(), '', false); diff --git a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/FactoryTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/FactoryTest.php similarity index 98% rename from src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/FactoryTest.php rename to src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/FactoryTest.php index 6b01c79..61b464a 100644 --- a/src/application/modules/WootookCore/test/unit/php/WootookTest/Core/DependencyInjection/FactoryTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/FactoryTest.php @@ -1,6 +1,6 @@ + + + + + ./php/WootookTest/Core + + + + From 7a9b3e9196891b29077f3a98b9181c08784aa1b2 Mon Sep 17 00:00:00 2001 From: Gregory PLANCHAT Date: Thu, 12 Jul 2012 03:37:22 +0200 Subject: [PATCH 04/14] Updated Travis CI integration Signed-off-by: Gregory PLANCHAT --- .travis.yml | 2 +- build.xml | 146 ------------------ build/build.sh | 11 +- .../modules/WootookCore/test/bootstrap.php | 4 +- 4 files changed, 10 insertions(+), 153 deletions(-) delete mode 100644 build.xml diff --git a/.travis.yml b/.travis.yml index a09e130..b73c6ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,4 @@ language: php php: - 5.4 -script: build/build.sh +script: sh build/build.sh diff --git a/build.xml b/build.xml deleted file mode 100644 index fe8adf3..0000000 --- a/build.xml +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/build/build.sh b/build/build.sh index 0b75c51..90e032f 100644 --- a/build/build.sh +++ b/build/build.sh @@ -1,10 +1,13 @@ echo " * Wootook unit testing" -MODULES_DIR="`pwd`/../src/application/modules" +MODULES_DIR="`pwd`/src/application/modules" -for file in "$MODULES_DIR/*" +for file in `find $MODULES_DIR -mindepth 1 -maxdepth 1 -type d` do - echo " * Running ${file} module tests" - phpunit --strict --configuration $MODULES_DIR/${file}/test/$phpunit.xml $MODULES_DIR/${file} + echo " * Running `basename ${file}` module tests (Unit tests)" + phpunit --strict --configuration ${file}/test/phpunit.xml ${file}/test/php/WootookUnit + + #echo " * Running `basename ${file}` module tests (Integration tests)" + #phpunit --strict --configuration ${file}/test/phpunit.xml ${file}/test/php/WootookUnit done diff --git a/src/application/modules/WootookCore/test/bootstrap.php b/src/application/modules/WootookCore/test/bootstrap.php index d7fead5..067d936 100644 --- a/src/application/modules/WootookCore/test/bootstrap.php +++ b/src/application/modules/WootookCore/test/bootstrap.php @@ -2,7 +2,7 @@ spl_autoload_register(function ($class) { static $map; if (!$map) { - $map = include dirname(dirname(dirname(__DIR__))) . '/autoload_classmap.php'; + $map = include dirname(__DIR__) . '/autoload_classmap.php'; } if (!isset($map[$class])) { @@ -11,4 +11,4 @@ spl_autoload_register(function ($class) { return require $map[$class]; }); -require dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/code/core/Wootook.php'; +require dirname(dirname(dirname(__DIR__))) . '/code/core/Wootook.php'; From 6b393762d9fccf22c084766d25b6616f6b5884ce Mon Sep 17 00:00:00 2001 From: Gregory PLANCHAT Date: Thu, 12 Jul 2012 19:55:44 +0200 Subject: [PATCH 05/14] Fixed class call in unit tests Signed-off-by: Gregory PLANCHAT --- .../Core/DependencyInjection/FactoryTest.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/FactoryTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/FactoryTest.php index 61b464a..185ceb1 100644 --- a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/FactoryTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/FactoryTest.php @@ -32,19 +32,11 @@ class FactoryTest extends \PHPUnit_Framework_TestCase { $this->_app = $this->getMock('Wootook\\Core\\App\\App', array('__construct'), array('')); $this->_registry = new \Wootook\Core\DependencyInjection\Registry($this->_app); - $this->_config = new \Wootook\Core\Config\Node(array( - 'Test\\Foo' => array( - 'app' => array('instance' => $this->_app), - 'std-class' => array('registry' => 'registry-stored-instance') - ), - 'Test\\Bar' => null, - 'Test\\Baz' => null - )); } public function testGetRegistryWhilePassedToConstructor() { - $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_config, $this->_registry); + $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_registry); $this->assertAttributeSame($this->_registry, '_registry', $object); $this->assertSame($object->getRegistry(), $this->_registry); @@ -52,7 +44,7 @@ class FactoryTest extends \PHPUnit_Framework_TestCase public function testGetRegistryWhileNonePassedToConstructor() { - $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_config); + $object = new \Wootook\Core\DependencyInjection\Factory($this->_app); $this->assertInstanceOf('Wootook\\Core\\DependencyInjection\\Registry', $object->getRegistry()); $this->assertAttributeNotEmpty('_registry', $object); @@ -66,8 +58,8 @@ class FactoryTest extends \PHPUnit_Framework_TestCase public function testGetDefinition() { - $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_config, $this->_registry); + $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_registry); - $this->assertInstanceOf('Wootook\\Core\\DependencyInjection\\Definition', $object->getDefinition('Test\\Foo')); + $this->assertInstanceOf('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', $object->getClassDefinition('stdClass')); } } From 8e8b4b3513ef3643d61c8648882a4d48a3a33618 Mon Sep 17 00:00:00 2001 From: Gregory PLANCHAT Date: Tue, 17 Jul 2012 20:10:13 +0200 Subject: [PATCH 06/14] Updated DependencyInjection component Signed-off-by: Gregory PLANCHAT --- build/build.sh | 4 +- .../modules/WootookCore/autoload_classmap.php | 1 + .../src/Wootook/Core/Base/Util/FileSystem.php | 68 +++++ .../Wootook/Core/Config/Adapter/PhpArray.php | 12 +- .../Database/Sql/Dml/Condition/Condition.php | 14 +- .../Wootook/Core/Database/Sql/Dml/Delete.php | 4 +- .../Wootook/Core/Database/Sql/Dml/Insert.php | 2 +- .../Sql/Dml/Section/Renderer/Where.php | 18 -- .../Wootook/Core/Database/Sql/Dml/Select.php | 2 +- .../Wootook/Core/Database/Sql/Dml/Update.php | 2 +- .../Wootook/Core/Database/Statement/Mysql.php | 1 - .../src/Wootook/Core/DateTime/Formatter.php | 2 +- .../DependencyInjection/Config/Config.php | 10 +- .../Definition/ArgumentDefinition.php | 18 +- .../Definition/MethodDefinition.php | 124 +++++--- .../modules/WootookCore/test/bootstrap.php | 1 - .../Sql/Dml/Condition/ConditionTest.php | 41 +-- .../Definition/MethodDefinitionTest.php | 287 +++++++++++++++--- .../modules/WootookCore/test/phpunit.xml | 15 +- 19 files changed, 471 insertions(+), 155 deletions(-) create mode 100644 src/application/modules/WootookCore/src/Wootook/Core/Base/Util/FileSystem.php diff --git a/build/build.sh b/build/build.sh index 90e032f..76df89f 100644 --- a/build/build.sh +++ b/build/build.sh @@ -5,9 +5,9 @@ MODULES_DIR="`pwd`/src/application/modules" for file in `find $MODULES_DIR -mindepth 1 -maxdepth 1 -type d` do echo " * Running `basename ${file}` module tests (Unit tests)" - phpunit --strict --configuration ${file}/test/phpunit.xml ${file}/test/php/WootookUnit + phpunit --strict --colors --configuration ${file}/test/phpunit.xml ${file}/test/php/WootookUnit #echo " * Running `basename ${file}` module tests (Integration tests)" - #phpunit --strict --configuration ${file}/test/phpunit.xml ${file}/test/php/WootookUnit + #phpunit --strict --colors --configuration ${file}/test/phpunit.xml ${file}/test/php/WootookUnit done diff --git a/src/application/modules/WootookCore/autoload_classmap.php b/src/application/modules/WootookCore/autoload_classmap.php index 1a3400c..52d6e08 100644 --- a/src/application/modules/WootookCore/autoload_classmap.php +++ b/src/application/modules/WootookCore/autoload_classmap.php @@ -4,6 +4,7 @@ '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\\Base\\Util\FileSystem' => __DIR__ . '/src/Wootook/Core/Base/Util/FileSystem.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', diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Base/Util/FileSystem.php b/src/application/modules/WootookCore/src/Wootook/Core/Base/Util/FileSystem.php new file mode 100644 index 0000000..3516202 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Base/Util/FileSystem.php @@ -0,0 +1,68 @@ + + * 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 . + * + * --> 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\Util; + +use Wootook\Core\Profiler; + +class FileSystem +{ + public function fileExists($fileName) + { + if ($fileName === null || empty($fileName)) { + return false; + } + + if (($fp = @fopen($fileName, 'r', true)) === false) { + return false; + } + fclose($fp); + + return true; + } + + public function directoryExists($directoryName) + { + if ($directoryName === null || empty($directoryName)) { + return false; + } + + return is_dir($directoryName); + } + + public function includeFile($fileName) + { + if ($fileName === null || empty($fileName)) { + return null; + } + + return include $fileName; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/PhpArray.php b/src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/PhpArray.php index 18e158a..0282447 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/PhpArray.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/PhpArray.php @@ -30,25 +30,29 @@ namespace Wootook\Core\Config\Adapter; -use Wootook\Core\Exception as CoreException; +use Wootook\Core\Base\Util, + Wootook\Core\Exception as CoreException; class PhpArray extends Adapter { + protected $_ioHelper = null; + public function __construct($filename = null) { if ($filename !== null) { $this->load($filename); } + + $this->_ioHelper = new Util\FileSystem(); } public function load($filename) { - // Undesired dependency to the \Wootook class - if (!\Wootook::fileExists($filename)) { + if (!$this->_ioHelper->fileExists($filename)) { throw new CoreException\DataAccessException(sprintf('Could not load config file "%s"', $filename)); } - $data = include $filename; + $data = $this->_ioHelper->includeFile($filename); if (!is_array($data)) { throw new CoreException\DataAccessException('Configuration file could not be loaded.'); diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Condition.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Condition.php index 64e94c2..cc807d3 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Condition.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Condition.php @@ -61,28 +61,28 @@ abstract class Condition return $this->_query; } - protected function _addPlaceholder(Placeholder\Placeholder $placeholder) + public function addPlaceholder(Placeholder\Placeholder $placeholder) { $this->_placeholders[] = $placeholder; return $this; } - protected function _clearPlaceholders() + public function clearPlaceholders() { $this->_placeholders = array(); return $this; } - protected function _getAllPlaceholders() + public function getAllPlaceholders() { return $this->_placeholders; } public function beforePrepare(Statement\Statement $statement) { - foreach ($this->_getAllPlaceholders() as $placeholder) { + foreach ($this->getAllPlaceholders() as $placeholder) { /** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */ $placeholder->beforePrepare($statement); } @@ -92,7 +92,7 @@ abstract class Condition public function afterPrepare(Statement\Statement $statement) { - foreach ($this->_getAllPlaceholders() as $placeholder) { + foreach ($this->getAllPlaceholders() as $placeholder) { /** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */ $placeholder->afterPrepare($statement); } @@ -102,7 +102,7 @@ abstract class Condition public function beforeExecute(Statement\Statement $statement) { - foreach ($this->_getAllPlaceholders() as $placeholder) { + foreach ($this->getAllPlaceholders() as $placeholder) { /** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */ $placeholder->beforeExecute($statement); } @@ -112,7 +112,7 @@ abstract class Condition public function afterExecute(Statement\Statement $statement) { - foreach ($this->_getAllPlaceholders() as $placeholder) { + foreach ($this->getAllPlaceholders() as $placeholder) { /** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */ $placeholder->afterExecute($statement); } diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Delete.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Delete.php index 025cd52..5302b13 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Delete.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Delete.php @@ -28,10 +28,10 @@ * */ -namespace Wootook\Core\Database\Sql; +namespace Wootook\Core\Database\Sql\Dml; class Delete - extends DmlFilterableQuery + extends DmlQuery { const FROM = 'FROM'; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Insert.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Insert.php index c262915..14abfaf 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Insert.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Insert.php @@ -28,7 +28,7 @@ * */ -namespace Wootook\Core\Database\Sql; +namespace Wootook\Core\Database\Sql\Dml; use Wootook\Core\Database\Sql\Placeholder; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Where.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Where.php index 1807256..55e2ee1 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Where.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Where.php @@ -37,24 +37,6 @@ use Wootook\Core, 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) { diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Select.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Select.php index e18e588..95f36a1 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Select.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Select.php @@ -28,7 +28,7 @@ * */ -namespace Wootook\Core\Database\Sql; +namespace Wootook\Core\Database\Sql\Dml; use Wootook\Core\Database\Sql\Dml\Section, Wootook\Core\Database\Sql\Placeholder; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Update.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Update.php index 018d80e..51a297a 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Update.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Update.php @@ -28,7 +28,7 @@ * */ -namespace Wootook\Core\Database\Sql; +namespace Wootook\Core\Database\Sql\Dml; use Wootook\Core\Database\Sql\Dml\Section, Wootook\Core\Database\Sql\Placeholder; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Mysql.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Mysql.php index 9d9a87d..6904516 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Mysql.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Mysql.php @@ -32,7 +32,6 @@ 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; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DateTime/Formatter.php b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/Formatter.php index c1f4954..44b8196 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DateTime/Formatter.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/Formatter.php @@ -34,6 +34,6 @@ namespace Wootook\Core\DateTime; * Date formatter and parser */ class Formatter - extends \IntlDateFormatter +// extends \IntlDateFormatter { } diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php index 3f04a2c..10be5d5 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php @@ -2,22 +2,22 @@ namespace Wootook\Core\DependencyInjection\Config; -use Wootook\Core\Config, +use Wootook\Core\Config\Node, Wootook\Core\DependencyInjection; class Config { - public function __invoke(DependencyInjection\Factory $factory, Config\Node $config) + public function __invoke(DependencyInjection\Factory $factory, Node $config) { foreach ($config as $className => $classConfig) { $classDefinition = $factory->initClassDefinition($className); $factory->registerClassDefinition($className, $classDefinition); - if ($classConfig->methods instanceof Config\Node) { + if ($classConfig->methods instanceof Node) { foreach ($classConfig->methods as $methodName => $methodConfig) { - $classDefinition-> + //$classDefinition-> } } } } -} \ No newline at end of file +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php index 4336845..9b5281e 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php @@ -51,13 +51,9 @@ class ArgumentDefinition 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->setReflector($methodDefinition->getArgumentReflector($argumentName)); $this->_registry = $registry; } @@ -98,6 +94,16 @@ class ArgumentDefinition return $this; } + public function getType() + { + return $this->_type; + } + + public function getValue() + { + return $this->_value; + } + public function getReflector() { return $this->_reflector; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php index 142634e..5d73f4f 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php @@ -72,11 +72,19 @@ class MethodDefinition $this->_registry = $registry; } + /** + * @param $argumentPosition + * @return \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition + */ protected function _getArgumentDefinitionInstance($argumentPosition) { return new $this->_argumentDefinitionHandlerClass($this, $argumentPosition); } + /** + * @param \Wootook\Core\DependencyInjection\Registry $registry + * @return MethodDefinition + */ public function setRegistry(DependencyInjection\Registry $registry) { $this->_registry = $registry; @@ -84,91 +92,100 @@ class MethodDefinition return $this; } + /** + * @return null|\Wootook\Core\DependencyInjection\Registry + */ public function getRegistry() { return $this->_registry; } + /** + * @param string|int $argumentPosition + * @param mixed $argumentValue + * @return MethodDefinition + * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException + */ 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'); - } + $this->getArgumentDefinition($argumentPosition)->bindValue($argumentValue); return $this; } + /** + * @param string|int $argumentPosition + * @param mixed $argumentVariable + * @return MethodDefinition + * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException + */ 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'); - } + $this->getArgumentDefinition($argumentPosition)->bindVariable($argumentVariable); return $this; } - public function bindArgumentRegistry($argumentPosition, $argumentKey) + /** + * @param string|int $argumentPosition + * @param string $registryKey + * @return MethodDefinition + * @throws \Wootook\Core\Exception\DependencyInjection\RuntimeException + * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException + */ + public function bindArgumentRegistryEntry($argumentPosition, $registryKey) { 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'); - } + $this->getArgumentDefinition($argumentPosition)->bindRegistryEntry($registryKey); return $this; } + /** + * @param int|string $argumentPosition + * @return \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition + * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException + */ 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.'); + if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) { + $argumentPosition = $this->_argumentIndex[$argumentPosition]; } + + if (!is_int($argumentPosition)) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Argument not found.'); + } + + if (!isset($this->_arguments[$argumentPosition])) { + $this->_arguments[$argumentPosition] = $this->_getArgumentDefinitionInstance($argumentPosition); + } + + return $this->_arguments[$argumentPosition]; } + /** + * @return array + */ public function getAllArgumentDefinitions() { return $this->_arguments; } + /** + * @return \ReflectionMethod + */ public function getReflector() { return $this->_reflector; } + /** + * @param \ReflectionMethod $reflector + * @return MethodDefinition + */ public function setReflector(\ReflectionMethod $reflector) { $this->_reflector = $reflector; @@ -184,14 +201,21 @@ class MethodDefinition return $this; } + /** + * @param $argumentPosition + * @return \ReflectionParameter + * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException + */ 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'); + if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) { + $argumentPosition = $this->_argumentIndex[$argumentPosition]; } + + if (!is_int($argumentPosition) || !isset($this->_argumentReflectors[$argumentPosition])) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Argument not found.'); + } + + return $this->_argumentReflectors[$argumentPosition]; } } diff --git a/src/application/modules/WootookCore/test/bootstrap.php b/src/application/modules/WootookCore/test/bootstrap.php index 067d936..858d9f2 100644 --- a/src/application/modules/WootookCore/test/bootstrap.php +++ b/src/application/modules/WootookCore/test/bootstrap.php @@ -11,4 +11,3 @@ spl_autoload_register(function ($class) { return require $map[$class]; }); -require dirname(dirname(dirname(__DIR__))) . '/code/core/Wootook.php'; diff --git a/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Condition/ConditionTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Condition/ConditionTest.php index 21cc0c7..771d872 100644 --- a/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Condition/ConditionTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Condition/ConditionTest.php @@ -123,9 +123,9 @@ class ConditionTest $conditionMock = $this->buildMock(); $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); - $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + $conditionMock->addPlaceholder($placeholderMock); - $result = $this->callNonPublicMethod($conditionMock, '_getAllPlaceholders'); + $result = $conditionMock->getAllPlaceholders(); $this->assertArrayHasKey(0, $result); $this->assertSame($placeholderMock, $result[0]); } @@ -135,25 +135,27 @@ class ConditionTest $conditionMock = $this->buildMock(); $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); - $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); - $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); - $this->callNonPublicMethod($conditionMock, '_clearPlaceholders'); + $conditionMock->addPlaceholder($placeholderMock); + $conditionMock->addPlaceholder($placeholderMock); + $conditionMock->clearPlaceholders(); $expected = array(); - $this->assertEquals($expected, $this->callNonPublicMethod($conditionMock, '_getAllPlaceholders')); + $this->assertEquals($expected, $conditionMock->getAllPlaceholders()); } public function testPlaceholderCallTrigger_beforePrepare() { + /** @var \Wootook\Core\Database\Sql\Dml\Condition\Condition $conditionMock */ $conditionMock = $this->buildMock(); - $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); + $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder', + array(), '', true, true, true, array('beforePrepare')); - $placeholderMock->expects($this->any()) + $placeholderMock->expects($this->once()) ->method('beforePrepare') ->with($this->_statementMock) ; - $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + $conditionMock->addPlaceholder($placeholderMock); $conditionMock->beforePrepare($this->_statementMock); } @@ -161,14 +163,15 @@ class ConditionTest public function testPlaceholderCallTrigger_afterPrepare() { $conditionMock = $this->buildMock(); - $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); + $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder', + array(), '', true, true, true, array('afterPrepare')); - $placeholderMock->expects($this->any()) + $placeholderMock->expects($this->once()) ->method('afterPrepare') ->with($this->_statementMock) ; - $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + $conditionMock->addPlaceholder($placeholderMock); $conditionMock->afterPrepare($this->_statementMock); } @@ -176,14 +179,15 @@ class ConditionTest public function testPlaceholderCallTrigger_beforeExecute() { $conditionMock = $this->buildMock(); - $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); + $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder', + array(), '', true, true, true, array('beforeExecute')); - $placeholderMock->expects($this->any()) + $placeholderMock->expects($this->once()) ->method('beforeExecute') ->with($this->_statementMock) ; - $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + $conditionMock->addPlaceholder($placeholderMock); $conditionMock->beforeExecute($this->_statementMock); } @@ -191,14 +195,15 @@ class ConditionTest public function testPlaceholderCallTrigger_afterExecute() { $conditionMock = $this->buildMock(); - $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); + $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder', + array(), '', true, true, true, array('afterExecute')); - $placeholderMock->expects($this->any()) + $placeholderMock->expects($this->once()) ->method('afterExecute') ->with($this->_statementMock) ; - $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + $conditionMock->addPlaceholder($placeholderMock); $conditionMock->afterExecute($this->_statementMock); } diff --git a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php index a4dab1e..3eca6b5 100644 --- a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php @@ -3,6 +3,7 @@ namespace WootookUnit\Core\DependencyInjection\Definition; use Wootook\Core\Config, + Wootook\Core\DependencyInjection, Wootook\Core\DependencyInjection\Definition; class MethodDefinitionTest extends \PHPUnit_Framework_TestCase @@ -42,9 +43,31 @@ class MethodDefinitionTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf($argumentDefinitionClassName, $definition->getArgumentDefinition('fooArgumentOne')); } + public function testMethodDefinitionInstantiation_withRegistry_withSpecialArgumentDefinitionClassName() + { + $app = $this->getMock('Wootook\\Core\\App\\App', array(), array(), '', false); + /** @var \Wootook\Core\DependencyInjection\Registry $registry */ + $registry = $this->getMock('Wootook\\Core\\DependencyInjection\\Registry', array(), array($app)); + + $argumentDefinitionClassName = \uniqid('WootookUnit_Core_DependencyInjection_Mock_ArgumentDefinition_TestNewInstance_'); + $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ArgumentDefinition', array(), array(), $argumentDefinitionClassName, false); + + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $mock */ + $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array('getReflector'), array(), '', false); + + $mock->expects($this->once()) + ->method('getReflector') + ->will($this->returnValue(new \ReflectionClass(__CLASS__))) + ; + + $definition = new Definition\MethodDefinition($mock, 'methodToTest', $registry, $argumentDefinitionClassName); + + $this->assertInstanceOf($argumentDefinitionClassName, $definition->getArgumentDefinition('fooArgumentOne')); + } + public function testMethodDefinitionAccessors_getReflector() { - $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array(), array(), '', false); + $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array('getReflector'), array(), '', false); $mock->expects($this->once()) ->method('getReflector') @@ -58,7 +81,7 @@ class MethodDefinitionTest extends \PHPUnit_Framework_TestCase public function testMethodDefinitionMutators_setReflector() { - $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array(), array(), '', false); + $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array('getReflector'), array(), '', false); $mock->expects($this->once()) ->method('getReflector') @@ -71,43 +94,237 @@ class MethodDefinitionTest extends \PHPUnit_Framework_TestCase $this->assertSame($reflector, $definition->getReflector()); } - /* - public function testBuildWithoutConstructorArguments_callBindConstructorArgumentValue() + + public function testMethodDefinition_accessorAndMutatorForRegistry() { - $definition = new Definition\ClassDefinition('MyNamespace\\MyClass'); + $registryMock = $this->getMock('Wootook\\Core\\DependencyInjection\\Registry', array(), array(), '', false); + $classDefinitionMock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array('getReflector'), array(), '', false); - $definition->bindConstructorArgumentValue(0, 36); - $this->assertEquals(36, $definition->getConstructorArgument(0)); - } - - public function testBuildWithoutConstructorArguments_callBindConstructorArgumentVariable() - { - $definition = new Definition\ClassDefinition('MyNamespace\\MyClass'); - - $variable = 36; - $definition->bindConstructorArgumentVariable(0, $variable); - - $variable = 12; - $this->assertEquals(12, $definition->getConstructorArgument(0)); - $this->assertSame($variable, $definition->getConstructorArgument(0)); - } - - public function testBuildWithoutConstructorArguments_callBindConstructorArgumentRegistry() - { - $definition = new Definition\ClassDefinition('MyNamespace\\MyClass'); - $registry = $this->getMock('Wootook\\Core\\DependencyInjection\\Registry'); - - $object = new \StdClass(); - $registry->expects($this->once()) - ->method('get') - ->with('my_object') - ->will($this->returnValue($object)) + $classDefinitionMock->expects($this->once()) + ->method('getReflector') + ->will($this->returnValue(new \ReflectionClass(__CLASS__))) ; - $definition->setRegistry($registry); - $definition->bindConstructorArgumentRegistry(0, 'my_object'); + $definition = new Definition\MethodDefinition($classDefinitionMock, __FUNCTION__); + $definition->setRegistry($registryMock); - $this->assertSame($object, $definition->getConstructorArgument(0)); + $this->assertSame($registryMock, $definition->getRegistry()); + } + + public function testMethodDefinition_bindArgumentValue_withNumericArgumentIndex() + { + $classDefinition = new Definition\ClassDefinition(__CLASS__); + + $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', + array('getArgumentDefinition'), array($classDefinition, 'methodToTest')); + + $definition->expects($this->once()) + ->method('getArgumentDefinition') + ->with(0) + ->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0))) + ; + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->bindArgumentValue(0, 65); + } + + public function testMethodDefinition_bindArgumentVariable_withNumericArgumentIndex() + { + $classDefinition = new Definition\ClassDefinition(__CLASS__); + + $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', + array('getArgumentDefinition'), array($classDefinition, 'methodToTest')); + + $definition->expects($this->once()) + ->method('getArgumentDefinition') + ->with(0) + ->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0))) + ; + + $variable = 65; + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->bindArgumentVariable(0, $variable); + } + + public function testMethodDefinition_bindArgumentRegistryEntry_withNumericArgumentIndex() + { + $classDefinition = new Definition\ClassDefinition(__CLASS__); + $registry = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Registry') + ->disableOriginalConstructor() + ->setMethods(array('get')) + ->getMock(); + + $registry->expects($this->any())->method('get')->will($this->returnValue(36)); + + $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', + array('getArgumentDefinition'), array($classDefinition, 'methodToTest', $registry)); + + $definition->expects($this->once()) + ->method('getArgumentDefinition') + ->with(0) + ->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0, $registry))) + ; + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->bindArgumentRegistryEntry(0, 'foo'); + } + + public function testMethodDefinition_bindArgumentValue_withNamedArgumentIndex() + { + $classDefinition = new Definition\ClassDefinition(__CLASS__); + + $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', + array('getArgumentDefinition'), array($classDefinition, 'methodToTest')); + + $definition->expects($this->once()) + ->method('getArgumentDefinition') + ->with('fooArgumentOne') + ->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0))) + ; + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->bindArgumentValue('fooArgumentOne', 65); + } + + public function testMethodDefinition_bindArgumentVariable_withNamedArgumentIndex() + { + $classDefinition = new Definition\ClassDefinition(__CLASS__); + + $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', + array('getArgumentDefinition'), array($classDefinition, 'methodToTest')); + + $definition->expects($this->once()) + ->method('getArgumentDefinition') + ->with('fooArgumentOne') + ->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0))) + ; + + $variable = 65; + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->bindArgumentVariable('fooArgumentOne', $variable); + } + + public function testMethodDefinition_bindArgumentRegistryEntry_withNamedArgumentIndex() + { + $classDefinition = new Definition\ClassDefinition(__CLASS__); + $registry = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Registry') + ->disableOriginalConstructor() + ->setMethods(array('get')) + ->getMock(); + + $registry->expects($this->any())->method('get')->will($this->returnValue(36)); + + $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', + array('getArgumentDefinition'), array($classDefinition, 'methodToTest', $registry)); + + $definition->expects($this->once()) + ->method('getArgumentDefinition') + ->with('fooArgumentOne') + ->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0, $registry))) + ; + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->bindArgumentRegistryEntry('fooArgumentOne', 'foo'); + } + + public function testMethodDefinition_bindArgumentRegistryEntry_withNoRegistry() + { + $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') + ->disableOriginalConstructor() + ->getMock() + ; + + $classDefinition->expects($this->once()) + ->method('getReflector') + ->will($this->returnValue(new \ReflectionClass(__CLASS__))) + ; + + $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', + array('getArgumentDefinition'), array($classDefinition, 'methodToTest')); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\RuntimeException'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->bindArgumentRegistryEntry('fooArgumentOne', 'foo'); + } + + public function testMethodDefinition_getArgumentDefinition_withInvalidArgumentId() + { + $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') + ->disableOriginalConstructor() + ->getMock() + ; + + $classDefinition->expects($this->once()) + ->method('getReflector') + ->will($this->returnValue(new \ReflectionClass(__CLASS__))) + ; + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->getArgumentDefinition(1.5); + } + + public function testMethodDefinition_getArgumentReflector_withNumericArgumentId() + { + $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') + ->disableOriginalConstructor() + ->getMock() + ; + + $classDefinition->expects($this->once()) + ->method('getReflector') + ->will($this->returnValue(new \ReflectionClass(__CLASS__))) + ; + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $reflector = $definition->getArgumentReflector(0); + $this->assertInstanceOf('ReflectionParameter', $reflector); + $this->assertEquals(0, $reflector->getPosition()); + } + + public function testMethodDefinition_getArgumentReflector_withNamedArgumentId() + { + $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') + ->disableOriginalConstructor() + ->getMock() + ; + + $classDefinition->expects($this->once()) + ->method('getReflector') + ->will($this->returnValue(new \ReflectionClass(__CLASS__))) + ; + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $reflector = $definition->getArgumentReflector('fooArgumentOne'); + $this->assertInstanceOf('ReflectionParameter', $reflector); + $this->assertEquals(0, $reflector->getPosition()); + } + + public function testMethodDefinition_getArgumentReflector_withInvalidArgumentId() + { + $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') + ->disableOriginalConstructor() + ->getMock() + ; + + $classDefinition->expects($this->once()) + ->method('getReflector') + ->will($this->returnValue(new \ReflectionClass(__CLASS__))) + ; + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->getArgumentReflector(1.5); } - */ } diff --git a/src/application/modules/WootookCore/test/phpunit.xml b/src/application/modules/WootookCore/test/phpunit.xml index 612b9f2..c05f63b 100644 --- a/src/application/modules/WootookCore/test/phpunit.xml +++ b/src/application/modules/WootookCore/test/phpunit.xml @@ -1,7 +1,7 @@ - ./php/WootookTest/Core + ./php/WootookUnit/Core + + + + ../src/Wootook/Core + + + + + + + From 07f18f5e766bb1e14443772a0d086dcbdc8b2698 Mon Sep 17 00:00:00 2001 From: Gregory PLANCHAT Date: Tue, 17 Jul 2012 20:19:20 +0200 Subject: [PATCH 07/14] Updated PHPUnit config Signed-off-by: Gregory PLANCHAT --- src/application/modules/WootookCore/test/phpunit.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/application/modules/WootookCore/test/phpunit.xml b/src/application/modules/WootookCore/test/phpunit.xml index c05f63b..6271b05 100644 --- a/src/application/modules/WootookCore/test/phpunit.xml +++ b/src/application/modules/WootookCore/test/phpunit.xml @@ -21,7 +21,7 @@ --> - + From 2bed707ecd35a21d050b990b836d6ec1379b281b Mon Sep 17 00:00:00 2001 From: Gregory PLANCHAT Date: Tue, 17 Jul 2012 23:27:44 +0200 Subject: [PATCH 08/14] Updated DependencyInjection component's API Signed-off-by: Gregory PLANCHAT --- .../DependencyInjection/Config/Config.php | 3 +- .../Definition/ClassDefinition.php | 88 ++++++++--- .../Definition/MethodDefinition.php | 139 ++++++++++++----- .../Core/DependencyInjection/Factory.php | 52 ++++++- .../DependencyInjection/Config/ConfigTest.php | 143 ++++++++++++++++++ .../Definition/ClassDefinitionTest.php | 2 +- .../Core/DependencyInjection/FactoryTest.php | 80 +++++++++- 7 files changed, 441 insertions(+), 66 deletions(-) create mode 100644 src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Config/ConfigTest.php diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php index 10be5d5..198e1f2 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php @@ -10,8 +10,7 @@ class Config public function __invoke(DependencyInjection\Factory $factory, Node $config) { foreach ($config as $className => $classConfig) { - $classDefinition = $factory->initClassDefinition($className); - $factory->registerClassDefinition($className, $classDefinition); + $factory->addClassDefinition($className); if ($classConfig->methods instanceof Node) { foreach ($classConfig->methods as $methodName => $methodConfig) { diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ClassDefinition.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ClassDefinition.php index 8adc5ce..df3fdc4 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ClassDefinition.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ClassDefinition.php @@ -11,15 +11,17 @@ class ClassDefinition { protected $_className = null; protected $_reflector = null; - protected $_methods = array(); + protected $_methodDefinitions = array(); - protected $_methodDefinitionHandlerClass = null; + protected $_registry = null; + + protected $_methodDefinitionClassName = 'Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition'; /** * @param string $className * @param null|string $methodDefinitionHandlerClass */ - public function __construct($className, $methodDefinitionHandlerClass = null) + public function __construct($className, DependencyInjection\Registry $registry = null, $methodDefinitionHandlerClass = null) { $this->_className = $className; try { @@ -35,13 +37,16 @@ class ClassDefinition } } - /** - * @param string $methodName - * @return \Wootook\Core\DependencyInjection\Definition\MethodDefinition - */ - protected function _getMethodDefinitionInstance($methodName) + public function setRegistry(DependencyInjection\Registry $registry) { - return new $this->_methodDefinitionHandlerClass($this, $methodName); + $this->_registry = $registry; + + return $this; + } + + public function getRegistry() + { + return $this->_registry; } /** @@ -49,17 +54,50 @@ class ClassDefinition * @return \Wootook\Core\DependencyInjection\Definition\MethodDefinition * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException */ - public function getMethodDefinition($methodName) + public function getMethodDefinition($methodName, $registerInstanceIfNew = false) { 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); + if (isset($this->_methodDefinitions[$methodName])) { + return $this->_methodDefinitions[$methodName]; } - return $this->_methods[$methodName]; + $definition = $this->initMethodDefinition($methodName); + if ($registerInstanceIfNew === true) { + $this->registerMethodDefinition($methodName, $definition); + } + return $definition; + } + + /** + * @param string $methodName + * @return \Wootook\Core\DependencyInjection\Definition\MethodDefinition + */ + public function initMethodDefinition($methodName) + { + $class = $this->getMethodDefinitionClassName(); + + return new $class($this, $methodName, $this->getRegistry()); + } + + public function registerMethodDefinition($methodName, MethodDefinition $methodDefinition) + { + if (!is_string($methodName)) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Method names only accept string.'); + } + + $this->_methodDefinitions[$methodName] = $methodDefinition; + + return $this; + } + + public function addMethodDefinition($methodName) + { + $this->registerMethodDefinition($methodName, $this->initMethodDefinition($methodName)); + + return $this; } public function setMethodDefinition($methodName, MethodDefinition $definition) @@ -68,17 +106,31 @@ class ClassDefinition throw new CoreException\DependencyInjection\InvalidArgumentException('Method names only accept string.'); } - $this->_methods[$methodName] = $definition; + $this->_methodDefinitions[$methodName] = $definition; return $this; } - public function getAllMethodDefinitions() + public function setMethodDefinitionClassName($methodDefinitionClassName) { - return $this->_methods; + if (!is_string($methodDefinitionClassName)) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Class names only accept string.'); + } + + return $this->_methodDefinitionClassName; } - public function newInstance(Array $args = array(), $withoutConstructorCall = false) + public function getMethodDefinitionClassName() + { + return $this->_methodDefinitionClassName; + } + + public function getAllMethodDefinitions() + { + return $this->_methodDefinitions; + } + + public function newInstance(Array $args = array()) { try { if ($this->getReflector()->hasMethod('__construct')) { @@ -104,7 +156,7 @@ class ClassDefinition public function reset() { - return $this->_methods = array(); + return $this->_methodDefinitions = array(); } public function getReflector() diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php index 5d73f4f..3bf86fd 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php @@ -27,7 +27,7 @@ class MethodDefinition /** * @var array */ - protected $_arguments = array(); + protected $_argumentDefinitions = array(); /** * @var array @@ -44,7 +44,7 @@ class MethodDefinition */ protected $_registry = null; - protected $_argumentDefinitionHandlerClass = null; + protected $_argumentDefinitionClassName = 'Wootook\\Core\\DependencyInjection\\Definition\\ArgumentDefinition'; /** * @param ClassDefinition $classDefinition @@ -64,23 +64,12 @@ class MethodDefinition } if (is_string($argumentDefinitionHandlerClass)) { - $this->_argumentDefinitionHandlerClass = $argumentDefinitionHandlerClass; - } else { - $this->_argumentDefinitionHandlerClass = __NAMESPACE__ . '\\ArgumentDefinition'; + $this->setArgumentDefinitionClassName($argumentDefinitionHandlerClass); } $this->_registry = $registry; } - /** - * @param $argumentPosition - * @return \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition - */ - protected function _getArgumentDefinitionInstance($argumentPosition) - { - return new $this->_argumentDefinitionHandlerClass($this, $argumentPosition); - } - /** * @param \Wootook\Core\DependencyInjection\Registry $registry * @return MethodDefinition @@ -100,6 +89,98 @@ class MethodDefinition return $this->_registry; } + /** + * @param int|string $argumentPosition + * @return \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition + * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException + */ + public function getArgumentDefinition($argumentPosition, $registerInstanceIfNew = false) + { + if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) { + $argumentPosition = $this->_argumentIndex[$argumentPosition]; + } + + if (!is_int($argumentPosition)) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Argument could only be found by position or by name.'); + } + + if (isset($this->_argumentDefinitions[$argumentPosition])) { + return $this->_argumentDefinitions[$argumentPosition]; + } + + $definition = $this->initArgumentDefinition($argumentPosition); + if ($registerInstanceIfNew === true) { + $this->registerArgumentDefinition($argumentPosition, $definition); + } + return $definition; + } + + public function initArgumentDefinition($argumentPosition) + { + if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) { + $argumentPosition = $this->_argumentIndex[$argumentPosition]; + } + + if (!is_int($argumentPosition)) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Argument could only be found by position or by name.'); + } + + $class = $this->getArgumentDefinitionClassName(); + + return new $class($this, $argumentPosition, $this->getRegistry()); + } + + public function registerArgumentDefinition($argumentPosition, ArgumentDefinition $argumentDefinition) + { + if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) { + $argumentPosition = $this->_argumentIndex[$argumentPosition]; + } + + if (!is_int($argumentPosition)) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Argument could only be found by position or by name.'); + } + + $this->_argumentDefinitions[$argumentPosition] = $argumentDefinition; + + return $this; + } + + public function addArgumentDefinition($argumentPosition) + { + $this->registerArgumentDefinition($argumentPosition, $this->initArgumentDefinition($argumentPosition)); + + return $this; + } + + public function setArgumentDefinition($argumentPosition, ArgumentDefinition $definition) + { + if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) { + $argumentPosition = $this->_argumentIndex[$argumentPosition]; + } + + if (!is_int($argumentPosition)) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Argument could only be found by position or by name.'); + } + + $this->_argumentDefinitions[$argumentPosition] = $definition; + + return $this; + } + + public function setArgumentDefinitionClassName($argumentDefinitionClassName) + { + if (!is_string($argumentDefinitionClassName)) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Class names only accept string.'); + } + + return $this->_argumentDefinitionClassName; + } + + public function getArgumentDefinitionClassName() + { + return $this->_argumentDefinitionClassName; + } + /** * @param string|int $argumentPosition * @param mixed $argumentValue @@ -108,7 +189,7 @@ class MethodDefinition */ public function bindArgumentValue($argumentPosition, $argumentValue) { - $this->getArgumentDefinition($argumentPosition)->bindValue($argumentValue); + $this->getArgumentDefinition($argumentPosition, true)->bindValue($argumentValue); return $this; } @@ -121,7 +202,7 @@ class MethodDefinition */ public function bindArgumentVariable($argumentPosition, &$argumentVariable) { - $this->getArgumentDefinition($argumentPosition)->bindVariable($argumentVariable); + $this->getArgumentDefinition($argumentPosition, true)->bindVariable($argumentVariable); return $this; } @@ -139,39 +220,17 @@ class MethodDefinition throw new CoreException\DependencyInjection\RuntimeException('No registry available'); } - $this->getArgumentDefinition($argumentPosition)->bindRegistryEntry($registryKey); + $this->getArgumentDefinition($argumentPosition, true)->bindRegistryEntry($registryKey); return $this; } - /** - * @param int|string $argumentPosition - * @return \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition - * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException - */ - public function getArgumentDefinition($argumentPosition) - { - if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) { - $argumentPosition = $this->_argumentIndex[$argumentPosition]; - } - - if (!is_int($argumentPosition)) { - throw new CoreException\DependencyInjection\InvalidArgumentException('Argument not found.'); - } - - if (!isset($this->_arguments[$argumentPosition])) { - $this->_arguments[$argumentPosition] = $this->_getArgumentDefinitionInstance($argumentPosition); - } - - return $this->_arguments[$argumentPosition]; - } - /** * @return array */ public function getAllArgumentDefinitions() { - return $this->_arguments; + return $this->_argumentDefinitions; } /** diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Factory.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Factory.php index 018e3d7..bbff31f 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Factory.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Factory.php @@ -16,11 +16,15 @@ class Factory protected $_classDefinitionClassName = 'Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition'; - protected function _construct(Registry $registry = null) + protected function _construct(Registry $registry = null, $classDefinitionClassName = null) { if ($registry !== null) { $this->setRegistry($registry); } + + if ($classDefinitionClassName !== null) { + $this->setClassDefinitionClassName($classDefinitionClassName); + } } public function setRegistry(Registry $registry) @@ -39,23 +43,38 @@ class Factory return $this->_registry; } - public function getClassDefinition($className) + public function getClassDefinition($className, $registerInstanceIfNew = false) { + if (!is_string($className)) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Class names only accept string.'); + } + if (isset($this->_classDefinitions[$className])) { return $this->_classDefinitions[$className]; } + $definition = $this->initClassDefinition($className); + if ($registerInstanceIfNew === true) { + $this->registerClassDefinition($className, $definition); + } + return $definition; + return $this->initClassDefinition($className); } public function initClassDefinition($className) { $class = $this->getClassDefinitionClassName(); + return new $class($className); } public function registerClassDefinition($className, Definition\ClassDefinition $classDefinition) { + if (!is_string($className)) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Class names only accept string.'); + } + $this->_classDefinitions[$className] = $classDefinition; return $this; @@ -68,9 +87,29 @@ class Factory return $this; } - public function setClassDefinitionClassName($className) + public function setClassDefinition($className, Definition\ClassDefinition $definition) { - $this->_classDefinitionClassName = $className; + if (!is_string($className)) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Class names only accept string.'); + } + + $this->_classDefinitions[$className] = $definition; + + return $this; + } + + public function getAllClassDefinitions() + { + return $this->_classDefinitions; + } + + public function setClassDefinitionClassName($classDefinitionClassName) + { + if (!is_string($classDefinitionClassName)) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Class names only accept string.'); + } + + $this->_classDefinitionClassName = $classDefinitionClassName; return $this; } @@ -80,6 +119,11 @@ class Factory return $this->_classDefinitionClassName; } + public function reset() + { + return $this->_classDefinitions = array(); + } + public function __invoke($className, Array $additionalArguments = array()) { $definition = $this->getClassDefinition($className); diff --git a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Config/ConfigTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Config/ConfigTest.php new file mode 100644 index 0000000..de0327e --- /dev/null +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Config/ConfigTest.php @@ -0,0 +1,143 @@ +_app = $this->getMock('Wootook\\Core\\App\\App', array('__construct'), array('')); + $this->_registry = new \Wootook\Core\DependencyInjection\Registry($this->_app); + } + + public function testGetRegistryWhilePassedToConstructor() + { + $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_registry); + + $this->assertAttributeSame($this->_registry, '_registry', $object); + $this->assertSame($object->getRegistry(), $this->_registry); + } + + public function testGetClassDefinition_usingSpecialClassName() + { + $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_registry, 'stdClass'); + + $this->assertInstanceOf('stdClass', $object->getClassDefinition('stdClass')); + } + + public function testGetRegistryWhileNonePassedToConstructor() + { + $object = new \Wootook\Core\DependencyInjection\Factory($this->_app); + + $this->assertInstanceOf('Wootook\\Core\\DependencyInjection\\Registry', $object->getRegistry()); + $this->assertAttributeNotEmpty('_registry', $object); + $this->assertAttributeNotSame($this->_registry, '_registry', $object); + + $object->setRegistry($this->_registry); + + $this->assertAttributeSame($this->_registry, '_registry', $object); + $this->assertSame($object->getRegistry(), $this->_registry); + } + + public function testGetUndeclaredClassDefinition() + { + $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_registry); + + $this->assertInstanceOf('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', $object->getClassDefinition('stdClass')); + } + + public function testGetDeclaredClassDefinition() + { + $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_registry); + + $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') + ->disableOriginalConstructor() + ->getMock() + ; + + $object->registerClassDefinition('stdClass', $classDefinition); + + $this->assertInstanceOf('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', $object->getClassDefinition('stdClass')); + } + + public function testAddClassDefinition() + { + $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') + ->disableOriginalConstructor() + ->getMock() + ; + + $object = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Factory') + ->disableOriginalConstructor() + ->setMethods(array('initClassDefinition', 'registerClassDefinition')) + ->getMock() + ; + + $object->expects($this->once()) + ->method('initClassDefinition') + ->with('stdClass') + ->will($this->returnValue($classDefinition)) + ; + + $object->expects($this->once()) + ->method('registerClassDefinition') + ->with('stdClass', $classDefinition) + ->will($this->returnSelf()) + ; + + $object->addClassDefinition('stdClass'); + } + + public function testInstanceInvocation() + { + $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') + ->disableOriginalConstructor() + ->setMethods(array('newInstance')) + ->getMock() + ; + + $classDefinition->expects($this->once()) + ->method('newInstance') + ->with(array()) + ->will($this->returnValue(new \stdClass)) + ; + + $object = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Factory') + ->disableOriginalConstructor() + ->setMethods(array('getClassDefinition')) + ->getMock() + ; + + $object->expects($this->once()) + ->method('getClassDefinition') + ->with('stdClass') + ->will($this->returnValue($classDefinition)) + ; + + $object('stdClass'); + } +} diff --git a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/ClassDefinitionTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/ClassDefinitionTest.php index 12b54b8..2d07a4b 100644 --- a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/ClassDefinitionTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/ClassDefinitionTest.php @@ -18,7 +18,7 @@ class ClassDefinitionTest extends \PHPUnit_Framework_TestCase $methodDefinitionClassName = \uniqid('WootookUnit_Core_DependencyInjection_Mock_MethodDefinition_TestNewInstance_'); $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), $methodDefinitionClassName, false); - $definition = new Definition\ClassDefinition(__CLASS__, $methodDefinitionClassName); + $definition = new Definition\ClassDefinition(__CLASS__, null, $methodDefinitionClassName); $this->assertInstanceOf($methodDefinitionClassName, $definition->getMethodDefinition(__FUNCTION__)); } diff --git a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/FactoryTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/FactoryTest.php index 185ceb1..01d3349 100644 --- a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/FactoryTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/FactoryTest.php @@ -42,6 +42,13 @@ class FactoryTest extends \PHPUnit_Framework_TestCase $this->assertSame($object->getRegistry(), $this->_registry); } + public function testGetClassDefinition_usingSpecialClassName() + { + $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_registry, 'stdClass'); + + $this->assertInstanceOf('stdClass', $object->getClassDefinition('stdClass')); + } + public function testGetRegistryWhileNonePassedToConstructor() { $object = new \Wootook\Core\DependencyInjection\Factory($this->_app); @@ -56,10 +63,81 @@ class FactoryTest extends \PHPUnit_Framework_TestCase $this->assertSame($object->getRegistry(), $this->_registry); } - public function testGetDefinition() + public function testGetUndeclaredClassDefinition() { $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_registry); $this->assertInstanceOf('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', $object->getClassDefinition('stdClass')); } + + public function testGetDeclaredClassDefinition() + { + $object = new \Wootook\Core\DependencyInjection\Factory($this->_app, $this->_registry); + + $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') + ->disableOriginalConstructor() + ->getMock() + ; + + $object->registerClassDefinition('stdClass', $classDefinition); + + $this->assertInstanceOf('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', $object->getClassDefinition('stdClass')); + } + + public function testAddClassDefinition() + { + $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') + ->disableOriginalConstructor() + ->getMock() + ; + + $object = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Factory') + ->disableOriginalConstructor() + ->setMethods(array('initClassDefinition', 'registerClassDefinition')) + ->getMock() + ; + + $object->expects($this->once()) + ->method('initClassDefinition') + ->with('stdClass') + ->will($this->returnValue($classDefinition)) + ; + + $object->expects($this->once()) + ->method('registerClassDefinition') + ->with('stdClass', $classDefinition) + ->will($this->returnSelf()) + ; + + $object->addClassDefinition('stdClass'); + } + + public function testInstanceInvocation() + { + $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') + ->disableOriginalConstructor() + ->setMethods(array('newInstance')) + ->getMock() + ; + + $classDefinition->expects($this->once()) + ->method('newInstance') + ->with(array()) + ->will($this->returnValue(new \stdClass)) + ; + + $object = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Factory') + ->disableOriginalConstructor() + ->setMethods(array('getClassDefinition')) + ->getMock() + ; + + $object->expects($this->once()) + ->method('getClassDefinition') + ->with('stdClass') + ->will($this->returnValue($classDefinition)) + ; + + $object('stdClass'); + } } From af103cce2cacc8cbeb732f10563a77ec516ec364 Mon Sep 17 00:00:00 2001 From: Gregory PLANCHAT Date: Thu, 19 Jul 2012 19:23:30 +0200 Subject: [PATCH 09/14] Updated DependencyInjection component's API Signed-off-by: Gregory PLANCHAT --- .../Definition/ArgumentDefinition.php | 4 +- .../Definition/ClassDefinition.php | 127 +++- .../Definition/MethodDefinition.php | 54 +- .../Definition/ClassDefinitionTest.php | 447 +++++++++---- .../Definition/MethodDefinitionTest.php | 610 +++++++++++++----- .../modules/WootookCore/test/phpunit.xml | 6 +- 6 files changed, 913 insertions(+), 335 deletions(-) diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php index 9b5281e..ea033c1 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php @@ -55,7 +55,9 @@ class ArgumentDefinition $this->setReflector($methodDefinition->getArgumentReflector($argumentName)); - $this->_registry = $registry; + if ($registry !== null) { + $this->setRegistry($registry); + } } public function setRegistry(DependencyInjection\Registry $registry) diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ClassDefinition.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ClassDefinition.php index df3fdc4..d72783d 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ClassDefinition.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ClassDefinition.php @@ -1,4 +1,32 @@ + * 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 . + * + * --> 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\DependencyInjection\Definition; @@ -7,21 +35,47 @@ use Wootook\Core\Base\Service, Wootook\Core\DependencyInjection, Wootook\Core\Exception as CoreException; +/** + * Class definition for the DependencyInjection component, used to define a + * class's dependencies. + * + * @package WootookCore + * @subpackage DependencyInjection + * @author Grégory PLANCHAT + * @see http://wootook.org/ + */ class ClassDefinition { + /** + * @var string + */ protected $_className = null; + + /** + * @var \ReflectionClass + */ protected $_reflector = null; + + /** + * @var array + */ protected $_methodDefinitions = array(); + /** + * @var null|\Wootook\Core\DependencyInjection\Registry + */ protected $_registry = null; + /** + * @var string + */ protected $_methodDefinitionClassName = 'Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition'; /** * @param string $className * @param null|string $methodDefinitionHandlerClass */ - public function __construct($className, DependencyInjection\Registry $registry = null, $methodDefinitionHandlerClass = null) + public function __construct($className, DependencyInjection\Registry $registry = null, $methodDefinitionClassName = null) { $this->_className = $className; try { @@ -30,13 +84,19 @@ class ClassDefinition throw new CoreException\DependencyInjection\BadMethodCallException($e->getMessage(), $e->getCode(), $e); } - if (is_string($methodDefinitionHandlerClass)) { - $this->_methodDefinitionHandlerClass = $methodDefinitionHandlerClass; - } else { - $this->_methodDefinitionHandlerClass = __NAMESPACE__ . '\\MethodDefinition'; + if ($methodDefinitionClassName !== null) { + $this->setMethodDefinitionClassName($methodDefinitionClassName); + } + + if ($registry !== null) { + $this->setRegistry($registry); } } + /** + * @param \Wootook\Core\DependencyInjection\Registry $registry + * @return ClassDefinition + */ public function setRegistry(DependencyInjection\Registry $registry) { $this->_registry = $registry; @@ -44,6 +104,9 @@ class ClassDefinition return $this; } + /** + * @return null|\Wootook\Core\DependencyInjection\Registry + */ public function getRegistry() { return $this->_registry; @@ -77,11 +140,21 @@ class ClassDefinition */ public function initMethodDefinition($methodName) { + if (!is_string($methodName)) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Method names only accept string.'); + } + $class = $this->getMethodDefinitionClassName(); return new $class($this, $methodName, $this->getRegistry()); } + /** + * @param $methodName + * @param MethodDefinition $methodDefinition + * @return ClassDefinition + * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException + */ public function registerMethodDefinition($methodName, MethodDefinition $methodDefinition) { if (!is_string($methodName)) { @@ -93,6 +166,10 @@ class ClassDefinition return $this; } + /** + * @param $methodName + * @return ClassDefinition + */ public function addMethodDefinition($methodName) { $this->registerMethodDefinition($methodName, $this->initMethodDefinition($methodName)); @@ -100,6 +177,12 @@ class ClassDefinition return $this; } + /** + * @param $methodName + * @param MethodDefinition $definition + * @return ClassDefinition + * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException + */ public function setMethodDefinition($methodName, MethodDefinition $definition) { if (!is_string($methodName)) { @@ -111,25 +194,43 @@ class ClassDefinition return $this; } + /** + * @param $methodDefinitionClassName + * @return string + * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException + */ public function setMethodDefinitionClassName($methodDefinitionClassName) { if (!is_string($methodDefinitionClassName)) { throw new CoreException\DependencyInjection\InvalidArgumentException('Class names only accept string.'); } - return $this->_methodDefinitionClassName; + $this->_methodDefinitionClassName = $methodDefinitionClassName; + + return $this; } + /** + * @return string + */ public function getMethodDefinitionClassName() { return $this->_methodDefinitionClassName; } + /** + * @return array + */ public function getAllMethodDefinitions() { return $this->_methodDefinitions; } + /** + * @param array $args + * @return object + * @throws \Wootook\Core\Exception\DependencyInjection\RuntimeException + */ public function newInstance(Array $args = array()) { try { @@ -145,6 +246,10 @@ class ClassDefinition } } + /** + * @return mixed + * @throws \Wootook\Core\Exception\DependencyInjection\RuntimeException + */ public function newInstanceWithoutConstructor() { try { @@ -154,16 +259,26 @@ class ClassDefinition } } + /** + * @return array + */ public function reset() { return $this->_methodDefinitions = array(); } + /** + * @return null|\ReflectionClass + */ public function getReflector() { return $this->_reflector; } + /** + * @param \ReflectionClass $reflector + * @return ClassDefinition + */ public function setReflector(\ReflectionClass $reflector) { $this->_reflector = $reflector; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php index 3bf86fd..6e5720e 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php @@ -51,7 +51,7 @@ class MethodDefinition * @param $methodName * @param null|\Wootook\Core\DependencyInjection\Registry $registry */ - public function __construct(ClassDefinition $classDefinition, $methodName, DependencyInjection\Registry $registry = null, $argumentDefinitionHandlerClass = null) + public function __construct(ClassDefinition $classDefinition, $methodName, DependencyInjection\Registry $registry = null, $argumentDefinitionClassName = null) { $this->_classDefinition = $classDefinition; @@ -63,11 +63,13 @@ class MethodDefinition throw new CoreException\DependencyInjection\BadMethodCallException($e->getMessage(), $e->getCode(), $e); } - if (is_string($argumentDefinitionHandlerClass)) { - $this->setArgumentDefinitionClassName($argumentDefinitionHandlerClass); + if ($argumentDefinitionClassName !== null) { + $this->setArgumentDefinitionClassName($argumentDefinitionClassName); } - $this->_registry = $registry; + if ($registry !== null) { + $this->setRegistry($registry); + } } /** @@ -133,7 +135,12 @@ class MethodDefinition public function registerArgumentDefinition($argumentPosition, ArgumentDefinition $argumentDefinition) { if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) { + $argumentName = $argumentPosition; $argumentPosition = $this->_argumentIndex[$argumentPosition]; + } else if (($reflector = $argumentDefinition->getReflector()) instanceof \ReflectionParameter) { + $argumentName = $reflector->getName(); + } else { + $argumentName = null; } if (!is_int($argumentPosition)) { @@ -141,6 +148,9 @@ class MethodDefinition } $this->_argumentDefinitions[$argumentPosition] = $argumentDefinition; + if ($argumentName !== null) { + $this->_argumentIndex[$argumentName] = $argumentPosition; + } return $this; } @@ -167,13 +177,33 @@ class MethodDefinition return $this; } + /** + * @return array + */ + public function getAllArgumentDefinitions() + { + return $this->_argumentDefinitions; + } + + /** + * @return array + */ + public function reset() + { + $this->_argumentDefinitions = array(); + + return $this; + } + public function setArgumentDefinitionClassName($argumentDefinitionClassName) { if (!is_string($argumentDefinitionClassName)) { throw new CoreException\DependencyInjection\InvalidArgumentException('Class names only accept string.'); } - return $this->_argumentDefinitionClassName; + $this->_argumentDefinitionClassName = $argumentDefinitionClassName; + + return $this; } public function getArgumentDefinitionClassName() @@ -216,23 +246,11 @@ class MethodDefinition */ public function bindArgumentRegistryEntry($argumentPosition, $registryKey) { - if (($registry = $this->getRegistry()) === null) { - throw new CoreException\DependencyInjection\RuntimeException('No registry available'); - } - $this->getArgumentDefinition($argumentPosition, true)->bindRegistryEntry($registryKey); return $this; } - /** - * @return array - */ - public function getAllArgumentDefinitions() - { - return $this->_argumentDefinitions; - } - /** * @return \ReflectionMethod */ @@ -272,7 +290,7 @@ class MethodDefinition } if (!is_int($argumentPosition) || !isset($this->_argumentReflectors[$argumentPosition])) { - throw new CoreException\DependencyInjection\InvalidArgumentException('Argument not found.'); + throw new CoreException\DependencyInjection\BadMethodCallException('Argument does not exist.'); } return $this->_argumentReflectors[$argumentPosition]; diff --git a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/ClassDefinitionTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/ClassDefinitionTest.php index 2d07a4b..60cf743 100644 --- a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/ClassDefinitionTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/ClassDefinitionTest.php @@ -7,53 +7,177 @@ use Wootook\Core\Config, class ClassDefinitionTest extends \PHPUnit_Framework_TestCase { + public function methodToTest($fooArgumentOne, $fooArgumentTwo = null) + { + // This method exists only for testing method introspection with the Dependency Injection component + } + + /** + * @return \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition + */ + public function getMethodDefinitionMock(Array $additionalMethods = array()) + { + $argumentDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition') + ->setMethods($additionalMethods) + ->disableOriginalConstructor(true) + ->getMock() + ; + + return $argumentDefinition; + } + + /** + * @return \Wootook\Core\DependencyInjection\Registry + */ + public function getRegistryMock(Array $additionalMethods = array()) + { + $registry = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Registry') + ->setMethods($additionalMethods) + ->disableOriginalConstructor(true) + ->getMock() + ; + + return $registry; + } + public function testClassDefinitionInstantiation_withNonExistingClass() { $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\BadMethodCallException'); new Definition\ClassDefinition('InexistentClass'); } - public function testClassDefinitionInstantiation_withSpecialMethodDefinitionClassName() + public function testClassDefinitionInstantiation_withExistingClass() { - $methodDefinitionClassName = \uniqid('WootookUnit_Core_DependencyInjection_Mock_MethodDefinition_TestNewInstance_'); - $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), $methodDefinitionClassName, false); + $definition = new Definition\ClassDefinition('stdClass'); - $definition = new Definition\ClassDefinition(__CLASS__, null, $methodDefinitionClassName); - - $this->assertInstanceOf($methodDefinitionClassName, $definition->getMethodDefinition(__FUNCTION__)); + $this->assertEquals('stdClass', $definition->getReflector()->getName()); } - public function testClassDefinitionInstantiation_assignNewMethodDefinitionInstance() + public function testClassDefinitionInstantiation_withExistingClassWithRegistry() { - $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), '', false); + /** @var \Wootook\Core\DependencyInjection\Registry $registry */ + $registry = $this->getRegistryMock(); - $definition = new Definition\ClassDefinition(__CLASS__); - $definition->setMethodDefinition(__FUNCTION__, $mock); + $definition = new Definition\ClassDefinition('stdClass', $registry); - $this->assertSame($mock, $definition->getMethodDefinition(__FUNCTION__)); + $this->assertEquals('stdClass', $definition->getReflector()->getName()); + $this->assertSame($registry, $definition->getRegistry()); } - public function testGetMethodDefinition_withInvalidMethodName() + public function testClassDefinitionInstantiation_withExistingClass_withRegistry_withSpecialMethodDefinitionClassName() + { + /** @var \Wootook\Core\DependencyInjection\Registry $registry */ + $registry = $this->getRegistryMock(); + + $definition = new Definition\ClassDefinition('stdClass', $registry, 'stdClass'); + + $this->assertEquals('stdClass', $definition->getMethodDefinitionClassName()); + $this->assertSame($registry, $definition->getRegistry()); + } + + public function testClassDefinitionInstantiation_withInvalidSpecialArgumentDefinitionClassName() + { + /** @var \Wootook\Core\DependencyInjection\Registry $registry */ + $registry = $this->getRegistryMock(); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); + $definition = new Definition\ClassDefinition('stdClass', $registry, 32); + } + + public function testClassDefinitionInstantiation_validateReflectorInstance() + { + $definition = new Definition\ClassDefinition('stdClass'); + + $this->assertInstanceOf('ReflectionClass', $definition->getReflector()); + $this->assertEquals('stdClass', $definition->getReflector()->getName()); + } + + public function testClassDefinitionAccessorsAndMutators_usingReflector() + { + $definition = new Definition\classDefinition('stdClass'); + + $this->assertInstanceOf('ReflectionClass', $definition->getReflector()); + + $reflector = new \Reflectionclass(__CLASS__); + $definition->setReflector($reflector); + + $this->assertSame($reflector, $definition->getReflector()); + } + + public function testClassDefinitionMethodDefinitions_initMethodDefinition() + { + $definition = new Definition\ClassDefinition(__CLASS__, null, 'stdClass'); + + $methodDefinition = $definition->initMethodDefinition('methodToTest'); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); + $definition->initMethodDefinition(0); + } + + public function testClassDefinitionMethodDefinitions_registerMethodDefinition() + { + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $methodDefinition */ + $methodDefinition = $this->getMethodDefinitionMock(); + + $definition = new Definition\ClassDefinition('stdClass'); + + $definition->registerMethodDefinition('methodToTest', $methodDefinition); + $this->assertCount(1, $definition->getAllMethodDefinitions()); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); + $definition->registerMethodDefinition(array(), $methodDefinition); + } + + public function testClassDefinitionMethodDefinitions_addMethodDefinition() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition $argumentDefinition */ + $methodDefinition = $this->getMethodDefinitionMock(array('__construct')); + + $definition = new Definition\ClassDefinition(__CLASS__, null, get_class($methodDefinition)); + + $definition->addMethodDefinition('methodToTest'); + $this->assertCount(1, $definition->getAllMethodDefinitions()); + $this->assertInstanceOf(get_class($methodDefinition), $definition->getAllMethodDefinitions()['methodToTest']); + } + + public function testClassDefinitionMethodDefinitions_setMethodDefinition() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition $argumentDefinition */ + $methodDefinition = $this->getMethodDefinitionMock(); + + $definition = new Definition\ClassDefinition(__CLASS__, null, 'stdClass'); + + $definition->setMethodDefinition('methodToTest', $methodDefinition); + $this->assertCount(1, $definition->getAllMethodDefinitions()); + $this->assertInstanceOf(get_class($methodDefinition), $definition->getAllMethodDefinitions()['methodToTest']); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); + $definition->setMethodDefinition(0, $methodDefinition); + } + + public function testClassDefinition_getMethodDefinitionWithInvalidMethodName() { $definition = new Definition\ClassDefinition(__CLASS__); $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); - $definition->getMethodDefinition(42); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->getMethodDefinition(1.5); } - public function testSetMethodDefinition_withInvalidMethodName() + public function testMethodDefinition_getArgumentReflector_withInexistentMethodName() { - $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), '', false); - - $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); - $definition = new Definition\ClassDefinition(__CLASS__); - $definition->setMethodDefinition(42, $mock); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\BadMethodCallException'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->getMethodDefinition('inexistentMethod'); } public function testGetAllMethodDefinitions() { - $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), '', false); + $mock = $this->getMethodDefinitionMock(); $definition = new Definition\ClassDefinition(__CLASS__); $definition->setMethodDefinition('fooMethod', $mock); @@ -66,7 +190,7 @@ class ClassDefinitionTest extends \PHPUnit_Framework_TestCase public function testReset() { - $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), '', false); + $mock = $this->getMethodDefinitionMock(); $definition = new Definition\ClassDefinition(__CLASS__); $definition->setMethodDefinition('fooMethod', $mock); @@ -76,127 +200,166 @@ class ClassDefinitionTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array(), $definition->getAllMethodDefinitions()); } - public function testClassDefinitionAccessors_getReflector() - { - $definition = new Definition\ClassDefinition(__CLASS__); - $this->assertInstanceOf('\\ReflectionClass', $definition->getReflector()); - } +// public function testClassDefinitionInstantiation_withSpecialMethodDefinitionClassName() +// { +// $methodDefinitionClassName = \uniqid('WootookUnit_Core_DependencyInjection_Mock_MethodDefinition_TestNewInstance_'); +// $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), $methodDefinitionClassName, false); +// +// $definition = new Definition\ClassDefinition(__CLASS__, null, $methodDefinitionClassName); +// +// $this->assertInstanceOf($methodDefinitionClassName, $definition->getMethodDefinition(__FUNCTION__)); +// } - public function testClassDefinitionMutators_setReflector() - { - $definition = new Definition\ClassDefinition(__CLASS__); - $reflector = new \ReflectionClass(__CLASS__); - $definition->setReflector($reflector); - - $this->assertSame($reflector, $definition->getReflector()); - } - - public function testNewInstance_hasNoConstructor() - { - $this->markTestSkipped("Method ReflectionClass::newInstance() couldn't be mocked due to API<->Reflection inconsistencies."); - - $reflectionClassMock = $this->getMock('ReflectionClass', array('hasMethod', 'newInstance'), array('stdClass')); - $reflectionClassMock->expects($this->once()) - ->method('hasMethod') - ->with('__construct') - ->will($this->returnValue(false)) - ; - $reflectionClassMock->expects($this->once()) - ->method('newInstance') - ->will($this->returnValue(new \stdClass())) - ; - - $classDefinition = new Definition\ClassDefinition(__CLASS__); - $classDefinition->setReflector($reflectionClassMock); - - $this->assertInstanceOf('stdClass', $classDefinition->newInstance()); - } - - public function testNewInstance_usingConstructor() - { - $expectedArguments = array(42); - - $reflectionClassMock = $this->getMock('ReflectionClass', array('hasMethod', 'newInstanceArgs'), array('stdClass')); - $reflectionClassMock->expects($this->once()) - ->method('hasMethod') - ->with('__construct') - ->will($this->returnValue(true)) - ; - $reflectionClassMock->expects($this->once()) - ->method('newInstanceArgs') - ->with($expectedArguments) - ->will($this->returnValue(new \stdClass())) - ; - - $classDefinition = new Definition\ClassDefinition(__CLASS__); - $classDefinition->setReflector($reflectionClassMock); - - $methodDefinitionMock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array('compileArgs'), array(), '', false); - $methodDefinitionMock->expects($this->once()) - ->method('compileArgs') - ->will($this->returnValue(array(42))) - ; - $classDefinition->setMethodDefinition('__construct', $methodDefinitionMock); - - $this->assertInstanceOf('stdClass', $classDefinition->newInstance()); - } - - public function testNewInstance_usingNonPublicConstructor() - { - $reflectionClassMock = $this->getMock('ReflectionClass', array('hasMethod', 'newInstanceArgs'), array('stdClass')); - $reflectionClassMock->expects($this->once()) - ->method('hasMethod') - ->with('__construct') - ->will($this->returnValue(true)) - ; - $reflectionClassMock->expects($this->once()) - ->method('newInstanceArgs') - ->will($this->throwException($this->getMock('ReflectionException'))) - ; - - $classDefinition = new Definition\ClassDefinition(__CLASS__); - $classDefinition->setReflector($reflectionClassMock); - - $methodDefinitionMock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array('compileArgs'), array(), '', false); - $methodDefinitionMock->expects($this->once()) - ->method('compileArgs') - ->will($this->returnValue(array(42))) - ; - $classDefinition->setMethodDefinition('__construct', $methodDefinitionMock); - - $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\RuntimeException'); - - $this->assertInstanceOf('stdClass', $classDefinition->newInstance()); - } - - public function testNewInstanceWithoutConstructor() - { - $reflectionClassMock = $this->getMock('ReflectionClass', array('newInstanceWithoutConstructor'), array('stdClass')); - $reflectionClassMock->expects($this->once()) - ->method('newInstanceWithoutConstructor') - ->will($this->returnValue(new \stdClass())) - ; - - $classDefinition = new Definition\ClassDefinition(__CLASS__); - $classDefinition->setReflector($reflectionClassMock); - - $this->assertInstanceOf('stdClass', $classDefinition->newInstanceWithoutConstructor()); - } - - public function testNewInstanceWithoutConstructor_throwsException() - { - $reflectionClassMock = $this->getMock('ReflectionClass', array('newInstanceWithoutConstructor'), array('stdClass')); - $reflectionClassMock->expects($this->once()) - ->method('newInstanceWithoutConstructor') - ->will($this->throwException($this->getMock('ReflectionException'))) - ; - - $classDefinition = new Definition\ClassDefinition(__CLASS__); - $classDefinition->setReflector($reflectionClassMock); - - $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\RuntimeException'); - - $this->assertInstanceOf('stdClass', $classDefinition->newInstanceWithoutConstructor()); - } +// public function testClassDefinitionInstantiation_assignNewMethodDefinitionInstance() +// { +// $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), '', false); +// +// $definition = new Definition\ClassDefinition(__CLASS__); +// $definition->setMethodDefinition(__FUNCTION__, $mock); +// +// $this->assertSame($mock, $definition->getMethodDefinition(__FUNCTION__)); +// } +// +// public function testGetMethodDefinition_withInvalidMethodName() +// { +// $definition = new Definition\ClassDefinition(__CLASS__); +// +// $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); +// $definition->getMethodDefinition(42); +// } +// +// public function testSetMethodDefinition_withInvalidMethodName() +// { +// $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array(), array(), '', false); +// +// $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); +// +// $definition = new Definition\ClassDefinition(__CLASS__); +// $definition->setMethodDefinition(42, $mock); +// } +// +// public function testClassDefinitionAccessors_getReflector() +// { +// $definition = new Definition\ClassDefinition(__CLASS__); +// +// $this->assertInstanceOf('\\ReflectionClass', $definition->getReflector()); +// } +// +// public function testClassDefinitionMutators_setReflector() +// { +// $definition = new Definition\ClassDefinition(__CLASS__); +// $reflector = new \ReflectionClass(__CLASS__); +// $definition->setReflector($reflector); +// +// $this->assertSame($reflector, $definition->getReflector()); +// } +// +// public function testNewInstance_hasNoConstructor() +// { +// $this->markTestSkipped("Method ReflectionClass::newInstance() couldn't be mocked due to API<->Reflection inconsistencies."); +// +// $reflectionClassMock = $this->getMock('ReflectionClass', array('hasMethod', 'newInstance'), array('stdClass')); +// $reflectionClassMock->expects($this->once()) +// ->method('hasMethod') +// ->with('__construct') +// ->will($this->returnValue(false)) +// ; +// $reflectionClassMock->expects($this->once()) +// ->method('newInstance') +// ->will($this->returnValue(new \stdClass())) +// ; +// +// $classDefinition = new Definition\ClassDefinition(__CLASS__); +// $classDefinition->setReflector($reflectionClassMock); +// +// $this->assertInstanceOf('stdClass', $classDefinition->newInstance()); +// } +// +// public function testNewInstance_usingConstructor() +// { +// $expectedArguments = array(42); +// +// $reflectionClassMock = $this->getMock('ReflectionClass', array('hasMethod', 'newInstanceArgs'), array('stdClass')); +// $reflectionClassMock->expects($this->once()) +// ->method('hasMethod') +// ->with('__construct') +// ->will($this->returnValue(true)) +// ; +// $reflectionClassMock->expects($this->once()) +// ->method('newInstanceArgs') +// ->with($expectedArguments) +// ->will($this->returnValue(new \stdClass())) +// ; +// +// $classDefinition = new Definition\ClassDefinition(__CLASS__); +// $classDefinition->setReflector($reflectionClassMock); +// +// $methodDefinitionMock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array('compileArgs'), array(), '', false); +// $methodDefinitionMock->expects($this->once()) +// ->method('compileArgs') +// ->will($this->returnValue(array(42))) +// ; +// $classDefinition->setMethodDefinition('__construct', $methodDefinitionMock); +// +// $this->assertInstanceOf('stdClass', $classDefinition->newInstance()); +// } +// +// public function testNewInstance_usingNonPublicConstructor() +// { +// $reflectionClassMock = $this->getMock('ReflectionClass', array('hasMethod', 'newInstanceArgs'), array('stdClass')); +// $reflectionClassMock->expects($this->once()) +// ->method('hasMethod') +// ->with('__construct') +// ->will($this->returnValue(true)) +// ; +// $reflectionClassMock->expects($this->once()) +// ->method('newInstanceArgs') +// ->will($this->throwException($this->getMock('ReflectionException'))) +// ; +// +// $classDefinition = new Definition\ClassDefinition(__CLASS__); +// $classDefinition->setReflector($reflectionClassMock); +// +// $methodDefinitionMock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array('compileArgs'), array(), '', false); +// $methodDefinitionMock->expects($this->once()) +// ->method('compileArgs') +// ->will($this->returnValue(array(42))) +// ; +// $classDefinition->setMethodDefinition('__construct', $methodDefinitionMock); +// +// $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\RuntimeException'); +// +// $this->assertInstanceOf('stdClass', $classDefinition->newInstance()); +// } +// +// public function testNewInstanceWithoutConstructor() +// { +// $reflectionClassMock = $this->getMock('ReflectionClass', array('newInstanceWithoutConstructor'), array('stdClass')); +// $reflectionClassMock->expects($this->once()) +// ->method('newInstanceWithoutConstructor') +// ->will($this->returnValue(new \stdClass())) +// ; +// +// $classDefinition = new Definition\ClassDefinition(__CLASS__); +// $classDefinition->setReflector($reflectionClassMock); +// +// $this->assertInstanceOf('stdClass', $classDefinition->newInstanceWithoutConstructor()); +// } +// +// public function testNewInstanceWithoutConstructor_throwsException() +// { +// $reflectionClassMock = $this->getMock('ReflectionClass', array('newInstanceWithoutConstructor'), array('stdClass')); +// $reflectionClassMock->expects($this->once()) +// ->method('newInstanceWithoutConstructor') +// ->will($this->throwException($this->getMock('ReflectionException'))) +// ; +// +// $classDefinition = new Definition\ClassDefinition(__CLASS__); +// $classDefinition->setReflector($reflectionClassMock); +// +// $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\RuntimeException'); +// +// $this->assertInstanceOf('stdClass', $classDefinition->newInstanceWithoutConstructor()); +// } } diff --git a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php index 3eca6b5..945b681 100644 --- a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php @@ -13,252 +13,417 @@ class MethodDefinitionTest extends \PHPUnit_Framework_TestCase // This method exists only for testing method introspection with the Dependency Injection component } - public function testMethodDefinitionInstantiation_withNonExistingMethod() + /** + * @param array $additionalMethods + * @return \Wootook\Core\DependencyInjection\Definition\ClassDefinition + */ + public function getClassDefinitionMock(Array $additionalMethods = array()) { - $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array(), array(), '', false); + $methods = array_merge($additionalMethods, array('getReflector')); - $mock->expects($this->once()) + $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') + ->setMethods($methods) + ->disableOriginalConstructor(true) + ->getMock() + ; + + $classDefinition->expects($this->once()) ->method('getReflector') ->will($this->returnValue(new \ReflectionClass(__CLASS__))) ; + return $classDefinition; + } + + /** + * @return \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition + */ + public function getArgumentDefinitionMock(Array $additionalMethods = array()) + { + $argumentDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ArgumentDefinition') + ->setMethods($additionalMethods) + ->disableOriginalConstructor(true) + ->getMock() + ; + + return $argumentDefinition; + } + + /** + * @return \Wootook\Core\DependencyInjection\Registry + */ + public function getRegistryMock(Array $additionalMethods = array()) + { + $registry = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Registry') + ->setMethods($additionalMethods) + ->disableOriginalConstructor(true) + ->getMock() + ; + + return $registry; + } + + public function testMethodDefinitionInstantiation_withNonExistingMethod() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\BadMethodCallException'); - new Definition\MethodDefinition($mock, 'inexistentMethod'); + new Definition\MethodDefinition($classDefinition, 'inexistentMethod'); + } + + public function testMethodDefinitionInstantiation_withExistingMethod() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + new Definition\MethodDefinition($classDefinition, 'methodToTest'); } public function testMethodDefinitionInstantiation_withoutRegistry_withSpecialArgumentDefinitionClassName() { - $argumentDefinitionClassName = \uniqid('WootookUnit_Core_DependencyInjection_Mock_ArgumentDefinition_TestNewInstance_'); - $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ArgumentDefinition', array(), array(), $argumentDefinitionClassName, false); + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); - $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array(), array(), '', false); + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest', null, 'stdClass'); - $mock->expects($this->once()) - ->method('getReflector') - ->will($this->returnValue(new \ReflectionClass(__CLASS__))) - ; - - $definition = new Definition\MethodDefinition($mock, 'methodToTest', null, $argumentDefinitionClassName); - - $this->assertInstanceOf($argumentDefinitionClassName, $definition->getArgumentDefinition('fooArgumentOne')); + $this->assertEquals('stdClass', $definition->getArgumentDefinitionClassName()); } public function testMethodDefinitionInstantiation_withRegistry_withSpecialArgumentDefinitionClassName() { - $app = $this->getMock('Wootook\\Core\\App\\App', array(), array(), '', false); /** @var \Wootook\Core\DependencyInjection\Registry $registry */ - $registry = $this->getMock('Wootook\\Core\\DependencyInjection\\Registry', array(), array($app)); + $registry = $this->getRegistryMock(); - $argumentDefinitionClassName = \uniqid('WootookUnit_Core_DependencyInjection_Mock_ArgumentDefinition_TestNewInstance_'); - $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ArgumentDefinition', array(), array(), $argumentDefinitionClassName, false); + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); - /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $mock */ - $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array('getReflector'), array(), '', false); + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest', $registry, 'stdClass'); - $mock->expects($this->once()) - ->method('getReflector') - ->will($this->returnValue(new \ReflectionClass(__CLASS__))) - ; - - $definition = new Definition\MethodDefinition($mock, 'methodToTest', $registry, $argumentDefinitionClassName); - - $this->assertInstanceOf($argumentDefinitionClassName, $definition->getArgumentDefinition('fooArgumentOne')); + $this->assertEquals('stdClass', $definition->getArgumentDefinitionClassName()); + $this->assertSame($registry, $definition->getRegistry()); } - public function testMethodDefinitionAccessors_getReflector() + public function testMethodDefinitionInstantiation_withInvalidSpecialArgumentDefinitionClassName() { - $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array('getReflector'), array(), '', false); + /** @var \Wootook\Core\DependencyInjection\Registry $registry */ + $registry = $this->getRegistryMock(); - $mock->expects($this->once()) - ->method('getReflector') - ->will($this->returnValue(new \ReflectionClass(__CLASS__))) - ; + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); - $definition = new Definition\MethodDefinition($mock, __FUNCTION__); - - $this->assertInstanceOf('\\ReflectionMethod', $definition->getReflector()); + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest', $registry, 32); } - public function testMethodDefinitionMutators_setReflector() + public function testMethodDefinitionInstantiation_validateReflectorInstance() { - $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array('getReflector'), array(), '', false); + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); - $mock->expects($this->once()) - ->method('getReflector') - ->will($this->returnValue(new \ReflectionClass(__CLASS__))) - ; + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); - $definition = new Definition\MethodDefinition($mock, __FUNCTION__); - $reflector = new \ReflectionMethod(__CLASS__, __FUNCTION__); + $this->assertInstanceOf('ReflectionMethod', $definition->getReflector()); + $this->assertEquals('methodToTest', $definition->getReflector()->getName()); + } + + public function testMethodDefinitionAccessorsAndMutators_usingReflector() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + $this->assertInstanceOf('ReflectionMethod', $definition->getReflector()); + + $reflector = new \ReflectionMethod(__CLASS__, 'methodToTest'); $definition->setReflector($reflector); $this->assertSame($reflector, $definition->getReflector()); } - public function testMethodDefinition_accessorAndMutatorForRegistry() + public function testMethodDefinitionAccessors_usingArgumentReflector() { - $registryMock = $this->getMock('Wootook\\Core\\DependencyInjection\\Registry', array(), array(), '', false); - $classDefinitionMock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array('getReflector'), array(), '', false); + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); - $classDefinitionMock->expects($this->once()) - ->method('getReflector') - ->will($this->returnValue(new \ReflectionClass(__CLASS__))) - ; + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); - $definition = new Definition\MethodDefinition($classDefinitionMock, __FUNCTION__); - $definition->setRegistry($registryMock); + $reflector = $definition->getArgumentReflector(0); + $this->assertInstanceOf('ReflectionParameter', $reflector); + $this->assertEquals('fooArgumentOne', $reflector->getName()); + $this->assertEquals(0, $reflector->getPosition()); - $this->assertSame($registryMock, $definition->getRegistry()); + $reflector = $definition->getArgumentReflector('fooArgumentOne'); + $this->assertInstanceOf('ReflectionParameter', $reflector); + $this->assertEquals('fooArgumentOne', $reflector->getName()); + $this->assertEquals(0, $reflector->getPosition()); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\BadMethodCallException'); + $definition->getArgumentReflector(array()); } - public function testMethodDefinition_bindArgumentValue_withNumericArgumentIndex() + public function testMethodDefinitionArgumentDefinitions_initArgumentDefinition() { - $classDefinition = new Definition\ClassDefinition(__CLASS__); + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest', null, 'stdClass'); + + $argumentDefinition = $definition->initArgumentDefinition(0); + $this->assertInstanceOf('stdClass', $argumentDefinition); + + $argumentDefinition = $definition->initArgumentDefinition('fooArgumentOne'); + $this->assertInstanceOf('stdClass', $argumentDefinition); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); + $definition->initArgumentDefinition(array()); + } + + public function testMethodDefinitionArgumentDefinitions_registerArgumentDefinition() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + /** @var \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition $argumentDefinition */ + $argumentDefinition = $this->getArgumentDefinitionMock(); + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + $definition->registerArgumentDefinition(0, $argumentDefinition); + $this->assertCount(1, $definition->getAllArgumentDefinitions()); + + $definition->registerArgumentDefinition('fooArgumentOne', $argumentDefinition); + $this->assertCount(1, $definition->getAllArgumentDefinitions()); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); + $definition->registerArgumentDefinition(array(), $argumentDefinition); + } + + public function testMethodDefinitionArgumentDefinitions_addArgumentDefinition() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + /** @var \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition $argumentDefinition */ + $argumentDefinition = $this->getArgumentDefinitionMock(array('__construct')); + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest', null, get_class($argumentDefinition)); + + $definition->addArgumentDefinition(0); + $this->assertCount(1, $definition->getAllArgumentDefinitions()); + $this->assertInstanceOf(get_class($argumentDefinition), $definition->getAllArgumentDefinitions()[0]); + } + + public function testMethodDefinitionArgumentDefinitions_setArgumentDefinition() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + /** @var \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition $argumentDefinition */ + $argumentDefinition = $this->getArgumentDefinitionMock(); + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest', null, 'stdClass'); + + $definition->setArgumentDefinition(0, $argumentDefinition); + $this->assertCount(1, $definition->getAllArgumentDefinitions()); + $this->assertInstanceOf(get_class($argumentDefinition), $definition->getAllArgumentDefinitions()[0]); + + $definition->setArgumentDefinition('fooArgumentOne', $argumentDefinition); + $this->assertCount(1, $definition->getAllArgumentDefinitions()); + $this->assertInstanceOf(get_class($argumentDefinition), $definition->getAllArgumentDefinitions()[0]); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); + $definition->setArgumentDefinition(array(), $argumentDefinition); + } + + public function testMethodDefinitionBindings_bindArgumentValueWithNumericArgumentIndex() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array('getArgumentDefinition'), array($classDefinition, 'methodToTest')); + $argumentDefinition = $this->getArgumentDefinitionMock(array('bindValue')); + $definition->expects($this->once()) ->method('getArgumentDefinition') - ->with(0) - ->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0))) + ->with(0, true) + ->will($this->returnValue($argumentDefinition)) + ; + + $argumentDefinition->expects($this->once()) + ->method('bindValue') + ->with(65) ; /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ $definition->bindArgumentValue(0, 65); } - public function testMethodDefinition_bindArgumentVariable_withNumericArgumentIndex() + public function testMethodDefinitionBindings_bindArgumentValueWithNamedArgumentIndex() { - $classDefinition = new Definition\ClassDefinition(__CLASS__); + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array('getArgumentDefinition'), array($classDefinition, 'methodToTest')); + $argumentDefinition = $this->getArgumentDefinitionMock(array('bindValue')); + $definition->expects($this->once()) ->method('getArgumentDefinition') - ->with(0) - ->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0))) + ->with('fooArgumentOne', true) + ->will($this->returnValue($argumentDefinition)) ; - $variable = 65; - /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ - $definition->bindArgumentVariable(0, $variable); - } - - public function testMethodDefinition_bindArgumentRegistryEntry_withNumericArgumentIndex() - { - $classDefinition = new Definition\ClassDefinition(__CLASS__); - $registry = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Registry') - ->disableOriginalConstructor() - ->setMethods(array('get')) - ->getMock(); - - $registry->expects($this->any())->method('get')->will($this->returnValue(36)); - - $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', - array('getArgumentDefinition'), array($classDefinition, 'methodToTest', $registry)); - - $definition->expects($this->once()) - ->method('getArgumentDefinition') - ->with(0) - ->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0, $registry))) - ; - - /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ - $definition->bindArgumentRegistryEntry(0, 'foo'); - } - - public function testMethodDefinition_bindArgumentValue_withNamedArgumentIndex() - { - $classDefinition = new Definition\ClassDefinition(__CLASS__); - - $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', - array('getArgumentDefinition'), array($classDefinition, 'methodToTest')); - - $definition->expects($this->once()) - ->method('getArgumentDefinition') - ->with('fooArgumentOne') - ->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0))) + $argumentDefinition->expects($this->once()) + ->method('bindValue') + ->with(65) ; /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ $definition->bindArgumentValue('fooArgumentOne', 65); } - public function testMethodDefinition_bindArgumentVariable_withNamedArgumentIndex() + public function testMethodDefinitionBindings_bindArgumentVariableWithNumericArgumentIndex() { - $classDefinition = new Definition\ClassDefinition(__CLASS__); + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array('getArgumentDefinition'), array($classDefinition, 'methodToTest')); + $argumentDefinition = $this->getArgumentDefinitionMock(array('bindVariable')); + $definition->expects($this->once()) ->method('getArgumentDefinition') - ->with('fooArgumentOne') - ->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0))) + ->with(0, true) + ->will($this->returnValue($argumentDefinition)) ; - $variable = 65; + $argumentDefinition->expects($this->once()) + ->method('bindVariable') + ->with(42) + ; + + $variable = 42; + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->bindArgumentVariable(0, $variable); + } + + public function testMethodDefinitionBindings_bindArgumentVariableWithNamedArgumentIndex() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', + array('getArgumentDefinition'), array($classDefinition, 'methodToTest')); + + $argumentDefinition = $this->getArgumentDefinitionMock(array('bindVariable')); + + $definition->expects($this->once()) + ->method('getArgumentDefinition') + ->with('fooArgumentOne', true) + ->will($this->returnValue($argumentDefinition)) + ; + + $argumentDefinition->expects($this->once()) + ->method('bindVariable') + ->with(42) + ; + + $variable = 42; /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ $definition->bindArgumentVariable('fooArgumentOne', $variable); } - public function testMethodDefinition_bindArgumentRegistryEntry_withNamedArgumentIndex() + public function testMethodDefinitionBindings_bindArgumentRegistryEntryWithNumericArgumentIndex() { - $classDefinition = new Definition\ClassDefinition(__CLASS__); - $registry = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Registry') - ->disableOriginalConstructor() - ->setMethods(array('get')) - ->getMock(); - - $registry->expects($this->any())->method('get')->will($this->returnValue(36)); + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + /** @var \Wootook\Core\DependencyInjection\Registry $registry */ + $registry = $this->getRegistryMock(); $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array('getArgumentDefinition'), array($classDefinition, 'methodToTest', $registry)); + $argumentDefinition = $this->getArgumentDefinitionMock(array('bindRegistryEntry')); + $definition->expects($this->once()) ->method('getArgumentDefinition') - ->with('fooArgumentOne') - ->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0, $registry))) + ->with(0, true) + ->will($this->returnValue($argumentDefinition)) + ; + + $argumentDefinition->expects($this->once()) + ->method('bindRegistryEntry') + ->with('foo') + ; + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->bindArgumentRegistryEntry(0, 'foo'); + } + + public function testMethodDefinitionBindings_bindArgumentRegistryEntryWithNamedArgumentIndex() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + /** @var \Wootook\Core\DependencyInjection\Registry $registry */ + $registry = $this->getRegistryMock(); + + $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', + array('getArgumentDefinition'), array($classDefinition, 'methodToTest', $registry)); + + $argumentDefinition = $this->getArgumentDefinitionMock(array('bindRegistryEntry')); + + $definition->expects($this->once()) + ->method('getArgumentDefinition') + ->with('fooArgumentOne', true) + ->will($this->returnValue($argumentDefinition)) + ; + + $argumentDefinition->expects($this->once()) + ->method('bindRegistryEntry') + ->with('foo') ; /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ $definition->bindArgumentRegistryEntry('fooArgumentOne', 'foo'); } - public function testMethodDefinition_bindArgumentRegistryEntry_withNoRegistry() + public function testMethodDefinitionBindings_bindArgumentRegistryEntryWithNoRegistry() { - $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') - ->disableOriginalConstructor() - ->getMock() - ; - - $classDefinition->expects($this->once()) - ->method('getReflector') - ->will($this->returnValue(new \ReflectionClass(__CLASS__))) - ; + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); $definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition', array('getArgumentDefinition'), array($classDefinition, 'methodToTest')); + $argumentDefinition = $this->getArgumentDefinitionMock(array('bindRegistryEntry')); + + $definition->expects($this->once()) + ->method('getArgumentDefinition') + ->with('fooArgumentOne', true) + ->will($this->returnValue($argumentDefinition)) + ; + + $argumentDefinition->expects($this->once()) + ->method('bindRegistryEntry') + ->with('foo') + ->will($this->throwException(new \Wootook\Core\Exception\DependencyInjection\RuntimeException)) + ; $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\RuntimeException'); /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ $definition->bindArgumentRegistryEntry('fooArgumentOne', 'foo'); } - public function testMethodDefinition_getArgumentDefinition_withInvalidArgumentId() + public function testMethodDefinition_getArgumentDefinitionWithInvalidArgumentId() { - $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') - ->disableOriginalConstructor() - ->getMock() - ; - - $classDefinition->expects($this->once()) - ->method('getReflector') - ->will($this->returnValue(new \ReflectionClass(__CLASS__))) - ; + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); @@ -270,15 +435,8 @@ class MethodDefinitionTest extends \PHPUnit_Framework_TestCase public function testMethodDefinition_getArgumentReflector_withNumericArgumentId() { - $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') - ->disableOriginalConstructor() - ->getMock() - ; - - $classDefinition->expects($this->once()) - ->method('getReflector') - ->will($this->returnValue(new \ReflectionClass(__CLASS__))) - ; + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); @@ -288,17 +446,23 @@ class MethodDefinitionTest extends \PHPUnit_Framework_TestCase $this->assertEquals(0, $reflector->getPosition()); } + public function testMethodDefinition_getArgumentReflector_withInexistentNumericArgumentId() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\BadMethodCallException'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->getArgumentReflector(5); + } + public function testMethodDefinition_getArgumentReflector_withNamedArgumentId() { - $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') - ->disableOriginalConstructor() - ->getMock() - ; - - $classDefinition->expects($this->once()) - ->method('getReflector') - ->will($this->returnValue(new \ReflectionClass(__CLASS__))) - ; + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); @@ -308,23 +472,139 @@ class MethodDefinitionTest extends \PHPUnit_Framework_TestCase $this->assertEquals(0, $reflector->getPosition()); } + public function testMethodDefinition_getArgumentReflector_withInexistentNamedArgumentId() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\BadMethodCallException'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->getArgumentReflector('inexistentArgument'); + } + public function testMethodDefinition_getArgumentReflector_withInvalidArgumentId() { - $classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition') - ->disableOriginalConstructor() - ->getMock() - ; + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); - $classDefinition->expects($this->once()) - ->method('getReflector') - ->will($this->returnValue(new \ReflectionClass(__CLASS__))) - ; + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\BadMethodCallException'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->getArgumentReflector(1.5); + } + + public function testMethodDefinition_getArgumentDefinition_withNumericArgumentId() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $argumentDefinition = $definition->getArgumentDefinition(0); + $this->assertInstanceOf('Wootook\\Core\\DependencyInjection\\Definition\\ArgumentDefinition', $argumentDefinition); + } + + public function testMethodDefinition_getArgumentDefinition_withInexistentNumericArgumentId() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\BadMethodCallException'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->getArgumentDefinition(5); + } + + public function testMethodDefinition_getArgumentDefinition_withNamedArgumentId() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $argumentDefinition = $definition->getArgumentDefinition('fooArgumentOne'); + $this->assertInstanceOf('Wootook\\Core\\DependencyInjection\\Definition\\ArgumentDefinition', $argumentDefinition); + } + + public function testMethodDefinition_getArgumentDefinition_withInexistentNamedArgumentId() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ - $definition->getArgumentReflector(1.5); + $definition->getArgumentDefinition('inexistentArgument'); + } + + public function testMethodDefinition_getArgumentDefinition_withInvalidArgumentId() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + $this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->getArgumentDefinition(1.5); + } + + public function testMethodDefinition_getArgumentDefinition_withExistingArgument() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->addArgumentDefinition(0); + + $argumentDefinition = $definition->getArgumentDefinition(0); + $this->assertInstanceOf('Wootook\\Core\\DependencyInjection\\Definition\\ArgumentDefinition', $argumentDefinition); + } + + public function testMethodDefinition_getArgumentDefinition_withInexistingArgumentRegistered() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $argumentDefinition = $definition->getArgumentDefinition(0, true); + $this->assertInstanceOf('Wootook\\Core\\DependencyInjection\\Definition\\ArgumentDefinition', $argumentDefinition); + } + + public function testMethodDefinition_resetArgumentDefinitionList() + { + /** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $classDefinition */ + $classDefinition = $this->getClassDefinitionMock(); + + $definition = new Definition\MethodDefinition($classDefinition, 'methodToTest'); + + /** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */ + $definition->getArgumentDefinition(0, true); + $definition->getArgumentDefinition(1, true); + + $all = $definition->getAllArgumentDefinitions(); + $this->assertInternalType('array', $all); + $this->assertCount(2, $all); + + $definition->reset(); + $all = $definition->getAllArgumentDefinitions(); + $this->assertInternalType('array', $all); + $this->assertCount(0, $all); } } diff --git a/src/application/modules/WootookCore/test/phpunit.xml b/src/application/modules/WootookCore/test/phpunit.xml index 6271b05..76bb90c 100644 --- a/src/application/modules/WootookCore/test/phpunit.xml +++ b/src/application/modules/WootookCore/test/phpunit.xml @@ -21,15 +21,15 @@ --> - - --> + From 74c4f31f7f7c9b2d15cb1719c4d0be2201fe0aaa Mon Sep 17 00:00:00 2001 From: Mandalorien Date: Tue, 22 Jan 2013 17:21:24 +0100 Subject: [PATCH 10/14] Update src/application/code/core/Legacies/Empire/install/mysql5/install-1.5.0.php correction --- .../core/Legacies/Empire/install/mysql5/install-1.5.0.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/application/code/core/Legacies/Empire/install/mysql5/install-1.5.0.php b/src/application/code/core/Legacies/Empire/install/mysql5/install-1.5.0.php index c4fc32e..ba30531 100644 --- a/src/application/code/core/Legacies/Empire/install/mysql5/install-1.5.0.php +++ b/src/application/code/core/Legacies/Empire/install/mysql5/install-1.5.0.php @@ -351,8 +351,8 @@ CREATE TABLE IF NOT EXISTS {$this->getTableName('planets')} ( `gauss_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0, `ionic_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0, `buster_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0, - `small_protection_shield` ENUM('0','1') NOT NULL DEFAULT 0, - `big_protection_shield` ENUM('0','1') NOT NULL DEFAULT 0, + `small_protection_shield` ENUM('0','1') NOT NULL DEFAULT '0', + `big_protection_shield` ENUM('0','1') NOT NULL DEFAULT '0', `interceptor_misil` SMALLINT NOT NULL DEFAULT 0, `interplanetary_misil` SMALLINT NOT NULL DEFAULT 0, `metal_mine_porcent` TINYINT NOT NULL DEFAULT 10, From 4b92511baecccb576fae091aedab691eb9f75121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20TALON?= Date: Sun, 24 Feb 2013 17:56:44 +0100 Subject: [PATCH 11/14] Fix second parameter of function date (options.php) --- .gitignore | 1 + src/options.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c40f034..24b99ed 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ config.php .idea/ coverage/ src/application/cache/* +src/application/configs/local.php diff --git a/src/options.php b/src/options.php index a33c7bb..34c5b1e 100644 --- a/src/options.php +++ b/src/options.php @@ -250,7 +250,7 @@ $mode = isset($_GET['mode']) ? $_GET['mode'] : null; $parse['opt_modev_data'] = ($user['urlaubs_modus'] == 1)?" checked='checked'/":''; $parse['opt_modev_exit'] = ($user['urlaubs_modus'] == 0)?" checked='1'/":''; $parse['Vaccation_mode'] = $lang['Vaccation_mode']; - $parse['vacation_until'] = date("d.m.Y G:i:s",$user['urlaubs_until']); + $parse['vacation_until'] = date("d.m.Y G:i:s",$user['urlaubs_until']->getTimestamp()); $parse['user_settings_rep'] = ($user['settings_rep'] == 1) ? " checked='checked'/":''; $parse['user_settings_esp'] = ($user['settings_esp'] == 1) ? " checked='checked'/":''; $parse['user_settings_wri'] = ($user['settings_wri'] == 1) ? " checked='checked'/":''; From 8ebc4cd91f744a5c836df7c4e06599a7918132cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20TALON?= Date: Sun, 24 Feb 2013 18:11:09 +0100 Subject: [PATCH 12/14] Fix undefined dpath (options.php) --- src/options.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/options.php b/src/options.php index 34c5b1e..dfe2ea2 100644 --- a/src/options.php +++ b/src/options.php @@ -49,15 +49,15 @@ $mode = isset($_GET['mode']) ? $_GET['mode'] : null; message($lang['You_cant_exit_vmode'], $lan['Error'] ,"options.php",1); } } + + $dpath = (!$user["dpath"]) ? DEFAULT_SKINPATH : $user["dpath"]; if ($_POST && $mode == "change") { // Array ( [db_character] - $iduser = $user["id"]; - $avatar = $_POST["avatar"]; + $iduser = $user["id"]; + $avatar = $_POST["avatar"]; - if ($_POST["dpath"] != "") - $dpath = $_POST["dpath"]; - else - $dpath = (!$user["dpath"]) ? DEFAULT_SKINPATH : $user["dpath"]; + if ($_POST["dpath"] != "") + $dpath = $_POST["dpath"]; // Gestion des options speciales pour les admins if ($user['authlevel'] != LEVEL_PLAYER) { From 6f1e5e4467e1bfc44167f2ab57f8d2b64a1c21ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20TALON?= Date: Sun, 24 Feb 2013 19:01:04 +0100 Subject: [PATCH 13/14] Fix Marchand Fix undefined value in options.php --- src/marchand.php | 23 +++++++++++------------ src/options.php | 7 ++----- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/marchand.php b/src/marchand.php index 6f6876e..ed76401 100644 --- a/src/marchand.php +++ b/src/marchand.php @@ -39,13 +39,13 @@ function ModuleMarchand ( $CurrentUser, &$CurrentPlanet ) { $parse = $lang; - if ($_POST['ress'] != '') { + if (isset($_POST['ress']) && $_POST['ress'] != '') { $PageTPL = gettemplate('message_body'); $Error = false; $CheatTry = false; - $Metal = $_POST['metal']; - $Crystal = $_POST['cristal']; - $Deuterium = $_POST['deut']; + $Metal = isset($_POST['metal']) ? $_POST['metal'] : 0; + $Crystal = isset($_POST['cristal']) ? $_POST['cristal'] : 0; + $Deuterium = isset($_POST['deut']) ? $_POST['deut'] : 0; if ($Metal < 0) { $Metal *= -1; $CheatTry = true; @@ -72,8 +72,8 @@ function ModuleMarchand ( $CurrentUser, &$CurrentPlanet ) { case 'cristal': $Necessaire = (( $Metal * 0.5) + ( $Deuterium * 2)); - if ($CurrentPlanet['crystal'] > $Necessaire) { - $CurrentPlanet['crystal'] -= $Necessaire; + if ($CurrentPlanet['cristal'] > $Necessaire) { + $CurrentPlanet['cristal'] -= $Necessaire; } else { $Message = $lang['mod_ma_noten'] ." ". $lang['Crystal'] ."! "; $Error = true; @@ -94,17 +94,17 @@ function ModuleMarchand ( $CurrentUser, &$CurrentPlanet ) { if ($Error == false) { if ($CheatTry == true) { $CurrentPlanet['metal'] = 0; - $CurrentPlanet['crystal'] = 0; + $CurrentPlanet['cristal'] = 0; $CurrentPlanet['deuterium'] = 0; } else { $CurrentPlanet['metal'] += $Metal; - $CurrentPlanet['crystal'] += $Crystal; + $CurrentPlanet['cristal'] += $Crystal; $CurrentPlanet['deuterium'] += $Deuterium; } $QryUpdatePlanet = "UPDATE {{table}} SET "; $QryUpdatePlanet .= "`metal` = '". $CurrentPlanet['metal'] ."', "; - $QryUpdatePlanet .= "`crystal` = '". $CurrentPlanet['crystal'] ."', "; + $QryUpdatePlanet .= "`cristal` = '". $CurrentPlanet['cristal'] ."', "; $QryUpdatePlanet .= "`deuterium` = '". $CurrentPlanet['deuterium'] ."' "; $QryUpdatePlanet .= "WHERE "; $QryUpdatePlanet .= "`id` = '". $CurrentPlanet['id'] ."';"; @@ -118,7 +118,7 @@ function ModuleMarchand ( $CurrentUser, &$CurrentPlanet ) { } $parse['mes'] = $Message; } else { - if ($_POST['action'] != 2) { + if (!isset($_POST['action']) || $_POST['action'] != 2) { $PageTPL = gettemplate('marchand_main'); } else { $parse['mod_ma_res'] = "1"; @@ -145,8 +145,7 @@ function ModuleMarchand ( $CurrentUser, &$CurrentPlanet ) { $Page = parsetemplate ( $PageTPL, $parse ); return $Page; } - - $Page = ModuleMarchand ( $user, $planetrow ); + $Page = ModuleMarchand ( $user, $planet ); display ( $Page, $lang['mod_marchand'], true, '', false ); // ----------------------------------------------------------------------------------------------------------- diff --git a/src/options.php b/src/options.php index dfe2ea2..8490b7a 100644 --- a/src/options.php +++ b/src/options.php @@ -61,7 +61,7 @@ $mode = isset($_GET['mode']) ? $_GET['mode'] : null; // Gestion des options speciales pour les admins if ($user['authlevel'] != LEVEL_PLAYER) { - if ($_POST['adm_pl_prot'] == 'on') { + if (isset($_POST['adm_pl_prot']) && $_POST['adm_pl_prot'] == 'on') { doquery ("UPDATE {{table}} SET `id_level` = '".$user['authlevel']."' WHERE `id_owner` = '".$user['id']."';", 'planets'); } else { doquery ("UPDATE {{table}} SET `id_level` = '0' WHERE `id_owner` = '".$user['id']."';", 'planets'); @@ -191,10 +191,7 @@ $mode = isset($_GET['mode']) ? $_GET['mode'] : null; `settings_bud` = '$settings_bud', `settings_mis` = '$settings_mis', `settings_rep` = '$settings_rep', - `db_deaktjava` = '$db_deaktjava', - `kolorminus` = '$kolorminus', - `kolorplus` = '$kolorplus', - `kolorpoziom` = '$kolorpoziom' + `db_deaktjava` = '$db_deaktjava' WHERE `id` = '$iduser' LIMIT 1", "users"); if (isset($_POST["db_password"]) && md5($_POST["db_password"]) == $user["password"]) { From 5797328adcf7065b6c446b0c42b97f1c1a262e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20TALON?= Date: Sun, 24 Feb 2013 20:45:07 +0100 Subject: [PATCH 14/14] Fix date of messages and undefined var --- src/includes/functions/SendSimpleMessage.php | 2 +- src/messages.php | 19 ++++++++------- src/resources.php | 2 +- src/search.php | 25 ++++++++++---------- src/stat.php | 8 ++++--- 5 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/includes/functions/SendSimpleMessage.php b/src/includes/functions/SendSimpleMessage.php index 3e19e1c..3d2b0ab 100644 --- a/src/includes/functions/SendSimpleMessage.php +++ b/src/includes/functions/SendSimpleMessage.php @@ -49,7 +49,7 @@ function SendSimpleMessage ( $Owner, $Sender, $Time, $Type, $From, $Subject, $Me $QryInsertMessage = "INSERT INTO {{table}} SET "; $QryInsertMessage .= "`message_owner` = '". $Owner ."', "; $QryInsertMessage .= "`message_sender` = '". $Sender ."', "; - $QryInsertMessage .= "`message_time` = '" . $Time . "', "; +// $QryInsertMessage .= "`message_time` = '" . $Time . "', "; $QryInsertMessage .= "`message_type` = '". $Type ."', "; $QryInsertMessage .= "`message_from` = '". addslashes( $From ) ."', "; $QryInsertMessage .= "`message_subject` = '". addslashes( $Subject ) ."', "; diff --git a/src/messages.php b/src/messages.php index bb8bb1d..9d080e5 100644 --- a/src/messages.php +++ b/src/messages.php @@ -40,11 +40,11 @@ if(!isset($user['authlevel'])) { includeLang('messages'); -$OwnerID = $_GET['id']; -$MessCategory = $_GET['messcat']; -$MessPageMode = (string) $_GET['mode']; -$DeleteWhat = $_POST['deletemessages']; -if (isset ($DeleteWhat)) { +$OwnerID = isset($_GET['id']) ? $_GET['id'] : null; +$MessCategory = isset($_GET['messcat']) ? $_GET['messcat'] : null; +$MessPageMode = isset($_GET['mode']) ? (string) $_GET['mode'] : null; +$DeleteWhat = isset($_POST['deletemessages']) ? $_POST['deletemessages'] : null; +if (!empty($DeleteWhat)) { $MessPageMode = "delete"; } @@ -55,6 +55,9 @@ $MessageType = array (0, 1, 2, 3, 4, 5, 15, 99, 100 ); $TitleColor = array (0 => '#FFFF00', 1 => '#FF6699', 2 => '#FF3300', 3 => '#FF9900', 4 => '#773399', 5 => '#009933', 15 => '#030070', 99 => '#007070', 100 => '#ABABAB'); $BackGndColor = array (0 => '#663366', 1 => '#336666', 2 => '#000099', 3 => '#666666', 4 => '#999999', 5 => '#999999', 15 => '#999999', 99 => '#999999', 100 => '#999999'); +$page = null; +$text = null; + for ($MessType = 0; $MessType < 101; $MessType++) { if (in_array($MessType, $MessageType) ) { $WaitingMess[$MessType] = $UnRead[$messfields[$MessType]]; @@ -230,7 +233,7 @@ $Message = trim ( nl2br ( strip_tags ( $_POST['text'], '
    ' ) ) ); } $page .= "
    "; + $page .= "\"".$lang['mess_answer']."\""; } else { $page .= ""; } @@ -254,12 +257,12 @@ $Message = trim ( nl2br ( strip_tags ( $_POST['text'], '
    ' ) ) ); } $page .= "\n"; $page .= ""; $page .= ""; - $page .= ""; + $page .= ""; $page .= ""; $page .= ""; + $page .= "\"".$lang['mess_answer']."\""; } else { $page .= ""; } diff --git a/src/resources.php b/src/resources.php index 222c86d..0d0ff77 100644 --- a/src/resources.php +++ b/src/resources.php @@ -252,7 +252,7 @@ $user = Wootook_Player_Model_Session::getSingleton()->getPlayer(); $planet = $user->getCurrentPlanet(); $Page = BuildRessourcePage($user, $planet); -display($Page, $lang['Resources']); +display($Page, 'Resources', false); // ----------------------------------------------------------------------------------------------------------- // History version diff --git a/src/search.php b/src/search.php index 7a90a53..5b469f5 100644 --- a/src/search.php +++ b/src/search.php @@ -32,15 +32,15 @@ define('INSIDE' , true); define('INSTALL' , false); require_once dirname(__FILE__) .'/application/bootstrap.php'; -$searchtext = mysql_escape_string($_POST['searchtext']); -$type = $_POST['type']; +$searchtext = isset($_POST['searchtext']) ? mysql_escape_string($_POST['searchtext']) : null; +$type = isset($_POST['type']) ? $_POST['type'] : null; -$dpath = (!$user["dpath"]) ? DEFAULT_SKINPATH : $user["dpath"]; +$dpath = (empty($user["dpath"])) ? DEFAULT_SKINPATH : $user["dpath"]; includeLang('search'); +$search_results = null; +$result_list = null; $i = 0; -//creamos la query -$searchtext = mysql_escape_string($_POST["searchtext"]); switch($type){ case "playername": $table = gettemplate('search_user_table'); @@ -89,7 +89,7 @@ if(isset($searchtext) && isset($type)){ }else{ $pquery = doquery("SELECT name FROM {{table}} WHERE id = {$s['id_planet']}","planets",true); $s['planet_name'] = $pquery['name']; - $s['ally_name'] = ($aquery['ally_name']!='')?"{$aquery['ally_name']}":''; + $s['ally_name'] = (!empty($aquery['ally_name']))?"{$aquery['ally_name']}":''; } //ahora la alianza if($s['ally_id']!=0&&$s['ally_request']==0){ @@ -99,8 +99,9 @@ if(isset($searchtext) && isset($type)){ } - - $s['position'] = "".$s['rank'].""; + if (!empty($s['rank'])) { + $s['position'] = "".$s['rank'].""; + } $s['dpath'] = $dpath; $s['coordinated'] = "{$s['galaxy']}:{$s['system']}:{$s['planet']}"; $s['buddy_request'] = $lang['buddy_request']; @@ -122,10 +123,10 @@ if(isset($searchtext) && isset($type)){ } //el resto... -$lang['type_playername'] = ($_POST["type"] == "playername") ? " SELECTED" : ""; -$lang['type_planetname'] = ($_POST["type"] == "planetname") ? " SELECTED" : ""; -$lang['type_allytag'] = ($_POST["type"] == "allytag") ? " SELECTED" : ""; -$lang['type_allyname'] = ($_POST["type"] == "allyname") ? " SELECTED" : ""; +$lang['type_playername'] = (isset($_POST["type"]) && $_POST["type"] == "playername") ? " SELECTED" : ""; +$lang['type_planetname'] = (isset($_POST["type"]) && $_POST["type"] == "planetname") ? " SELECTED" : ""; +$lang['type_allytag'] = (isset($_POST["type"]) && $_POST["type"] == "allytag") ? " SELECTED" : ""; +$lang['type_allyname'] = (isset($_POST["type"]) && $_POST["type"] == "allyname") ? " SELECTED" : ""; $lang['searchtext'] = $searchtext; $lang['search_results'] = $search_results; //esto es algo repetitivo ... w diff --git a/src/stat.php b/src/stat.php index c623527..e99027e 100644 --- a/src/stat.php +++ b/src/stat.php @@ -35,19 +35,20 @@ require_once dirname(__FILE__) .'/application/bootstrap.php'; includeLang('stat'); $parse = $lang; -$who = (isset($_POST['who'])) ? $_POST['who'] : $_GET['who']; +$who = (isset($_POST['who'])) ? $_POST['who'] : isset($_GET['who']) ? $_GET['who'] : null; if (!isset($who)) { $who = 1; } -$type = (isset($_POST['type'])) ? $_POST['type'] : $_GET['type']; +$type = (isset($_POST['type'])) ? $_POST['type'] : isset($_GET['type']) ? $_GET['type'] : null; if (!isset($type)) { $type = 1; } -$range = (isset($_POST['range'])) ? $_POST['range'] : $_GET['range']; +$range = (isset($_POST['range'])) ? $_POST['range'] : isset($_GET['range']) ? $_GET['range'] : null; if (!isset($range)) { $range = 1; } +$start = 0; $parse['who'] = ""; $parse['who'] .= ""; @@ -144,6 +145,7 @@ if ($who == 2) { } } else { $MaxUsers = doquery ("SELECT COUNT(*) AS `count` FROM {{table}} WHERE `db_deaktjava` = '0';", 'users', true); + $LastPage = 0; if ($MaxUsers['count'] > 100) { $LastPage = floor($MaxUsers['count'] / 100); }
    "; - $Result .= ""; + $Result .= ""; $Result .= ""; $Result .= $MissionType6Link; @@ -124,7 +124,7 @@ function GalaxyRowPlanet ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowUser, $Galaxy // $Result .= ", STICKY, MOUSEOFF, DELAY, ". ($user["settings_tooltiptime"] * 1000) .", CENTER, OFFSETX, -40, OFFSETY, -40 );'"; $Result .= ", STICKY, MOUSEOFF, DELAY, 750, CENTER, OFFSETX, -40, OFFSETY, -40 );'"; $Result .= " onmouseout='return nd();'>"; - $Result .= ""; + $Result .= ""; // $Result .= $GalaxyRowPlanet["name"]; $Result .= ""; } @@ -133,4 +133,4 @@ function GalaxyRowPlanet ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowUser, $Galaxy return $Result; } -?> +?> \ No newline at end of file diff --git a/src/includes/functions/GalaxyRowPlanetName.php b/src/includes/functions/GalaxyRowPlanetName.php index 5a108ce..60a2477 100644 --- a/src/includes/functions/GalaxyRowPlanetName.php +++ b/src/includes/functions/GalaxyRowPlanetName.php @@ -62,14 +62,9 @@ function GalaxyRowPlanetName ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowUser, $Ga $EndColor = ""; } - $updateTimeLimit = new Wootook_Core_DateTime(); - $updateTimeLimit->sub(3600); - if ($updateTimeLimit->isLater($GalaxyRowPlanet['last_update']) && $GalaxyRowUser['id'] != $user['id']) { - if ($GalaxyRowPlanet['last_update'] instanceof Wootook_Core_DateTime) { - $Inactivity = pretty_time_hour(time() - $GalaxyRowPlanet['last_update']->getTimestamp()); - } else { - $Inactivity = pretty_time_hour(0); - } + if ($GalaxyRowPlanet['last_update'] > (time()-59 * 60) AND + $GalaxyRowUser['id'] != $user['id']) { + $Inactivity = pretty_time_hour(time() - $GalaxyRowPlanet['last_update']); } if ($GalaxyRow && $GalaxyRowPlanet["destruyed"] == 0) { if ($HavePhalanx <> 0) { @@ -90,25 +85,22 @@ function GalaxyRowPlanetName ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowUser, $Ga $Result .= $TextColor . $PhalanxTypeLink . $EndColor; - if ($GalaxyRowUser->getId() && $updateTimeLimit->isLater($GalaxyRowPlanet['last_update']) && - $GalaxyRowUser['id'] != $user['id']) { - - $updateTimeLimit = new Wootook_Core_DateTime(); - $updateTimeLimit->sub(600); - if ($GalaxyRowUser->getId() && $updateTimeLimit->isLater($GalaxyRowPlanet['last_update']) && - $GalaxyRowUser['id'] != $user['id']) { - $Result .= "(*)"; - } else { - $Result .= " (".$Inactivity.")"; - } - } - } elseif ($GalaxyRowPlanet["destruyed"] != 0) { - $Result .= $lang['gl_destroyedplanet']; - } + if ($GalaxyRowPlanet['last_update'] > (time()-59 * 60) AND + $GalaxyRowUser['id'] != $user['id']) { + if ($GalaxyRowPlanet['last_update'] > (time()-10 * 60) AND + $GalaxyRowUser['id'] != $user['id']) { + $Result .= "(*)"; + } else { + $Result .= " (".$Inactivity.")"; + } + } + } elseif ($GalaxyRowPlanet["destruyed"] != 0) { + $Result .= $lang['gl_destroyedplanet']; + } $Result .= "". stripslashes( $CurMess['message_subject'] ) ." "; if ($CurMess['message_type'] == 1) { $page .= ""; - $page .= "\"".$lang['mess_answer']."\"
    ". date("m-d H:i:s O", $CurMess['message_time']) ."". date("d-m-Y H:i:s", strtotime($CurMess['message_time'])) ."". stripslashes( $CurMess['message_from'] ) ."". stripslashes( $CurMess['message_subject'] ) ." "; if ($CurMess['message_type'] == 1) { $page .= ""; - $page .= "\"".$lang['mess_answer']."\"