I have made lots of classes and plan to create more and more. But, all of these are just scrambled all over. Here’s what I’m talking about :
new LoginSystem(); new FDM();
If you use another class named the same, then it will bring conflicts within your code. So, I decided them to group it with the namespace Fr, short for Francium – one of the least electronegative elements in the periodic table. I’m calling this the Francium project. It has nothing to do with the chemical element though. As per this project, all my current and future classes will become a child class of the Fr parent. And most of my current classes and the future ones will be static classes and not object oriented ones. Therefore the previous code will become :
Why I’m trying to leave objects is that, I hate making a variable for the object like so :
require "path/to/class.php"; $myObject = new \Fr\MyClass(); $myObject->the_function();
With the above, I have to call function from the variable which I do not like at all. Instead, using the static way, I can do this instead :
require "path/to/class.php"; \Fr\MyClass::the_function();
Although, there is a problem above that you have to name “\Fr\MyClass” every time you call a function, but still I love that anyway. Anyhow, it is to note that Object method of class is inevitable in certain situations. In those cases, objects will be used.
Here’s how you work with Francium. You can see the base class here.
There is a variable inside it called “default_config” containing an array with the default configuration. In that array, Database information and a main info about who is using the software is written. You can either change the default configuration or set custom ones without changing the default config.
1. Custom Config
For this, you pass your config array to the config() method. You do this by making another file like “config.php” and including it instead of the class file. Here is an example of “config.php” file :
require "Fr.ClassName.php"; \Fr\ClassName::config(array( "info" => array( "company" => "Test", "email" => "[email protected]" ) ));
Then, you include the above file in pages instead of “class.logsys.php” file. I recommend this custom config, because you can then easily update the class when a new version come out.
2. Change Default Config
You can directly change the values of the “\Fr\LS::$default_config” in the class file, so you won’t need to make another file for custom configuration. But beware, when you’re updating to a newer version of the class, be sure to reupdate the default configuration again. Now, what Fr does is merge the default config with the config you provided in the variable “config” through the function “\Fr\ClassName::config()”. \Fr\ClassName::construct() is called at the beginning by most of the functions in the class. It is the equivalent of __construct() in the object class.
\Fr\ClassName::log() function is used for entering log messages which is useful for debugging. These messages are sent by various functions and it is recorded in a file called “Francium.log“.
To enable log messages, create a file named “Francium.log” in the folder where the class file exists. You should also make the file writable by changing the permissions.
After doing the above, log messages will be written to the file automatically. To simply disable debugging, just remove the “Francium.log” file.
Here is an example of a log message entered in the “Francium.log” file :
[2015-03-28 20:41:24] Couldn't connect to database. Check \Fr\LS::$config["db"] credentials [2016-04-23 12:13:41] two_step_login: Token Callback not present
It is also to be noted that PHP’s error log will also be helpful in debugging. Hence at the beginning of the class, this line is present :
It’s recommended that you see both the logs for perfect debugging.
Francium Project also applies to my JavaScrpt projects. My current projects are being slowly ported to the Francium Object. Note that my jQuery plugins will also be moving to Francium object. Example :
The debugging is not currently set for JS projects, but some messages are shown in console.