{"id":15029939,"url":"https://github.com/w3yyb/amazephp","last_synced_at":"2025-06-22T12:09:12.870Z","repository":{"id":88996170,"uuid":"226629558","full_name":"w3yyb/AmazePHP","owner":"w3yyb","description":"AmazePHP - A simple \u0026 high performance PHP framework ","archived":false,"fork":false,"pushed_at":"2025-01-07T06:51:58.000Z","size":850,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-11T07:15:53.088Z","etag":null,"topics":["api","framework","php","php-framework","php-router","php8","router"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/w3yyb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-08T07:16:12.000Z","updated_at":"2025-01-07T06:52:01.000Z","dependencies_parsed_at":"2025-02-15T21:32:14.398Z","dependency_job_id":"e587d57b-407e-4973-8766-07a6849af222","html_url":"https://github.com/w3yyb/AmazePHP","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/w3yyb/AmazePHP","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w3yyb%2FAmazePHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w3yyb%2FAmazePHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w3yyb%2FAmazePHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w3yyb%2FAmazePHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/w3yyb","download_url":"https://codeload.github.com/w3yyb/AmazePHP/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w3yyb%2FAmazePHP/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261289423,"owners_count":23136071,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","framework","php","php-framework","php-router","php8","router"],"created_at":"2024-09-24T20:12:02.595Z","updated_at":"2025-06-22T12:09:07.858Z","avatar_url":"https://github.com/w3yyb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\nEnglish | [中文](./README_CN.md)\n\n\u003c/div\u003e  \n\n# AmazePHP\n## About AmazePHP  \nA 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.\nThere are no complicated concepts, so it has the lowest learning curve. \n\n## Features:  \n- Configuration  \n- Env Vars  \n- Routing    \n- Requests \n- Responses\n- Controllers \n- Middleware \n- Facades \n- Container \n- Database  \n- Http Client  \n- Logging   \n- View \u0026 Templates \n- Error Handling  \n- Cache \n- Session \n- Cookie \n- URL Generation \n- CSRF Protection \n\n\n## Installation:    \n```\ncomposer create-project amazephp/amazephp\n```\nor use git clone:\n```\ngit clone https://github.com/w3yyb/AmazePHP.git  \n\ncd AmazePHP \n\ncomposer install  \n```\n ## Run\n ```\n cd public/  \n\n php -S localhost:9080 server.php  \n ```\n Open http://localhost:9080  in your browser.\n\n ## Requirements:  \n php 8.1+  \n\n ## Directory Structure  \n\n ### The App Directory  \n 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.  \n ### The config Directory  \n The config directory, as the name implies, contains all of your application's configuration files.  Include the route config file.\n  ### The helper Directory  \nThe helper functions in it.\n### The AmazePHP Directory\nThe framework core directory, include some lib class. And you can put  your class file in it.\n### The public Directory\nThe 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.\n### The cache Directory\nThe cache directory contains your cache files, include log files.\n### The template Directory\nThe template directory contains your html template files.\n\n # Usage \n## Configuration \n ### get config  \n ``` \n  config('app'); //will read config/app.php,  app.php return an array.  \n\n  config('app.url')// == config('app')['url'];  \n\n  // Retrieve a default value if the configuration value does not exist...\n  $value = config('app.timezone', 'Asia/Seoul');\n  ``` \n  \n ### set config \n To set configuration values at runtime, pass an array to the config function:\n ``` \nconfig(['app.timezone' =\u003e 'America/Chicago']);\n``` \n \n \n## Cache  \n### get cache \n```\n$value = cache('key');\n```\n### set cache \n```\ncache(['key' =\u003e 'value'], 10);// Expires after 10 seconds\n``` \n### view \nThe template engine uses `BladeOne`, a template engine similar to the laravel `blade`, click here https://github.com/EFTEC/BladeOne/wiki/BladeOne-Manual view the BladeOne manual. \n```\necho view('greeting', ['name' =\u003e 'James']);\n``` \nThe first parameter is the template name, i.e. `template/greeting.blade.php` , and the second parameter is the variable passed into the template. \n###  get Environment configuration \n```\nenv('key');\n\nenv('key','default'); \n```\nThe 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.\n\n### Logging\n```\nlogger('some msg');//error log\n```\n```\nlogger('some msg','warning'); //warning log | support:emergency ,alert ,critical ,error ,warning ,notice ,info ,debug \n```\n### Routing \nsee config/route.php\n```\n  [\n        ['GET'], \n        '/',  \n        [App\\Controllers\\Index::class, 'index'],\n        'routename',\n        'middleware'=\u003e[App\\Middleware\\a2Middleware::class,App\\Middleware\\b2Middleware::class],\n  ],\n```\nThe 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.  \n\nThe 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.  \n\nThe third line indicates PHP callbacks, support for class methods, static methods of classes, anonymous functions, functions, etc. \n\nThe fourth line is optional and indicates the name of the named route. \n\nThe middleware key  is optional  register routing middleware.\n\n### Requests \n 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.\n\n\n #### usage\n ```\n $input = request()-\u003eall();\n$name = request()-\u003einput('name');\n$value = request()-\u003ecookie('name');\n$value = request()-\u003eheader('X-Header-Name');\n$method = request()-\u003emethod();\nrequest()-\u003ehost();\n$url = request()-\u003eurl();\n$urlWithQueryString = request()-\u003efullUrl();\n$uri = request()-\u003epath();\nif (request()-\u003eis('admin/*')) {\n    // ...\n}\n\n$input = request()-\u003eonly(['username', 'password']);\n \n$input = request()-\u003eexcept(['credit_card']);\n\n  $file = request()-\u003efile('upload');\n        if ($file \u0026\u0026 $file-\u003eisValid()) {\n            $file-\u003emove(PUBLIC_PATH.'/myfile.'.$file-\u003egetUploadExtension());\n            return json(['code' =\u003e 0, 'msg' =\u003e 'upload success']);\n        }\n\n ```\n More usage see AmazePHP/src/Request.php.\n\n  ### Responses  \n AmazePHP does not provide a Respose class  for performance reasons. \n Use header() funcion and echo or return  to response in controllers or middleware.\n### Controllers \nInstead 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.\n#### Writing Controllers \nIn `app/Controllers ` dir, you can write some controllers, for example:\n```\n\u003c?php\nnamespace App\\Controllers;\n\nclass Index\n{\n    public function index()\n    {\n        echo 'Hello AmazePHP!';\n    }\n}\n```\nOnce you have written a controller class and method, you may define a route to the controller method like so:\n```\n [\n        ['GET'],\n        '/',\n        [App\\Controllers\\Index::class, 'index']\n ],\n```\nWhen an incoming request matches the specified route URI, the index method on the App\\Controllers\\Index class will be invoked and the route parameters will be passed to the method. \n### Middleware \nMiddleware, also known as HTTP middleware, is mainly used to modify or filter HTTP requests or responses.All of these middleware are located in the app/Middleware directory.  \n \nMiddleware is divided into before middleware and after middleware.Before middleware is mainly used to modify HTTP requests. After middleware is mainly used to modify HTTP responses.\n\n```\nRequest-\u003eBefore middleware-\u003eActual action-\u003eAfter middleware-\u003eResponse\n```\n#### Defining Middleware \nThe main difference between before middleware and after middleware is where the code is executed. \nIn app/Middleware directory:\n##### Defining Before Middleware \nCreate such as  bMiddleware.php\n```\n\u003c?php\nnamespace App\\Middleware;\nuse AmazePHP\\MiddlewareInterface;\n\nclass bMiddleware implements MiddlewareInterface {\n\n    public function process($object, \\Closure $next,...$params)\n    {\n        \n        //Perform some logic here\n\n        return $next($object);\n    }\n\n}\n?\u003e\n\n```\n##### Defining After Middleware \nCreate such as  aMiddleware.php\n\n```\n\u003c?php\nnamespace App\\Middleware;\nuse AmazePHP\\MiddlewareInterface;\n\nclass aMiddleware implements MiddlewareInterface {\n\n    public function process($object, \\Closure $next,...$params)\n    {\n\n        $response = $next($object);\n         //Perform some logic here\n\n        return $response;\n    }\n\n}\n?\u003e\n\n```\n#### Registering Global Middleware\nIn config/middleware.php,write the following:\n```\nreturn [\n    App\\Middleware\\aMiddleware::class,\n    App\\Middleware\\bMiddleware::class,\n];\n```\n#### Register routing middleware \nSee Routing.\n\n### Facades \nThe 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 .\n#### sample:\nIn App\\Controllers\\Index Controller:\n\n```\n\u003c?php\nnamespace App\\Controllers;\nuse AmazePHP\\Facade\\Request;\nclass Index  \n{\n    public function index()\n    {\n        echo Request::url();//call Request.php url method statically. Same as calling  Request-\u003eurl().\n    }\n}\n```\nAll façades of the system are placed in the AmazePHP/src/Facade directory.\n\n\n### Container \n Container is a powerful tool for managing class dependencies and performing dependency injection.\n\n #### usage:\nFor example:\n```\n\u003c?php\nnamespace App\\Controllers;\nuse AmazePHP\\Request;\nclass Foo  \n{\n    public function bar(Request $request, $id)\n    {\n    echo $request-\u003eurl();\n    }\n}\n?\u003e\n```\nThe 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-\u003eurl() ` .  \nScenarios that support the use of dependency injection include (but are not limited to): \n- Controller   method;\n- closure definition of a route;\n- Middleware execution methods;\n    \n### http client \n```\n$response= httpGet('http://httpbin.org/get');\n$response= httpGet('http://httpbin.org/get',['headername'=\u003e'headervalue']);\n$response= httpHead('http://httpbin.org/get',['headername'=\u003e'headervalue']);\n$response= httpDelete('http://httpbin.org/delete',['headername'=\u003e'headervalue']);\n$response= httpPost('http://httpbin.org/post',['senddataname'=\u003e'senddatavalue']);\n$response= httpPut('http://httpbin.org/put',['senddataname'=\u003e'senddatavalue']);\n$response= httpPatch('http://httpbin.org/patch',['senddataname'=\u003e'senddatavalue']);\n```\n$response is an array containing status_code, header, and body data.  \n\nThe function parameters are as follows: \n```\nhttpGet($url,$header = [])\nhttpHead($url,$header = [])\nhttpDelete($url,$header = [])\n\nhttpPost($url, $data, $isJson = true,$method='POST',$header = [])\nhttpPut($url, $data, $isJson = true,$method='PUT',$header = [])\nhttpPatch($url, $data, $isJson = true,$method='PATCH',$header = [])\n```\n## session \nSession is closed by default, if you want to open, please change the SESSION_ENABLE in the .env file to true.\n### set session\n```\nsession([\"name\" =\u003e \"value\"]);\n```        \n### get session\n```\n$value = session('name')\n```\n## cookie \n### get cookie\n```\n$value = request()-\u003ecookie('name');\n```\n### set cookie \n```\ncookie('name','value',86400); // 86400 seconds\n```\n\n###  Database\nThe database component is using `PdoOne`, a database access object wrapper for PHP and PDO. Click https://github.com/EFTEC/PdoOne to see how to use it. \n\nBelow is an example of how to use it in a simple way.  \n\nselect: \n```\n$results = db()-\u003eselect(\"*\")-\u003efrom('users')-\u003ewhere(\"name like '%test%'\")-\u003etoList();\n\nprint_r($results);\n``` \nuse Raw Sql: \n```\n$sql='select * from users where id=1';\n\n$pdoStatement=db()-\u003erunRawQuery($sql,[],false);  // [] are the parameters\n\nprint_r($pdoStatement-\u003efetchAll());\n```\ninsert: \n```\ndb()-\u003einsert(\"users\"\n    ,['name','email','password']\n    ,['kevin','email@email.com','123456']);\n```\nupdate: \n```\ndb()-\u003eupdate(\"users\"\n,['name'=\u003e'Captain-Crunch','email'=\u003e'mail@mail.com'] // set\n,['id'=\u003e6]); // where\n```\ndelete: \n```\ndb()-\u003edelete(\"users\"\n  ,['id'=\u003e6]); // where\n```\n    \n### URL\n#### Accessing The Current URL \n```\n// Get the current URL without the query string...\necho url()-\u003ecurrent();\n \n// Get the current URL including the query string...\necho url()-\u003efull();\n \n// Get the full URL for the previous request...\necho url()-\u003eprevious(); \n```\n#### Generating URLs\n```\necho url(\"/posts/{$post-\u003eid}\"); // http://example.com/posts/1\n```\n#### URLs For Named Routes \n```\n[\n        ['GET'],\n        '/hello/{id}/foo/{sid}',\n        [new App\\Foo, 'bar'],\n        'nameroute1'//Named Route\n],\n\necho   route('nameroute1', ['id' =\u003e 1, 'sid' =\u003e 2]);\n\n// http://example.com/hello/1/foo/2\n``` \n## CSRF Protection \nIf you want to use it, first enable session. \n\nCross-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.\n\nAmazePHP 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. \n\nThe current session's CSRF token can be accessed  via the `csrf_token` helper function:\n```\n$token = csrf_token();\n```\nAnytime 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:\n```\n\u003cform method=\"POST\" action=\"/profile\"\u003e\n    @csrf\n \n    \u003c!-- Equivalent to... --\u003e\n    \u003cinput type=\"hidden\" name=\"_token\" value=\"{{ csrf_token() }}\" /\u003e\n\u003c/form\u003e\n```\n### X-CSRF-TOKEN \nIn 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:\n```\n\u003cmeta name=\"csrf-token\" content=\"{{ csrf_token() }}\"\u003e\n```\nThen, 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:\n```\n$.ajaxSetup({\n    headers: {\n        'X-CSRF-TOKEN': $('meta[name=\"csrf-token\"]').attr('content')\n    }\n});\n```\n### X-XSRF-TOKEN \nAmazePHP 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.\n\nThis 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.\n## Test\n```\n./phpunit --bootstrap vendor/autoload.php tests\n./phpunit --bootstrap vendor/autoload.php tests  --display-warnings\n./phpunit --bootstrap vendor/autoload.php tests  --display-deprecations\n```\n\n## Benchmark \nAmazePHP is about 9x faster than Laravel in `hello world` benchmark.  \nlaravel :     2900 rps.  \nAmazePHP: 23000 rps.  \nBoth open debugs, and Laravel uses the Array Session Driver. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw3yyb%2Famazephp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fw3yyb%2Famazephp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw3yyb%2Famazephp/lists"}