Download the PHP package sanderdlm/mono without Composer

On this page you can find all versions of the php package sanderdlm/mono. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mono

Mono

Mono is a minimal, modern PHP framework in a single file.

It contains no custom implementations, but rather acts as a wrapper around the following great projects:

  1. Routing (using nikic/FastRoute)
  2. Dependency injection (using php-di/php-di)
  3. Middlewares (using relay/relay)
  4. Templating (using twigphp/wig)
  5. Data-to-object mapping (using cuyz/valinor)

This is the interface of the Mono class:

Using just these methods, we have all the tools to build our application: ` Mono is not intended as a full-fledged framework, but rather as a proof-of-concept for small PHP apps. The goal is to show how far you can go by combining well-known libraries & PSR implementations.

The source code has comments and is easy to read.

1. Routing

You use $mono->addRoute() to add all your routes. Same method signature as the underlying FastRoute method. Route handlers are closures by default, since this is mainly intended as a framework for small apps, but you can use invokable controllers as well.

Read about the route pattern in the FastRoute documentation. The entered path is passed directly to FastRoute.

The first argument to the closure is the always current request, which is a PSR-7 ServerRequestInterface object. After that, the next arguments are the route parameters.

When $mono->run() is called, the current request is matched against the routes you added, the closure is invoked and the response is emitted.

1.1 Example with closure

1.2 Example with controller

Caching your routes in production is trivial. Pass a valid, writeable path for your cache file as a routeCacheFile parameter to your Mono object.

2. Dependency injection

When a Mono object is created, it constructs a basic PHP-DI container with default configuration. This means that any loaded classes (for example through PSR-4) can be autowired or pulled from the container manually.

You can fetch instances from the container with the get() method on your Mono object.

Custom container

If you need to define custom definitions, you can pass a custom container to the Mono constructor. See the PHP-DI documentation for more information.

3. Middleware

Mono is built as a middleware stack application. The default flow is:

You can add middleware to the stack with the addMiddleware() method. Middleware are either a callable or a class implementing the MiddlewareInterface interface. The middleware are executed in the order they are added.

`

You can find a bunch of great PSR-15 compatible middlewares already written in the middlewares/psr15-middlewares project. These can be plugged into Mono and used straight away.

4. Templating

If you want to use Twig, you have to pass the path to your templates folder in the Mono constructor.

Afterward, you can use the render() method on your Mono object to render a Twig template from that folder.

`

5. Data-to-object mapping

This allows you to map data (for example, from the request POST body) to an object (for example, a DTO):

If you want to override the default mapping behaviour, define a custom Treemapper implementation and set it in the container you pass to the Mono constructor.

Example of a custom mapper config:

Other

Debug mode

Mono has a debug mode that will catch all errors by default and show a generic 500 response.

When developing, you can disable this mode by passing false as the second argument to the Mono constructor. This will show the actual error messages and allow you to use dump inside your Twig templates.

Folder structure & project setup

Getting started with a new project is fast. Follow these steps:

  1. Create a new folder for your project.
  2. Run composer require sanderdlm/mono.
  3. Create a public folder in the root of your project. Add an index.php file. There is a "Hello world" example below.
  4. Optionally, create a templates folder in the root of your project. Add a home.twig file. There is an example below.
  5. Run php -S localhost:8000 -t public to start the built-in PHP server.
  6. Start developing your idea!

public/index.php:

templates/home.twig:

If you're planning to keep things simple, you can work straight in your index.php. If you need to define multiple files/classes, you can add a src folder and add the following PSR-4 autoloading snippet to your composer.json:

You can now access all of your classes in the src folder from your DI container (and autowire them!).

Extra packages

The following packages work really well with Mono. Most of them are quickly installed through Composer and then configured by adding a definition to the container.


All versions of mono with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2 || ^8.3
twig/twig Version ^3.7
relay/relay Version ^2.1
php-di/php-di Version ^7.0
nikic/fast-route Version ^1.3
laminas/laminas-diactoros Version ^3.3
laminas/laminas-httphandlerrunner Version ^2.9
cuyz/valinor Version ^1.9
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sanderdlm/mono contains the following files

Loading the files please wait ....