What is the purpose of the INPHINIT_START, INPHINIT_ROOT, INPHINIT_PATH and INPHINIT_COMPOSER constants?

Asked

Viewed 73 times

3

I’m studying about the micro-framework Inphinit. And in the index.php file are declared some constants that left me confused regarding their purposes.

Code of index.php:

define('INPHINIT_START', microtime(true));
define('INPHINIT_ROOT', rtrim(strtr(dirname(__FILE__), '\\', '/'), '/') . '/');
define('INPHINIT_PATH', INPHINIT_ROOT . 'system/');
define('INPHINIT_COMPOSER', false); 

Questions

I would like to know the purpose of the following constants:

  • constant INPHINIT_START
  • constant INPHINIT_ROOT
  • constant INPHINIT_PATH
  • constant INPHINIT_COMPOSER

I would also like to know the importance of each one in relation to the functioning of my web application?

1 answer

2


Basically they are used as pre-configurations of the whole framework, with the exception of INPHINIT_START which has another purpose (this I will quote last).

Constants for configuration

  • INPHINIT_ROOT:

    It is used to point out which directory you want to root for your project, usually the same location as where the index.php

    Note: in the default code I used the strtr to trade \ for / and the rtrim to remove additional bars that come the most right, is that there are some cases of variations of results in different versions of PHP that have probably been fixed, but sometimes a server by using an older PATCH version, for example in version 5.6.18 has been fixed, but the server problem for some reason still uses version 5.6.17. Note that PHP is not the only interpreter of PHP scripts, there is also the HHVM that interprets, the idea is to ensure that there are no differences of results between different systems and versions

  • INPHINIT_PATH:

    This should point to the folder system, If you want to customize the folder structure you can change the value of this constant, for example if you want to put index.php inside a folder called public and the system out of it, you can do so:

    define('INPHINIT_PATH', INPHINIT_ROOT . '../system/');
    
  • INPHINIT_COMPOSER:

    inphinit uses Composer to manage packages you want to install additional to your project, but does not use by default , he uses the UtilsAutoload(), in practice both are equal, however the UtilsAutoload() is a little more efficient, of course there may be something that works only specifically in the composer-autoload, then as a guarantee I left the option of being able to switch, to use the composer-autoload just define how true:

    define('INPHINIT_COMPOSER', true);
    

The constant INPHINIT_START

This constant has no purpose whatsoever for the operation of the framework (except for the class Inphinit\Experimental\Debug, which is a class used for development), its only utility is for you to be able to do "performance" tests (or better time it took to run), for example imagine that you want to do something similar to Google’s search engine:

google

You can do something like this:

<?php

use Inphinit\Routing\Route;

Route::set('GET', '/exemplo', function () {
    return 'Olá mundo! Sua página levou: ' . round(microtime(true) - INPHINIT_START, 4) . ' segundos';
});

And this will result:

tempo de resposta

Of course it is just an example and the focus is not this one specifically. How to use the class Inphinit\Experimental\Debug, is relatively simple, just change the system/dev.php and add this (in DEBUG mode):

<?php
use Inphinit\Experimental\Debug;

Debug::view('error', 'debug.error');

//              ^-- ação     ^-- nome da View

Debug::view('performance', 'debug.performance');

//              ^-- ação     ^-- nome da View

Comments are for execution only

All pages will display something like this in the footer:

debug

If the INPHINIT_START was not set properly probably would get an unexpected value.

Note that 'debug.performance' refers to the system/application/View/debug/performance.php, which you can customize:

<div class="box">
    <h1>Perfomance</h1>
    <p>Memory usage: <?php echo $usage; ?></p>
    <p>Memory peak: <?php echo $peak; ?></p>
    <p>Memory usage real: <?php echo $real; ?></p>
    <p>Time: <?php echo $time; ?></p>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.