├── .gitignore ├── README.md ├── composer.json ├── composer.lock ├── data └── menu.json ├── public ├── .htaccess └── index.php ├── src ├── App.php ├── Controller │ ├── BasicPageController.php │ └── ContactController.php ├── Service │ └── ConfigService.php └── services.yaml └── templates ├── forms └── contact.html └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | .idea/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # php-framework 2 | A lightweight custom php framework. 3 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babagana/php-framework", 3 | "description": "An ultimate php-framework created from ecPHP ecosystem packages and components.", 4 | "type": "project", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Babagana Zannah", 9 | "email": "babagana.tech@gmail.com" 10 | } 11 | ], 12 | "require": { 13 | "symfony/http-foundation": "^4.0", 14 | "twig/twig": "^2.4", 15 | "league/flysystem": "^1.0", 16 | "hirak/prestissimo": "^0.3.7", 17 | "symfony/dependency-injection": "^4.0", 18 | "symfony/config": "^4.0", 19 | "symfony/yaml": "^4.0" 20 | }, 21 | 22 | "autoload": { 23 | "psr-4": { 24 | "Weekend\\": "src/" 25 | } 26 | }, 27 | 28 | "scripts": { 29 | "start": "php -S localhost:4000 -t public/ " 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "9ced891d26f7e9fa65abf6ce9d61fcc5", 8 | "packages": [ 9 | { 10 | "name": "hirak/prestissimo", 11 | "version": "0.3.7", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/hirak/prestissimo.git", 15 | "reference": "45fcc8a65fb06b29cc5cdd1b0bae7a690aa09496" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/hirak/prestissimo/zipball/45fcc8a65fb06b29cc5cdd1b0bae7a690aa09496", 20 | "reference": "45fcc8a65fb06b29cc5cdd1b0bae7a690aa09496", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "composer-plugin-api": "^1.0.0", 25 | "ext-curl": "*", 26 | "php": "^5.3.2 || ^7.0" 27 | }, 28 | "require-dev": { 29 | "composer/composer": "1.0.0", 30 | "phpunit/phpunit": "^4.8", 31 | "squizlabs/php_codesniffer": "^2.5" 32 | }, 33 | "type": "composer-plugin", 34 | "extra": { 35 | "class": "Hirak\\Prestissimo\\Plugin" 36 | }, 37 | "autoload": { 38 | "psr-4": { 39 | "Hirak\\Prestissimo\\": "src/" 40 | } 41 | }, 42 | "notification-url": "https://packagist.org/downloads/", 43 | "license": [ 44 | "MIT" 45 | ], 46 | "authors": [ 47 | { 48 | "name": "Hiraku NAKANO", 49 | "email": "hiraku@tojiru.net" 50 | } 51 | ], 52 | "description": "composer parallel install plugin", 53 | "keywords": [ 54 | "install", 55 | "parallel", 56 | "speedup" 57 | ], 58 | "time": "2017-05-27T04:45:45+00:00" 59 | }, 60 | { 61 | "name": "league/flysystem", 62 | "version": "1.0.42", 63 | "source": { 64 | "type": "git", 65 | "url": "https://github.com/thephpleague/flysystem.git", 66 | "reference": "09eabc54e199950041aef258a85847676496fe8e" 67 | }, 68 | "dist": { 69 | "type": "zip", 70 | "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/09eabc54e199950041aef258a85847676496fe8e", 71 | "reference": "09eabc54e199950041aef258a85847676496fe8e", 72 | "shasum": "" 73 | }, 74 | "require": { 75 | "php": ">=5.5.9" 76 | }, 77 | "conflict": { 78 | "league/flysystem-sftp": "<1.0.6" 79 | }, 80 | "require-dev": { 81 | "ext-fileinfo": "*", 82 | "phpspec/phpspec": "^3.4", 83 | "phpunit/phpunit": "^5.7" 84 | }, 85 | "suggest": { 86 | "ext-fileinfo": "Required for MimeType", 87 | "ext-ftp": "Allows you to use FTP server storage", 88 | "ext-openssl": "Allows you to use FTPS server storage", 89 | "league/flysystem-aws-s3-v2": "Allows you to use S3 storage with AWS SDK v2", 90 | "league/flysystem-aws-s3-v3": "Allows you to use S3 storage with AWS SDK v3", 91 | "league/flysystem-azure": "Allows you to use Windows Azure Blob storage", 92 | "league/flysystem-cached-adapter": "Flysystem adapter decorator for metadata caching", 93 | "league/flysystem-eventable-filesystem": "Allows you to use EventableFilesystem", 94 | "league/flysystem-rackspace": "Allows you to use Rackspace Cloud Files", 95 | "league/flysystem-sftp": "Allows you to use SFTP server storage via phpseclib", 96 | "league/flysystem-webdav": "Allows you to use WebDAV storage", 97 | "league/flysystem-ziparchive": "Allows you to use ZipArchive adapter", 98 | "spatie/flysystem-dropbox": "Allows you to use Dropbox storage", 99 | "srmklive/flysystem-dropbox-v2": "Allows you to use Dropbox storage for PHP 5 applications" 100 | }, 101 | "type": "library", 102 | "extra": { 103 | "branch-alias": { 104 | "dev-master": "1.1-dev" 105 | } 106 | }, 107 | "autoload": { 108 | "psr-4": { 109 | "League\\Flysystem\\": "src/" 110 | } 111 | }, 112 | "notification-url": "https://packagist.org/downloads/", 113 | "license": [ 114 | "MIT" 115 | ], 116 | "authors": [ 117 | { 118 | "name": "Frank de Jonge", 119 | "email": "info@frenky.net" 120 | } 121 | ], 122 | "description": "Filesystem abstraction: Many filesystems, one API.", 123 | "keywords": [ 124 | "Cloud Files", 125 | "WebDAV", 126 | "abstraction", 127 | "aws", 128 | "cloud", 129 | "copy.com", 130 | "dropbox", 131 | "file systems", 132 | "files", 133 | "filesystem", 134 | "filesystems", 135 | "ftp", 136 | "rackspace", 137 | "remote", 138 | "s3", 139 | "sftp", 140 | "storage" 141 | ], 142 | "time": "2018-01-27T16:03:56+00:00" 143 | }, 144 | { 145 | "name": "psr/container", 146 | "version": "1.0.0", 147 | "source": { 148 | "type": "git", 149 | "url": "https://github.com/php-fig/container.git", 150 | "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" 151 | }, 152 | "dist": { 153 | "type": "zip", 154 | "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", 155 | "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", 156 | "shasum": "" 157 | }, 158 | "require": { 159 | "php": ">=5.3.0" 160 | }, 161 | "type": "library", 162 | "extra": { 163 | "branch-alias": { 164 | "dev-master": "1.0.x-dev" 165 | } 166 | }, 167 | "autoload": { 168 | "psr-4": { 169 | "Psr\\Container\\": "src/" 170 | } 171 | }, 172 | "notification-url": "https://packagist.org/downloads/", 173 | "license": [ 174 | "MIT" 175 | ], 176 | "authors": [ 177 | { 178 | "name": "PHP-FIG", 179 | "homepage": "http://www.php-fig.org/" 180 | } 181 | ], 182 | "description": "Common Container Interface (PHP FIG PSR-11)", 183 | "homepage": "https://github.com/php-fig/container", 184 | "keywords": [ 185 | "PSR-11", 186 | "container", 187 | "container-interface", 188 | "container-interop", 189 | "psr" 190 | ], 191 | "time": "2017-02-14T16:28:37+00:00" 192 | }, 193 | { 194 | "name": "symfony/config", 195 | "version": "v4.0.4", 196 | "source": { 197 | "type": "git", 198 | "url": "https://github.com/symfony/config.git", 199 | "reference": "ecd917899167922086ddb3247aa43eb1c418fcb2" 200 | }, 201 | "dist": { 202 | "type": "zip", 203 | "url": "https://api.github.com/repos/symfony/config/zipball/ecd917899167922086ddb3247aa43eb1c418fcb2", 204 | "reference": "ecd917899167922086ddb3247aa43eb1c418fcb2", 205 | "shasum": "" 206 | }, 207 | "require": { 208 | "php": "^7.1.3", 209 | "symfony/filesystem": "~3.4|~4.0" 210 | }, 211 | "conflict": { 212 | "symfony/finder": "<3.4" 213 | }, 214 | "require-dev": { 215 | "symfony/finder": "~3.4|~4.0", 216 | "symfony/yaml": "~3.4|~4.0" 217 | }, 218 | "suggest": { 219 | "symfony/yaml": "To use the yaml reference dumper" 220 | }, 221 | "type": "library", 222 | "extra": { 223 | "branch-alias": { 224 | "dev-master": "4.0-dev" 225 | } 226 | }, 227 | "autoload": { 228 | "psr-4": { 229 | "Symfony\\Component\\Config\\": "" 230 | }, 231 | "exclude-from-classmap": [ 232 | "/Tests/" 233 | ] 234 | }, 235 | "notification-url": "https://packagist.org/downloads/", 236 | "license": [ 237 | "MIT" 238 | ], 239 | "authors": [ 240 | { 241 | "name": "Fabien Potencier", 242 | "email": "fabien@symfony.com" 243 | }, 244 | { 245 | "name": "Symfony Community", 246 | "homepage": "https://symfony.com/contributors" 247 | } 248 | ], 249 | "description": "Symfony Config Component", 250 | "homepage": "https://symfony.com", 251 | "time": "2018-01-21T19:06:11+00:00" 252 | }, 253 | { 254 | "name": "symfony/dependency-injection", 255 | "version": "v4.0.4", 256 | "source": { 257 | "type": "git", 258 | "url": "https://github.com/symfony/dependency-injection.git", 259 | "reference": "f78ca49c6360c710ca8e316511e71a23b10e3bf2" 260 | }, 261 | "dist": { 262 | "type": "zip", 263 | "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/f78ca49c6360c710ca8e316511e71a23b10e3bf2", 264 | "reference": "f78ca49c6360c710ca8e316511e71a23b10e3bf2", 265 | "shasum": "" 266 | }, 267 | "require": { 268 | "php": "^7.1.3", 269 | "psr/container": "^1.0" 270 | }, 271 | "conflict": { 272 | "symfony/config": "<3.4", 273 | "symfony/finder": "<3.4", 274 | "symfony/proxy-manager-bridge": "<3.4", 275 | "symfony/yaml": "<3.4" 276 | }, 277 | "provide": { 278 | "psr/container-implementation": "1.0" 279 | }, 280 | "require-dev": { 281 | "symfony/config": "~3.4|~4.0", 282 | "symfony/expression-language": "~3.4|~4.0", 283 | "symfony/yaml": "~3.4|~4.0" 284 | }, 285 | "suggest": { 286 | "symfony/config": "", 287 | "symfony/expression-language": "For using expressions in service container configuration", 288 | "symfony/finder": "For using double-star glob patterns or when GLOB_BRACE portability is required", 289 | "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them", 290 | "symfony/yaml": "" 291 | }, 292 | "type": "library", 293 | "extra": { 294 | "branch-alias": { 295 | "dev-master": "4.0-dev" 296 | } 297 | }, 298 | "autoload": { 299 | "psr-4": { 300 | "Symfony\\Component\\DependencyInjection\\": "" 301 | }, 302 | "exclude-from-classmap": [ 303 | "/Tests/" 304 | ] 305 | }, 306 | "notification-url": "https://packagist.org/downloads/", 307 | "license": [ 308 | "MIT" 309 | ], 310 | "authors": [ 311 | { 312 | "name": "Fabien Potencier", 313 | "email": "fabien@symfony.com" 314 | }, 315 | { 316 | "name": "Symfony Community", 317 | "homepage": "https://symfony.com/contributors" 318 | } 319 | ], 320 | "description": "Symfony DependencyInjection Component", 321 | "homepage": "https://symfony.com", 322 | "time": "2018-01-29T09:29:16+00:00" 323 | }, 324 | { 325 | "name": "symfony/filesystem", 326 | "version": "v4.0.4", 327 | "source": { 328 | "type": "git", 329 | "url": "https://github.com/symfony/filesystem.git", 330 | "reference": "760e47a4ee64b4c48f4b30017011e09d4c0f05ed" 331 | }, 332 | "dist": { 333 | "type": "zip", 334 | "url": "https://api.github.com/repos/symfony/filesystem/zipball/760e47a4ee64b4c48f4b30017011e09d4c0f05ed", 335 | "reference": "760e47a4ee64b4c48f4b30017011e09d4c0f05ed", 336 | "shasum": "" 337 | }, 338 | "require": { 339 | "php": "^7.1.3" 340 | }, 341 | "type": "library", 342 | "extra": { 343 | "branch-alias": { 344 | "dev-master": "4.0-dev" 345 | } 346 | }, 347 | "autoload": { 348 | "psr-4": { 349 | "Symfony\\Component\\Filesystem\\": "" 350 | }, 351 | "exclude-from-classmap": [ 352 | "/Tests/" 353 | ] 354 | }, 355 | "notification-url": "https://packagist.org/downloads/", 356 | "license": [ 357 | "MIT" 358 | ], 359 | "authors": [ 360 | { 361 | "name": "Fabien Potencier", 362 | "email": "fabien@symfony.com" 363 | }, 364 | { 365 | "name": "Symfony Community", 366 | "homepage": "https://symfony.com/contributors" 367 | } 368 | ], 369 | "description": "Symfony Filesystem Component", 370 | "homepage": "https://symfony.com", 371 | "time": "2018-01-03T07:38:00+00:00" 372 | }, 373 | { 374 | "name": "symfony/http-foundation", 375 | "version": "v4.0.4", 376 | "source": { 377 | "type": "git", 378 | "url": "https://github.com/symfony/http-foundation.git", 379 | "reference": "82a3ee2c6662d08ca1adf99e1ef2e31ab48196d4" 380 | }, 381 | "dist": { 382 | "type": "zip", 383 | "url": "https://api.github.com/repos/symfony/http-foundation/zipball/82a3ee2c6662d08ca1adf99e1ef2e31ab48196d4", 384 | "reference": "82a3ee2c6662d08ca1adf99e1ef2e31ab48196d4", 385 | "shasum": "" 386 | }, 387 | "require": { 388 | "php": "^7.1.3", 389 | "symfony/polyfill-mbstring": "~1.1" 390 | }, 391 | "require-dev": { 392 | "symfony/expression-language": "~3.4|~4.0" 393 | }, 394 | "type": "library", 395 | "extra": { 396 | "branch-alias": { 397 | "dev-master": "4.0-dev" 398 | } 399 | }, 400 | "autoload": { 401 | "psr-4": { 402 | "Symfony\\Component\\HttpFoundation\\": "" 403 | }, 404 | "exclude-from-classmap": [ 405 | "/Tests/" 406 | ] 407 | }, 408 | "notification-url": "https://packagist.org/downloads/", 409 | "license": [ 410 | "MIT" 411 | ], 412 | "authors": [ 413 | { 414 | "name": "Fabien Potencier", 415 | "email": "fabien@symfony.com" 416 | }, 417 | { 418 | "name": "Symfony Community", 419 | "homepage": "https://symfony.com/contributors" 420 | } 421 | ], 422 | "description": "Symfony HttpFoundation Component", 423 | "homepage": "https://symfony.com", 424 | "time": "2018-01-29T09:06:29+00:00" 425 | }, 426 | { 427 | "name": "symfony/polyfill-mbstring", 428 | "version": "v1.7.0", 429 | "source": { 430 | "type": "git", 431 | "url": "https://github.com/symfony/polyfill-mbstring.git", 432 | "reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b" 433 | }, 434 | "dist": { 435 | "type": "zip", 436 | "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/78be803ce01e55d3491c1397cf1c64beb9c1b63b", 437 | "reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b", 438 | "shasum": "" 439 | }, 440 | "require": { 441 | "php": ">=5.3.3" 442 | }, 443 | "suggest": { 444 | "ext-mbstring": "For best performance" 445 | }, 446 | "type": "library", 447 | "extra": { 448 | "branch-alias": { 449 | "dev-master": "1.7-dev" 450 | } 451 | }, 452 | "autoload": { 453 | "psr-4": { 454 | "Symfony\\Polyfill\\Mbstring\\": "" 455 | }, 456 | "files": [ 457 | "bootstrap.php" 458 | ] 459 | }, 460 | "notification-url": "https://packagist.org/downloads/", 461 | "license": [ 462 | "MIT" 463 | ], 464 | "authors": [ 465 | { 466 | "name": "Nicolas Grekas", 467 | "email": "p@tchwork.com" 468 | }, 469 | { 470 | "name": "Symfony Community", 471 | "homepage": "https://symfony.com/contributors" 472 | } 473 | ], 474 | "description": "Symfony polyfill for the Mbstring extension", 475 | "homepage": "https://symfony.com", 476 | "keywords": [ 477 | "compatibility", 478 | "mbstring", 479 | "polyfill", 480 | "portable", 481 | "shim" 482 | ], 483 | "time": "2018-01-30T19:27:44+00:00" 484 | }, 485 | { 486 | "name": "symfony/yaml", 487 | "version": "v4.0.4", 488 | "source": { 489 | "type": "git", 490 | "url": "https://github.com/symfony/yaml.git", 491 | "reference": "ffc60bda1d4a00ec0b32eeabf39dc017bf480028" 492 | }, 493 | "dist": { 494 | "type": "zip", 495 | "url": "https://api.github.com/repos/symfony/yaml/zipball/ffc60bda1d4a00ec0b32eeabf39dc017bf480028", 496 | "reference": "ffc60bda1d4a00ec0b32eeabf39dc017bf480028", 497 | "shasum": "" 498 | }, 499 | "require": { 500 | "php": "^7.1.3" 501 | }, 502 | "conflict": { 503 | "symfony/console": "<3.4" 504 | }, 505 | "require-dev": { 506 | "symfony/console": "~3.4|~4.0" 507 | }, 508 | "suggest": { 509 | "symfony/console": "For validating YAML files using the lint command" 510 | }, 511 | "type": "library", 512 | "extra": { 513 | "branch-alias": { 514 | "dev-master": "4.0-dev" 515 | } 516 | }, 517 | "autoload": { 518 | "psr-4": { 519 | "Symfony\\Component\\Yaml\\": "" 520 | }, 521 | "exclude-from-classmap": [ 522 | "/Tests/" 523 | ] 524 | }, 525 | "notification-url": "https://packagist.org/downloads/", 526 | "license": [ 527 | "MIT" 528 | ], 529 | "authors": [ 530 | { 531 | "name": "Fabien Potencier", 532 | "email": "fabien@symfony.com" 533 | }, 534 | { 535 | "name": "Symfony Community", 536 | "homepage": "https://symfony.com/contributors" 537 | } 538 | ], 539 | "description": "Symfony Yaml Component", 540 | "homepage": "https://symfony.com", 541 | "time": "2018-01-21T19:06:11+00:00" 542 | }, 543 | { 544 | "name": "twig/twig", 545 | "version": "v2.4.4", 546 | "source": { 547 | "type": "git", 548 | "url": "https://github.com/twigphp/Twig.git", 549 | "reference": "eddb97148ad779f27e670e1e3f19fb323aedafeb" 550 | }, 551 | "dist": { 552 | "type": "zip", 553 | "url": "https://api.github.com/repos/twigphp/Twig/zipball/eddb97148ad779f27e670e1e3f19fb323aedafeb", 554 | "reference": "eddb97148ad779f27e670e1e3f19fb323aedafeb", 555 | "shasum": "" 556 | }, 557 | "require": { 558 | "php": "^7.0", 559 | "symfony/polyfill-mbstring": "~1.0" 560 | }, 561 | "require-dev": { 562 | "psr/container": "^1.0", 563 | "symfony/debug": "~2.7", 564 | "symfony/phpunit-bridge": "~3.3@dev" 565 | }, 566 | "type": "library", 567 | "extra": { 568 | "branch-alias": { 569 | "dev-master": "2.4-dev" 570 | } 571 | }, 572 | "autoload": { 573 | "psr-0": { 574 | "Twig_": "lib/" 575 | }, 576 | "psr-4": { 577 | "Twig\\": "src/" 578 | } 579 | }, 580 | "notification-url": "https://packagist.org/downloads/", 581 | "license": [ 582 | "BSD-3-Clause" 583 | ], 584 | "authors": [ 585 | { 586 | "name": "Fabien Potencier", 587 | "email": "fabien@symfony.com", 588 | "homepage": "http://fabien.potencier.org", 589 | "role": "Lead Developer" 590 | }, 591 | { 592 | "name": "Armin Ronacher", 593 | "email": "armin.ronacher@active-4.com", 594 | "role": "Project Founder" 595 | }, 596 | { 597 | "name": "Twig Team", 598 | "homepage": "http://twig.sensiolabs.org/contributors", 599 | "role": "Contributors" 600 | } 601 | ], 602 | "description": "Twig, the flexible, fast, and secure template language for PHP", 603 | "homepage": "http://twig.sensiolabs.org", 604 | "keywords": [ 605 | "templating" 606 | ], 607 | "time": "2017-09-27T18:10:31+00:00" 608 | } 609 | ], 610 | "packages-dev": [], 611 | "aliases": [], 612 | "minimum-stability": "stable", 613 | "stability-flags": [], 614 | "prefer-stable": false, 615 | "prefer-lowest": false, 616 | "platform": [], 617 | "platform-dev": [] 618 | } 619 | -------------------------------------------------------------------------------- /data/menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "index": { 3 | "title": "Hello Universe", 4 | "content": "Welcome to our own framework" 5 | }, 6 | "about": { 7 | "title": "About", 8 | "content": "This is a super content site." 9 | } 10 | } -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | # Web server configuration 2 | 3 | RewriteEngine On # Enable re-write module 4 | 5 | # check that request is not for an existing file (img, css, js etc) 6 | RewriteCond %{REQUEST_FILENAME} !-f 7 | 8 | # Route everything else to index.php 9 | RewriteRule . index.php [L] -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | run($request); 13 | $response->send(); 14 | 15 | -------------------------------------------------------------------------------- /src/App.php: -------------------------------------------------------------------------------- 1 | container = new ContainerBuilder(); 22 | $loader = new YamlFileLoader($this->container, new FileLocator(__DIR__)); 23 | $loader->load('services.yaml'); 24 | $this->twig = $this->container->get('twig'); 25 | $this->filesystem = $this->container->get('filesystem'); 26 | } 27 | 28 | public function run(Request $request) 29 | { 30 | $routes = [ 31 | '/' => 'basic_page_controller', 32 | '/index' => 'basic_page_controller', 33 | '/about' => 'basic_page_controller', 34 | '/contact' => 'contact_controller' 35 | ]; 36 | $path = $request->getPathInfo(); 37 | $method = strtolower($request->getMethod()); // method type get,post 38 | 39 | if(isset($routes[$path])) { 40 | $controller = $this->container->get($routes[$path]); 41 | if(is_callable([$controller, $method])) { 42 | return call_user_func_array(array($controller, $method), array($path, $request)); 43 | } 44 | } 45 | return Response::create("Page not found App.php", 404); 46 | } 47 | } -------------------------------------------------------------------------------- /src/Controller/BasicPageController.php: -------------------------------------------------------------------------------- 1 | twig = $twig; 24 | $this->config = $config; 25 | } 26 | 27 | /** 28 | * @param $path 29 | * @return Response|static 30 | * @throws \Twig_Error_Loader 31 | * @throws \Twig_Error_Runtime 32 | * @throws \Twig_Error_Syntax 33 | */ 34 | public function get($path) { 35 | $page = ($path == '/') ? 'index' : substr($path, 1); 36 | $menu = $this->config->getConfig(); 37 | if(isset($menu[$page])) { 38 | 39 | $content = $this->twig->render('index.html', $menu[$page]); 40 | return new Response($content); 41 | } 42 | return Response::create('page not found', 404); 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /src/Controller/ContactController.php: -------------------------------------------------------------------------------- 1 | twig = $twig; 21 | } 22 | 23 | /** 24 | * @return Response 25 | * @throws \Twig_Error_Loader 26 | * @throws \Twig_Error_Runtime 27 | * @throws \Twig_Error_Syntax 28 | */ 29 | public function get() 30 | { 31 | $form = $this->twig->render('forms/contact.html'); 32 | $content = $this->twig->render('index.html', [ 33 | 'title' => 'Contact', 34 | 'content' => $form 35 | ]); 36 | return new Response($content); 37 | 38 | } 39 | 40 | /** 41 | * @return Response 42 | * @throws \Twig_Error_Loader 43 | * @throws \Twig_Error_Runtime 44 | * @throws \Twig_Error_Syntax 45 | */ 46 | public function post() 47 | { 48 | // TODO: validate input 49 | $content = $this->twig->render('index.html', [ 50 | 'title' => 'Contact', 51 | 'content' => 'Thank you for you message.' 52 | ]); 53 | return new Response($content); 54 | 55 | } 56 | } -------------------------------------------------------------------------------- /src/Service/ConfigService.php: -------------------------------------------------------------------------------- 1 | config = json_decode($filesystem->read('menu.json'), true); 21 | } 22 | 23 | /** 24 | * @return mixed 25 | */ 26 | public function getConfig() 27 | { 28 | return $this->config; 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /src/services.yaml: -------------------------------------------------------------------------------- 1 | parameters: 2 | template_dir: '../templates' 3 | data_dir: '../data' 4 | 5 | services: 6 | loader: 7 | class: Twig_Loader_Filesystem 8 | arguments: ['%template_dir%'] 9 | 10 | twig: 11 | class: Twig_Environment 12 | arguments: ['@loader'] 13 | 14 | adapter: 15 | class: League\Flysystem\Adapter\Local 16 | arguments: ['%data_dir%'] 17 | 18 | filesystem: 19 | class: League\Flysystem\Filesystem 20 | arguments: ['@adapter'] 21 | 22 | contact_controller: 23 | class: Weekend\Controller\ContactController 24 | arguments: ['@twig'] 25 | 26 | config_service: 27 | class: Weekend\Service\ConfigService 28 | arguments: ['@filesystem'] 29 | 30 | basic_page_controller: 31 | class: Weekend\Controller\BasicPageController 32 | arguments: ['@twig', '@config_service'] -------------------------------------------------------------------------------- /templates/forms/contact.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
-------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{ title }} 6 | 7 | 8 | 9 |

{{ title}}

10 |

{{ content | raw}}

11 | 12 | --------------------------------------------------------------------------------