To configure your project properly, basic configuration has to be set on entry point: public/index.php. This is mandatory config which tells the framework what is where.
All other configuration files are located in configs directory.
Mandatory - index.php
This configuration is used on every HTTP request and CLI call and it's mandatory for system to work. Here's
what every item in
This is domain with schema or array of domains with schema. Schema has to be defined so framework can know if you're using SSL or not. Remember that this is also used in CLI where domain can't be automatically detected.
||You're using domain example.com with SSL|
||You're using domain localhost:3000 without SSL|
You can get these values by using:
|Class and method||return value|
||You'll get domain part only, like
||Returns full schema and domain in use, like
||This is alias to
This is key-value array with the list of other domains or locations where your assets are located. This is useful if you're using CDN, or you simply want to have different locations for development and production environment.
||You placed your assets in public folder relative to the domain set under
||Your assets are placed behind CDN|
||Your assets can be reached locally|
You can get the path to your assets using
Route::asset(), where first parameter is the file name with or without
additional sub-location and second parameter is optional key from the config above. If second parameter is not
provided, framework will use the first item from
\Koldy\Route::asset('logo.png'); // returns https://example.com/static/logo.png \Koldy\Route::asset('images/logo.png'); // returns https://example.com/static/images/logo.png \Koldy\Route::asset('logo.png', 'cdn'); // returns https://cdn.example.com/logo.png \Koldy\Route::asset('logo.png', 'dev'); // returns http://localhost:3000/static/logo.png
Final configuration in
index.php would look like:
'assets' => [ 'static' => '/static', 'cdn' => 'https://cdn.example.com', 'dev' => 'http://localhost:3000/static' ]
This gives you ability to make your own structure of the project or when needed in some special cases, some of the folders can be placed on totally different file system location outside of the project.
||Path to your application directory where by default is all other backend stuff||
||Path to storage directory where usually are all files generated on the server. This directory is ignored by
||Path to your templates (or so called views)||
||Path to your modules directory||
||Path to your CLI scripts||
||Path to directory where all config files are located||
This gives you ability to override location of your configs per file.
Example: You might have a config file named
configs folder for your development environment and
you're using it with
Application::getConfig('site-conf') which is fine. In this case, framework will look for the
config file on
[projectRoot]/configs/site-conf.php by default. But, when your app is deployed on production server,
you might want to read this config from a location outside of project root. In this case, you can define
key with value like
/var/configs/site-conf.php and framework will do the rest.
Final config would look like:
'config' => [ 'site-conf' => '/var/configs/other-conf.php' ]
This tells framework weather you're running in
production mode. Note that there's no
environment. More on that read under live section.
This setting is usually used on cases like error handling. Error details and stacktrace will be exposed during development so you can see error right away, while it won't be exposed on production environment.
||App is running in development environment|
||App is running in production environment|
Final config example:
'env' => \Koldy\Application::PRODUCTION
If you're using Webpack, Gulp, Grunt, Bower or any other package manager, you'll probably want to handle paths to assets differently for development and differently on production server.
This is boolean variable that tells if you're running this system live or not. Framework internally doesn't use this setting, but you should.
In standard development, you'll need to implement 3rd party tracking code, like Google Analytics, Intercom and such, but you'll want to hide tracking code on all other systems other than live system.
Final config example:
'live' => true
To use this setting, use
Application::isLive() which returns
If you're looking for
testing environment, you can get it by combining
env. This is how we see it:
||You're running this system locally for development|
||You're running system locally, but including "live" stuff. This can be temporary, just for testing to see if you implemented everything correctly|
||You are running in production environment, but not live - this is
||You are running fully live on your production server|
This is standard timezone string from PHP. Put the timezone you need.
UTC and it's required.
In standard development when working with multiple timezones, all dates and times are stored in database or other permanent storage in UTC and when you need to show the time to user, it is then converted to the user's local timezone.
As it says, this is array of additional include paths. This is useful if you're having multiple projects and you want to access directories on other locations or you have some library project outside of your project and you're depending on it.
Final config example:
'additional_include_path' => [__DIR__ . '/../../library']
This is random key with the maximum length of 32 characters that you should generate. Make it unique.
It is used when framework needs some uniqueness per project. For example, if you're using
Crypt class and you try
to encrypt and decrypt something without providing a key, framework will then use this key as its
key for encrypting.
routing_class and routing_options
This is class name of routing class that will be used for resolving HTTP requests and translating it into controllers
and methods. The class name has to extend
\Koldy\Route\AbstractRoute in order to make this work.
\Koldy\Route\DefaultRoute class and there's 99% chance that it will suit all your needs just fine.
routing_options is array that will be passed to constructor of
routing_class as first parameter.
Final config example:
'routing_class' => '\Koldy\Route\DefaultRoute', 'routing_options' => [ 'always_restful' => false ],
In our case,
DefaultRoute accepts only
always_restful setting. If you create your own routing class, then you can
set the array of any structure here. Read more on DefaultRoute docs.
This block contains some common security stuff, such as OpenSSL default method and CSRF settings. Example:
'security' => [ 'openssl_default_method' => 'aes-256-cbc', 'csrf' => [ 'enabled' => false, 'parameter_name' => 'csrf', 'cookie_name' => 'csrf_token', 'session_key_name' => 'csrf_token' ] ]
Find more info about OpenSSL methods here.
Find more details about CSRF implementation here.
This is array of some file system specific work. So far, only default chmod setting should be defined here. Example:
'filesystem' => [ 'default_chmod' => 0755 ]
This is array of possible log writers. Think of it like this: when you use
Log::debug('something');, where should it
go? Should it end up in file on filesystem, database, in console, Slack or somewhere else? All log options should be
Read more about Log here.
Alternative Location Of Mandatory Configuration
Having all mandatory configuration in
index.php is good for performance reasons - you eliminate loading configuration
from other file on literally every execution. In some rare cases, you'd want to have this configuration in separate
file, usually when you have multiple entry points (entry points that aren't going through index.php).
In this case, whole configuration array you're passing to
useConfig() should be moved to
return [ 'site_url' => 'https://domain.com', ... ];
Then, instead of passing array to
useConfig(), simply pass location of
application.php file. If
configs folder, you can use:
Koldy\Application::useConfig(__DIR__ . '/../configs/application.php');