コード例 #1
0
 static function __static()
 {
     xp::$loader = new self();
     // Scan include-path, setting up classloaders for each element
     foreach (xp::$classpath as $element) {
         if ('' === $element) {
             continue;
         } else {
             if ('!' === $element[0]) {
                 $before = TRUE;
                 $element = substr($element, 1);
             } else {
                 $before = FALSE;
             }
         }
         $resolved = realpath($element);
         if (is_dir($resolved)) {
             $cl = FileSystemClassLoader::instanceFor($resolved, FALSE);
         } else {
             if (is_file($resolved)) {
                 $cl = ArchiveClassLoader::instanceFor($resolved, FALSE);
             } else {
                 if ('/' !== $element[0] && ':' !== $element[1]) {
                     // If not fully qualified
                     $element .= ' (in ' . getcwd() . ')';
                 }
                 xp::error('[bootstrap] Classpath element [' . $element . '] not found');
             }
         }
         isset(self::$delegates[$cl->instanceId()]) || self::registerLoader($cl, $before);
     }
 }
コード例 #2
0
function runnable()
{
    $p = new ParamString();
    $class = xp::reflect(basename($p->value(0), '.class.php'));
    $target = array($class, 'main');
    if (!is_callable($target)) {
        xp::error('Target ' . $class . '::main() is not runnable');
        // Bails out
    }
    xp::$cn[$class] = 'Runnable$' . $class;
    exit(call_user_func($target, $p));
}
コード例 #3
0
function __estrict($code, $msg, $file, $line)
{
    if (0 == error_reporting()) {
        return;
    }
    switch ($msg) {
        case 1 == preg_match('/^Undefined (offset|variable|index)/', $msg):
        case 1 == preg_match('/^Use of undefined constant/', $msg):
        case 1 == preg_match('/to string conversion$/', $msg):
        case 1 == preg_match('/^Missing argument/', $msg):
        case 1 == preg_match('/^Illegal string offset/', $msg):
        case 1 == preg_match('/^Illegal offset type/', $msg):
            xp::error(xp::stringOf(new Error('[strict] "' . $msg . '" at ' . $file . ':' . $line)));
            // Bails
        // Bails
        default:
            __error($code, $msg, $file, $line);
    }
}
コード例 #4
0
        }
        return sprintf('%u', ord($id[0]) << 24 | ($s['dev'] & 0xff) << 16 | $s['ino'] & 0xffff);
    }
}
// }}}
// {{{ internal void unlock(void)
//     Shutdown function
function __unlock()
{
    if (isset($_SERVER['sync'])) {
        shmop_delete($_SERVER['sync']);
        shmop_close($_SERVER['sync']);
        unset($_SERVER['sync']);
    }
}
// }}}
if (!extension_loaded('shmop')) {
    xp::error('[sapi::synchronized] Shmop extension not available');
    // Bails out
}
$identifier = ftok($_SERVER['argv'][0], 'x');
if (!($shm = shmop_open($identifier, 'n', 0664, 0xa))) {
    $shm = shmop_open($identifier, 'a', 0, 0);
    $pid = shmop_read($shm, 0x0, 0xa);
    shmop_close($shm);
    xp::error(sprintf('[sapi::synchronized] Already running under pid %d [key=%s]', $pid, $identifier));
    // Bails out
}
shmop_write($shm, getmypid(), 0x0);
$_SERVER['sync'] = $shm;
register_shutdown_function('__unlock');
コード例 #5
0
ファイル: lang.base.php プロジェクト: johannes85/core
 function loadClass0($class)
 {
     $name = strtr($class, '.', '\\');
     if (isset(xp::$cl[$class])) {
         return $name;
     }
     foreach (xp::$classpath as $path) {
         // We rely on paths having been expanded including a trailing directory separator
         // character inside bootstrap(). This way, we can save testing for whether the path
         // entry is a directory with file system stat() calls.
         if (DIRECTORY_SEPARATOR === $path[strlen($path) - 1]) {
             $f = $path . strtr($class, '.', DIRECTORY_SEPARATOR) . xp::CLASS_FILE_EXT;
             $cl = 'lang.FileSystemClassLoader';
         } else {
             $f = 'xar://' . $path . '?' . strtr($class, '.', '/') . xp::CLASS_FILE_EXT;
             $cl = 'lang.archive.ArchiveClassLoader';
         }
         if (!file_exists($f)) {
             continue;
         }
         // Load class
         xp::$cl[$class] = $cl . '://' . $path;
         xp::$cll++;
         $r = (include $f);
         xp::$cll--;
         if (false === $r) {
             unset(xp::$cl[$class]);
             continue;
         }
         // Register class name and call static initializer if available
         method_exists($name, '__static') && (xp::$cli[] = [$name, '__static']);
         if (0 === xp::$cll) {
             $invocations = xp::$cli;
             xp::$cli = [];
             foreach ($invocations as $inv) {
                 $inv($name);
             }
         }
         return $name;
     }
     xp::error('Cannot bootstrap class ' . $class . ' (include_path= ' . get_include_path() . ')');
 }
コード例 #6
0
ファイル: lang.base.php プロジェクト: Gamepay/xp-framework
 static function sapi()
 {
     foreach ($a = func_get_args() as $name) {
         foreach (xp::$classpath as $path) {
             $filename = 'sapi' . DIRECTORY_SEPARATOR . strtr($name, '.', DIRECTORY_SEPARATOR) . '.sapi.php';
             if (is_dir($path) && file_exists($f = $path . DIRECTORY_SEPARATOR . $filename)) {
                 require_once $f;
                 continue 2;
             } else {
                 if (is_file($path) && file_exists($f = 'xar://' . $path . '?' . strtr($filename, DIRECTORY_SEPARATOR, '/'))) {
                     require_once $f;
                     continue 2;
                 }
             }
         }
         xp::error('Cannot open SAPI ' . $name . ' (include_path=' . get_include_path() . ')');
     }
     xp::$registry['sapi'] = $a;
 }