예제 #1
0
파일: Response.php 프로젝트: ngnpope/jerity
 /**
  *
  */
 protected function encodeArrayToXML($data, $parent, $pretty_print = false)
 {
     $content = '';
     $parent_sing = Inflector::singularize($parent);
     $numeric_keys = Arrays::isNumericallyKeyed($data);
     if ($pretty_print !== false) {
         $prefix = str_repeat('  ', $pretty_print);
     } else {
         $prefix = '';
     }
     foreach ($data as $key => $value) {
         $key = $numeric_keys ? $parent_sing : $key;
         $content .= $prefix . '<' . htmlspecialchars($key) . '>';
         switch (true) {
             case is_array($value):
             case is_object($value):
                 if ($pretty_print !== false) {
                     $content .= "\n";
                 }
                 $content .= $this->encodeArrayToXML($value, $key, $pretty_print !== false ? $pretty_print + 1 : false) . $prefix;
                 break;
             case is_bool($value):
                 $content .= $value ? 'true' : 'false';
                 break;
             case is_string($value):
             case is_numeric($value):
             default:
                 $content .= htmlspecialchars($value);
                 break;
         }
         $content .= '</' . htmlspecialchars($key) . '>';
         if ($pretty_print !== false) {
             $content .= "\n";
         }
     }
     return $content;
 }
예제 #2
0
 /**
  * @dataProvider  isNumericallyKeyedProvider
  */
 public function testIsNumericallyKeyed($expected, $input)
 {
     $this->assertSame($expected, Arrays::isNumericallyKeyed($input));
 }
예제 #3
0
파일: Scaffold.php 프로젝트: ngnpope/jerity
 /**
  * Generate form elements suitable for updating the given record in the
  * given table.
  *
  * @param  string                  $table      The table for which elements
  *                                             should be generated.
  * @param  mixed                   $primary_key  The primary key value for an 
  *                                               update form.
  * @param  \Jerity\Form\Generator  $generator  An existing form that should 
  *                                             be added to. If not provided,
  *                                             a new instance is created.
  *
  * @return  \Jerity\Form\Generator  The generator with other fields added.
  */
 public function generateUpdateForm($table, $primary_key, Form\Generator $generator = null)
 {
     $generator = $this->generateForm($table, 'update', $generator, $primary_key);
     // fetch row and populate form
     $data = $this->fetchRow($table, $primary_key);
     if (count($data)) {
         $generator->populateData(Arrays::collapseKeys($data, self::FORM_PREFIX . '_args[' . $table . ']'));
     }
     return $generator;
 }
예제 #4
0
파일: Chrome.php 프로젝트: ngnpope/jerity
 /**
  * Adds one or more content items to this template.
  * You may add content in the following ways:
  *   $c->setContent($content);
  *   $c->setContent($content0, $content1, ...);
  *   $c->setContent(array($content0, $content1, ...));
  *
  * @param  mixed  ...  The content item(s) to add.
  *
  * @return  Chrome  The current object, for method chaining.
  *
  * @throws  \InvalidArgumentException
  */
 public function setContent()
 {
     if (func_num_args() < 1) {
         throw new \InvalidArgumentException('You must specify a content item.');
     }
     $items = Arrays::flatten(func_get_args());
     foreach ($items as $i) {
         if (!$i instanceof Renderable && !is_string($i) && !(is_object($i) && method_exists($i, '__toString'))) {
             throw new \InvalidArgumentException('Non-renderable or non-string item set as content.');
         }
     }
     $this->content = $items;
     $this->contentIterator = null;
     return $this;
 }
예제 #5
0
 /**
  *
  */
 public function populateData(array $data, $replace = true)
 {
     // $data should be a single-dimension array
     $data = Arrays::collapseKeys($data);
     if ($replace) {
         $this->data = $data;
     } else {
         // merge and overwrite
         $this->data = $data + $this->data;
         # array addition is NOT commutative
     }
 }