PHP Classes

Simple PHP Framework Application: Example MVC application with the Symfony framework

Recommend this page to a friend!
  Info   View files Example   View files View files (23)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-11-25 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 32 This week: 1All time: 10,930 This week: 108Up
Version License PHP version Categories
simple-php-framework 1.0The PHP License7Libraries, Design Patterns, PHP 7, Ap...
Description 

Author

This package provides an example MVC application with the Symfony framework.

It defines routes to process HTTP requests using controllers defined using class files.

Currently, it provides controller classes for:

- Check if the current year is a leap year

- Show a dashboard on the home page

- Search for Twitter posts

Picture of Nahidul Hasan
  Performance   Level  
Name: Nahidul Hasan <contact>
Classes: 14 packages by
Country: Bangladesh Bangladesh
Innovation award
Innovation award
Nominee: 7x

Example

<?php

define
('ROOT_DIR', realpath(__DIR__ . '/../'));

require_once
__DIR__.'/../vendor/autoload.php';

use
Symfony\Component\HttpFoundation\Request;
use
Symfony\Component\HttpFoundation\Response;
use
Symfony\Component\Routing;
use
Symfony\Component\HttpKernel;
use
Symfony\Component\HttpKernel\Controller\ArgumentResolver;
use
Symfony\Component\HttpKernel\Controller\ControllerResolver;

function
render_template(Request $request)
{
   
extract($request->attributes->all(), EXTR_SKIP);
   
ob_start();
    include
sprintf(__DIR__.'/../src/pages/%s.php', $_route);

    return new
Response(ob_get_clean());
}


$dotenv = new Dotenv\Dotenv(ROOT_DIR);
$dotenv->load();

$request = Request::createFromGlobals();
$routes = include __DIR__.'/../src/routes.php';

$context = new Routing\RequestContext();
$matcher = new Routing\Matcher\UrlMatcher($routes, $context);

$controllerResolver = new ControllerResolver();
$argumentResolver = new ArgumentResolver();

$framework = new Simplex\Framework($matcher, $controllerResolver, $argumentResolver);
$response = $framework->handle($request);

$response->send();


Details

simple-php-framework

Trying to develop basic framework structure using symfony component

Installation:

Clone the repo

Run the following command

composer update

Run the PHP built-in server (php >= 7.0):

php -S 127.0.0.1:4321 -t web/ web/index.php

Now browse the project

http://127.0.0.1:4321/is_leap_year/2020

For docker

Run the following command

docker-compose up -d

Now browse the project

http://127.0.0.1:8097/is_leap_year/2020


  Files folder image Files  
File Role Description
Files folder imageConfig (1 file)
Files folder imagedocker (2 directories)
Files folder imagesrc (1 file, 6 directories)
Files folder imagetests (1 directory)
Files folder imageweb (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file docker-compose.yml Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file test.php Test Unit test class using PHPUnit

  Files folder image Files  /  Config  
File Role Description
  Accessible without login Plain text file api.php Aux. Auxiliary script

  Files folder image Files  /  docker  
File Role Description
Files folder imagenginx (1 file)
Files folder imagephp (2 files)

  Files folder image Files  /  docker  /  nginx  
File Role Description
  Accessible without login Plain text file default.conf Data Auxiliary data

  Files folder image Files  /  docker  /  php  
File Role Description
  Accessible without login Plain text file custom.ini Data Auxiliary data
  Accessible without login Plain text file Dockerfile Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageAPI (1 directory)
Files folder imageCalendar (2 directories)
Files folder imageContracts (1 file)
Files folder imageHelper (1 file)
Files folder imageServices (3 files)
Files folder imageSimplex (1 file)
  Accessible without login Plain text file routes.php Example Example script

  Files folder image Files  /  src  /  API  
File Role Description
Files folder imageController (2 files)

  Files folder image Files  /  src  /  API  /  Controller  
File Role Description
  Plain text file APIController.php Class Class source
  Plain text file HomeController.php Class Class source

  Files folder image Files  /  src  /  Calendar  
File Role Description
Files folder imageController (1 file)
Files folder imageModel (1 file)

  Files folder image Files  /  src  /  Calendar  /  Controller  
File Role Description
  Plain text file LeapYearController.php Class Class source

  Files folder image Files  /  src  /  Calendar  /  Model  
File Role Description
  Plain text file LeapYear.php Class Class source

  Files folder image Files  /  src  /  Contracts  
File Role Description
  Plain text file OutPutInterface.php Class Class source

  Files folder image Files  /  src  /  Helper  
File Role Description
  Plain text file Config.php Class Class source

  Files folder image Files  /  src  /  Services  
File Role Description
  Plain text file JsonOutputService.php Class Class source
  Plain text file TwitterAPIService.php Class Class source
  Plain text file TwitterHelperService.php Class Class source

  Files folder image Files  /  src  /  Simplex  
File Role Description
  Plain text file Framework.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageSimplex (1 directory)

  Files folder image Files  /  tests  /  Simplex  
File Role Description
Files folder imageTests (1 file)

  Files folder image Files  /  tests  /  Simplex  /  Tests  
File Role Description
  Plain text file FrameworkTest.php Class Class source

  Files folder image Files  /  web  
File Role Description
  Accessible without login Plain text file index.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:32
This week:1
All time:10,930
This week:108Up