{"id":13520127,"url":"https://github.com/esyede/alitphp","last_synced_at":"2025-03-31T16:30:34.952Z","repository":{"id":128851571,"uuid":"104596582","full_name":"esyede/alitphp","owner":"esyede","description":"Lightweight, blazing fast micro framework","archived":true,"fork":false,"pushed_at":"2018-07-25T16:18:58.000Z","size":191,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-02T05:22:59.021Z","etag":null,"topics":["framework","lightweight","mvc","php","tiny"],"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/esyede.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}},"created_at":"2017-09-23T20:20:30.000Z","updated_at":"2023-01-28T16:57:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"3bf1abe1-6e02-446b-84d3-4b9fea9c483f","html_url":"https://github.com/esyede/alitphp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esyede%2Falitphp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esyede%2Falitphp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esyede%2Falitphp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esyede%2Falitphp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/esyede","download_url":"https://codeload.github.com/esyede/alitphp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222670691,"owners_count":17020513,"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":["framework","lightweight","mvc","php","tiny"],"created_at":"2024-08-01T05:02:12.156Z","updated_at":"2024-11-02T03:30:19.357Z","avatar_url":"https://github.com/esyede.png","language":"PHP","readme":"# alitphp\nSimple, lightweight php microframework\n[Documentation](https://github.com/esyede/alitphp/wiki)\n\n### What you get?\n* Simple routing engine with middleware support\n* Simple native template\n* INI-style configuration\n* Dot-notation array access\n\n\n### Requirements\n * PHP 5.3+ (untested on php7)\n * Webserver (you can use built-in webserver on php5.4+)\n * `mode_rewrite` if you use apache\n * _PCRE_ 8.02+ (usually already bundled with php)\n * Writable access to `TMP` directory.\n\n\n\n### Webserver Configuration:\nApache\n```apache\nOptions +FollowSymlinks\nRewriteEngine On\n\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule ^ index.php [L]\n```\n\nNginX\n```nginx\nlocation / {\n    try_files $uri index.php;\n}\n```\n\n\n### Routing Engine\nAlit routing engine can be used either procedural or object orirnted way\n\n#### Procedural routing\n```php\n$fw=require('fw/alit.php');\n$fw-\u003eroute('GET /',function() {\n    echo 'Hello world!';\n});\n\n$fw-\u003erun();\n```\n\nRegex pattern is also supported:\n```php\n$fw-\u003eroute('GET /hello(/\\w+)?',function($word) {\n    echo 'Hello '.(isset($word)?$word:'dude');\n});\n```\n\nMultiple methods is supported:\n```php\n$fw-\u003eroute('GET|POST|PUT /',function() use($fw) {\n    echo 'Using '.$fw-\u003eget('METHOD').' on '.$fw-\u003eget('URI');\n});\n```\nSupported methods:\n`CONNECT` `DELETE` `GET` `HEAD` `OPTIONS` `PATCH` `POST` `PUT`\n\nDo you need middleware?\n```php\n$fw-\u003eroute('GET /admin',function() {\n    echo 'Actual route';\n});\n\n$fw-\u003ebefore('GET /admin',function() {\n    echo 'this is before-middleware...\u003cbr/\u003e';\n});\n\n$fw-\u003eafter('GET /admin',function() {\n    echo '\u003cbr/\u003e...this is after-middleware';\n});\n```\n\n\n#### Dealing with OOP\nFirstly, you must create the controller class:\n```php\n// file: user.php\nclass User {\n\n    function home() {\n        echo 'User home';\n    }\n\n    function profile($name) {\n        echo 'Profile of: '.(isset($name)?$name:'unknown');\n    }\n}\n```\n\nThen, register it to your route:\n```php\n$fw-\u003eroute('GET /user','User@home');\n$fw-\u003eroute('GET /user/profile(/[a-zA-Z]+)?','User@profile');\n```\n\n#### Routing to namespaced class?\n```php\n// File: application/controllers/test.php\nnamespace App\\Controllers;\nuse \\Alit;\n\nclass Test {\n    protected $fw;\n\n    function __construct() {\n        $this-\u003efw=Alit::instance();\n    }\n\n    function index() {\n        echo $this-\u003efw-\u003eget('METHOD').' method used here';\n    }\n    // ...\n}\n```\n\nAnd finally, you can register it to your route:\n```php\n$fw-\u003eroute('GET /test','App\\Controllers\\Test@index');\n```\n\nYou can also specify routes in a config file:\n```ini\n; File path: [root]/app.cfg\n\n[route]\nGET /                 = Welcome@home\nGET /profile(/\\w+)?   = Welcome@profile\nGET|POST|PUT /test    = App\\Controllers\\Test@index\n```\n\nAnd your _index.php_ will be more simpler:\n```php\n$fw=require('fw/alit.php');\n$fw-\u003econfig('app.cfg')-\u003erun();\n```\n\nDo you still need the middleware?\n```php\nclass Test {\n\n    function index() {\n        echo 'Actual route';\n    }\n\n    //! You can define middleware as a method name inside your controller classes\n    function before() {\n        echo 'this is before-middleware...\u003cbr/\u003e';\n    }\n\n    function after() {\n        echo '\u003cbr/\u003e...this is before-middleware';\n    }\n}\n```\n\n\n### Config Flags\nAlit provide some configuration flags such as:\n * `global` to define global hive assignment\n * `route` for automatic route definition\n * `config`  to includ other config files inside your current config\n\nYou can also define your own flags.\n```ini\n[global]\nVIEW = views/\n\n[route]\nGET /     = Welcome@home\nGET /test = App\\Controllers\\Test@index\n\n[config]\ndb.cfg   = TRUE\nuser.cfg = TRUE\n\n; Example of defining custom flag\n[books]\nprice = 1000\ndiscount = 0.2\nstore.name = Happy Bookstore\nstore.address.street = Walikukun, Ngawi\nstore.dummy.text     = This is an example \\\n                        how to truncate long text \\\n                        on your config file.\n```\n\n\n### Playing with hive\nHive (like a _bee hive_) is a variable that holds an array of whole system configuration.\nAlit provide simple methods to play with it. Let's take a look some of them:\n\nSet a value to hive:\n```php\n$fw-\u003eset('profile',array(\n    'uname'=\u003e'paijo77',\n    'surname'=\u003e 'Paijo',\n    'interest'=\u003earray('reading','football'),\n    'family'=\u003earray('wife'=\u003e'Painem')\n));\n$fw-\u003eset('profile.family.son','Jarwo');\n```\n\nMultiple set:\n```php\n$fw-\u003eset(array(\n    'entry' =\u003earray(\n        'title'=\u003e'Indonesia Raya',\n        'posted'=\u003e'14/10/2017',\n        'by'=\u003e'paijo77',\n        'category'=\u003e'Art',\n    ),\n    'categories'=\u003earray('General','Art'),\n    'settings.base.url'=\u003e'http://myblog.com'\n));\n```\n_Tip: You can also assign the hive value from config file_\n\nGet a value from hive:\n```php\n$fw-\u003eget('profile')['uname'];    // paijo77\n$fw-\u003eget('profile.surname');     // Paijo\n$fw-\u003eget('profile.interest.1');  // football\n$fw-\u003eget('profile.family.son');  // Jarwo\n$fw-\u003ehive()['entry']['title'];   // Indonesia Raya\n```\n\nAdd a value or array of value:\n```php\n$fw-\u003eadd('profile.nationality','Indonesia');\n$fw-\u003eadd(array(\n    'profile.city'=\u003e'Ngawi',\n    'profile.favorite.food'=\u003e'Nasi Goreng'\n));\n```\n\nCheck if key exists in hive:\n```php\n$fw-\u003ehas('profile.nationality'); // TRUE\n$fw-\u003ehas('profile.qwertyuiop'); // FALSE\n```\n\nErase a hive path or array of hive paths:\n```php\n$fw-\u003eerase('entry.by');\n// $fw-\u003eget('entry.by'); // NULL\n$fw-\u003eerase(array('profile.city','profile.favorite.food'));\n```\n\n\n#### Framework Variables\nAll framework variables are stored in `Alit::$hive` _protected_ property,\nBut, you can still get, set, add or dump it to see the contents:\n```php\n// See all hive vars\nvar_dump($fw-\u003ehive());\n// Or, see the ntire object\nvar_dump($fw);\n```\n\n\n### Loading Thirdparty Libraries\nSince it's a thirdparty libraries, you need to set the \ncontaining-path of your library to the `AUTOLOAD` directive in order to \nhelp alit find the library. Let's say you put your 3rd-party libraries\nin the `[root]/vendor` directory, so it will become:\n```php\n$fw-\u003eset('AUTOLOAD','vendor/');\n```\n\nAnd the folder struture of the libraries must match \nwith namespace inside your class. For example if your namespace \nis `Foo\\Bar` so your class file must be placed in:\n`vendor/Foo/Bar/YourClass.php`\n\nIt's also possible to set multiple 3rd-party directory \nusing `|`, `,` or `;` as separator:\n```php \n$fw-\u003eset('AUTOLOAD','vendor/|foo_vendor/;bar_vendor/,baz_vendor/');\n```\n\n\n### Debugging\nAlit provide a `DEBUG` directive that you can adjust to see more detailed error info:\n```php\n$fw-\u003eset('DEBUG',3);\n```\n\nPossible value for debug is:\n * 0 : Suppresses prints of the stack trace _(default)_\n * 1 : Prints files \u0026 lines\n * 2 : Prints classes \u0026 functions as well\n * 3 : Prints detailed infos of the objects as well\n\n\n### System Log\nYou can enable system log by setting the `LOG` hive to `TRUE`\nand alit will log your system errors to  `alit.log` file inside your `TMP` directory.\n```php\n$fw-\u003eset('LOG',TRUE);\n```\n\nYou can also make your custom log:\n```php\n$fw-\u003elog('[info] paijo is logged in!','info.log');\n```\n\n\n### Documentation\nWork in progress...\n\n\n### Contribute\nPlease fork and pull request if you find this useful.\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesyede%2Falitphp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fesyede%2Falitphp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesyede%2Falitphp/lists"}