{"id":15917531,"url":"https://github.com/takuya/simple-app","last_synced_at":"2025-04-03T11:41:51.795Z","repository":{"id":136551615,"uuid":"84794172","full_name":"takuya/simple-app","owner":"takuya","description":"どこでもすぐ使えるシンプルな構成","archived":false,"fork":false,"pushed_at":"2017-03-29T15:33:12.000Z","size":53,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-09T01:14:04.974Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/takuya.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}},"created_at":"2017-03-13T06:59:39.000Z","updated_at":"2017-03-13T06:59:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"917419eb-2f41-4b33-b0d3-8648035a705e","html_url":"https://github.com/takuya/simple-app","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.0357142857142857,"last_synced_commit":"076eb5c08041dd5402a7d43ff6bc4b502be6c294"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuya%2Fsimple-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuya%2Fsimple-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuya%2Fsimple-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuya%2Fsimple-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/takuya","download_url":"https://codeload.github.com/takuya/simple-app/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246998100,"owners_count":20866690,"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":[],"created_at":"2024-10-06T18:11:16.992Z","updated_at":"2025-04-03T11:41:51.770Z","avatar_url":"https://github.com/takuya.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"### とりあえずPHPですぐ動かせるようなセット\n\n- ファイルを置いたら動くように\n- リクエストを容易に捌けるように\n- フレームワークを使い始めると、アレコレ余計な作業が増えるので\n- 目の前のことに集中できるように\n\nなるべく何も余計なことがないように。\n\n## what is this ?\n\n\nThis is http requet mapper. This Apps mapping path to uri.  \n\nThis framework aimed at mapping function HTTP RESTful URI.\n\n\n```php\n\u003c?php \n$app-\u003eget (\"info\" , 'phpinfo');\n$app-\u003epost(\"info\", \"phpinfo\");\n\n$app-\u003eget (\"/items/:id\", [$item_obj, 'detail']);\n$app-\u003epost(\"/items/:id\", [$item_obj, 'add_new']);\n$app-\u003eput (\"/items/:id\", [$item_obj, 'update']);\n\n$app-\u003eget (\"/user/:name/profile/:twitter_id\", [$app, 'show_user']);\n$app-\u003epost(\"/user/:name/profile/:twitter_id\", [$app, 'new_user']);\n$app-\u003eput (\"/user/:name/profile/:twitter_id\", [$app, 'update_user']);\n\n\n```\n\nThis App will be routing  `PATH in uri`  to mapped `funciton`.\n\n## Directories\n\n```\n.\n├── composer.json\n├── composer.lock\n├── composer.phar\n├── .htaccess\n├── public/\n│   └── index.php\n├── templates/\n│   └── index.php\n└── vendor/\n```\n\n## Install and 'Hello World.'\n\nSample1. Routing by URI(PATH)\n\n\n### create directory\n```\nmkdir -p target/dir\ncd target/dir\n```\n### composer.phar\n```\ncurl -sS https://getcomposer.org/installer | php\n```\n### composer.json\n```\necho '\n{\"repositories\":[{\"type\":\"git\",\n\"url\":\"https://github.com/takuya/simple-app.git\"}],\n\"require\":{\"takuya/simple-app\":\"dev-master\"}}\n' \u003e composer.json\n```\n### composer install\n```\n./composer.phar install\n```\n### .htaccess\n```\necho '\nRewriteBase /target/dir\nRewriteRule .*  public/index.php [QSA,L]\n' \u003e .htaccess\n```\n#### pubic/index.php\n```\nmkdir -p target/dir/public\necho '\u003c?php\n\nrequire __DIR__.\"/\".'../vendor/autoload.php';\nuse takuya\\SimpleWebApp\\SimpleRoutedWebApp;\n\nclass MyApp extends SimpleRoutedWebApp {\n  public function sample(){return 'sample';}\n}\n//main\n$app = new MyApp();\n$app-\u003edocument_root = '/target/dir';\n$app-\u003eget(\"/sample\", [$app, 'sample']);\n$app-\u003eget(\"/info\" , 'phpinfo');\n$app-\u003erun();\n' \u003e public/index.php\n```\n#### templates dir \n\n```\nmkdir -p target/dir/templates\n```\n#### templates/sample.php\n```\necho '\u003c?php echo $contents;'\u003e templates/sample.php  \n```\n#### render template\n```\nclass MyApp extends SimpleRoutedWebApp {\n  public function sample(){return ['contents':'hello world.'];}\n}\n\n```\n\n### Routing Sample\n\n#### sample uri \n\n- GET /~takuya/sample \n- GET /~takuya/user/:name\n- GET /~takuya/list?limit=100\n- POST /~takuya/sample\n\n#### .htaccess\n```\nRewriteBase /~takuya\nRewriteRule .*  public/index.php [QSA,L]\n```\n#### public/index.php\n```php\n\u003c?php \n\n\nrequire __DIR__.\"/\".'../vendor/autoload.php';\nuse takuya\\SimpleWebApp\\SimpleRoutedWebApp;\n\nclass MyApp extends SimpleRoutedWebApp { }\n\n// main \n$app = new MyApp();\n$app-\u003edocument_root = '/~takuya';\n// set handlers\n$app-\u003epost(\"/sample\" ,function(){  echo 'Hello sample (POST)'; });\n$app-\u003eget(\"/sample\" ,function(){  echo 'Hello sample (GET)'; });\n$app-\u003eget(\"/list\",function() use ($app){\n  $defaults = ['limit':10];\n  $req= $app-\u003erequests($defaults);\n  echo $req-\u003elimit;\n}));\n$app-\u003epost(\"/user/:name\" ,function($param){ echo $params-\u003ename; }) );\n\n// execute\n$app-\u003erun();\n\n```\n### request sample\n```sh\n$ curl http://[::1]/~takuya/sample\nHello sample (GET)\n$ curl http://[::1]/~takuya/sample -d name=value\nHello sample (POST)\n$ curl http://[::1]/~takuya/user/alice\nalice\n$ curl http://[::1]/~takuya/list?limit=10\n10\n```\n\n### Sample2: Routing by GET parameter\n\n### Sample URI\n\n` /~takuya/?action=debug `  maping `$_GET['action']` to ` function ` .\n\n#### .htaccess\n```\nDirectoryIndex public/index.php\n```\n#### public/index.php\n```php\n\u003c?php \n\nuse takuya\\SimpleWebApp\\SimpleWebApp;\n\nclass MyApp extends SimpleWebApp {\n  public __construct(){\n    parent::__construct();\n    $this-\u003eact_key_name = \"act\"; \n    $this-\u003edefault_act = \"index\";\n  }\n}\n\n// main \n$app = new MyApp();\n\n// mapping handlers\n$app-\u003eget(\"debug\" , function() use ($app){  echo 1 ; });\n$app-\u003eget(\"info\" , 'phpinfo');\n$app-\u003epost(\"info\", \"phpinfo\");\n$app-\u003eget(\"sample\", function () use ($app) {\n  $app-\u003erender(\"sample.php\");\n});\n\n// run\n$app-\u003erun();\n\n```\n### Request sample\n```sh\n$ curl http://[::1]/~takuya/?act=debug\n1\n```\n\n## HTTP Request Paramters\n\nPHP request using  symbols variables are too much...\n\n```\n\nif ( empty( $_GET['limit'] ) ){ // how many shifts needed...\n}\n\n$request-\u003elimit; // so simple.\n\n```\n\n```php\n\u003c?php \n\nuse takuya\\SimpleWebApp\\SimpleRoutedWebApp;\n\nclass MyApp extends SimpleRoutedWebApp {\n  public function sample(){\n    $app = MyApp::getInstance();\n    \n    $defaults = [\n      'search' =\u003e '',\n      'limit' =\u003e 10,\n      'offset' =\u003e 0,\n    ]\n    $req = $app-\u003erequests($defaults);\n\n    //check range \n    $req-\u003elimit = $req-\u003elimit \u003c 1 ?: $defaults['limit'];\n    \n    $ret = query( $req-\u003esearch, $req-\u003elimit , $req-\u003eoffset );\n    // output\n    $app-\u003erender('sample.php', ['records'=\u003e$ret]);\n  }\n}\n\n// instance\n$app = new MyApp();\n$app-\u003edocument_root = '/~takuya';\n// mappping handlers\n$app-\u003eget(\"/sample\" , array( $app, 'sample' ));\n\n// run \n$app-\u003erun();\n\n\n?\u003e\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakuya%2Fsimple-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftakuya%2Fsimple-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakuya%2Fsimple-app/lists"}