Download the PHP package miklcct/thin_php_app without Composer

On this page you can find all versions of the php package miklcct/thin_php_app. 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 thin_php_app

Thin PHP application framework

This is a very thin framework for PSR-15 PHP application using MVC.

Currently, it offers the following functionality only:

It requires the following additional modules to work:

Moreover, you are suggested to add various libraries to improve the development experience.

Basic usage

In order to create a PHP application using the framework, you need to do the following:

  1. Subclass the provided Application class to handle your application logic for each entry point. The dependencies should be injected to the constructor of your concrete Application, and it receives a ServerRequestInterface and returns a ResponseInterface when run.

  2. Create views by writing templates and subclassing the provided abstract View (for non-template views), Template (for templates in any language) , PhpTemplate (for PHP templates) or StaticTemplate (for static templates) class. The view data for PHP templates should be declared as protected members in your concrete view, which is accessible in the template by $this->member.

    Helper functions are provided for easy output escaping:

    • html
    • xml
    • js
    • json
    • css
    • url

    If you are providing JSON API only, you (obviously) don't need to write any views.

  3. Create the entry point to start the application, which is accessible under the document root. The entry point should:

    1. require the composer autoloader.
    2. Set up error and exception handlers (optional).
    3. Create the Application and ServerRequestInterface objects.
    4. Run the application.
    5. Output the response.

Please refer to miklcct/thin_php_app_demo repository for how this framework works.

Controller

In this framework, application and controller refer to the same thing - something that accepts a request and returns a response.

Just implement your controller code in the provided Application class and you are good to go.

Routing

No routing functionality is built-in ecause I don't want to make everything go through a single entry point. This would make the entry controller bloated because all dependencies used in every route have to be injected into the main controller. I don't want to make a container mandatory and injecting container is also a bad idea.

Instead, create a PHP file on each entry point of the application, subclass the provided Application class and do the work specific to that route.

If you need to use SEO friendly URL, please use path info and web server rewrite. For example, if you want a specific blog page accessible under http://example.com/article/2018/01/24/hello-world, please create article.php under your document root, set up your web server to rewrite /article to /article.php

Alternatively, you can install a router as a middleware in the application.

Middleware

It is very easy to install PSR-15 middlewares in the framework.

Controller middleware

If you are using the provided Application class, just register it in getMiddlewares() method. Remember to call parent::getMiddlewares() inside the overridden method to inherit the previous middlewares.

Global middleware

It is also easy to install global middlewares. Just extend the provided Application class, register your global middlewares, and implement your controllers on top of it.

Installing middlewares on existing application

It is very easy to install middlewares on top of an existing PSR-15 application from another framework even if you don't use the provided Application class. MiddlewareApplication class is provided for such purpose.

View

Views are defined as content with a content type. You need to implement __toString() (for string), render() (for StreamInterface) and getContentType(). If you implement __toString you can use the provided StringToStream trait to fill in render(), conversely, if you implement render() you can use the provided StreamToString to fill in __toString().

Static and PHP templates

You can use the built-in StaticTemplate (for static page) or PhpTemplate (for PHP templates). Just implement getPathToTemplate() method.

Other template languages

You need to install the template engine (e.g. Smarty, Twig, etc.), extend the provided Template class and implement render() and __toString() methods to call the template engine.

View data

PHP templates are run in the context of your View object. You are recommend to access view data using protected fields and members (private will not work because it is rendered in a base class method). and add a docblock /* @var YourConcreteView $this */ near the beginning of your PHP templates such that IDE analysis will work.

Other template engines may have their own method to pass data into templates. You are recommended to declare exactly what data is expected in the view constructor, or use a factory object to produce views with correct data.

Error and Exception

There are two helper classes provided: ExceptionErrorHandler which will convert PHP error into ErrorException depending on your error_reporting setting, and ResponseFactoryExceptionHandler which will output responses from a factory when an exception is uncaught. Objects of these classes can be passed directly to set_error_handler() and set_exception_handler() respectively.

You can also register a middleware to handle exceptions from your application.

Code style and structure

All library codes are organised into the appropriate subfolder under src folder, and properly namespaced using PSR-4, even including constants and functions.

You MUST adhere to the following rules when making pull requests:

If existing code are found to violate the above rules, please open a bug report.


All versions of thin_php_app with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
ralouphie/getallheaders Version ^2.0|^3.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
shrikeh/teapot Version ^2.3
http-interop/response-sender Version ^1.0
ext-json Version *
psr/http-factory Version ^1.0
symfony/polyfill-php73 Version ^1.13
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 miklcct/thin_php_app contains the following files

Loading the files please wait ....