Пример #1
0
 /**
  * This method loads the specified file for reading.
  *
  * @access public
  * @static
  * @param Config\Reader $reader                             the config reader to use
  * @param boolean $case_sensitive                           whether keys are to be case sensitive
  * @param string $path                                      the path to the value to be returned
  * @return mixed                                            the resource as a collection
  */
 public static function unmarshal(Config\Reader $reader, $case_sensitive = true, $path = null)
 {
     if ($path !== null && !$case_sensitive) {
         $path = strtolower($path);
     }
     return static::useCollections($reader->read($path), Core\Convert::toBoolean($case_sensitive));
 }
Пример #2
0
 /**
  * This method returns whether the logger is enabled.
  *
  * @access public
  * @return boolean                                          whether the logger is enabled
  */
 public function isEnabled()
 {
     if ($this->policy->hasKey('enabled')) {
         Core\Convert::toBoolean($this->policy->getValue('enabled'));
     }
     return true;
 }
Пример #3
0
 /**
  * This method processes the models and returns the status.
  *
  * @access public
  * @param BT\Exchange $exchange                             the exchange given to process
  * @return integer                                          the status code
  */
 public function process(BT\Exchange $exchange)
 {
     $shuffle = Core\Convert::toBoolean($this->policy->getValue('shuffle'));
     if ($shuffle) {
         $this->tasks->shuffle();
     }
     $index = Core\Convert::toInteger($this->policy->getValue('index'));
     if ($this->tasks->hasIndex($index)) {
         return BT\Task\Handler::process($this->tasks->getValue($index), $exchange);
     }
     return BT\Task\Status::ERROR;
 }
Пример #4
0
 /**
  * This method processes the models and returns the status.
  *
  * @access public
  * @param BT\Exchange $exchange                             the exchange given to process
  * @return integer                                          the status code
  */
 public function process(BT\Exchange $exchange)
 {
     $count = $this->tasks->count();
     if ($count > 0) {
         $shuffle = Core\Convert::toBoolean($this->policy->getValue('shuffle'));
         if ($shuffle) {
             $this->tasks->shuffle();
         }
         $inactivesCt = 0;
         $successesCt = 0;
         $successesMax = min(Core\Convert::toInteger($this->policy->getValue('successes')), $count);
         $failuresCt = 0;
         $failuresMax = min(Core\Convert::toInteger($this->policy->getValue('failures')), $count);
         foreach ($this->tasks as $task) {
             $status = BT\Task\Handler::process($task, $exchange);
             switch ($status) {
                 case BT\Task\Status::INACTIVE:
                     $inactivesCt++;
                     break;
                 case BT\Task\Status::ACTIVE:
                     break;
                 case BT\Task\Status::SUCCESS:
                     $successesCt++;
                     if ($successesCt >= $successesMax) {
                         return BT\Task\Status::SUCCESS;
                     }
                     break;
                 case BT\Task\Status::FAILED:
                     $failuresCt++;
                     if ($failuresCt >= $failuresMax) {
                         return BT\Task\Status::FAILED;
                     }
                     break;
                 case BT\Task\Status::ERROR:
                 case BT\Task\Status::QUIT:
                     return $status;
             }
         }
         if ($inactivesCt != $count) {
             return BT\Task\Status::ACTIVE;
         }
     }
     return BT\Task\Status::INACTIVE;
 }
Пример #5
0
 /**
  * This method processes the models and returns the status.
  *
  * @access public
  * @param BT\Exchange $exchange                             the exchange given to process
  * @return integer                                          the status code
  */
 public function process(BT\Exchange $exchange)
 {
     $shuffle = Core\Convert::toBoolean($this->policy->getValue('shuffle'));
     if ($shuffle) {
         $this->tasks->shuffle();
     }
     $inactives = 0;
     foreach ($this->tasks as $task) {
         $status = BT\Task\Handler::process($task, $exchange);
         if ($status == BT\Task\Status::INACTIVE) {
             $inactives++;
         } else {
             if ($status != BT\Task\Status::SUCCESS) {
                 return $status;
             }
         }
     }
     return $inactives < $this->tasks->count() ? BT\Task\Status::SUCCESS : BT\Task\Status::INACTIVE;
 }
Пример #6
0
 /**
  * This method attempts to resolve the value as a boolean in accordance with the schema
  * definition.
  *
  * @access public
  * @static
  * @param mixed $value                                      the value to be resolved
  * @param array $definition                                 the schema definition
  * @return mixed                                            the resolved value
  * @throws Throwable\Runtime\Exception                      indicates that the value failed
  *                                                          to meet a requirement
  */
 public static function resolveBooleanValue($value, $definition)
 {
     if (MappingService\Data\ToolKit::isUnset($value)) {
         if (isset($definition['required']) && $definition['required']) {
             throw new Throwable\Runtime\Exception('Invalid value defined. Expected a value that is a boolean, but got :type.', array(':type' => Core\DataType::info($value)->type));
         }
         return $value;
     }
     $value = Core\Convert::toBoolean($value);
     return $value;
 }
