Fork me on GitHub

Configuration

Defining Environment

To setup environment for Hathoora PHP Framework installation you can use the following options:

1. Define HATHOORA_ENV in Apache using SetEnv directive. It can be defined in vhost configuration file as shown below.

        
            <VirtualHost *:80>
                DocumentRoot /some/path/hathoora/docroot
                ServerName mysite.com

                SetEnv HATHOORA_ENV prod

                <Directory /some/path/hathoora/docroot>
                    AllowOverride All

                    # if using apache 2.2, you might also need the following
                    # Order Deny,Allow
                    # Allow From All

                    # if using apache 2.4, you might also need the following
                    # Required All Granted

                </Directory>
            </VirtualHost>
        
    

2. By defining $env variable in HATHOORA_ROOTPATH/index.php as shown below.

        
            # File: HATHOORA_ROOTPATH/index.php

            // use prod environment by default
            $env = 'prod';

            if (isset($_SERVER['HATHOORA_ENV']))
                $env = $_SERVER['HATHOORA_ENV'];

            $env = "prod";
            use hathoora\kernel;

            $kernel = new kernel($env);
        
    

Environment value is then stored as constant HATHOORA_ENV that you may use in your code.

Supporting Application(s)

Hathoora PHP Framrwork support mutiple applications (or websites). Applications are defined in HATHOORA_ROOTPATH/boot/config/app_HATHOORA_ENV.yml.

You can define things like:

  • Multiple applications (or websites)
  • Multiple applications (or websites) for dev/prod/stag/etc environments
  • Regex pattern
  • Directory for code organization
  • Namespacing
  • Custom route dispatchers for advanced routing

Listed below are some various possibilites of supporting applications.


Example 1: If you have only one application then you can use something like the following:

        
            # File: HATHOORA_ROOTPATH/boot/config/app_HATHOORA_ENV.yml

            app:
                mySite:    <-- name of app
                    default: true # will be used as default
        
    

In this example the source for your application will be located in HATHOORA_ROOTPATH/app/mySite


Example 2: For supporting multiple applications like the following:

  • http://www.website1.com
  • http://www.website2.com
        
            # File: HATHOORA_ROOTPATH/boot/config/app_HATHOORA_ENV.yml

            app:
                website1:
                    pattern: '^www.website1.com(|/)'
                    default: true
                    directory: myCompany

                website2:
                    pattern: '^www.website2.com(|/)'
                    directory: myCompany
        
    

In this example URL pattern with be checked as following:

  • a URL matching pattern ^www.website1.com(|/) will be processed by website1's controller.
  • a URL matching pattern ^www.website2.com(|/) will be processed by website2's controller.

And soruce of applications would be locacted in:

  • website1 -> HATHOORA_ROOTPATH/app/myCompany/website1
  • website2 -> HATHOORA_ROOTPATH/app/myCompany/website2

Example 3: For loading different configurations for dev & prod environments, like the following.

  • http://dev.mysite.com
  • http://www.mysite.com
        
            # File: HATHOORA_ROOTPATH/boot/config/app_prod.yml
            app:
                mysite:
                    pattern: '^www.mysite.com(|/)'
                    default: true
                    directory: myCompany



            # File: HATHOORA_ROOTPATH/boot/config/app_dev.yml
            app:
                mysite:
                    pattern: '^dev.mysite.com(|/)'
                    default: true
                    directory: myCompany
        
    

Example 4: Code organization - If you wanted to have seperate code (for authentication/organization) between main website and admin panel in a scenario like the following:

  • http://www.mysite.com
  • http://www.mysite.com/admin
  • http://api.mysite.com

Then you can use a configuration like this.

        
            # File: HATHOORA_ROOTPATH/boot/config/app_HATHOORA_ENV.yml

            app:
                admin:
                    pattern: '^www.mysite.com/admin(|/)'
                    directory: myCompany

                site:
                    pattern: '^www.mysite.com(|/)'
                    default: true # will be used as default
                    directory: myCompany

                api:
                    pattern: '^api.mysite.com(|/)'
                    directory: myApiDirectory
                    # define custom namespace that follows psr0 
                    namespace: myApiDirectory/api

                # there is no URL for this one, this is purely for organization of code
                helper:
                    directory: myApiDirectory
        
    

