Ejemplo n.º 1
0
 /**
  * Set a value to entity. If property not exists, will not set it in.
  *
  * @param string $field Field name.
  * @param mixed  $value Value.
  *
  * @return  Entity Return self to support chaining.
  */
 public function set($field, $value = null)
 {
     if (!property_exists($this, $field)) {
         return $this;
     }
     return parent::set($field, $value);
 }
Ejemplo n.º 2
0
 /**
  * doExecute
  *
  * @return  void
  */
 public function doExecute()
 {
     $faker = Factory::create();
     $users = (new UserMapper())->findColumn('id');
     CategoryRecord::resetFieldsCache();
     $record = new CategoryRecord();
     $ids = array();
     foreach (range(1, 30) as $i) {
         $record->reset();
         $data = new Data();
         $data['title'] = $faker->sentence(rand(1, 3));
         $data['alias'] = OutputFilter::stringURLSafe($data['title']);
         $data['type'] = 'topic';
         $data['description'] = $faker->sentence(5);
         $data['image'] = $faker->imageUrl();
         $data['version'] = rand(1, 50);
         $data['topics'] = rand(10, 100);
         $data['posts'] = rand(10, 100);
         $data['created'] = $faker->dateTime->format(DateTime::FORMAT_SQL);
         $data['created_by'] = $faker->randomElement($users);
         $data['modified'] = $faker->dateTime->format(DateTime::FORMAT_SQL);
         $data['modified_by'] = $faker->randomElement($users);
         $data['state'] = $faker->randomElement(array(1, 1, 1, 1, 0, 0));
         // Color Image
         $params = array('bg_color' => $faker->randomElement($this->colors), 'image_icon' => $faker->randomElement($this->icons));
         $data['params'] = json_encode($params);
         $record->bind($data->dump());
         if ($i > 6) {
             $record->setLocation($faker->randomElement($ids), $record::LOCATION_LAST_CHILD);
         } else {
             $record->setLocation(1, $record::LOCATION_LAST_CHILD);
         }
         $record->store();
         $record->rebuildPath();
         $ids[] = $record->id;
         $this->command->out('.', false);
     }
     $this->command->out();
 }
Ejemplo n.º 3
0
 /**
  * load
  *
  * @param string $file
  * @param array  $data
  *
  * @return  string
  */
 public function load($file, $data = null)
 {
     $data = $this->data->bind(new Data($data));
     $renderer = new static($this->paths, $this->config);
     return $renderer->render($file, $data);
 }
Ejemplo n.º 4
0
 /**
  * Method to test walk()
  *
  * @return  void
  *
  * @covers Windwalker\Data\Data::walk
  */
 public function testWalk()
 {
     $data = new Data();
     $data->foo = 'bar';
     $data->baz = 'yoo';
     $data->walk(function (&$value, $key, $userdata) {
         $value = $userdata . ':' . $key . ':' . strtoupper($value);
     }, 'prefix');
     $this->assertEquals('prefix:baz:YOO', $data->baz);
 }