コード例 #1
0
ファイル: Schema.php プロジェクト: gossi/swagger
 private function parse($contents = [])
 {
     $data = CollectionUtils::toMap($contents);
     $this->title = $data->get('title');
     $this->discriminator = $data->get('discriminator');
     $this->readOnly = $data->has('readOnly') && $data->get('readOnly');
     $this->example = $data->get('example');
     $this->required = $data->get('required');
     $this->properties = new Definitions($data->get('properties'));
     if ($data->has('additionalProperties')) {
         $this->additionalProperties = new self($data->get('additionalProperties'));
     }
     $this->allOf = new ArrayList();
     if ($data->has('allOf')) {
         foreach ($data->get('allOf') as $schema) {
             $this->allOf->add(new self($schema));
         }
     }
     // parts
     $this->parseRef($data);
     $this->parseType($data);
     $this->parseDescription($data);
     $this->parseItems($data);
     $this->parseExternalDocs($data);
     $this->parseExtensions($data);
 }
コード例 #2
0
 /**
  * Recursively transforms data into a list (on the first level, deeper levels
  * transformed to an appropriate collection) (experimental API)
  *
  * @param array|Iterator $collection
  * @return ArrayList
  */
 public static function toList($collection)
 {
     $list = new ArrayList();
     foreach ($collection as $v) {
         $list->add(self::toCollection($v));
     }
     return $list;
 }
コード例 #3
0
 public function testToList()
 {
     $data = ['a' => 'b', 'c' => [1, ['x' => 'y'], 4], 'd' => ['x' => 'y', 'z' => 'zz']];
     $list = CollectionUtils::toList($data);
     $this->assertTrue($list instanceof ArrayList);
     $this->assertEquals('b', $list->get(0));
     $this->assertTrue($list->get(2) instanceof Map);
     $list = new ArrayList($data);
     $this->assertEquals('b', $list->get(0));
     $this->assertFalse($list->get(2) instanceof Map);
 }
コード例 #4
0
 public function testGroupStack()
 {
     $log = new ArrayList();
     $listener = function (GroupEvent $event) use($log) {
         $log->add($event->getName() . ' ' . $event->getGroup()->type);
     };
     $parser = new Parser();
     $parser->getContext()->addListener(Context::EVENT_GROUP_ENTER, $listener);
     $parser->getContext()->addListener(Context::EVENT_GROUP_LEAVE, $listener);
     $parser->parse($this->getCode());
     $this->assertEquals(['context.group_enter block', 'context.group_leave block', 'context.group_enter block', 'context.group_leave block', 'context.group_enter call', 'context.group_leave call', 'context.group_enter block', 'context.group_leave block', 'context.group_enter block', 'context.group_enter group', 'context.group_leave group', 'context.group_leave block'], $log->toArray());
 }
コード例 #5
0
 public function testSize()
 {
     $list = new ArrayList();
     $this->assertTrue($list->isEmpty());
     $this->assertEquals(0, $list->size());
     $list->add('item 1')->add('item 2');
     $this->assertFalse($list->isEmpty());
     $this->assertEquals(2, $list->size());
     $list->clear();
     $this->assertTrue($list->isEmpty());
     $this->assertEquals(0, $list->size());
     $list = new ArrayList(['item 1', 'item 2']);
     $this->assertFalse($list->isEmpty());
     $this->assertEquals(2, $list->size());
 }
コード例 #6
0
ファイル: SortTest.php プロジェクト: gossi/php-code-generator
 public function testDefaultPropertyComparator()
 {
     $list = new ArrayList();
     $list->add(PhpProperty::create('arr')->setVisibility(PhpProperty::VISIBILITY_PRIVATE));
     $list->add(PhpProperty::create('bar')->setVisibility(PhpProperty::VISIBILITY_PROTECTED));
     $list->add(PhpProperty::create('foo'));
     $list->add(PhpProperty::create('baz'));
     $list->sort(new DefaultPropertyComparator());
     $ordered = $list->map(function ($item) {
         return $item->getName();
     })->toArray();
     $this->assertEquals(['baz', 'foo', 'bar', 'arr'], $ordered);
 }
コード例 #7
0
 public function testEach()
 {
     $result = [];
     $list = new ArrayList(range(1, 10));
     $list->each(function ($value) use(&$result) {
         $result[] = $value;
     });
     $this->assertEquals($list->toArray(), $result);
 }
コード例 #8
0
 /**
  * Retrieves a token at the given index
  * 
  * @param int $index the given index
  * @return Token 
  */
 public function get($index)
 {
     return parent::get($index);
 }
コード例 #9
0
 /**
  * A list of tags sorted by tag-name
  * 
  * @return ArrayList
  */
 public function getSortedTags()
 {
     if ($this->comparator === null) {
         $this->comparator = new TagNameComparator();
     }
     // 1) group by tag name
     $group = new Map();
     foreach ($this->tags as $tag) {
         if (!$group->has($tag->getTagName())) {
             $group->set($tag->getTagName(), new ArrayList());
         }
         $group->get($tag->getTagName())->add($tag);
     }
     // 2) Sort the group by tag name
     $group->sortKeys(new TagNameComparator());
     // 3) flatten the group
     $sorted = new ArrayList();
     foreach ($group->values() as $tags) {
         $sorted->addAll($tags);
     }
     return $sorted;
 }
コード例 #10
0
 public function testComparison()
 {
     $list = new ArrayList(['author', 'since', 'see', 'param', 'author']);
     $list->sort(new TagNameComparator());
     $this->assertEquals(['see', 'author', 'author', 'since', 'param'], $list->toArray());
 }