Example #1
0
 /**
  * Get a global template var.
  *
  * @param   string  $key  The template var key.
  *
  * @return  mixed
  *
  * @since   1.0
  */
 public function __get($key)
 {
     if ($this->globals->exists($key)) {
         return $this->globals->get($key);
     }
     if ($this->debug) {
         trigger_error('No template var: ' . $key);
     }
     return '';
 }
Example #2
0
 /**
  * Check whether data exists in the session store
  *
  * @param   string  $name  Name of variable
  *
  * @return  boolean  True if the variable exists
  *
  * @since   4.0
  */
 public function has($name)
 {
     if (!$this->isStarted()) {
         $this->start();
     }
     return $this->data->exists($name);
 }
Example #3
0
 /**
  * Method to filter the form data.
  *
  * @param   array   $data   An array of field values to filter.
  * @param   string  $group  The dot-separated form group path on which to filter the fields.
  *
  * @return  mixed  Array or false.
  *
  * @since   11.1
  */
 public function filter($data, $group = null)
 {
     // Make sure there is a valid JForm XML document.
     if (!$this->xml instanceof SimpleXMLElement) {
         return false;
     }
     $input = new Registry($data);
     $output = new Registry();
     // Get the fields for which to filter the data.
     $fields = $this->findFieldsByGroup($group);
     if (!$fields) {
         // PANIC!
         return false;
     }
     // Filter the fields.
     foreach ($fields as $field) {
         $name = (string) $field['name'];
         // Get the field groups for the element.
         $attrs = $field->xpath('ancestor::fields[@name]/@name');
         $groups = array_map('strval', $attrs ? $attrs : array());
         $group = implode('.', $groups);
         $key = $group ? $group . '.' . $name : $name;
         // Filter the value if it exists.
         if ($input->exists($key)) {
             $output->set($key, $this->filterField($field, $input->get($key, (string) $field['default'])));
         }
     }
     return $output->toArray();
 }
 /**
  * Test the Joomla\Registry\Registry::exists method.
  *
  * @return  void
  *
  * @covers  Joomla\Registry\Registry::exists
  * @since   1.0
  */
 public function testExists()
 {
     $a = new Registry();
     $a->set('foo', 'bar1');
     $a->set('config.foo', 'bar2');
     $a->set('deep.level.foo', 'bar3');
     $this->assertThat($a->exists('foo'), $this->isTrue(), 'Line: ' . __LINE__ . ' The path should exist, returning true.');
     $this->assertThat($a->exists('config.foo'), $this->isTrue(), 'Line: ' . __LINE__ . ' The path should exist, returning true.');
     $this->assertThat($a->exists('deep.level.foo'), $this->isTrue(), 'Line: ' . __LINE__ . ' The path should exist, returning true.');
     $this->assertThat($a->exists('deep.level.bar'), $this->isFalse(), 'Line: ' . __LINE__ . ' The path should not exist, returning false.');
     $this->assertThat($a->exists('bar.foo'), $this->isFalse(), 'Line: ' . __LINE__ . ' The path should not exist, returning false.');
 }
Example #5
0
 /**
  * Method to filter the form data.
  *
  * @param   array   $data   An array of field values to filter.
  * @param   string  $group  The dot-separated form group path on which to filter the fields.
  *
  * @return  mixed  Array or false.
  *
  * @since   11.1
  */
 public function filter($data, $group = null)
 {
     // Make sure there is a valid JForm XML document.
     if (!$this->xml instanceof SimpleXMLElement) {
         return false;
     }
     $input = new Registry($data);
     $output = new Registry();
     // Get the fields for which to filter the data.
     $fields = $this->findFieldsByGroup($group);
     if (!$fields) {
         // PANIC!
         return false;
     }
     // Filter the fields.
     foreach ($fields as $field) {
         $name = (string) $field['name'];
         // Get the field groups for the element.
         $attrs = $field->xpath('ancestor::fields[@name]/@name');
         $groups = array_map('strval', $attrs ? $attrs : array());
         $group = implode('.', $groups);
         $key = $group ? $group . '.' . $name : $name;
         // Filter the value if it exists.
         if ($input->exists($key)) {
             $output->set($key, $this->filterField($field, $input->get($key, (string) $field['default'])));
         }
         // Get the JFormField object for this field, only it knows if it is supposed to be multiple.
         $jfield = $this->getField($name, $group);
         // Fields supporting multiple values must be stored as empty arrays when no values are selected.
         // If not, they will appear to be unset and then revert to their default value.
         if ($jfield && $jfield->multiple && !$output->exists($key)) {
             $output->set($key, array());
         }
     }
     return $output->toArray();
 }
 /**
  * Check whether data exists in the session store
  *
  * @param   string  $name       Name of variable
  * @param   string  $namespace  Namespace to use, default to 'default'
  *
  * @return  boolean  True if the variable exists
  *
  * @since   11.1
  */
 public function has($name, $namespace = 'default')
 {
     return $this->data->exists($namespace . '.' . $name);
 }
Example #7
0
 /**
  * @testdox  The Registry does not validate an empty path exists
  *
  * @covers   Joomla\Registry\Registry::exists
  */
 public function testEnsureEmptyPathsDoNotExist()
 {
     $a = new Registry();
     $this->assertFalse($a->exists(''), 'An empty path should not exist.');
 }