diff --git a/composer.json b/composer.json index b1680774..24288ad6 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ }, "require": { "php": ">=5.6.0", - "psr/log": "*", + "psr/log": ">=1.0.0", + "psr/container": ">=1.0.0", "pimple/pimple": "^3.0", "lemonphp/event": "^1.0", "matthiasmullie/minify": "^1.3" @@ -38,5 +39,5 @@ "psr-4": { "Jaxon\\Tests\\": "tests/" } - } + } } diff --git a/src/Contracts/Container.php b/src/Contracts/Container.php deleted file mode 100644 index 0f0847a5..00000000 --- a/src/Contracts/Container.php +++ /dev/null @@ -1,34 +0,0 @@ - - * @copyright 2016 Thierry Feuzeu - * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License - * @link https://github.com/jaxon-php/jaxon-core - */ - -namespace Jaxon\Contracts; - -interface Container -{ - /** - * Check if a given class is defined in the container - * - * @param string $sClass A full class name - * - * @return bool - */ - public function has($sClass); - - /** - * Get a class instance - * - * @param string $sClass A full class name - * - * @return mixed The class instance - */ - public function get($sClass); -} diff --git a/src/Jaxon.php b/src/Jaxon.php index 7be2deb2..a97c9ee3 100644 --- a/src/Jaxon.php +++ b/src/Jaxon.php @@ -46,7 +46,7 @@ class Jaxon implements LoggerAwareInterface * * @var string */ - private $sVersion = 'Jaxon 3.1.3'; + private $sVersion = 'Jaxon 3.2.0'; /* * Plugin types diff --git a/src/Plugin/Code/Generator.php b/src/Plugin/Code/Generator.php index a79ac0fe..6eda5139 100644 --- a/src/Plugin/Code/Generator.php +++ b/src/Plugin/Code/Generator.php @@ -28,7 +28,7 @@ class Generator * * @var string */ - const JS_LIB_URL = 'https://cdn.jsdelivr.net/gh/jaxon-php/jaxon-js@3.0/dist'; + const JS_LIB_URL = 'https://cdn.jsdelivr.net/gh/jaxon-php/jaxon-js@3.2/dist'; /** * The objects that generate code @@ -183,15 +183,6 @@ public function getJs() */ private function _getScript() { - $aConfigVars = $this->getOptionVars(); - $sYesScript = 'jaxon.ajax.response.process(command.response)'; - $sNoScript = 'jaxon.confirm.skip(command);jaxon.ajax.response.process(command.response)'; - $sQuestionScript = jaxon()->dialog()->confirm('msg', $sYesScript, $sNoScript); - - $aConfigVars['sQuestionScript'] = $this->_render('confirm.js', [ - 'sQuestionScript' => $sQuestionScript, - ]); - $sScript = ''; $sReadyScript = ''; foreach($this->aGenerators as $xGenerator) @@ -205,6 +196,7 @@ private function _getScript() } // These three parts are always rendered together + $aConfigVars = $this->getOptionVars(); return $this->_render('config.js', $aConfigVars) . "\n" . $sScript . "\n" . $this->_render('ready.js', ['sScript' => $sReadyScript]); } diff --git a/src/Response/Features/JsCommands.php b/src/Response/Features/JsCommands.php index 23abbe6f..074ca243 100644 --- a/src/Response/Features/JsCommands.php +++ b/src/Response/Features/JsCommands.php @@ -10,6 +10,8 @@ namespace Jaxon\Response\Features; +use Jaxon\Response\Response; + trait JsCommands { /** @@ -34,23 +36,58 @@ abstract public function addCommand(array $aAttributes, $mData); */ abstract protected function _addCommand($sName, array $aAttributes, $mData, $bRemoveEmpty = false); + /** + * Merge the response commands from the specified object with + * the response commands in this object + * + * @param Response|array $mCommands The object + * @param boolean $bBefore Add the new commands to the beginning of the list + * + * @return void + */ + abstract public function appendResponse($mCommands, $bBefore = false); + /** * Response command that prompts user with [ok] [cancel] style message box * * If the user clicks cancel, the specified number of response commands * following this one, will be skipped. * - * @param integer $iCmdNumber The number of commands to skip upon cancel - * @param string $sMessage The message to display to the user + * @param integer $iCommandCount The number of commands to skip upon cancel + * @param string $sMessage The message to display to the user * * @return Response */ - public function confirmCommands($iCmdNumber, $sMessage) + public function confirmCommands($iCommandCount, $sMessage) { - $aAttributes = ['id' => $iCmdNumber]; + $aAttributes = ['count' => $iCommandCount]; return $this->_addCommand('cc', $aAttributes, $sMessage); } + /** + * Response command that prompts user with [ok] [cancel] style message box + * + * If the user clicks cancel, the specified number of response commands + * following this one, will be skipped. + * + * @param string $sMessage The message to display to the user + * @param callable $xCallable The function + * + * @return Response + */ + public function confirm($sMessage, $xCallable) + { + $xResponse = jaxon()->newResponse(); + \call_user_func($xCallable, $xResponse); + $iCommandCount = $xResponse->getCommandCount(); + if($iCommandCount > 0) + { + $this->confirmCommands($iCommandCount, $sMessage); + $this->appendResponse($xResponse); + } + return $this; + } + /** * Add a command to display an alert message to the user * diff --git a/src/Utils/DI/Container.php b/src/Utils/DI/Container.php index 1a856331..c30e42ed 100644 --- a/src/Utils/DI/Container.php +++ b/src/Utils/DI/Container.php @@ -33,7 +33,6 @@ use Jaxon\Plugin\Manager as PluginManager; use Jaxon\Plugin\Code\Generator as CodeGenerator; use Jaxon\Contracts\Session as SessionContract; -use Jaxon\Contracts\Container as ContainerContract; use Jaxon\App\App; use Jaxon\App\Bootstrap; @@ -53,6 +52,8 @@ use Jaxon\Utils\Session\Manager as SessionManager; use Jaxon\Utils\Http\URI; +use Pimple\Container as PimpleContainer; +use Psr\Container\ContainerInterface; use Lemon\Event\EventDispatcher; use Closure; use ReflectionClass; @@ -62,14 +63,14 @@ class Container /** * The Dependency Injection Container * - * @var \Pimple\Container + * @var PimpleContainer */ private $libContainer = null; /** * The Dependency Injection Container * - * @var \Jaxon\Contracts\Container + * @var ContainerInterface */ private $appContainer = null; @@ -80,7 +81,7 @@ class Container */ public function __construct(array $aOptions) { - $this->libContainer = new \Pimple\Container(); + $this->libContainer = new PimpleContainer(); $this->libContainer[Container::class] = $this; $sTranslationDir = realpath(__DIR__ . '/../../../translations'); @@ -92,7 +93,7 @@ public function __construct(array $aOptions) /** * Get the container provided by the integrated framework * - * @return ContainerContract + * @return ContainerInterface */ public function getAppContainer() { @@ -102,11 +103,11 @@ public function getAppContainer() /** * Set the container provided by the integrated framework * - * @param ContainerContract $container The container implementation + * @param ContainerInterface $container The container implementation * * @return void */ - public function setAppContainer(ContainerContract $container) + public function setAppContainer(ContainerInterface $container) { $this->appContainer = $container; } diff --git a/src/start.php b/src/start.php index 891e7345..f29ed77c 100644 --- a/src/start.php +++ b/src/start.php @@ -2,6 +2,9 @@ use Jaxon\Jaxon; use Jaxon\Plugin\Plugin; +use Jaxon\Request\Factory\RequestFactory; +use Jaxon\Request\Factory\ParameterFactory; +use Jaxon\Response\Plugin\JQuery\Dom\Element as DomElement; /** * start.php - @@ -57,7 +60,7 @@ function jaxon_register_plugin(Plugin $xPlugin, $nPriority = 1000) /** * Get the single instance of the request factory, and set the class to call. * - * @return \Jaxon\Request\Factory\RequestFactory + * @return RequestFactory */ function rq($sClassName = null) { @@ -67,13 +70,28 @@ function rq($sClassName = null) /** * Get the single instance of the parameter factory * - * @return \Jaxon\Request\Factory\ParameterFactory + * @return ParameterFactory */ -function pr() +function pm() { return Jaxon::getInstance()->di()->getParameterFactory(); } +/** + * Get the single instance of the parameter factory + * + * The pr function is already defined in CakePHP, so it was renamed to pm. + * This function is therefore deprecated, and will be removed in a future version. + * + * @return ParameterFactory + */ +if(!function_exists('pr')) +{ + function pr() + { + return Jaxon::getInstance()->di()->getParameterFactory(); + } +} /** * Create a JQuery Element with a given selector * @@ -83,11 +101,11 @@ function pr() * @param string $sSelector The jQuery selector * @param string $sContext A context associated to the selector * - * @return \Jaxon\Response\Plugin\JQuery\Dom\Element + * @return DomElement */ function jq($sSelector = '', $sContext = '') { - return new \Jaxon\Response\Plugin\JQuery\Dom\Element($sSelector, $sContext); + return new DomElement($sSelector, $sContext); } /** @@ -99,7 +117,7 @@ function jq($sSelector = '', $sContext = '') * @param string $sSelector The jQuery selector * @param string $sContext A context associated to the selector * - * @return \Jaxon\Response\Plugin\JQuery\Dom\Element + * @return DomElement */ function jQuery($sSelector = '', $sContext = '') { diff --git a/templates/plugins/config.js.php b/templates/plugins/config.js.php index e28b1a3b..9402fdea 100644 --- a/templates/plugins/config.js.php +++ b/templates/plugins/config.js.php @@ -39,5 +39,3 @@ } } - -sQuestionScript; diff --git a/templates/plugins/confirm.js.php b/templates/plugins/confirm.js.php deleted file mode 100644 index 55a977e0..00000000 --- a/templates/plugins/confirm.js.php +++ /dev/null @@ -1,43 +0,0 @@ -jaxon.confirm = { - skip: function(command) { - numberOfCommands = command.id; - while (0 < numberOfCommands) { - jaxon.tools.queue.pop(command.response); - --numberOfCommands; - } - } -}; -/* - Function: jaxon.confirm.commands - - A rewrite of the jaxon.confirm.commands function which uses the user configured confirm library. - - Parameters: - command (object) - jaxon response object - - Returns: - true - The operation completed successfully. -*/ -jaxon.confirm.commands = function(command) { - command.fullName = 'confirmCommands'; - var msg = command.data; - /* - * Unlike javascript confirm(), third party confirm() functions are not blocking. - * Therefore, to prevent the next commands to run while the library is waiting for the user confirmation, - * the remaining commands are moved to a new queue in the command object. - * They will be processed in the confirm callbacks. - * Note that only one confirm command will be allowed in a Jaxon response. - */ - command.response = jaxon.tools.queue.create(jaxon.config.responseQueueSize); - while((obj = jaxon.tools.queue.pop(jaxon.response)) != null) - { - jaxon.tools.queue.push(command.response, obj); - delete obj; - } - sQuestionScript ?>; - return true; -}; - -jaxon.dom.ready(function() { - jaxon.command.handler.register("cc", jaxon.confirm.commands); -});