Edit this page

Architecture Concepts

Things You Should Know

  1. Entry point for all HTTP requests and CLI scripts is public/index.php.
  2. Mandatory configuration for all HTTP requests and CLI scripts is located in public/index.php.
  3. You can see recommended project structure here, but it can be different depending on configuration.
  4. Framework throws exceptions for everything. When PHP functions emit errors, we catch it and send it to log.
  5. You are not forced to use our stuff, so you can write your own caching, log, mail, session, response or routing handlers. Or you can develop your own and combine with our stuff.
  6. Use modules to logically separate parts of your system. Otherwise you'll end up in classes with thousands of lines of code.
  7. Validate all input parameters on all requests.
  8. Avoid writing raw database queries for CRUD operations.
  9. Do not repeat yourself.

Without philosophy and not too much text, it works like this:

How Things Work

HTTP requests

After you pointed your web server's directory root to public folder:

  1. Web server runs public/index.php - this is entry point for every request because you should have pretty URLs enabled.
  2. First thing that index.php does, it includes the vendor/autoload.php which is generated by Composer. It is possible to use framework without Composer, but it's not recommended because you won't have a system compatible with the PHP ecosystem, so we won't document this option.
  3. index.php calls Koldy\Application::useConfig() method where you should pass all configuration about your project, such as site domain, where is your application folder, custom configs directory, timezone, route class, some security options, log config and etc. Check mandatory configuration docs to see all possibilities.
  4. After that, index.php simply calls Koldy\Application::run() and now framework takes over using the configuration you provided in step before.

After this step, flow might vary depending on the config you provided, but let's use an example of some standard configuration which might look like this:

'site_url' => 'http://example.com',

'assets' => [
  'static' => '/static'
],

'paths' => [
  'application' => null,
  'storage' => null,
  'view' => null,
  'modules' => null,
  'scripts' => null,
  'configs' => "{$projectRoot}/configs/"
],

'routing_class' => '\Koldy\Route\DefaultRoute',
'routing_options' => [
  'always_restful' => false
]

You can read about configuration here.

  1. DefaultRoute is searching for the controller and method inside the controller depending on the request URI and the method type.
  2. Framework will return some response when it gets return value from the called action in the controller. If there's no method or controller, framework will throw \Koldy\Response\Exception\NotFoundException which should be handled by your ExceptionHandler or it'll use its own default handler.

Everything else depends on what is happening in the action in the controller. Framework won't load any additional file that is not needed. For example, if you're not using database in the controller's method, then framework won't load any configuration for database nor any other class needed for the database connections.

PHP Scripts / CLI

When script is called, framework will still execute public/index.php so your script will use the same configuration as your HTTP requests. Framework will then look for the script file depending on its name and it'll execute it.

There is nothing in the system that should use echo, print or similar functions and you should never use those functions as well! Use Log instead. When running the script, you can see the output from Log usage if Koldy\Log\Adapter\Out is set and enabled in public/index.php.