Example #1
0
/**
 * Возвращает контекст для использования в тестах.
 */
function get_test_context()
{
    static $ctx = null;
    if (null === $ctx) {
        $ctx = Context::yesIKnowThisIsStrangeButIWantANewInstance(array('url' => 'http://test.cms.molinos.ru/'));
    }
    return $ctx;
}
Example #2
0
 function stream_open($path, $mode, $options, &$opened_path)
 {
     if (null === self::$router) {
         Logger::log($message = 'API not initialized: router not set.', 'api');
     } elseif (false !== strpos($mode, 'w')) {
         Logger::log($message = 'XML API is read only.', 'api');
     } elseif (is_array($url = parse_url($path)) and 'localhost' == $url['host']) {
         if (isset($url['path']) and 0 === strpos($url['path'], '/api/')) {
             $realpath = substr($url['path'], 1);
             if (isset($url['query'])) {
                 $realpath .= '?' . $url['query'];
             }
             try {
                 $time = microtime(true);
                 $ctx = Context::yesIKnowThisIsStrangeButIWantANewInstance(array('url' => $realpath));
                 if ($tmp = self::$router->dispatch($ctx)) {
                     $this->data = $tmp->dump();
                 } else {
                     $this->data = html::em('error');
                 }
                 Logger::log(sprintf('OK %f %s', microtime(true) - $time, substr($path, 16)), 'api');
             } catch (Exception $e) {
                 Logger::log(sprintf('ERROR %s', substr($path, 16)), 'api');
                 $this->data = html::em('error', array('type' => get_class($e), 'message' => $e->getMessage()));
             }
             if ($options & STREAM_USE_PATH) {
                 $opened_path = $path;
             }
             return true;
         }
     }
     if ($options & STREAM_REPORT_ERRORS) {
         trigger_error($message, E_WARNING);
     }
     return false;
 }