In this example order matters - first hit. Code for your application will be located as following:

  • http://www.mysite.com -> HATHOORA_ROOTPATH/app/myCompany/site
  • http://www.mysite.com/admin -> HATHOORA_ROOTPATH/app/myCompany/admin
  • http://api.mysite.com -> HATHOORA_ROOTPATH/app/myApiDirectory/api
  • NO URL, purely for organization -> HATHOORA_ROOTPATH/app/myApiDirectory/helper

Application Specific Configuration

Hathoora PHP Framework supports multiple applications and each application will have its own configuration specific to it needs.

These configurations are located at HATHOORA_ROOTPATH/app/directory/namespace/config/config_HATHOORA_ENV.yml and can be nested.

A sample configuration is shown below:

        
            # File HATHOORA_ROOTPATH/app/directory/namespace/config/config_HATHOORA_ENV.yml

            # Import config which will be overwritten
            imports:
                - { resource: config_gold.yml }

            # framework configurations..
            hathoora:

                # assets management
                gulaboo:
                    assets:
                        enabled: 1
                        version: v1
                translation:
                    enabled: 1
                    debug: 0

                logger:
                    profiling:
                        enabled: 0
                    logging:
                        enabled: 0
                        level: DEBUG
                    webprofiler:
                        enabled: 0
                        content_types: ['text/html']
                        skip_on_ajax: 1
                        skip_on_post_params: []
                        skip_on_get_params: []

                template:
                    engine:
                        name: Stuob # other option is Smarty
                    # when using smarty as the engine, using the following configurations
                    Smarty:
                        caching: 0
                        cache_lifetime: 0
                        ....

                database:
                    default: mysql://dbuser:dbpassword@dbhost:3306/dbname
                    db2: mysql://dbuser:dbpassword@dbhost:3306/dbname

                    # Advanced configuration also avaialble, see Databases for more information

                # for hathoora cache service
                cache:
                    debug: 0
                    pools:
                        common: { driver: 'memcache', servers: [{host: localhost, port: 11211}]}
                        commonRedis: { driver: 'redis', servers: [{host: localhost, port: 6379}]}



            # other custom configurations
            myConfig:
                var1: value1

            myConfig2:
                nested1:
                    var1: value1



            # to define services
            services:
                assets:
                    class: \namespace\class
                    type: static

                #; returns logged in user obect
                service2:
                    class: \namespace\class
                    # when you call the service, following method on the class is executed and returned
                    method: functionToExec

                #hathoora cache service
                cache:
                    class: \hathoora\cache\cache
                    calls:
                        setContainer: [ @container@ ]
                    type: static

                # factory service
                cache.posts:
                    factory_service: @cache@
                    factory_method: pool
                    factory_method_args: [ "common" ]



            # observers
            listeners:
                event:
                    listener1:
                        class: \namespace\class
                        method: functionToPassTo

                    listener2:
                        class: \namespace\class
                        method: functionToPassTo
            ...
        
    

Application configuration has basically following main parts:

  • hathoora: to define framework confirguation within scope of application.
  • services: for defining services within scope of application.
  • listeners: for defining listeners within scope of application.
  • Define anything else for your application needs.

Learn more about how to access configurations here.

