{"id":36978097,"url":"https://github.com/vgalvoso/phunctional-php","last_synced_at":"2026-01-13T22:47:31.308Z","repository":{"id":62920659,"uuid":"539651664","full_name":"vgalvoso/phunctional-php","owner":"vgalvoso","description":"A functional programming PHP framework.","archived":false,"fork":false,"pushed_at":"2025-06-17T20:23:36.000Z","size":191,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-11T13:16:51.706Z","etag":null,"topics":["functional-programming","no-dependencies","php","php-framework"],"latest_commit_sha":null,"homepage":"https://phunctional.brewdevs.com","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}},"created_at":"2022-09-21T19:24:41.000Z","updated_at":"2025-06-17T20:23:06.000Z","dependencies_parsed_at":"2022-11-09T06:34:45.993Z","dependency_job_id":null,"html_url":"https://github.com/vgalvoso/phunctional-php","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/vgalvoso/phunctional-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgalvoso%2Fphunctional-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgalvoso%2Fphunctional-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgalvoso%2Fphunctional-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgalvoso%2Fphunctional-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vgalvoso","download_url":"https://codeload.github.com/vgalvoso/phunctional-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgalvoso%2Fphunctional-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28403734,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["functional-programming","no-dependencies","php","php-framework"],"created_at":"2026-01-13T22:47:31.228Z","updated_at":"2026-01-13T22:47:31.302Z","avatar_url":"https://github.com/vgalvoso.png","language":"PHP","readme":"# PHunctional PHP\n**Functional PHP Framework**\n\n## Introduction\n\nPHunctional PHP is a functional PHP framework.\n\nToday's development uses complicated or too much abstraction of codes, it doesn't have to be that way.\n\nDoesn't it cool to easily know what the code does in one look?\n\nDoesn't it cool to focus on the output rather than wasting your time on technical stuffs?\n\nDoesn't it cool to use a framework immediately without overwhelming configurations and dependencies?\n\nThis is what PHunctional PHP is all about.\n\n## Structure\n\nHere is the basic directory structure of PHunctional PHP.\n\n```\napi/\nlib/\n    Database.php\n    DotEnv.php\n    Helper.php\n    Sql.php\npublic/\n    css/\n    js/\n    res/\nroutes/\n    api.php\n    view.php\nview/\nsection/\n    header.php\n    footer.php\n.env\n.htaccess\nindex.php\nREADME.md\n```\n\n## Installation\n\nDownload the latest version and extract it on your web server's root folder.\n\nThen rename the extracted root folder into your project's name.\n\nOr use composer:\n\n```bash\ncomposer create-project vgalvoso/phunctional your_project_name\n```\n\nAfter extracting or creating your project, open a terminal in your project directory and run:\n\n```bash\ncomposer install\n```\n\nThis will initialize Composer to let you add dependencies when needed.\n\n## Build Your First App\n\nHello World! Yes, let's create your first hello world using PHunctional PHP.\n\nAfter you download and extract the latest version (see installation), create a PHP file inside the `view` folder and name it `hello_world.php`.\n\nLet's assume you named your root folder \"helloworld\", this is what your project directory might look like.\n\n![Helloworld directory](https://raw.githubusercontent.com/vgalvoso/phunctional-php/refs/heads/master/public/res/img/hello_world.png)\n\nCopy and paste this code inside `hello_world.php`:\n\n```php\n\u003c?php include \"section/header.php\"; ?\u003e\n\u003ch1\u003eHello World!\u003c/h1\u003e\n\u003c?php include \"section/footer.php\"; ?\u003e\n```\n\nOpen `routes/web.php` and add a new view route. Your `routes/web.php` should look something like this:\n\n```php\n\u003c?php\nview(\"\", \"home\");\nview(\"hello\", \"hello_world\");\nnotFound();\n```\n\nNow try to access this on your browser: `http://localhost/helloworld/hello`\n\nIt should look like this:\n\n![Helloworld directory](https://raw.githubusercontent.com/vgalvoso/phunctional-php/refs/heads/master/public/res/img/hello_page.png)\n\nCongratulations! You created your first hello world using PHunctional PHP.\n\n## Routing\n\nDefine your routes inside `routes/web.php` for views and `routes/api.php` for API endpoints.\n\nThere are 4 functions for creating routes:\n\n1. **view(routeName, fileName)**  \n     Use this function to show views.  \n     - `[routeName]` - Custom named route.  \n     - `[fileName]` - File to call inside view folder.\n\n2. **post(routeName, fileName)**  \n     Use this function for POST requests.  \n     - `[routeName]` - Custom named route.  \n     - `[fileName]` - File to call inside api folder.\n\n3. **get(routeName, fileName)**  \n     Use this function for GET requests.  \n     - `[routeName]` - Custom named route.  \n     - `[fileName]` - File to call inside api folder.\n\n4. **put(routeName, fileName)**  \n     Use this function for PUT requests.  \n     - `[routeName]` - Custom named route.  \n     - `[fileName]` - File to call inside api folder.\n\n**Sample `routes/web.php`:**\n\n```php\n\u003c?php\nview(\"\", \"home\");\nview(\"hello\", \"hello_world\");\nnotFound();\n```\n\n**Sample `routes/api.php`:**\n\n```php\n\u003c?php\npost(\"validateLogin\", \"login\");\nget(\"getUsers\", \"users/all\");\nnotFound();\n```\n\nThe `notFound()` function should be placed at the end to handle unmatched routes.\n\n## Views\n\nPlace your views inside the `view` folder.\n\nLet's create a view for our default route.\n\n**view/home.php**\n\n```php\n\u003c?php include \"section/header.php\"; ?\u003e\n\n\u003ch1\u003eHello World!\u003c/h1\u003e\n\n\u003c?php include \"section/footer.php\"; ?\u003e\n```\n\n## Database Setup\n\nPHunctional PHP uses a simple `Database.php` file for database connections. Configuration is managed via the `.env` file.\n\n### 1. Configure `.env`\n\nAdd your database credentials to the `.env` file in your project root:\n\n```\nAPP_ENV=development\nDEFAULT_SERVER=localhost\nDEFAULT_USER=root\nDEFAULT_PASS=root\nDEFAULT_DBNAME=helloworld_db\nDEFAULT_DRIVER=mysql\nDEFAULT_PORT=3306\n```\n\n### 2. Using `Database.php`\n\nHere is a sample `lib/Database.php` file:\n\n```php\n\u003c?php\n$db = array(\n    \"default\" =\u003e array(\n        \"server\" =\u003e getenv('DEFAULT_SERVER'),\n        \"user\" =\u003e getenv('DEFAULT_USER'),\n        \"pass\" =\u003e getenv('DEFAULT_PASS'),\n        \"dbname\" =\u003e getenv('DEFAULT_DBNAME'),\n        \"driver\" =\u003e getenv('DEFAULT_DRIVER'),\n        \"port\" =\u003e getenv('DEFAULT_PORT')\n    )\n);\n```\n\nThis file loads the database credentials from environment variables and stores them in the `$db` array.\n\n## Creating an API\n\nYou can easily create API endpoints in PHunctional PHP by adding files inside the `api` folder and defining routes in `routes/api.php`.\n\n### 1. Create a Sample Database\n\nFirst, create a sample database and a `users` table. You can run the following SQL queries in your MySQL client:\n\n```sql\n-- 1. Create the database\nCREATE DATABASE IF NOT EXISTS myapp_db;\n\n-- 2. Use the newly created database\nUSE myapp_db;\n\n-- 3. Create the users table\nCREATE TABLE users (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    username VARCHAR(50) NOT NULL UNIQUE,\n    email VARCHAR(100) NOT NULL UNIQUE,\n    password VARCHAR(255) NOT NULL,\n    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\n);\n```\n\n### 2. Create `api/add_user.php`\n\nCreate a new file `api/add_user.php` with the following code to handle adding a user:\n\n```php\n\u003c?php\n$query = \"INSERT INTO users (username, email, password) VALUES (:username, :email, :password)\";\n$inputs = [\n    \"username\" =\u003e $username,\n    \"email\" =\u003e $email,\n    \"password\" =\u003e password_hash($password, PASSWORD_DEFAULT),\n];\nif ($sql-\u003eexec($query, $inputs))\n    echo \"User added successfully.\";\nelse\n    echo \"Error adding user: \" . $sql-\u003egetError();\n```\n\n\u003e **Note:** In PHunctional PHP, POST payload keys are automatically converted into variables, so you can use `$username`, `$email`, and `$password` directly. No need to use `$_POST` or `$_GET`.\n\n\u003e **Note:** The `$sql` object is automatically available and uses the \"default\" database configuration from `Database.php`. If you want to use a different configuration, you can initialize it with `$sql = new Sql('configname');`.\n\n### 3. Add the Route in `routes/api.php`\n\nOpen `routes/api.php` and add the following line:\n\n```php\npost(\"users\", \"add_user\");\n```\n\nNow you can send a POST request to `/users` with `username`, `email`, and `password` in the JSON body to add a new user.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvgalvoso%2Fphunctional-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvgalvoso%2Fphunctional-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvgalvoso%2Fphunctional-php/lists"}