Example of using the slim framework to access pysh

Source: Internet
Author: User
Tags require

In actual development, you need to view the structure of the interface return value and the actual data sample. It is troublesome to write the controller and access the url each time.

Therefore, it is extremely convenient to call the model and function defined in the website application in an interactive way like php-.

The directory structure is as follows:

App/
Public/
Tinker

What is the logical implementation of an app for a website?
Under public, there is an index. php entry for the website.
Tinker is the file that we need to access pysh to implement REPL.

Because the PATH_INFO value is required in the Slim, but this value does not exist when running the command line, you need to mock it in the code. The code is as follows:

The code is as follows: Copy code

#! /Usr/bin/env php
<? Php

Require _ DIR _. '/vendor/autoload. Php ';

$ App = require _ DIR _. '/app/bootstrap. Php ';

$ App-> environment = \ 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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.