{"id":39752112,"url":"https://github.com/gstsdev/armor-lib","last_synced_at":"2026-01-18T11:26:59.511Z","repository":{"id":62487186,"uuid":"223648664","full_name":"gstsdev/armor-lib","owner":"gstsdev","description":"Armor aims to be an useful routing framework for PHP developers.","archived":false,"fork":false,"pushed_at":"2020-10-09T19:33:29.000Z","size":186,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-05-05T09:02:23.749Z","etag":null,"topics":["armor-lib","extensions","framework","php","routing"],"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/gstsdev.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}},"created_at":"2019-11-23T20:27:58.000Z","updated_at":"2020-07-25T19:56:49.000Z","dependencies_parsed_at":"2022-11-02T10:46:36.117Z","dependency_job_id":null,"html_url":"https://github.com/gstsdev/armor-lib","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/gstsdev/armor-lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gstsdev%2Farmor-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gstsdev%2Farmor-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gstsdev%2Farmor-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gstsdev%2Farmor-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gstsdev","download_url":"https://codeload.github.com/gstsdev/armor-lib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gstsdev%2Farmor-lib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28535164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T10:13:46.436Z","status":"ssl_error","status_checked_at":"2026-01-18T10:13:11.045Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["armor-lib","extensions","framework","php","routing"],"created_at":"2026-01-18T11:26:59.409Z","updated_at":"2026-01-18T11:26:59.492Z","avatar_url":"https://github.com/gstsdev.png","language":"PHP","readme":"# armor-lib (x.y.z)\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/armor/framework?label=latest%20stable)](https://packagist.org/packages/armor/framework)\n[![Build Status](https://travis-ci.org/14mPr0gr4mm3r/armor-lib.svg?branch=master)](https://travis-ci.org/14mPr0gr4mm3r/armor-lib)\n[![Armor Health](https://github.com/14mPr0gr4mm3r/armor-lib/workflows/Armor%20Health/badge.svg?branch=master)](https://github.com/14mPr0gr4mm3r/armor-lib/actions)\n[![Minimum PHP Version Support](https://img.shields.io/packagist/php-v/armor/framework)](https://php.net)\n[![Latest Dev Version](https://img.shields.io/packagist/v/armor/framework?include_prereleases\u0026label=latest%20dev)](https://packagist.org/packages/armor/framework)\n[![Packagist Downloads](https://img.shields.io/packagist/dt/armor/framework)](https://packagist.org/packages/armor/framework/stats)\n[![License](https://img.shields.io/packagist/l/armor/framework)](https://github.com/14mPr0gr4mm3r/armor-lib/blob/master/LICENSE)\n\nArmor (**A** **R**outing and **MOR**e Things Framework) aims to be an useful routing framework for PHP developers.\n\nIt implements classes and methods to handle requests and respond them. And besides this, it can even receive **extensions**, or the famous \"**plugins**\", whatever you like to call it.\n\nBelow, you can get started on how to install it, how to use it to handle requests and, for now, how to create templates\nand send them as response, by using the extension library, [_ArmorUI_](https://github.com/14mPr0gr4mm3r/armor-ui).\n\n\n## Getting Started\n\n### Installing Armor\n\nThis step is very simple: just use [_Composer_](https://getcomposer.org)!\n\n```\ncomposer require armor/framework\n```\n\n### Implemeting Armor\n\nFirst of all, when creating an application that uses Armor, you have to create an application instance:\n\n```php\n\u003c?php\nrequire \"../vendor/autoload.php\";\n\n$app = new Armor\\Application();\n```\n\n**Note**: Optionally, you can pass a text encoder as an argument, which will be used up front to encode the response content. By default, it uses the `utf8_encode`.\n\nAnd at the bottom of the main file, put the call to the `Application#run` method:\n\n```php\n$app-\u003erun();\n```\n\nSo, the file should be something like that:\n\n```php\n\u003c?php\nrequire \"../vendor/autoload.php\";\n\n$app = new Armor\\Application();\n\n//The request handlers\n/**\n * $app-\u003eget('/', function() {...});\n * \n * $app-\u003eget('/path/to', function() {...});\n * \n */\n\n$app-\u003erun();\n```\n\n**Note: you should create the file `.htaccess` to redirect all requests to the main (`index.php`) file**\n\nNow, when talking about handling the requests properly, we must say that Armor offers a simple and easy way to handle a request, based on the method that has been used to perform it:\n\n```php\n// Handles a GET request for \"/path/to\"\n$app-\u003eget('/path/to', function() {\n    //...\n});\n// Handles a POST request for \"/path/to\"\n$app-\u003epost('/path/to', function() {\n    //...\n});\n```\n\nAt the moment, Armor only handles GET and POST requests. But, in the future, it may support more.\n\nThe callback that is passed as argument must receive **at least** two parameters: a `Request` object and \na `Response` object.\n\nThe `Request` object provides information about the path requested, the search-query parameters, and the **route parameters**. The last name may not sound familiar, but if you are a back-end developer, you might have seen something like this:\n\n```php\n$app-\u003eget('/path/to/$(section)', function(Request $req, Response $res) {\n    if ($req-\u003epath['section'] == 'something') {\n        //do something\n    }\n    //...\n});\n```\n\nAnd the `Response` object provides a lot of methods for appending content to the response.\n\nBelow, you can see a small example of handling a request and sending a response:\n\n```php\n$app = new Armor\\Application();\n\n$app-\u003eget('/', function(Request $req, Response $res) {\n    $res-\u003eappend(\"\u003chtml\u003e\n        \u003cbody\u003e\n            \u003ch1\u003eHello, World!\u003c/h1\u003e\n            \u003cp\u003eThis is an example page, and you are accessing {$req-\u003epath-\u003eabsolute}\u003c/p\u003e\n        \u003c/body\u003e\n    \u003c/html\u003e\");\n\n    return $res-\u003eend();\n});\n\n$app-\u003erun();\n```\n\nAs you can see, we are handling a request to the path `/`. We append a simple message to the response, which uses the `absolute` value of the `path` property of the `Request` object. And, finally, we complete the response, and returns it final result. That \"return\" is used by Armor to know if the response has been correctly built, or something unexpected has occurred. If it does, Armor throws a `ResponseNotCorrectlyCompletedException`.\n\nWell, there is a lot to know about Armor. In the future, it may be fully covered by a more detailed documentation.\n\n### A little talk about using templates\n\nThere is an extension library that can be used to create some UI, called _ArmorUI_. For now, it provides two classes: `TemplateManager`, which is responsible for loading templates from their directories, and `Template`, which is the template object itself. It works like that:\n\n```php\n/** \n * This example is a snippet taken and adapted from the 'example01', available at https://github.com/14mPr0gr4mm3r/armor-examples\n * @author 14mPr0gr4mm3r\n * @license MIT\n*/\n\n$templ = new ArmorUI\\TemplateManager(\"./\", ['header', 'index']);\n\n$app-\u003eget('/', function(Request $req, Response $res) use($templ) {\n    $templ-\u003egetTemplate('index')-\u003esendAsResponse($res);\n\n    return $res-\u003eend();\n});\n```\n\nHere, we loaded two templates: \"_header.templ.armor_\" and \"_index.templ.armor_\". They are on the same directory that the \nsource file is. We load the manager from the inside of the closure, and use it to load the `index` template (`getTemplate`) and to \nsend it. For sending the template, we pass the `Response` object by reference to the `Template#sendAsResponse` method. And then, we finish the request handling process.\n\nInstead, to avoid adding the `use` keyword to \"request handling closures\", we could use the `Application#use` method, \nlike this:\n\n```php\n$templ = new ArmorUI\\TemplateManager(\"./\", ['header', 'index']);\n\n$app-\u003euse('templ', $templ);\n\n$app-\u003eget('/', function(Request $req, Response $res, Application $app) {\n    $app['templ']-\u003egetTemplate('index')-\u003esendAsResponse($res);\n\n    return $res-\u003eend();\n});\n```\n\nAnd here, we see the third, but **optional**, parameter: the `Application` instance created by the user and used to \ndefine the route.\n\n## Final Considerations\n\nI admit that those were a very few lines. But, in the future, the quality and detail of the documentation might get better.\n\nGood studies, from 14mPr0gr4mm3r.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgstsdev%2Farmor-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgstsdev%2Farmor-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgstsdev%2Farmor-lib/lists"}