PHPackages                             amazephp/amazephp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. amazephp/amazephp

ActiveProject[Framework](/categories/framework)

amazephp/amazephp
=================

The AmazePHP Framework.

2.3.2(2y ago)56MITPHPPHP ^8.1

Since May 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/w3yyb/AmazePHP)[ Packagist](https://packagist.org/packages/amazephp/amazephp)[ RSS](/packages/amazephp-amazephp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (17)Used By (0)

English | [中文](./README_CN.md)

AmazePHP
========

[](#amazephp)

About AmazePHP
--------------

[](#about-amazephp)

A good choice for starting a PHP project, it can be used for web and API development. It only takes one minute to start a project. It has super high performance and a very easy-to-use development experience. There are no complicated concepts, so it has the lowest learning curve.

Features:
---------

[](#features)

- Configuration
- Env Vars
- Routing
- Requests
- Responses
- Controllers
- Middleware
- Facades
- Container
- Database
- Http Client
- Logging
- View &amp; Templates
- Error Handling
- Cache
- Session
- Cookie
- URL Generation
- CSRF Protection

Installation:
-------------

[](#installation)

```
composer create-project amazephp/amazephp

```

or use git clone:

```
git clone https://github.com/w3yyb/AmazePHP.git

cd AmazePHP

composer install

```

Run
---

[](#run)

```
cd public/

php -S localhost:9080 server.php

```

Open  in your browser.

Requirements:
-------------

[](#requirements)

php 8.1+

Directory Structure
-------------------

[](#directory-structure)

### The App Directory

[](#the-app-directory)

The app directory contains the core code of your application. We'll explore this directory in more detail soon; however, almost all of the classes in your application will be in this directory.

### The config Directory

[](#the-config-directory)

The config directory, as the name implies, contains all of your application's configuration files. Include the route config file.

### The helper Directory

[](#the-helper-directory)

The helper functions in it.

### The AmazePHP Directory

[](#the-amazephp-directory)

The framework core directory, include some lib class. And you can put your class file in it.

### The public Directory

[](#the-public-directory)

The public directory contains the index.php file, which is the entry point for all requests entering your application and configures autoloading. This directory also houses your assets such as images, JavaScript, and CSS.

### The cache Directory

[](#the-cache-directory)

The cache directory contains your cache files, include log files.

### The template Directory

[](#the-template-directory)

The template directory contains your html template files.

Usage
=====

[](#usage)

Configuration
-------------

[](#configuration)

### get config

[](#get-config)

```
 config('app'); //will read config/app.php,  app.php return an array.

 config('app.url')// == config('app')['url'];

 // Retrieve a default value if the configuration value does not exist...
 $value = config('app.timezone', 'Asia/Seoul');

```

### set config

[](#set-config)

To set configuration values at runtime, pass an array to the config function:

```
config(['app.timezone' => 'America/Chicago']);

```

Cache
-----

[](#cache)

### get cache

[](#get-cache)

```
$value = cache('key');

```

### set cache

[](#set-cache)

```
cache(['key' => 'value'], 10);// Expires after 10 seconds

```

### view

[](#view)

The template engine uses `BladeOne`, a template engine similar to the laravel `blade`, click here  view the BladeOne manual.

```
echo view('greeting', ['name' => 'James']);

```

The first parameter is the template name, i.e. `template/greeting.blade.php` , and the second parameter is the variable passed into the template.

### get Environment configuration

[](#get-environment-configuration)

```
env('key');

env('key','default');

```

The second value passed to the env function is the "default value". This value will be returned if no environment variable exists for the given key.

### Logging

[](#logging)

```
logger('some msg');//error log

```

```
logger('some msg','warning'); //warning log | support:emergency ,alert ,critical ,error ,warning ,notice ,info ,debug

```

### Routing

[](#routing)

see config/route.php

```
  [
        ['GET'],
        '/',
        [App\Controllers\Index::class, 'index'],
        'routename',
        'middleware'=>[App\Middleware\a2Middleware::class,App\Middleware\b2Middleware::class],
  ],

```

The first line is the HTTP request method, which supports HEAD, GET, POST, PUT, PATCH, DELETE. `['POST,GET']` means that both POST and GET are supported. `['*']` indicates that all HTTP methods are supported.

The second line represents the path, like `/users/{uid}/posts/[{pid}][/]`: in curly braces is variable parameters , optional parameters in brackets, i.e. parameters that have not passed in the URL, `[/]` for remove the trailing slash.

The third line indicates PHP callbacks, support for class methods, static methods of classes, anonymous functions, functions, etc.

The fourth line is optional and indicates the name of the named route.

The middleware key is optional register routing middleware.

### Requests

[](#requests)

AmazePHP\\Request class provides an object-oriented way to interact with the current HTTP request being handled by your application as well as retrieve the input, cookies, and files that were submitted with the request.

#### usage

[](#usage-1)

```
$input = request()->all();
$name = request()->input('name');
$value = request()->cookie('name');
$value = request()->header('X-Header-Name');
$method = request()->method();
request()->host();
$url = request()->url();
$urlWithQueryString = request()->fullUrl();
$uri = request()->path();
if (request()->is('admin/*')) {
   // ...
}

$input = request()->only(['username', 'password']);

$input = request()->except(['credit_card']);

 $file = request()->file('upload');
       if ($file && $file->isValid()) {
           $file->move(PUBLIC_PATH.'/myfile.'.$file->getUploadExtension());
           return json(['code' => 0, 'msg' => 'upload success']);
       }

```

More usage see AmazePHP/src/Request.php.

### Responses

[](#responses)

AmazePHP does not provide a Respose class for performance reasons. Use header() funcion and echo or return to response in controllers or middleware.

### Controllers

[](#controllers)

Instead of defining all of your request handling logic as closures in your route files, you may wish to organize this behavior using "controller" classes. Controllers can group related request handling logic into a single class. For example, a `UserController` class might handle all incoming requests related to users, including showing, creating, updating, and deleting users. By default, controllers are stored in the `app/Controllers` directory.

#### Writing Controllers

[](#writing-controllers)

In `app/Controllers ` dir, you can write some controllers, for example:

```

```

##### Defining After Middleware

[](#defining-after-middleware)

Create such as aMiddleware.php

```

```

#### Registering Global Middleware

[](#registering-global-middleware)

In config/middleware.php,write the following:

```
return [
    App\Middleware\aMiddleware::class,
    App\Middleware\bMiddleware::class,
];

```

#### Register routing middleware

[](#register-routing-middleware)

See Routing.

### Facades

[](#facades)

The façade provides a static call interface for the (dynamic) classes of the framework's core class library.Enables you to statically call dynamic class methods .

#### sample:

[](#sample)

In App\\Controllers\\Index Controller:

```

```

The bar method depends on the Request class.You can put the Request $request in the bar parameters.Framework will auto call the Request class,so you can use the Request class method:e.g. `$request->url()` .
Scenarios that support the use of dependency injection include (but are not limited to):

- Controller method;
- closure definition of a route;
- Middleware execution methods;

### http client

[](#http-client)

```
$response= httpGet('http://httpbin.org/get');
$response= httpGet('http://httpbin.org/get',['headername'=>'headervalue']);
$response= httpHead('http://httpbin.org/get',['headername'=>'headervalue']);
$response= httpDelete('http://httpbin.org/delete',['headername'=>'headervalue']);
$response= httpPost('http://httpbin.org/post',['senddataname'=>'senddatavalue']);
$response= httpPut('http://httpbin.org/put',['senddataname'=>'senddatavalue']);
$response= httpPatch('http://httpbin.org/patch',['senddataname'=>'senddatavalue']);

```

$response is an array containing status\_code, header, and body data.

The function parameters are as follows:

```
httpGet($url,$header = [])
httpHead($url,$header = [])
httpDelete($url,$header = [])

httpPost($url, $data, $isJson = true,$method='POST',$header = [])
httpPut($url, $data, $isJson = true,$method='PUT',$header = [])
httpPatch($url, $data, $isJson = true,$method='PATCH',$header = [])

```

session
-------

[](#session)

Session is closed by default, if you want to open, please change the SESSION\_ENABLE in the .env file to true.

### set session

[](#set-session)

```
session(["name" => "value"]);

```

### get session

[](#get-session)

```
$value = session('name')

```

cookie
------

[](#cookie)

### get cookie

[](#get-cookie)

```
$value = request()->cookie('name');

```

### set cookie

[](#set-cookie)

```
cookie('name','value',86400); // 86400 seconds

```

### Database

[](#database)

The database component is using `PdoOne`, a database access object wrapper for PHP and PDO. Click  to see how to use it.

Below is an example of how to use it in a simple way.

select:

```
$results = db()->select("*")->from('users')->where("name like '%test%'")->toList();

print_r($results);

```

use Raw Sql:

```
$sql='select * from users where id=1';

$pdoStatement=db()->runRawQuery($sql,[],false);  // [] are the parameters

print_r($pdoStatement->fetchAll());

```

insert:

```
db()->insert("users"
    ,['name','email','password']
    ,['kevin','email@email.com','123456']);

```

update:

```
db()->update("users"
,['name'=>'Captain-Crunch','email'=>'mail@mail.com'] // set
,['id'=>6]); // where

```

delete:

```
db()->delete("users"
  ,['id'=>6]); // where

```

### URL

[](#url)

#### Accessing The Current URL

[](#accessing-the-current-url)

```
// Get the current URL without the query string...
echo url()->current();

// Get the current URL including the query string...
echo url()->full();

// Get the full URL for the previous request...
echo url()->previous();

```

#### Generating URLs

[](#generating-urls)

```
echo url("/posts/{$post->id}"); // http://example.com/posts/1

```

#### URLs For Named Routes

[](#urls-for-named-routes)

```
[
        ['GET'],
        '/hello/{id}/foo/{sid}',
        [new App\Foo, 'bar'],
        'nameroute1'//Named Route
],

echo   route('nameroute1', ['id' => 1, 'sid' => 2]);

// http://example.com/hello/1/foo/2

```

CSRF Protection
---------------

[](#csrf-protection)

If you want to use it, first enable session.

Cross-site request forgeries are a type of malicious exploit whereby unauthorized commands are performed on behalf of an authenticated user. Thankfully, AmazePHP makes it easy to protect your application from cross-site request forgery (CSRF) attacks.

AmazePHP automatically generates a CSRF "token" for each active user session managed by the application. This token is used to verify that the authenticated user is the person actually making the requests to the application. Since this token is stored in the user's session and changes each time the session is regenerated, a malicious application is unable to access it.

The current session's CSRF token can be accessed via the `csrf_token` helper function:

```
$token = csrf_token();

```

Anytime you define a "POST", "PUT", "PATCH", or "DELETE" HTML form in your application, you should include a hidden CSRF `_token` field in the form so that the CSRF protection middleware can validate the request. For convenience, you may use the `@csrf `Blade directive to generate the hidden token input field:

```

    @csrf

```

### X-CSRF-TOKEN

[](#x-csrf-token)

In addition to checking for the CSRF token as a POST parameter, the `lib\VerifyCsrfToken` will also check for the `X-CSRF-TOKEN` request header. You could, for example, store the token in an HTML `meta` tag:

```

```

Then, you can instruct a library like jQuery to automatically add the token to all request headers. This provides simple, convenient CSRF protection for your AJAX based applications using legacy JavaScript technology:

```
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

```

### X-XSRF-TOKEN

[](#x-xsrf-token)

AmazePHP stores the current CSRF token in an encrypted `XSRF-TOKEN` cookie that is included with each response generated by the framework. You can use the cookie value to set the `X-XSRF-TOKEN` request header.

This cookie is primarily sent as a developer convenience since some JavaScript frameworks and libraries, like Angular and Axios, automatically place its value in the `X-XSRF-TOKEN` header on same-origin requests.

Test
----

[](#test)

```
./phpunit --bootstrap vendor/autoload.php tests
./phpunit --bootstrap vendor/autoload.php tests  --display-warnings
./phpunit --bootstrap vendor/autoload.php tests  --display-deprecations

```

Benchmark
---------

[](#benchmark)

AmazePHP is about 9x faster than Laravel in `hello world` benchmark.
laravel : 2900 rps.
AmazePHP: 23000 rps.
Both open debugs, and Laravel uses the Array Session Driver.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

16

Last Release

1059d ago

Major Versions

1.4.0 → 2.0.02023-06-16

PHP version history (2 changes)1.0PHP 8.1.\*

1.1PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/a1d87839592a7916b1180993b7688835aff235d43402e34dd48de2282192eb34?d=identicon)[w3yyb](/maintainers/w3yyb)

---

Top Contributors

[![w3yyb](https://avatars.githubusercontent.com/u/2957912?v=4)](https://github.com/w3yyb "w3yyb (112 commits)")

---

Tags

apiframeworkphpphp-frameworkphp-routerphp8routerframeworkAmazePHP

### Embed Badge

![Health badge](/badges/amazephp-amazephp/health.svg)

```
[![Health](https://phpackages.com/badges/amazephp-amazephp/health.svg)](https://phpackages.com/packages/amazephp-amazephp)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[silverstripe/framework

The SilverStripe framework

7213.5M2.5k](/packages/silverstripe-framework)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M369](/packages/laravel-zero-framework)[yorcreative/laravel-scrubber

A laravel package that scrubs sensitive information for you.

15467.2k2](/packages/yorcreative-laravel-scrubber)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
