{"id":13607711,"url":"https://github.com/juneszh/alight","last_synced_at":"2026-02-25T09:01:28.273Z","repository":{"id":55677318,"uuid":"512721516","full_name":"juneszh/alight","owner":"juneszh","description":"Alight is a light-weight PHP framework. Easily and quickly build high performance RESTful web applications.","archived":false,"fork":false,"pushed_at":"2025-12-05T09:41:49.000Z","size":132,"stargazers_count":89,"open_issues_count":0,"forks_count":6,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-12-07T14:14:27.363Z","etag":null,"topics":["light-weight","php","php-framework","rest-api","restful","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/juneszh.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-07-11T11:03:18.000Z","updated_at":"2025-12-05T09:41:53.000Z","dependencies_parsed_at":"2024-01-27T14:25:10.248Z","dependency_job_id":"62765253-421a-4fb5-ba70-0470a94890ab","html_url":"https://github.com/juneszh/alight","commit_stats":{"total_commits":31,"total_committers":1,"mean_commits":31.0,"dds":0.0,"last_synced_commit":"1f88c9012b5ca1635dfbdc3d6bd412b261c255fc"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/juneszh/alight","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juneszh%2Falight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juneszh%2Falight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juneszh%2Falight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juneszh%2Falight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juneszh","download_url":"https://codeload.github.com/juneszh/alight/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juneszh%2Falight/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29815261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T05:36:42.804Z","status":"ssl_error","status_checked_at":"2026-02-25T05:36:31.934Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["light-weight","php","php-framework","rest-api","restful","router"],"created_at":"2024-08-01T19:01:20.922Z","updated_at":"2026-02-25T09:01:27.989Z","avatar_url":"https://github.com/juneszh.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# Alight\nAlight is a light-weight PHP framework. Easily and quickly build high performance RESTful web applications. Out-of-the-box built-in routing, database, caching, error handling, logging and job scheduling libraries. Focus on creating solutions for the core process of web applications. Keep simple and extensible.\n\n## Alight Family\n\n| Project                                                     | Description                                                                       |\n| ----------------------------------------------------------- | --------------------------------------------------------------------------------- |\n| [Alight](https://github.com/juneszh/alight)                 | Basic framework built-in routing, database, caching, etc.                         |\n| [Alight-Admin](https://github.com/juneszh/alight-admin)     | A full admin panel extension based on Alight. No front-end coding required.       |\n| [Alight-Project](https://github.com/juneszh/alight-project) | A template for beginner to easily create web applications by Alight/Alight-Admin. |\n\n## Requirements\nPHP 7.4+\n\n## Getting Started\n* [Installation](#installation)\n* [Configuration](#configuration)\n* [Routing](#routing)\n* [Database](#database)\n* [Caching](#caching)\n* [Error Handling](#error-handling)\n* [Job Scheduling](#job-scheduling)\n* [Helpers](#helpers)\n\n## Installation\n### Step 1: Install Composer\nDon’t have Composer? [Install Composer](https://getcomposer.org/download/) first.\n\n### Step 2: Creating Project\n#### Using template with create-project\n```bash\n$ composer create-project juneszh/alight-project {PROJECT_DIRECTORY}\n```\nThe project template contains common folder structure, suitable for MVC pattern, please refer to: [Alight-Project](https://github.com/juneszh/alight-project).\n\n*It is easy to customize folders by modifying the configuration. But the following tutorials are based on the template configuration.*\n\n### Step 3: Configuring a Web Server\nNginx example (Nginx 1.17.10, PHP 7.4.3, Ubuntu 20.04.3):\n```nginx\nserver {\n    listen 80;\n    listen [::]:80;\n\n    root /var/www/{PROJECT_DIRECTORY}/public;\n\n    index index.php;\n\n    server_name {YOUR_DOMAIN};\n\n    location / {\n        try_files $uri $uri/ /index.php?$query_string;\n    }\n\n    location ~ \\.php$ {\n        include snippets/fastcgi-php.conf;\n        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;\n    }\n}\n```\n\n## Configuration\nAll of the configuration options for the Alight framework will be imported from the file 'config/app.php', which you need to create yourself. For example:\n\nFile: config/app.php\n```php\n\u003c?php\n\nreturn [\n    'app' =\u003e [\n        'debug' =\u003e false,\n        'timezone' =\u003e 'Europe/Kiev',\n        'storagePath' =\u003e 'storage',\n        'domainLevel' =\u003e 2,\n        'corsDomain' =\u003e null,\n        'corsHeaders' =\u003e null,\n        'corsMethods' =\u003e null,\n        'cacheAdapter' =\u003e null,\n        'errorHandler' =\u003e null,\n        'errorPageHandler' =\u003e null,\n    ],\n    'route' =\u003e 'config/route/web.php',\n    'database' =\u003e [\n        'type' =\u003e 'mysql',\n        'host' =\u003e '127.0.0.1',\n        'database' =\u003e 'alight',\n        'username' =\u003e 'root',\n        'password' =\u003e '',\n    ],\n    'cache' =\u003e [\n        'type' =\u003e 'file',\n    ],\n    'job' =\u003e 'config/job.php',\n];\n```\n\n### Get some items in the config\n```php\n\u003c?php\n\nAlight\\Config::get('app');\nAlight\\Config::get('app', 'storagePath');\n```\n\n### Available Configuration\nSee [Config.php](./src/Config.php) for details.\n\n## Routing\nBefore learning routing rules, you need to create a php file first that stores routing rules. Because the routing cache is updated or not, it is based on the modification time of the routing file. For example:\n\nFile: config/route/web.php\n```php\nAlight\\Route::get('/', 'Controller::index');\n```\n\nFile: config/app.php\n```php\n\u003c?php\n\nreturn [\n    'route' =\u003e 'config/route/web.php'\n    // Also supports multiple files\n    // 'route' =\u003e ['config/route/web.php', config/route/api.php'] \n];\n```\n\nBy the way, the route configuration supports importing specified files for **subdomains**:\n```php\n\u003c?php\n\nreturn [\n    'route' =\u003e [\n        //Import on any request\n        '*' =\u003e 'config/route/web.php', \n        //Import when requesting admin.yourdomain.com\n        'admin' =\u003e 'config/route/admin.php', \n        //Import multiple files when requesting api.yourdomain.com\n        'api' =\u003e ['config/route/api.php', 'config/route/api_mobile.php'], \n    ]\n];\n```\n\n### Basic Usage\n```php\nAlight\\Route::get($pattern, $handler);\n// Example\nAlight\\Route::get('/', 'Controller::index');\nAlight\\Route::get('/', ['Controller', 'index']);\n// Or try this to easy trigger hints from IDE\nAlight\\Route::get('/', [Controller::class, 'index']);\n// With default args\nAlight\\Route::get('post/list[/{page}]', [Controller::class, 'list'], ['page' =\u003e 1]);\n\n// Common HTTP request methods\nAlight\\Route::options('/', 'handler');\nAlight\\Route::head('/', 'handler');\nAlight\\Route::post('/', 'handler');\nAlight\\Route::delete('/', 'handler');\nAlight\\Route::put('/', 'handler');\nAlight\\Route::patch('/', 'handler');\n\n// Map for Custom methods\nAlight\\Route::map(['GET', 'POST'], 'test', 'handler');\n\n// Any for all common methods\nAlight\\Route::any('test', 'handler');\n```\n\n### Regular Expressions\n```php\n// Matches /user/42, but not /user/xyz\nAlight\\Route::get('user/{id:\\d+}', 'handler');\n\n// Matches /user/foobar, but not /user/foo/bar\nAlight\\Route::get('user/{name}', 'handler');\n\n// Matches /user/foo/bar as well, using wildcards\nAlight\\Route::get('user/{name:.+}', 'handler');\n\n// The /{name} suffix is optional\nAlight\\Route::get('user[/{name}]', 'handler');\n\n// Root wildcards for single page app\nAlight\\Route::get('/{path:.*}', 'handler');\n```\n**nikic/fast-route** handles all regular expressions in the routing path. See [FastRoute Usage](https://github.com/nikic/FastRoute#defining-routes) for details.\n\n### Options\n\n#### Group\n```php\nAlight\\Route::group('admin');\n// Matches /admin/role/list\nAlight\\Route::get('role/list', 'handler');\n// Matches /admin/role/info\nAlight\\Route::get('role/info', 'handler');\n\n// Override the group\nAlight\\Route::group('api');\n// Matches /api/news/list\nAlight\\Route::get('news/list', 'handler');\n```\n\n#### Customize 'any'\nYou can customize the methods contained in `Alight\\Route::any()`.\n```php\nAlight\\Route::setAnyMethods(['GET', 'POST']);\nAlight\\Route::any('only/get/and/post', 'handler');\n```\n\n#### Before handler\nIf you want to run some common code before route's handler.\n```php\n// For example log every hit request\nAlight\\Route::beforeHandler([svc\\Request::class, 'log']);\n\nAlight\\Route::get('test', 'handler');\nAlight\\Route::post('test', 'handler');\n```\n\n\n\n#### Disable route caching\nNot recommended, but if your code requires: \n```php\n// Effective in the current route file\nAlight\\Route::disableCache();\n```\n\n#### Life cycle\nAll routing options only take effect in the current file and will be auto reset by `Alight\\Route::init()` before the next file is imported. For example:\n\nFile: config/admin.php\n```php\nAlight\\Route::group('admin');\nAlight\\Route::setAnyMethods(['GET', 'POST']);\n\n// Matches '/admin/login' by methods 'GET', 'POST'\nAlight\\Route::any('login', 'handler');\n```\n\nFile: config/web.php\n```php\n// Matches '/login' by methods 'GET', 'POST', 'PUT', 'DELETE', etc\nAlight\\Route::any('login', 'handler');\n```\n\n### Utilities\n#### Cache-Control header\nSend a Cache-Control header to control caching in browsers and shared caches (CDN) in order to optimize the speed of access to unmodified data.\n```php\n// Cache one day\nAlight\\Route::get('about/us', 'handler')-\u003ecache(86400);\n// Or force disable cache\nAlight\\Route::put('user/info', 'handler')-\u003ecache(0);\n```\n\n#### Handling user authorization\nWe provide a simple authorization handler to manage user login status.\n```php\n// Define a global authorization verification handler\nAlight\\Route::authHandler([\\svc\\Auth::class, 'verify']);\n\n// Enable verification in routes\nAlight\\Route::get('user/info', 'handler')-\u003eauth();\nAlight\\Route::get('user/password', 'handler')-\u003eauth();\n\n// No verification by default\nAlight\\Route::get('about/us', 'handler');\n\n// In general, routing with authorization will not use browser cache\n// So auth() has built-in cache(0) to force disable cache\n// Please add cache(n) after auth() to override the configuration if you need\nAlight\\Route::get('user/rank/list', 'handler')-\u003eauth()-\u003ecache(3600);\n```\nFile: app/service/Auth.php\n```php\nnamespace svc;\n\nclass Auth\n{\n    public static function verify()\n    {\n        // Some codes about get user session from cookie or anywhere\n        // Returns the user id if authorization is valid\n        // Otherwise returns 0 or something else for failure\n        // Then use Router::getAuthId() in the route handler to get this id again\n        return $userId;\n    }\n}\n```\n\n#### Request cooldown\nMany times the data submitted by the user takes time to process, and we don't want to receive the same data before it's processed. So we need to set the request cooldown time. The user will receive a 429 error when requesting again within the cooldown.\n```php\n// Cooldown only takes effect when authorized\nAlight\\Route::put('user/info', 'handler')-\u003eauth()-\u003ecd(2);\nAlight\\Route::post('user/status', 'handler')-\u003eauth()-\u003ecd(2);\n```\n\n#### Cross-Origin Resource Sharing (CORS)\nWhen your API needs to be used for Ajax requests by a third-party website (or your project has multiple domains), you need to send a set of CORS headers. For specific reasons, please refer to: [Mozilla docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS).\n\n```php\n// Domains in config will receive the common cors header\nAlight\\Route::put('share/config', 'handler')-\u003ecors(); \n\n// The specified domain will receive the common cors header\nAlight\\Route::put('share/specified', 'handler')-\u003ecors('abc.com');\n\n// The specified domain will receive the specified cors header\nAlight\\Route::put('share/specified2', 'handler')-\u003ecors('abc.com', 'Authorization', ['GET', 'POST']);\n\n// All domains will receive a 'Access-Control-Allow-Origin: *' header\nAlight\\Route::put('share/all/http', 'handler')-\u003ecors('*'); \n\n// All domains will receive a 'Access-Control-Allow-Origin: [From Origin]' header\nAlight\\Route::put('share/all/https', 'handler')-\u003ecors('origin');\n```\n*If your website is using CDN, please use this utility carefully. To avoid request failure after the header is cached by CDN.*\n\n\n## Database\nAlight passes the 'database' configuration to the **catfan/medoo** directly. For specific configuration options, please refer to [Medoo Get Started](https://medoo.in/api/new). For example:\n\nFile: config/app.php\n```php\n\u003c?php\n\nreturn [\n    'database' =\u003e [\n        'type' =\u003e 'mysql',\n        'host' =\u003e '127.0.0.1',\n        'database' =\u003e 'alight',\n        'username' =\u003e 'root',\n        'password' =\u003e '',\n    ],\n    // Multiple databases (The first database is default)\n    // 'database' =\u003e [\n    //     'main' =\u003e [\n    //         'type' =\u003e 'mysql',\n    //         'host' =\u003e '127.0.0.1',\n    //         'database' =\u003e 'alight',\n    //         'username' =\u003e 'root',\n    //         'password' =\u003e '',\n    //     ],\n    //     'remote' =\u003e [\n    //         'type' =\u003e 'mysql',\n    //         'host' =\u003e '1.1.1.1',\n    //         'database' =\u003e 'alight',\n    //         'username' =\u003e 'root',\n    //         'password' =\u003e '',\n    //     ],\n    // ]\n];\n```\n\n### Basic Usage\n`Alight\\Database::init()` is a static and single instance implementation of `new Medoo\\Medoo()`, so it inherits all functions of `Medoo()`. Single instance makes each request connect to the database only once and reuse it, effectively reducing the number of database connections.\n```php\n// Initializes the default database\n$db = \\Alight\\Database::init();\n// Initializes others database with key\n$db2 = \\Alight\\Database::init('remote');\n\n$userList = $db-\u003eselect('user', '*', ['role' =\u003e 1]);\n$userInfo = $db-\u003eget('user', '*', ['id' =\u003e 1]);\n\n$db-\u003einsert('user', ['name' =\u003e 'anonymous', 'role' =\u003e 2]);\n$id = $db-\u003eid();\n\n$result = $db-\u003eupdate('user', ['name' =\u003e 'alight'], ['id' =\u003e $id]);\n$result-\u003erowCount();\n\n```\n\nSee [Medoo Documentation](https://medoo.in/doc) for usage details.\n\n## Caching\nAlight supports multiple cache drivers and multiple cache interfaces with **symfony/cache**. The configuration options 'dsn' and 'options' will be passed to the cache adapter, more details please refer to [Available Cache Adapters](https://symfony.com/doc/current/components/cache.html#available-cache-adapters). For example:\n\nFile: config/app.php\n```php\n\u003c?php\n\nreturn [\n    'cache' =\u003e [\n        'type' =\u003e 'file',\n    ],\n    // Multiple cache (The first cache is the default)\n    // 'cache' =\u003e [\n    //     'file' =\u003e [\n    //         'type' =\u003e 'file',\n    //     ],\n    //     'memcached' =\u003e [\n    //         'type' =\u003e 'memcached',\n    //         'dsn' =\u003e 'memcached://localhost',\n    //         'options' =\u003e [],\n    //     ],\n    //     'redis' =\u003e [\n    //         'type' =\u003e 'redis',\n    //         'dsn' =\u003e 'redis://localhost',\n    //         'options' =\u003e [],\n    //     ],\n    // ]\n];\n```\n\n### Basic Usage (PSR-16)\nLike database, `Alight\\Cache::init()` is a static and single instance implementation of the cache client to improve concurrent request performance.\n\n```php\n// Initializes the default cache\n$cache = \\Alight\\Cache::init();\n// Initializes others cache with key\n$cache2 = \\Alight\\Cache::init('redis');\n\n// Use SimpleCache(PSR-16) interface\nif (!$cache-\u003ehas('test')){\n    $cache-\u003eset('test', 'hello world!', 3600);\n}\n$cacheData = $cache-\u003eget('test');\n$cache-\u003edelete('test');\n```\n\n### PSR-6 Interface\n```php\n$cache6 = \\Alight\\Cache::psr6('memcached');\n$cacheItem = $cache6-\u003egetItem('test');\nif (!$cacheItem-\u003eisHit()){\n    $cacheItem-\u003eexpiresAfter(3600);\n    $cacheItem-\u003eset('hello world!');\n    // Bind to a tag\n    $cacheItem-\u003etag('alight');\n}\n$cacheData = $cacheItem-\u003eget();\n$cache6-\u003edeleteItem('test');\n// Delete all cached items in the same tag\n$cache6-\u003einvalidateTags('alight')\n\n// Or symfony/cache adapter style\n$cacheData = $cache6-\u003eget('test', function ($item){\n    $item-\u003eexpiresAfter(3600);\n    return 'hello world!';\n});\n$cache6-\u003edelete('test');\n```\n\n### Native Interface\nAlso supports memcached or redis native interfaces for using advanced caching:\n```php\n$memcached = \\Alight\\Cache::memcached('memcached');\n$memcached-\u003eincrement('increment');\n\n$redis = \\Alight\\Cache::redis('redis');\n$redis-\u003elPush('list', 'first');\n```\n\n### More Adapter\n**symfony/cache** supports more than 10 adapters, but we only have built-in 3 commonly used, such as filesystem, memcached, redis. If you need more adapters, you can expand it. For example:\n\nFile: config/app.php\n```php\n\u003c?php\n\nreturn [\n    'app' =\u003e [\n        'cacheAdapter' =\u003e [svc\\Cache::class, 'adapter'],\n    ],\n    'cache' =\u003e [\n        // ...\n        'apcu' =\u003e [\n            'type' =\u003e 'apcu'\n        ],\n        'array' =\u003e [\n            'type' =\u003e 'array',\n            'defaultLifetime' =\u003e 3600\n        ]\n    ]\n];\n\n```\n\nFile: app/service/Cache.php\n```php\nnamespace svc;\n\nuse Symfony\\Component\\Cache\\Adapter\\ApcuAdapter;\nuse Symfony\\Component\\Cache\\Adapter\\ArrayAdapter;\nuse Symfony\\Component\\Cache\\Adapter\\NullAdapter;\n\nclass Cache\n{\n    public static function adapter(array $config)\n    {\n        switch ($config['type']) {\n            case 'apcu':\n                return new ApcuAdapter();\n                break;\n            case 'array':\n                return new ArrayAdapter($config['defaultLifetime']);\n            default:\n                return new NullAdapter();\n                break;\n        }\n    }\n}\n```\n\nSee [Symfony Cache Component](https://symfony.com/doc/current/components/cache.html) for more information.\n\n## Error Handling\nAlight catches all errors via `Alight\\App::start()`. When turn on 'debug' in the app configuration, errors will be output in pretty html (by **filp/whoops**) or JSON.\n\nFile: config/app.php\n```php\n\u003c?php\n\nreturn [\n    'app' =\u003e [\n        'debug' =\u003e true,\n    ]\n];\n\n```\n\n### Custom Handler\nWhen turn off 'debug' in production environment, Alight just logs errors to file and outputs HTTP status. \nYou can override these default behaviors by app configuration. For example:\n\nFile: config/app.php\n```php\n\u003c?php\n\nreturn [\n    'app' =\u003e [\n        'errorHandler' =\u003e [svc\\Error::class, 'catch'],\n        'errorPageHandler' =\u003e [svc\\Error::class, 'page'],\n    ]\n];\n\n```\n\nFile: app/service/Error.php\n```php\nnamespace svc;\n\nclass Error\n{\n    public static function catch(Throwable $exception)\n    {\n        // Some code like sending an email or using Sentry or something\n    }\n\n    public static function page(int $status)\n    {\n        switch ($status) {\n            case 400:\n                // Page code...\n                break;\n            case 401:\n                // Page code...\n                break;\n            case 403:\n                // Page code...\n                break;\n            case 404:\n                // Page code...\n                break;\n            case 500:\n                // Page code...\n                break;\n            default:\n                // Page code...\n                break;\n        }\n    }\n}\n```\n\n## Job Scheduling\n\nIf you need to run php scripts in the background periodically.\n### Step 1: Setting Up CRON\n```bash\n$ sudo contab -e\n```\nAdd the following to the end line:\n```bash\n* * * * * sudo -u www-data /usr/bin/php /var/www/{PROJECT_DIRECTORY}/app/scheduler.php \u003e\u003e /dev/null 2\u003e\u00261\n```\n\n### Step 2: Create Jobs\nFile: config/job.php\n```php\nAlight\\Job::call('handler')-\u003eminutely();\nAlight\\Job::call('handler')-\u003ehourly();\nAlight\\Job::call('handler')-\u003edaily();\nAlight\\Job::call('handler')-\u003eweekly();\nAlight\\Job::call('handler')-\u003emonthly();\nAlight\\Job::call('handler')-\u003eyearly();\nAlight\\Job::call('handler')-\u003eeveryMinutes(5);\nAlight\\Job::call('handler')-\u003eeveryHours(2);\nAlight\\Job::call('handler')-\u003edate('2022-08-02 22:00');\n```\n\n### Tips\nEach handler runs only one process at a time, and the default max runtime of a process is 1 hour. If your handler needs a longer runtime, use timeLimit().\n```php\nAlight\\Job::call('handler')-\u003ehourly()-\u003etimeLimit(7200);// 7200 seconds\n```\n\n## Helpers\n\n### Project Root Path\nAlight provides `Alight\\App::root()` to standardize the format of file paths in project. \n\n```php\n// Suppose the absolute path of the project is /var/www/my_project/\n\\Alight\\App::root('public/favicon.ico'); // /var/www/my_project/public/favicon.ico\n\n// Of course, you can also use absolute path files with the first character  '/'\n\\Alight\\App::root('/var/data/config/web.php');\n```\n\nThe file paths in the configuration are all based on the `Alight\\App::root()`. For example:\n```php\nAlight\\App::start([\n    'route' =\u003e 'config/route/web.php',     // /var/www/my_project/config/route/web.php\n    'job' =\u003e 'config/job.php'          // /var/www/my_project/config/job.php\n]);\n```\n### API Response\nAlight provides `Alight\\Response::api()` to standardize the format of API Response. \n```php\nHTTP 200 OK\n\n{\n    \"error\": 0,      // API error code\n    \"message\": \"OK\", // API status description\n    \"data\": {}       // Object data\n}\n```\nStatus Definition:\n| HTTP Status | API Error | Description                                                  |\n| ----------: | --------: | ------------------------------------------------------------ |\n|         200 |         0 | OK                                                           |\n|         200 |      1xxx | General business errors, only display message to user        |\n|         200 |      2xxx | Special business errors, need to define next action for user |\n|         4xx |       4xx | Client errors                                                |\n|         5xx |       5xx | Server errors                                                |\n\nFor example:\n```php\n\\Alight\\Response::api(0, null, ['name' =\u003e 'alight']);\n// Response:\n// HTTP 200 OK\n//\n// {\n//     \"error\": 0,\n//     \"message\": \"OK\",\n//     \"data\": {\n//         \"name\": \"alight\"\n//     }\n// }\n\n\\Alight\\Response::api(1001, 'Invalid request parameter.');\n// Response:\n// HTTP 200 OK\n//\n// {\n//     \"error\": 1001,\n//     \"message\": \"Invalid request parameter.\",\n//     \"data\": {}\n// }\n\n\\Alight\\Response::api(500, 'Unable to connect database.');\n// Response:\n// HTTP 500 Internal Server Error\n//\n// {\n//     \"error\": 500,\n//     \"message\": \"Unable to connect database.\",\n//     \"data\": {}\n// }\n```\n\n\n\n### Views\nAlight provides `Alight\\Response::render()` to display a view template call the render method with the path of the template file and optional template data:\n\nFile: app/controller/Pages.php\n```php\nnamespace ctr;\nclass Pages\n{\n    public static function index()\n    {\n        \\Alight\\Response::render('hello.php', ['name' =\u003e 'Ben']);\n    }\n}\n```\n\nFile: app/view/hello.php\n```php\n\u003ch1\u003eHello, \u003c?= $name ?\u003e!\u003c/h1\u003e\n```\n\nFile: config/route/web.php\n```php\nAlight\\Route::get('/', [ctr\\Pages::class, 'index']);\n```\n\nThe project's homepage output would be:\n```php\nHello, Ben!\n```\n\n### Others\nThere are also some useful helpers placed in different namespaces. Please click the file for details:\n\n| Namespace       | File                               |\n| --------------- | ---------------------------------- |\n| Alight\\Request  | [Request.php](./src/Request.php)   |\n| Alight\\Response | [Response.php](./src/Response.php) |\n| Alight\\Utility  | [Utility.php](./src/Utility.php)   |\n\n## Credits\n* Composer requires\n    * [nikic/fast-route](https://github.com/nikic/FastRoute)\n    * [catfan/medoo](https://medoo.in)\n    * [symfony/cache](https://symfony.com/doc/current/components/cache.html)\n    * [monolog/monolog](https://github.com/Seldaek/monolog)\n    * [filp/whoops](https://github.com/filp/whoops)\n    * [voku/html-min](https://github.com/voku/HtmlMin)\n* Special thanks\n    * [mikecao/flight](https://flightphp.com)\n \n\n## License\n* [MIT license](./LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuneszh%2Falight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuneszh%2Falight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuneszh%2Falight/lists"}