Пример #7
0
 /**
  * This constructor initializes the class.
  *
  * @access public
  * @param mixed $schema                                     the JSON schema
  * @param boolean $case_sensitive                           whether field names are case
  *                                                          sensitive
  */
 public function __construct($schema, $case_sensitive = true)
 {
     parent::__construct();
     $this->schema = MappingService\Data\Model\JSON\Helper::resolveJSONSchema($schema);
     $this->case_sensitive = Core\Convert::toBoolean($case_sensitive);
 }
Пример #8
0
 /**
  * This method initializes the class with the specified values (if any are provided).
  *
  * @access public
  * @param \Traversable $elements                            a traversable array or collection
  * @param boolean $case_sensitive                           whether field names are case
  *                                                          sensitive
  */
 public function __construct($elements = null, $case_sensitive = true)
 {
     $this->case_sensitive = Core\Convert::toBoolean($case_sensitive);
     parent::__construct($elements);
 }
Пример #9
0
 /**
  * This method parses a child node.
  *
  * @access protected
  * @param \SimpleXMLElement $node                           a reference to a child node
  * @return \Unicity\Common\Mutable\ICollection              a collection representing the data
  *                                                          in the soap file
  * @throws \Unicity\Throwable\Parse\Exception               indicates that an unrecognized child
  *                                                          node was encountered
  */
 protected function parseChildElement(\SimpleXMLElement $node)
 {
     $children = $node->children();
     if (count($children) > 0) {
         $list = new Common\Mutable\ArrayList();
         $map = new Common\Mutable\HashMap();
         foreach ($children as $child) {
             $name = $child->getName();
             $value = $this->parseChildElement($child);
             $temp = new Common\Mutable\HashMap();
             $temp->putEntry($name, $value);
             $list->addValue($temp);
             $map->putEntry($name, $value);
         }
         return $list->count() > $map->count() || $this->directives->hasKey('expandableProperties') && $this->directives->getValue('expandableProperties')->hasValue($node->getName()) ? $list : $map;
     } else {
         $value = dom_import_simplexml($node)->textContent;
         $value = trim($value);
         if ($value == '') {
             $value = Core\Data\Undefined::instance();
         } else {
             if (preg_match('/^(true|false)$/i', $value)) {
                 $value = Core\Convert::toBoolean($value);
             } else {
                 if (preg_match('/^[+-]?(0|[1-9][0-9]*)((\\.[0-9]+)|([eE][+-]?(0|[1-9][0-9]*)))$/', $value)) {
                     $value = Core\Convert::toDouble($value);
                 } else {
                     if (filter_var($value, FILTER_VALIDATE_INT) !== false) {
                         $value = Core\Convert::toInteger($value);
                     } else {
                         $value = Core\Convert::toString($value);
                     }
                 }
             }
         }
         return $value;
     }
 }
Пример #10
0
 /**
  * This method parses a custom node.
  *
  * @access protected
  * @param \SimpleXMLElement $node                           a reference to a custom node
  * @return \Unicity\Common\Mutable\ICollection              a collection representing the data
  *                                                          in the soap file
  * @throws \Unicity\Throwable\Parse\Exception               indicates that an unrecognized child
  *                                                          node was encountered
  */
 protected function parseCustomElement(\SimpleXMLElement $node)
 {
     $children = $this->getElementChildren($node, null);
     if (count($children) > 0) {
         $list = new Common\Mutable\ArrayList();
         $map = new Common\Mutable\HashMap();
         foreach ($children as $child) {
             $name = $child->getName();
             $value = $this->parseCustomElement($child);
             $temp = new Common\Mutable\HashMap();
             $temp->putEntry($name, $value);
             $list->addValue($temp);
             $map->putEntry($name, $value);
         }
         return $list->count() > $map->count() || $this->directives->hasKey('expandableProperties') && $this->directives->getValue('expandableProperties')->hasValue($node->getName()) ? $list : $map;
     } else {
         $value = dom_import_simplexml($node)->textContent;
         $value = trim($value);
         if ($value == '') {
             $attributes = $node->attributes('xsi', true);
             if (isset($attributes['nil'])) {
                 $nil = SOAP\Data\XML::valueOf($attributes['nil']);
                 if (!SOAP\Data\XML\Syntax::isBoolean($nil)) {
                     throw new Throwable\Parse\Exception('Unable to process SOAP XML. Expected a valid boolean token, but got ":token".', array(':token' => $nil));
                 }
                 $value = strtolower($nil) != 'false' ? null : Core\Data\Undefined::instance();
             } else {
                 $value = Core\Data\Undefined::instance();
             }
         } else {
             if (preg_match('/^(true|false)$/i', $value)) {
                 $value = Core\Convert::toBoolean($value);
             } else {
                 if (preg_match('/^[+-]?(0|[1-9][0-9]*)((\\.[0-9]+)|([eE][+-]?(0|[1-9][0-9]*)))$/', $value)) {
                     $value = Core\Convert::toDouble($value);
                 } else {
                     if (filter_var($value, FILTER_VALIDATE_INT) !== false) {
                         $value = Core\Convert::toInteger($value);
                     } else {
                         $value = Core\Convert::toString($value);
                     }
                 }
             }
         }
         return $value;
     }
 }