Download the PHP package popphp/popcorn without Composer
On this page you can find all versions of the php package popphp/popcorn. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download popphp/popcorn
More information about popphp/popcorn
Files in popphp/popcorn
Package popcorn
Short Description Popcorn, A REST-Based PHP Micro Framework
License BSD-3-Clause
Homepage http://popcorn.popphp.org/
Informations about the package popcorn
Popcorn PHP Micro Framework
- Overview
- Install
- Quickstart
- Advanced
- Custom Methods
RELEASE INFORMATION
Popcorn PHP REST-Based Micro Framework 4.1.1
Released October 16, 2023
Overview
Popcorn PHP Micro Framework is a REST-based micro framework. It is a small component that acts as a layer for Pop PHP to enforce the REST-based routing rules of a web application. It supports PHP 8.1+.
popcorn
is a component of Pop PHP Framework.
Top
Install
Install popcorn
using Composer.
composer require popphp/popcorn
Or, require it in your composer.json file
"require": {
"popphp/popcorn" : "^4.1.1"
}
Top
Quickstart
In a simple index.php
file, you can define the routes you want to allow
in your application. In this example, closures are used as the controllers.
The wildcard route *
can serve as a "catch-all" to handle routes that are
not found or not allowed.
The above example defines two GET
routes and wildcard to handle failures.
We can define a POST
route like in this example below:
If you attempted access that above URL via GET (or any method that wasn't POST),
it would fail. If you access that URL via POST, but with the wrong token, it will
return the Auth failed
message as enforced by the application. Access the URL
via POST with the correct token, and it will be successful.
Top
Advanced
In a more advanced example, we can take advantage of more of an MVC-style
of wiring up an application using the core components of Pop PHP with
Popcorn. Keeping it simple, let's look at a controller class
MyApp\Controller\IndexController
like this:
and two view scripts, index.phtml
and error.phtml
, respectively:
Then we can set the app like this:
The default
parameter sets the controller as the default controller to handle
routes that aren't found. Typically, there is a default action in the controller,
such as an error
method, to handle this.
Top
Custom Methods
If your web server allows the configuration of custom HTTP methods, Popcorn supports that and allows you to register custom HTTP methods with the application.
Then you can submit requests with your custom HTTP methods like this:
Top
All versions of popcorn with dependencies
popphp/popphp Version ^4.2.9
popphp/pop-cookie Version ^4.0.1
popphp/pop-http Version ^5.1.0
popphp/pop-session Version ^4.0.0
popphp/pop-view Version ^4.0.0