时间:2021-07-01 10:21:17 帮助过:12人阅读
所以如果能像 php -a这样交互的方式调用网站应用中定义的model和function的话,将会极其的方便。
目录结构如下:
app/public/tinker
app为网站具体逻辑实现的部分
public下面有1个index.php为网站的入口
tinker就是我们需要接入pysh,实现REPL的文件了
由于Slim里面需要PATH_INFO的值,但是命令行运行的时候,这个值是不存在的,所以需要在代码中mock一下;代码如下:
#!/usr/bin/env phpenvironment = \Slim\Environment::mock([ 'PATH_INFO' => '/playground']);$app->notFound(function () use ($app) { $path = $app->environment['PATH_INFO']; echo "Cannot route to $path" . PHP_EOL; $app->stop();});$app->error(function (\Exception $e) use ($app) { echo $e . PHP_EOL; $app->stop();});$app->any('/playground', function () { $config = new \Psy\Configuration([ 'tabCompletion' => true, 'tabCompletionMatchers' => [ new \Psy\TabCompletion\Matcher\ClassNamesMatcher, new \Psy\TabCompletion\Matcher\ClassMethodsMatcher, new \Psy\TabCompletion\Matcher\ClassAttributesMatcher, new \Psy\TabCompletion\Matcher\FunctionsMatcher, ], ]); $shell = new \Psy\Shell(); $shell->run();});$app->run();