php 构建Slim框架作为phar

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 构建Slim框架作为phar相关的知识,希望对你有一定的参考价值。

<?php

require('Slim/Slim.php');
\Slim\Slim::registerAutoloader();
<?php

$srcRoot = realpath(__DIR__."/vendor/slim/slim");
$buildRoot = realpath(__DIR__);

$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($srcRoot.DIRECTORY_SEPARATOR.'Slim', FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::LEAVES_ONLY);

echo "Build Slim phar\n";

$phar = new Phar($buildRoot.'/slim.phar', 0, 'slim.phar');
$phar->buildFromIterator($iterator, $srcRoot);
$phar->addFile(__DIR__.DIRECTORY_SEPARATOR.'autoload.php', 'autoload.php');
$phar->setStub($phar->createDefaultStub("autoload.php"));

exit("Build complete\n");
{
    "require": {
        "slim/slim": "@stable"
    },
    "config": {
      "preferred-install": "dist"
    },
    "prefer-stable": true,
    "scripts": {
        "post-update-cmd": "php build.php",
        "post-install-cmd": "php build.php"
    }
}
<?php

require(__DIR__.'/slim.phar');

$app = new \Slim\Slim();
var_dump($app);

以上是关于php 构建Slim框架作为phar的主要内容,如果未能解决你的问题,请参考以下文章

使用 php Slim 框架实现访问控制认证

Slim 框架总是返回 404 错误

安装composer slim(php web api micro services)

CORS无法在php slim框架中工作

如何让 Slim 框架工作而无需将 /index.php 放入 URL?

php 将Symfony控制台组件构建为phar