function parseUrl($url, $module, $context, $acceptedAttaches = array()) { $res = false; $request = array('action' => 'parseUrl', 'url' => $url, 'context' => $context, 'module' => $module, 'accepted_attaches' => $acceptedAttaches, 'encoding' => 'UTF-8', 'app' => $this->_serviceApp); $result = $this->execServiceAction($request); if ($result['success']) { $res = $result['response']; } elseif (in_array($result['response'], array(404, 500))) { $response = $this->_httpClient->setUri($url)->setMethod(Zend_Http_Client::GET)->setHeaders('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')->setHeaders('Accept-Language', 'ru,en-us;q=0.7,en;q=0.3')->setHeaders('Accept-Encoding', 'gzip, deflate')->setHeaders('Accept-Charset', 'windows-1251,utf-8;q=0.7,*;q=0.7')->request(); $request['action'] = 'parseResponse'; $request['response'] = $response->asString(); $result = $this->execServiceAction($request); if ($result['success']) { $res = $result['response']; } } if (!$result['success']) { Lms_Debug::warn('Service returned ' . $result['response'] . ' ' . $result['message']); throw new Lms_Service_DataParser_Exception('Service returned ' . $result['response'] . ' ' . $result['message']); } if ($res && count($acceptedAttaches) && isset($res['suburls'])) { foreach ($res['suburls'] as $attachName => $subUrlStruct) { if (!isset($res['attaches'][$attachName])) { list($subModule, $subContext, $subUrl) = $subUrlStruct; $res['attaches'][$attachName] = $this->parseUrl($subUrl, $subModule, $subContext); } } } return $res; }
public static function compileTo($outputFile) { if (!count(self::$loadedFiles)) { return; } $fp = fopen($outputFile, "a+"); if (flock($fp, LOCK_EX)) { if ($filesize = filesize($outputFile)) { fseek($fp, 0); $currentFile = fread($fp, $filesize); } else { $currentFile = ''; } if (!$currentFile) { $appendSource = "<?php\n"; $existingClasses = array(); } else { $appendSource = ''; $existingClasses = self::getClassesFromSource($currentFile); } for ($i = 0; $i < count(self::$loadedFiles); $i++) { $filename = self::$loadedFiles[$i]; if (self::$excludeRegexp && preg_match(self::$excludeRegexp, $filename)) { continue; } $f = @fopen($filename, "r", true); $fstat = fstat($f); $file = fread($f, $fstat['size']); fclose($f); $classes = self::getClassesFromSource($file); if (!count(array_intersect($existingClasses, $classes))) { if (strpos($file, '__FILE__') === false) { Lms_Debug::debug("Complile autoload {$filename}"); $endFile = substr($file, -2) == '?>' ? -2 : null; $appendSource .= $endFile === null ? substr($file, 5) : substr($file, 5, -2); } else { //Потенциально ненадежно, но работает $filePath = self::realPath($filename); if ($filePath) { Lms_Debug::warn("Complile autoload with __FILE__ constant {$filename}"); $file = str_replace('__FILE__', "'{$filePath}'", $file); $endFile = substr($file, -2) == '?>' ? -2 : null; $appendSource .= $endFile === null ? substr($file, 5) : substr($file, 5, -2); } } } else { Lms_Debug::debug("Conflict detect on file {$filename}. Complile autoload terminated."); $appendSource = ''; break; } } if ($appendSource) { fseek($fp, 0, SEEK_END); fwrite($fp, $appendSource); } flock($fp, LOCK_UN); } fclose($fp); }