Agile Toolkit is branched for refactoring
I have been working on a refactoring in a separate branch. Right now it looks stable, so I’m putting more details in here:
(you can try new branch by using svn switch)
The largest change is introduction of PathFinder. I have already mentioned it. The purpose of the class is to unify not only loading of different things, but it links together the concepts of URL and Paths. For example, let’s say you are looking for myfile.js. This file could be located in several locations, templates/js, amodules3/templates/js etc. PathFinder collects information about all available locations and what type of files are there. It also tries to identify the base URL of each location, so if you want to provide http link to myfile.js, you can do so.
The interface with the new class looks very simple. You do not need to do anything – it work out of the box. It will automatically load with any API. It will automatically include your base location and amodules3 library. If you are using more locations (addons, other modules), you will have to add them:
This instructs that the new directory which is relative to base path will contain additional php classes. You can also attach locations containing multiple resource types:
$this->addLocation('..',array( 'php'=>array('lib','addons'), // do not import pages from main 'js'=>'templates/js', 'banners'=>'banners', 'logs'=>'logs', 'dbupdates'=>'docs/dbupdates', )) ->setBasePath(dirname(dirname(dirname(__FILE__)))) ->setBaseURL(dirname($this->api->pathfinder->base_location->getURL())); ;
setBasePath and setBaseURL will instruct how to access that directory. Instead of defining base paths you can also define parent location. Take a look at amodules3/lib/Testing.php
This will instruct new location that it is actually a sub-location of atk4_location. Therefore URL and Path will be calculated in relation to that location by adding ‘test’ (as first argument to addLocation). By the way, you can use $api->add(‘Testing’), which will include this new location. This should give you some idea how you can add external plugins, and how you can attach them. Really simple.
As you saw in the code, pathfinder registers itself under $api->pathfinder. It will contain 2 properties – base_location and atk4_location. They are objects, however you can use them as strings. Code should be well commented, so feel free to browse.
Finally – how you can actually locate something?
$relative_path=$api->locate('php','myfile.php'); $url_to_js=$api->locateURL('js','myplugin/myplugin.js'); $log_dir=$api->locatePath('logs'); // full path to log directory
All internal components are rewritten to use new location engine. Location engine is therefore mandatory and is the first class API is going to initialise.
Windows users (who lack symlinks) should be happy too. By default system properly finds a physical path of amodules3 directory and it assumes it’s location on the web in /amodules3. If that’s not true however – you can change this through config variable $config['atk4']['base_path']=’/admin/amodules3′. Of course it’s optional setting.
Notice: BASE_PATH, AMODULES3_LIB and other defined constants are no longer set. Do not use them and try to take out paths from config file.
URL and getDestinationURL imported
Right, getDestinationURL is now implemented as object. I was already explaining about that. No big changes are here, except that this will allow more methods accept either page names your pre-formatted URLs.
You can now call setLength($paragraphs,$words). This should help you to get just the right amount of filler-text for your UI.
As I have mentioned before, we are trying to improve consistency through the library. Methods starting with “add” will now be returning new objects instead of $this. It might affect your code severely especially with addField() chains in forms. $f->addField() is returning filed now. For that reason I was able to severely clean up Form, it does not need to route calls such as setValueList().
For the same reason some methods are renamed, in particular $form->addCondition() and $form->addConditionFromGET() are renamed into $form->setCondition() and $form->setConditionFromGET(). Those methods are returning $this and are properly chained. Name is changed to reflect this.
There are no temporary compatibility for this.
I welcome you to try the new branch. I am going to port two projects of ours to this new branch. Please report any problems here or through mantis and I’ll deal with them asap.