Beispiel #1
0
 /**
  * Finalize the block; mark it closed for modification
  *
  * @param int          $lineNumber
  * @param InlineParser $inlineParser
  * @param ReferenceMap $refMap
  */
 public function finalize($lineNumber, CommonMark_InlineParser $inlineParser, CommonMark_Reference_ReferenceMap $refMap)
 {
     if (!$this->open) {
         return;
     }
     $this->open = false;
     if ($lineNumber > $this->startLine) {
         $this->endLine = $lineNumber - 1;
     } else {
         $this->endLine = $lineNumber;
     }
     switch ($this->getType()) {
         case self::TYPE_PARAGRAPH:
             $this->stringContent = preg_replace('/^  */m', '', implode("\n", $this->strings->toArray()));
             // Try parsing the beginning as link reference definitions:
             while ($this->stringContent[0] === '[' && ($pos = $inlineParser->parseReference($this->stringContent, $refMap))) {
                 $this->stringContent = substr($this->stringContent, $pos);
                 if ($this->isStringContentBlank()) {
                     //RegexHelper::getInstance()->isBlank($this->stringContent)) {
                     $this->type = self::TYPE_REFERENCE_DEF;
                     break;
                 }
             }
             break;
         case self::TYPE_ATX_HEADER:
         case self::TYPE_SETEXT_HEADER:
         case self::TYPE_HTML_BLOCK:
             $this->stringContent = implode("\n", $this->strings->toArray());
             break;
         case self::TYPE_INDENTED_CODE:
             $reversed = array_reverse($this->strings->toArray(), true);
             foreach ($reversed as $index => $line) {
                 if ($line == '' || $line === "\n" || preg_match('/^(\\n *)$/', $line)) {
                     unset($reversed[$index]);
                 } else {
                     break;
                 }
             }
             $fixed = array_reverse($reversed);
             $tmp = implode("\n", $fixed);
             if (substr($tmp, -1) !== "\n") {
                 $tmp .= "\n";
             }
             $this->stringContent = $tmp;
             break;
         case self::TYPE_FENCED_CODE:
             // first line becomes info string
             $this->setExtra('info', CommonMark_Util_RegexHelper::unescape(trim($this->strings->first())));
             if ($this->strings->count() == 1) {
                 $this->stringContent = '';
             } else {
                 $this->stringContent = implode("\n", $this->strings->slice(1)) . "\n";
             }
             break;
         case self::TYPE_LIST:
             $this->setExtra('tight', true);
             // tight by default
             $numItems = $this->children->count();
             $i = 0;
             while ($i < $numItems) {
                 /** @var BlockElement $item */
                 $item = $this->children->get($i);
                 // check for non-final list item ending with blank line:
                 $lastItem = $i == $numItems - 1;
                 if ($item->endsWithBlankLine() && !$lastItem) {
                     $this->setExtra('tight', false);
                     break;
                 }
                 // Recurse into children of list item, to see if there are
                 // spaces between any of them:
                 $numSubItems = $item->getChildren()->count();
                 $j = 0;
                 while ($j < $numSubItems) {
                     $subItem = $item->getChildren()->get($j);
                     $lastSubItem = $j == $numSubItems - 1;
                     if ($subItem->endsWithBlankLine() && !($lastItem && $lastSubItem)) {
                         $this->setExtra('tight', false);
                         break;
                     }
                     $j++;
                 }
                 $i++;
             }
             break;
         default:
             break;
     }
 }
Beispiel #2
0
 public function test_filter_map()
 {
     $arc = new ArrayCollection(array('aap', 'aap', 'noot', 'mies'));
     $filtered = $arc->filter(function ($i) {
         return $i != 'aap';
     });
     $this->assertInstanceOf('\\SAML2\\Utilities\\ArrayCollection', $filtered);
     $this->assertEquals($filtered->get(0), null);
     $this->assertEquals($filtered->get(1), null);
     $this->assertEquals($filtered->get(2), 'noot');
     $this->assertEquals($filtered->get(3), 'mies');
     $mapped = $arc->map(function ($i) {
         return ucfirst($i);
     });
     $this->assertInstanceOf('\\SAML2\\Utilities\\ArrayCollection', $mapped);
     $this->assertEquals($mapped->get(0), 'Aap');
     $this->assertEquals($mapped->get(1), 'Aap');
     $this->assertEquals($mapped->get(2), 'Noot');
     $this->assertEquals($mapped->get(3), 'Mies');
     // ensure original is not changed
     $this->assertEquals($arc->get(0), 'aap');
     $this->assertEquals($arc->get(1), 'aap');
     $this->assertEquals($arc->get(2), 'noot');
     $this->assertEquals($arc->get(3), 'mies');
 }
 /** {@inheritDoc} */
 public function get($key)
 {
     $this->initialize();
     return $this->collection->get($key);
 }