miniframe/miniframe

Very lightweight Request/Response PHP framework, for micro applications

v1.0.2 2021-09-19 11:28 UTC

This package is auto-updated.

Last update: 2024-03-20 15:48:56 UTC


README

This PHP Framework is being setup as a very lightweight Request/Response PHP framework with as few dependencies as possible, with the goal to set up small (micro) applications in a short amount of time.

This repository contains the base for a new Miniframe PHP Framework-based project.
You can read this readme from top to bottom, or jump to a specific section:

Set up your project

These steps are described using Docker. You can also install Composer and a webserver locally, but that's not documented here.

Installing Docker

If you already have Docker installed, you can skip this section and jump directly to Creating a new project with Composer.

Creating a new project with Composer

There is no need to download and configure this project. Composer can do this for you.
Open a cmd.exe / bash console in an empty project folder and create a new project:

  • For Windows:
    docker run --rm --tty --volume "%CD%:/var/www/html" garrcomm/php-apache-composer composer create-project miniframe/miniframe .
  • For Unix-based OS'es:
    docker run --rm --volume "${PWD}:/var/www/html" garrcomm/php-apache-composer composer create-project miniframe/miniframe .

If you want to understand what's happening, here we'll explain this command line;

  • docker run - we want to run a docker container.
  • --rm - remove the container after use.
  • --tty - For windows; use a pseudo-TTY to show colors on the console as well.
  • --volume "??:/var/www/html" - which path must be mounted to /var/www/html inside the container
  • garrcomm/php-apache-composer - the container to run (see hub.docker.com)

Now follows the command that should be executed within the container;

  • composer create-project miniframe/miniframe - Create a project based on the Composer miniframe/miniframe package
  • -s dev tells Composer to set stability to development. This will be obsolete soon.
  • . Tells Composer to create the project in the current folder (which we mounted with --volume in Docker)

Start your project

First, we need to bring up a Docker container and enter the console. The pre-configured container is configured in docker-compose.yaml.

  1. Open a cmd.exe / bash console in the project folder
  2. Start the Docker container: docker-compose up -d
  3. Open the console within the container with docker-compose exec php bash
  4. Now all you need to do is run: composer install
  5. You may close the console by typing: exit and enter.

You can now access the project at http://localhost/

When you're done, you can bring the Docker container down by running docker-compose down

Files in this repository

This repository isn't large (that's the whole idea, to keep things small). It contains the following 12 files:

FilenameDescription
/config/framework.iniConfiguration of this project
/public/.htaccessTells the Apache webserver to rewrite all unknown requests to index.php
/public/index.phpThe kick starter of the framework; all requests should end up here
/src/Controller/Index.phpThe controller that's triggered for the / request
/src/Controller/Readme.phpThe controller that's triggered for the /readme request
/templates/index.html.phpThe template for the / request
/templates/readme.html.phpThe template for the /readme request
/.gitignoreTells the version control system to ignore specific files
/composer.jsonDescribes the dependencies of this project and contains other metadata as well
/composer.lockGenerated file by Composer that tells which exact versions are in use of dependencies
/docker-compose.yamlContains Docker configuration for running this application
/README.mdThis file

Available middlewares

In the config/framework.ini, you'll see a middleware directive in the configuration. Multiple middlewares can be loaded, and are loaded in the sequence in which they are configured.

These middlewares are included in the Miniframe Core bundle and can be used to quickly set up a basic application, or as example for building your own middleware classes:

Class nameDescription
UrlToMvcRouterURL To MVC Router; documentation at https://bitbucket.org/miniframe/core/src/v1/src/Middleware/UrlToMvcRouter.md
BasicAuthenticationBasic HTTP Authentication; documentation at https://bitbucket.org/miniframe/core/src/v1/src/Middleware/BasicAuthentication.md
AccessListDeny / Allow clients based by their IP; documentation at https://bitbucket.org/miniframe/core/src/v1/src/Middleware/AccessList.md
SessionPHP Sessions; documentation at https://bitbucket.org/miniframe/core/src/v1/src/Middleware/Session.md

A full list of middlewares can be found at https://miniframe.dev/middlewares

Optional bundles

These Miniframe bundles are optionally available through Composer:

Bundle nameDescription
miniframe/twig-bundleAddon for using Twig templates. Documentation at https://bitbucket.org/miniframe/twig-bundle/src/v1/README.md
miniframe/sentry-bundleAddon for logging errors to Sentry. Documentation at https://bitbucket.org/miniframe/sentry-bundle/src/v1/README.md
miniframe/social-loginAddon for authentication with several external services. Documentation at https://bitbucket.org/miniframe/social-login/src/v1/README.md
miniframe/developer-toolbarAddon for easier debugging. Documentation at https://bitbucket.org/miniframe/sentry-bundle/src/v1/README.md
miniframe/mailer-bundleAddon for sending mails through PHPMailer. Documentation at https://bitbucket.org/miniframe/mailer-bundle/src/v1/README.md

You can install them by executing composer require [package name] on the console.

In the future, more external Miniframe bundles will become available through Composer. For more about those, check out https://miniframe.dev/