"Fossies" - the Fresh Open Source Software Archive

Member "papayacms-core-6.9.4/src/system/Papaya/UI/Control/Command/Action.php" (13 Dec 2019, 2738 Bytes) of package /linux/www/papayacms-core-6.9.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Action.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 /**
    3  * papaya CMS
    4  *
    5  * @copyright 2000-2018 by papayaCMS project - All rights reserved.
    6  * @link http://www.papaya-cms.com/
    7  * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License, version 2
    8  *
    9  *  You can redistribute and/or modify this script under the terms of the GNU General Public
   10  *  License (GPL) version 2, provided that the copyright and license notes, including these
   11  *  lines, remain unmodified. papaya is distributed in the hope that it will be useful, but
   12  *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   13  *  FOR A PARTICULAR PURPOSE.
   14  */
   15 namespace Papaya\UI\Control\Command;
   16 
   17 use Papaya\Request;
   18 use Papaya\UI;
   19 use Papaya\XML;
   20 
   21 /**
   22  * A command that executes an action depending on a specific set of parameters
   23  *
   24  * @package Papaya-Library
   25  * @subpackage UI
   26  */
   27 class Action extends UI\Control\Command {
   28   /**
   29    * Dialog object
   30    *
   31    * @var \Papaya\UI\Dialog
   32    */
   33   private $_data;
   34 
   35   /**
   36    * Dialog event callbacks
   37    *
   38    * @var \Papaya\UI\Control\Command\Dialog\Callbacks
   39    */
   40   private $_callbacks;
   41 
   42   /**
   43    * Execute command and append result to output xml
   44    *
   45    * @param XML\Element $parent
   46    *
   47    * @return XML\Element
   48    */
   49   public function appendTo(XML\Element $parent) {
   50     if ($this->data()->validate()) {
   51       $this->callbacks()->onValidationSuccessful($this, $parent);
   52     } else {
   53       $this->callbacks()->onValidationFailed($this, $parent);
   54     }
   55     return $parent;
   56   }
   57 
   58   /**
   59    * Getter/Setter to the validated parameters data subobject.
   60    *
   61    * @param Request\Parameters\Validator $data
   62    *
   63    * @return Request\Parameters\Validator|\Papaya\UI\Dialog
   64    */
   65   public function data(Request\Parameters\Validator $data = NULL) {
   66     if (NULL !== $data) {
   67       $this->_data = $data;
   68     } elseif (NULL === $this->_data) {
   69       $this->_data = $this->_createData();
   70     }
   71     return $this->_data;
   72   }
   73 
   74   /**
   75    * Create parameters validator using the "getDefintion()" callback
   76    *
   77    * @param array|null $definitions
   78    *
   79    * @return Request\Parameters\Validator
   80    */
   81   protected function _createData(array $definitions = NULL) {
   82     return new Request\Parameters\Validator(
   83       NULL !== $definitions ? $definitions : $this->callbacks()->getDefinition(),
   84       $this->parameters()
   85     );
   86   }
   87 
   88   /**
   89    * Getter/Setter for the callbacks object
   90    *
   91    * @param Action\Callbacks $callbacks
   92    *
   93    * @return Action\Callbacks
   94    */
   95   public function callbacks(Action\Callbacks $callbacks = NULL) {
   96     if (NULL !== $callbacks) {
   97       $this->_callbacks = $callbacks;
   98     } elseif (NULL === $this->_callbacks) {
   99       $this->_callbacks = new Action\Callbacks();
  100     }
  101     return $this->_callbacks;
  102   }
  103 }