Page Took:         5.76 msec
Page Memory:   536.82k
docs / viewController / view (200)
Request UUID: 59ef1d60a0d5d9.47225334
Get
Post
Cookies
Files
Session
Server
Response
No data.
No data.
No data.
No data.
No data.
REDIRECT_HATHOORA_ENV
prod
REDIRECT_STATUS
200
HATHOORA_ENV
prod
HTTP_HOST
hathoora.org
HTTP_X_FORWARDED_FOR
54.166.203.76
HTTP_X_REAL_IP
54.166.203.76
HTTP_CONNECTION
close
HTTP_ACCEPT_ENCODING
x-gzip, gzip, deflate
HTTP_USER_AGENT
CCBot/2.0 (http://commoncrawl.org/faq/)
HTTP_ACCEPT
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_IF_MODIFIED_SINCE
Tue, 26 Sep 2017 05:21:19 GMT
PATH
/sbin:/usr/sbin:/bin:/usr/bin
SERVER_SIGNATURE
Apache/2.2.15 (CentOS) Server at hathoora.org Port 80
SERVER_SOFTWARE
Apache/2.2.15 (CentOS)
SERVER_NAME
hathoora.org
SERVER_ADDR
192.168.1.11
SERVER_PORT
80
REMOTE_ADDR
207.126.164.119
DOCUMENT_ROOT
/var/websites/hathoora.org/docroot
SERVER_ADMIN
webmaster@hathoora.org
SCRIPT_FILENAME
/var/websites/hathoora.org/docroot/index.php
REMOTE_PORT
56752
REDIRECT_URL
/docs/v1/configuration
GATEWAY_INTERFACE
CGI/1.1
SERVER_PROTOCOL
HTTP/1.0
REQUEST_METHOD
GET
QUERY_STRING
REQUEST_URI
/docs/v1/configuration
SCRIPT_NAME
/index.php
PHP_SELF
/index.php
REQUEST_TIME_FLOAT
1508842848.658
REQUEST_TIME
1508842848
Status: 200
Headers:
Content-Type
text/html; charset=UTF-8
Configutation
Key Value
app.admin
Array
(
    [pattern] => /admin(|/)
    [directory] => hathoora
    [namespace] => hathoora\admin
)
app.docs
Array
(
    [pattern] => /docs(|/)
    [directory] => hathoora
    [dispatcher] => Array
        (
            [class] => customDispatcher
            [method] => dispatch
        )

)
app.site
Array
(
    [default] => 1
)
hathoora.logger
Array
(
    [profiling] => Array
        (
            [enabled] => 1
        )

    [logging] => Array
        (
            [enabled] => 1
            [level] => DEBUG
        )

    [webprofiler] => Array
        (
            [enabled] => 1
            [system] => 
            [show_redirects] => 
        )

)
hathoora.template
Array
(
    [engine] => Array
        (
            [name] => Stuob
        )

)
hathoora.database
Array
(
    [default] => mysql://dbuser:dbpassword@dbhost:3306/dbname
)
services.container
Array
(
    [class] => \hathoora\container
    [method] => getContainer
)
Logging (14)
hathoora.logger.logging.enabled: 1
# Time (msec) Level Memory (KB) Message
1 2.175 DEBUG 309.74 Configuration loaded:
Array
(
    [0] => app_prod.yml
    [1] => config_prod.yml
)
2 2.413 DEBUG 323.35 Listener "kernel.terminate[webprofiler]" has been added because of hathoora.logger.webprofiler.enabled
3 2.562 DEBUG 326.74 Event kernel.ready has been registered.
4 2.753 DEBUG 335.11 Calling App dispatcher (Array ( [class] => customDispatcher [method] => dispatch ) )...
5 2.895 DEBUG 349.53 Event kernel.route has been registered.
6 3.156 DEBUG 378.90 Event kernel.controller has been registered.
7 3.206 DEBUG 379.85 Calling controller (\docs\controller\viewController::view) with following params
Array
(
    [0] => v1
    [1] => configuration
)
8 3.823 INFO 467.20 Template (docs/v1/configuration.tpl.php) loaded
9 4.058 INFO 497.91 Template (/var/websites/hathoora.org/app/hathoora/docs//resources/templates/components/htmlMeta.tpl.php) loaded
10 4.194 INFO 499.16 Template (/var/websites/hathoora.org/app/hathoora/docs//resources/templates/components/flashMessages.tpl.php) loaded
11 5.605 INFO 445.64 Template (docs.tpl.php) fetched.
12 5.630 DEBUG 445.23 Event kernel.response has been registered.
13 5.648 DEBUG 446.42 Event kernel.terminate has been registered.
14 5.687 DEBUG 449.64 Event kernel.terminate->webprofiler has been notified.
Profiling
template
# Time (msec) Name Cached Took (msec)
1 3.314 docs.tpl.php 0 2.245