How Emergence Works

This page at the moment is more specifically written for advanced PHP coders that would like a top down view of how this framework differs from others.

At it's core Emergence loads into memory by using the PHP environmental variable auto_prepend_file. The file specified in this variable will be automatically executed prior to the execution of the actual webpage's code. This allows us to load into memory a bunch of utility functions as well as setup a generic load order that is universal to all sites. This part of the code is usually hidden while developing code on an emergence site. The only other server side configuration necessary is the common mod_rewrite rule that sends all URLs that do not have a server side corresponding file to a common index.php file. From there based on the domain the engine will load the appropriate config file containing some environmental variables and the database credentials. Finally once complete control is taken by the engine it can decide what to load. This centralized system allows Emergence to take over entire URL paths for all sites for specific utilities. For example you might create a new model by using ActiveRecord or VersionedRecord but before you can begin to use it you'll need to use the /table_manager utility to create your tables. That is assuming you don't wanna do it manually in text or phpmyadmin.

At it's heart Emergence tries to up-end the usual framework architecture by centralizing all file includers and loaders which allows one to at that point implement a totally virtual file system. This means that every single file uploaded to the server exists as a physical file on the server but not with it's original file name. All Emergence sites contain every file and revision of said file by indexing the virtual filesystem in a table called `_e_files` and using the assigned index ID to store the file on the server. In practice you might decide to show a specific static template called 'hello_world.tpl'. The code would be RequestHandler::handleRequest('hello_world'). One side effect of having a virtual file system is being forced to create a virtual file transfer mechanism so that on every save or upload of the files to the site it can create a new entry in `_e_files` thereby creating a new version of said uploaded file. To facilitate that Emergence creates a WebDAV file transfer portal on every site through the /develop path. Every user in the Persons table that has AccessLevel set to Developer will automatically gain access to this development portal. WebDAV is by definition a stateless protocol that works over HTTP. This means that one can use a web browser to look through the /develop folder as well as that PHP can be the WebDAV server itself. Since PHP itself is controlling it we can use the site's own authentication system for the WebDAV portal as well. Furthermore each individual save is versioned and a record is kept of who made the change as well as when, automatically. Going back in time with this system could not be easier. Simply delete the last record in `_e_files` and that syntax error you just uploaded breaking the site is gone!

Finally in the event that a file does not exist in the virtual file system it can be inherited from a parent site over an HTTP handshake. In fact all new sites built in Emergence are created from a generic skeleton website which includes all the components necessary for all sites such as user login, registration, and any classes one might want to use. When the site is first created it's virtual directory structure is empty. If one were to set it up and visit the page's main page the first load would take a while. This is because the virtual directory system is cloning files from a _parent site that is configured to work over HTTP. Browsing the WebDAV directory structure on a new site one will find empty folders but all sites that have a parent will also have a _parent folder. While working on a child site anyone can open a file in _parent. As soon as you attempt to save it though it saves only to the child site and from then on the child site will cease using the parent's file.