Esempio n. 1
0
 /**
  * Remove a structure
  *
  * @param   int|string|array|Structure  $structureOrPrimaryKeys
  * @return  int
  */
 public function delete($structureOrPrimaryKeys)
 {
     if ($structureOrPrimaryKeys instanceof Structure) {
         $structure = $structureOrPrimaryKeys->resetContents();
     } else {
         if (null === $structureOrPrimaryKeys || is_scalar($structureOrPrimaryKeys)) {
             $structure = $this->createStructure(array('rootId' => $structureOrPrimaryKeys));
         } else {
             $structureOrPrimaryKeys = (array) $structureOrPrimaryKeys;
             $structure = $this->createStructure(array('rootId' => isset($structureOrPrimaryKeys['rootId']) ? $structureOrPrimaryKeys['rootId'] : reset($structureOrPrimaryKeys)));
         }
     }
     return $this->save($structure);
 }
Esempio n. 2
0
 /**
  * Accept entry
  *
  * @return  void
  */
 protected function acceptEntry()
 {
     $this->acceptWhiteSpace(';');
     if (!empty($this->buffer)) {
         switch ($this->buffer[0]) {
             case '@':
                 if ('@charset' == strtolower(substr($this->buffer, 0, 8))) {
                     $this->buffer = substr($this->buffer, 8);
                     $this->acceptWhiteSpace();
                     $charset = $this->acceptString();
                     if ('utf-8' != $charset) {
                         if (function_exists('iconv')) {
                             $conv = @iconv($charset, 'utf-8', $this->buffer);
                         } else {
                             $conv = @mb_convert_encoding($this->buffer, 'utf-8', $charset);
                         }
                         if (!empty($conv)) {
                             $this->buffer = $conv;
                         }
                     }
                 } else {
                     if ('@import' == strtolower(substr($this->buffer, 0, 7))) {
                         $oldBuffer = $this->buffer;
                         $this->buffer = substr($this->buffer, 7);
                         $this->acceptWhiteSpace();
                         $this->sheet->addImport($this->acceptUrl());
                         $this->acceptSafeValue();
                         $this->appendExtra(substr($oldBuffer, 0, strlen($oldBuffer) - strlen($this->buffer)) . ";\n");
                         $oldBuffer = null;
                     } else {
                         if ('@media' == strtolower(substr($this->buffer, 0, 6))) {
                             $this->buffer = substr($this->buffer, 6);
                             $this->acceptWhiteSpace();
                             list($media, $this->buffer) = explode('{', $this->buffer, 2);
                             $this->acceptWhiteSpace();
                             $media = preg_replace('/\\s+/', ' ', rtrim($media, self::WHITE_SPACE));
                             if (!empty($this->media)) {
                                 $media = end($this->media) . ' and ' . $media;
                             }
                             $this->media[] = $media;
                         } else {
                             $newBuffer = preg_replace('/^[^\\{\\;]+/', '', $this->buffer);
                             $this->appendExtra(substr($this->buffer, 0, strlen($this->buffer) - strlen($newBuffer)));
                             $this->buffer = $newBuffer;
                         }
                     }
                 }
                 break;
             case '}':
                 $this->buffer = substr($this->buffer, 1);
                 $this->acceptWhiteSpace();
                 if (!empty($this->media)) {
                     array_pop($this->media);
                 }
                 break;
             case '{':
                 $this->appendExtra($this->acceptUnknowBrackets());
                 break;
             default:
                 list($selector, $this->buffer) = explode('{', $this->buffer, 2);
                 $this->acceptWhiteSpace();
                 $rule = array('media' => end($this->media), 'selector' => preg_replace('/\\s+/', ' ', rtrim($selector, self::WHITE_SPACE)));
                 if (($mapper = $this->sheet->getMapper()) && ($ruleMapper = $mapper->getRuleMapper())) {
                     $rule = $ruleMapper->create($rule);
                 } else {
                     $rule = new RuleStructure($rule);
                 }
                 while (true) {
                     $this->acceptWhiteSpace(';');
                     if (empty($this->buffer)) {
                         break;
                     }
                     if ('}' == $this->buffer[0]) {
                         $this->buffer = substr($this->buffer, 1);
                         break;
                     }
                     $this->acceptProperty($rule);
                 }
                 $this->sheet->addRule($rule);
                 break;
         }
     }
 }