{"id":33993860,"url":"https://github.com/vgalvoso/phpeasy","last_synced_at":"2025-12-13T07:33:34.797Z","repository":{"id":199183426,"uuid":"702322646","full_name":"vgalvoso/phpeasy","owner":"vgalvoso","description":"PHPEasy is an API-centric PHP framework. Code as close to PHP language itself rather than a framework.","archived":false,"fork":false,"pushed_at":"2024-04-08T06:03:54.000Z","size":169,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-28T08:14:41.390Z","etag":null,"topics":["htmx","lightweight","php","php-framework","php-frameworks","phpeasy"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vgalvoso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-10-09T05:12:22.000Z","updated_at":"2025-05-05T11:58:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"afddcb1e-883c-42e9-ac18-48c5dcd4aa45","html_url":"https://github.com/vgalvoso/phpeasy","commit_stats":null,"previous_names":["vgalvoso/phpeasy"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/vgalvoso/phpeasy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgalvoso%2Fphpeasy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgalvoso%2Fphpeasy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgalvoso%2Fphpeasy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgalvoso%2Fphpeasy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vgalvoso","download_url":"https://codeload.github.com/vgalvoso/phpeasy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgalvoso%2Fphpeasy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27702038,"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","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["htmx","lightweight","php","php-framework","php-frameworks","phpeasy"],"created_at":"2025-12-13T07:33:33.907Z","updated_at":"2025-12-13T07:33:34.788Z","avatar_url":"https://github.com/vgalvoso.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Welcome to PHPEasy\nPHPEasy is an API-centric PHP framework. Code as close to PHP language itself rather than a framework.\n\n\n## Features\n1. REST API development\n2. Full-stack web app development\n3. File-based routing\n4. Lightweight, no too much dependencies and configurations\n5. Simple Database Abstraction Layer\n6. Helper Functions such as input validator, code generator, upload file, etc.\n7. Promotes ubt not limitted to procedural programming\n8. Supports PHP 8 and above , MySQL, MSSQL and SQlite\n9. Includes basic css(mystyle.css) and js(vanscript.js) utility library.\n\n## Main Points\n1. Promotes to master the PHP language itself rather than a framework.\n2. Direct to the point coding, no too much abstractions.\n3. Use of Data Abstraction Layer rather than ORM, focused on maximum performance without large database calls used by orms.\n\n## Table of Contents\nI. [Intro]\n\nII. [Pre-requisites]\n\nIII. [Installation]\n1. [Views]\n2. [APIs]\n3. [API Functions]\n4. [Working with Database]\n5. [Progressive]\n6. [Extra]\n\n[Intro]: #intro\n[Pre-requisites]: #pre-requisites\n[Installation]: #installation\n[Views]: #1-views\n[APIs]: #2-apis\n[API Functions]: #3-api-functions\n[Working with Database]: #4-working-with-database\n[Progressive]: #5-progressive\n[Extra]: #6-extras\n\n## Intro\nThis is for someone who loves Vanilla PHP and its simplicity.\nNowadays you must follow coding standards(OOP,SOLID,DRY,etc.) and mvc frameworks to do web development\nusing PHP. PHP frameworks out there comes with too much files, configurations, classes and dependencies.\nI made this mini framework so php developers can do web development faster while mastering and enjoying \nthe PHP language itself (Yes! no need to learn so many libraries).\n\n## Pre-requisites\n1. PHP 8^.\n2. Composer.\n\n## Installation\nComposer - open a terminal inside your root or htdocs folder and execute the command below.\n```\ncomposer create-project vgalvoso/phpeasy my_phpeasy\n```\nyou can change [my_phpeasy] to any project name you want.\n\nNow open your browser and go to http://localhost/my_phpeasy\n\n## 1. Views\nCreate views inside View folder.\n\nView routes will be automatically created based on View folder structure.\n\nLook at examples below.\n1. View file path: [View/admin/dashboard.php], the route: [\"admin/dashboard\"].\n2. View file path: [View/login.php], the route: [\"login\"].\n\nYou can ommit the file name if the view file is named [index.php]:\n1. View file path: [View/index.php], the route: [\"\"].\n2. View file path: [VIew/admin/index.php], the route: [\"admin\"].\n\n\n## 1.1 View components\n(SPA)Single Page Applications are composed of view components.\n\nView components are accessible only through ajax requests.\n\nJust call Core/Helper/component(); at the top of view file to specify it as a view component.\n\nExample: View/admin/users_table.php\n```html\n\u003c?= Core/Helper/component(); ?\u003e\n\u003ctable\u003e\n    \u003cthead\u003e\n        \u003ctr\u003e\n            \u003cth\u003eUsername\u003c/th\u003e\n            \u003cth\u003eFirst Name\u003c/th\u003e\n            \u003cth\u003eLast Name\u003c/th\u003e\n        \u003c/tr\u003e\n    \u003c/thead\u003e\n    \u003ctbody id=\"users_tbl\"\u003e\n        \u003ctr\u003e\u003ctd\u003eNo Contents\u003c/td\u003e\u003c/tr\u003e\n    \u003c/tbody\u003e\n\u003c/table\u003e\n```\n\n## 2. APIs\nPHPEasy supports REST API.\n\nAll APIs are placed inside api folder.\n\nAPI routes will automaticaly created through api folder file structure and implemented functions inside the php file named with http verbs e.g.(get(),post(),patch()).\n\nSo for example you omitted the delete() function, you can't call DELETE api/users/{id}.\n\nHere is an example of a Users REST API.\n\nAPI file path: [api/users.php]\n\nRoutes:\n1. GET api/users - Get all users\n2. GET api/users/{id} - Get user by id\n3. POST api/users - Create new user\n4. DELETE api/users/{id} - Delete a user\n5. PUT api/users/{id} - Replace user\n6. PATCH api/users/{id} - Update a user\n```php\n\u003c?php\n\nuse Core\\DAL;\n\nuse function Core\\Helper\\error;\nuse function Core\\Helper\\getRequestBody;\nuse function Core\\Helper\\response;\nuse function Core\\Helper\\startAPI;\n\nstartAPI();\n\nfunction get(){\n    $db = new DAL();\n    //GET user by id\n    if(defined('URI_PARAM')){\n        $query = \"SELECT * FROM users WHERE id = :id\";\n        $param = [\"id\" =\u003e URI_PARAM];\n        if(!$user = $db-\u003egetItem($query,$param))\n            response([]);\n        response([$user]);\n    }\n    //GET All users\n    $query = \"SELECT * FROM users\";\n    $users = $db-\u003egetItems($query);\n    response($users);\n}\n\nfunction post(){\n    $db = new DAL();\n    $rq = (object)getRequestBody();\n    $values = [\n        \"username\" =\u003e $rq-\u003eusername,\n        \"firstname\" =\u003e $rq-\u003efirstname,\n        \"lastname\" =\u003e $rq-\u003elastname,\n        \"usertype\" =\u003e $rq-\u003eusertype,\n        \"password\" =\u003e password_hash($rq-\u003epassword,PASSWORD_BCRYPT)\n    ];\n    if(!$db-\u003einsert(\"users\",$values))\n        error($db-\u003egetError());\n    response(\"New User added!\");\n}\n\nfunction delete(){\n    if(!defined('URI_PARAM'))\n        error(\"Invalid Request! Please specify user id\");\n    $db = new DAL();\n    $id = URI_PARAM;\n    if(!$db-\u003edelete(\"users\",\"id=:id\",[\"id\" =\u003e $id]))\n        error($db-\u003egetError());\n    response(\"User Deleted Successfuly!\");\n}\n\nfunction patch(){\n    if(!defined('URI_PARAM'))\n        error(\"Invalid Request! Please specify user id\");\n    $db = new DAL();\n    $id = URI_PARAM;\n    $rq = (object)getRequestBody();\n    $values = [\n        \"firstname\" =\u003e $rq-\u003efirstname,\n        \"lastname\" =\u003e $rq-\u003elastname];\n    $params = [\"id\" =\u003e $id];\n\n    $db = new DAL();\n\n    if(!$db-\u003eupdate(\"users\",\"id=:id\",$values,$params))\n        error($db-\u003egetError());\n    response(\"User Updated Successfuly\");\n}\n\n//EOF\n\n```\n\n## 3. API Functions\nAPIs in PHPEasy encourages a procedural coding style, \n\nso here are the list of functions that you can use in API implementations:\n\n## 3.3 startAPI\nInitialize a PHP file as a REST API.\n\nAfter calling this function you can implement http verbs as function.\n\nExample:\n```php\n\u003c?php\nuse function Core\\Helper\\startAPI;\n\nstartAPI();\n\nfunction get(){\n    //Handle GET request to api/users\n}\n```\n\nError response will be received if you try to request using http methods other than GET.\n\n## 3.4 getRequestBody\nGet request body and convert it into assoc array.\n\nExample:\n\n```php\n\u003c?php\nuse Core\\Helper\\getRequestBody;\n\n$rq = getRequestBody();\n$username = $rq[\"username\"];\n$password = $rq[\"password\"];\n//you can convert it to object for easy access\n//$rq = (object)$rq;\n//$username = $rq-\u003eusername;\n//$password = $rq-\u003epassword;\n```\n## 3.5 validate($inputs,$validations)\nValidate a key-value pair array based on validation rules.\n- Return true if valid, exit and return 400 status code and error details if not.\n- Use it to validate request data ($_GET,$_POST).\n- `$inputs` - Associative array to be validated.\n- `$validations` - Associative array containing keys that matched keys in $data and values are the validation rules.\n\nExample:\n\n```php\n\u003c?php\nuse function Core\\Helper\\getRequestBody;\nuse function Core\\Validator\\validate;\n\n$rq = getRequestBody();\n$dataRules = [\"uname\" =\u003e \"required|string\",\n    \"upass\" =\u003e \"required|string\",\n    \"firstName\" =\u003e \"required|string\",\n    \"lastName\" =\u003e \"required|string\"];\nvalidate($rq,$dataRules);\n```\n\n## 3.6 error(string|array $message)\nOutput response with 400 status code and error message\n- `$message` - String|Array Error Message\n\n## 3.7 response(string|array $content,int $statusCode = 200,string $contentType = 'application/json')\nSet content type and status code then output content and exit script\n- `$content` string|array -  The content to output\n- `$statusCode` int - The response status code (default 200)\n- `$contentType` string - The content type (default application/json).\n Available content-types: [ application/json | plain/text | text/html ]\n\n## 3.8 to($route)\nInclude specified view\n- `$route` string - View file path\n\nMostly used for calling SPA component\n\n## 3.9 redirect($path=\"\")\nRedirect to specified view.\n\nIf path is not specified, redirect based on session.\n- `$view` string - Path to view\n\n## 3.10 esc($string)\nShorter syntax for htmlspecialchars()\n- `$string` - String to sanitize\n- Use it for HTML sanitization.\n\n## 3.11 generateCode($length = 6)\nGenerate a randomized alphanumeric code\n- `$length` - Length of code to be generated (default 6)\n\n## 3.12 objectToSession($object)\nExtract object keys and values and store to session array\n- `$object` - The object to extract\nExample:\n\n```php\n\u003c?php\nuse Core\\DAL;\n\n$db = new DAL();\n\nif(!$user = $db-\u003egetItem(1))\n    invalid(\"User does not exist!\");\n\nobjToSession($userInfo);\n```\n\n## 3.13 uploadFile($uploadFile,$uploadPath)\nGenerate new file name and upload the file\n - `string $uploadFile` $_FILE key\n * `string $uploadPath` Location for upload file must add \"/\" to the end\n * returns boolean|string New file name if successful, false otherwise\n\n## 3.14 session($sessionVar,$value = null)\nGet/Set a session variable\n- `$sessionVar` - Session Key\n- `$value` - Sets a session value if null\n\n## 3.15 objArrayToValues($objArr,$item)\nConvert an array of objects to indexed array containing values of specified item.\n- `$objArr` - Array if ibjects to convert\n- `$item` - object item to extract\n\n## 4. Working with database\nPHPEasy introduces DAL() class for database operations.\nSupports MYSql, MSSql and SQLite.\n\nSet database configurations in Config/Database.php\n\nBelow are DAL() functions\n\n## 4.1 Initialize\n```php\n$db = new DAL();\n```\n\n## 4.2 insert\nExecutes an INSERT statement;\n- `$table` - The table name to be inserted\n- `$values` - Associative array containing keys that match table fields and the values to insert.\n- returns boolean\n\nExample:\n```php\n$values = [\"username\" =\u003e $uname,\n    \"password\" =\u003e $upass,\n    \"firstname\" =\u003e $firstName,\n    \"lastname\" =\u003e $lastName];\n$db-\u003einsert(\"users\",$values);\n```\n\n## 4.3 update\nExecutes update statement\n- `string $table` The table to update\n- `string $condition` Conditions eg. id = :id\n- `array $values` Associative array containing values to update eg .`[\"age\" =\u003e 27]`\n- `array $params` Values for conditions eg . [\"id\" =\u003e 1]\n- return boolean\n\nExample:\n```php\n$values = [\n    \"firstname\" =\u003e $firstName,\n    \"lastname\" =\u003e $lastName];\n$params = [\"id\" =\u003e 1];\n\n$db = new DAL();\n\n$db-\u003eupdate(\"users\",\"id=:id\",$values,$params);\n```\n\n## 4.4 delete\nExecutes delete statement\n- `string $table` The table to delete from\n- `string $condition` Conditions using prepared statement eg. id = :id AND name = :name\n- `array $params` Values for conditions eg. [\"id\" =\u003e 1,\"name\" =\u003e \"Juan Dela Cruz\"]\n- return boolean\n\nExample:\n```php\n$delete(\"users\",\"id=:id\",[\"id\" =\u003e 1]);\n```\n\n## 4.5 getItems\nSelect multiple items\n- `string $query` Select statement\n- `array $inputs` Parameters for prepared statement default(null)\n- return array|false\n\nExample:\n```php\n$db = new DAL();\n\n$sql = \"SELECT * FROM users WHERE lastname = :surname\";\n$params = [\"surname\" =\u003e $lastName];\n\n$users = $db-\u003egetItems($sql,$params);\n```\n## 4.6 getItem\nSelect single row query\n- `string $query` Select statement\n- `array $inputs` Parameters for prepared statement default(null)\n- return object|false\n\nExample:\n```php\n$db = new DAL();\n\n$sql = \"SELECT * FROM users WHERE id=:userId\";\n$params = [\"userId\" =\u003e 1];\n\n$users = $db-\u003egetItem($sql,$params);\n```\n\n## 4.7 startTrans()\nStart a database transaction.\n\n## 4.8 commit()\nCommit database transaction.\n- Place this before returning a response in api.\n\n## 4.9 rollback()\nRollback database transaction.\n- Rarely used because when you exit the script without calling commit(), \n- rollback() will be automatically executed.\n\n## 4.10 getError()\nReturns Database Errors\n- A very useful debugging tool.\n\n## 4.11 lastId($field=null)\nGet lastId inserted to database\n- `string $field` Specify a lastId field, default null\n\n## 4.12 getDriver()\nGet the database friver that is currently used.\n\n\n```\n - api/getAllUser.php\n```php\n\u003c?php\n$db = new DAL();\n$users = new Users($db);\n\n$usersList = $users-\u003egetAll();\n```\n\nYou can use models or not depending on project requirements.\n\nDAL class is accessible directly in api files, you can execute a query directly on api implementation without creating a Model.\n\n## 5. Progressive\nPHPEasy is progressive, you can add Models, Services if you like, just update the composer.json file if you added other directory.\n\n## 6. Extras\nSee \n- js helpers: public/js/vanscript.js\n- css: public/css/mystyle.css","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvgalvoso%2Fphpeasy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvgalvoso%2Fphpeasy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvgalvoso%2Fphpeasy/lists"}