/** * Метод разбирает файл с ребусами, который выглядит как: * * ребус 1 * ответ 1.1 * ответ 1.2 * * ребус 2 * ответ 2.1 * ответ 2.2 * * @return type */ private function parseAnswersFile(DirItem $di) { $result = array(); $lines = explode("\n", trim($di->getFileContents(false))); $current = null; foreach ($lines as $line) { $line = trim($line); if ($line && !$current) { //Начинается новый ребус $current = $line; $result[$current] = array(); } else { if ($line && $current) { //Ответ на ребус $result[$current][] = $line; } else { if (!$line && $current) { //Пробел, закончили ребус $current = null; } } } } if ($this->LOGGER->isEnabled()) { $this->LOGGER->info('Rebuses of {}:', $di->getRelPath()); $this->LOGGER->info(print_r($result, true)); $this->LOGGER->info(); } return $result; }
public function appendFile(DirItem $file, $ensure = true) { $contents = trim($file->getFileContents($ensure)); if ($contents) { $contents = remove_utf8_bom($contents); $this->appendMlComment("+ FILE [{$file->getName()}]"); $this->di->writeLineToFile($contents); } unset($contents); }
public function getSpriteItems() { if (!is_array($this->items)) { $this->items = array(); $contents = $this->cssDi->getFileContents(); if ($contents) { $pattern = "/\\.sprite-{$this->name}-([^{|^ ]*)/si"; $matches = array(); preg_match_all($pattern, $contents, $matches, PREG_PATTERN_ORDER); $this->items = $matches[1]; } } return $this->items; }
public function getContents() { return $this->di->getFileContents(); }
public function current() { $num = $this->di->getFileContents(false); return is_inumeric($num) ? 1 * $num : null; }