1. Core Features

Some of the greatest features, as well as supporting web services out of the box, lies in Eden's core. The core's purpose is to give the end developer an easier experience in OOP and design patterns while tackling some of the most complicated problems that exist in web development today.

Simple Interface

Eden simplifies the way you code in PHP through a concept called Simple Interface.

Simple Interface is a design made to simplify the steps it takes to get a result set or to perform an action which benefits end developers.

Figure 1 below further explains Simple Interface by instantiating a class and calling method in one line.

Figure 1. Our Hello World Example
eden('debug')->output('Hello World'); //--> Hello World

/* vs */

$debug = new Eden_Debug();
$debug->output('Hello World'); //--> Hello World

In the example above, we called a class named Eden_Debug and printed out a string in one line. Using PHP normally, you would need to perform this in two lines (following common coding standards) and declare a variable. If this were a static method we could get it down to one line, but static methods does not solve for classes needing initial arguments.


The next example demonstrates passing initial arguments in a class and printing the results after various method calls.

Figure 2. The Chain
echo eden('type', 'Hello World')->str_replace(' ','-')->strtolower()->substr(0, 8); //--> hello-wo

/* vs */

echo substr(strtolower(str_replace(' ', '-', 'Hello World')), 0, 8); //--> hello-wo

Figure 2 above shows that we passed Hello World into Eden_Type_String then replace spaces with a dash, lower casing and show only the first eight characters, again in one line. We can do the same with regular PHP however when another developer has to read that, they have to read it inner to outer versus left to right.

For both sets of code in Figure 2 it's bad practice to put so much code on the same line. Our next example shows the same code as Figure 2 except in a more vertical fashion.

Figure 3. Vertical
echo eden('type', 'Hello World')
	->str_replace(' ','-')
	->substr(0, 8); //--> hello-wo

/* vs */

$string = 'Hello World';
$string = str_replace(' ', '-', $string);
$string = strtolower($string);
$string = substr($string, 0, 8);
echo $string; //--> hello-wo

You probably noticed when using Eden, we didn't have to create a variable. This is the same case when dealing with multiple classes. You can instantiate classes all in the same chain.

Figure 4. Jumping from class to class
echo eden('session')				//instantiate Eden_Session class
	->start()						//start the session
	->set('name', 'developer')		//set session data
	->Eden_Type(2, 3, 4) 			//instantiate Eden_Type_Array class
	->implode(' ');					//--> 1 2 3 4

Objects as Arrays

While living in an object oriented world, sometimes it's conceptually easier to think of datasets as arrays. In Eden, classes like Eden_Session, Eden_Cookie, Eden_Array, Eden_File, Eden_Folder and database models can be accesed as arrays.

Figure 5. ArrayAccess
$session = eden('session')->start();
$session['name'] = 'Chris';
echo $_SESSION['name']; //--> Chris

$cookie = eden('cookie')->set('age', 29);
echo $cookie['age']; //--> 29

$array = eden('type', 1, 2, 4);
foreach($array as $value) {
	echo $value.' '; //-->1 2 4

$file = eden('file', '/some/path/to/file.txt');
echo $file[1]; //--> some

$folder = eden('folder', '/some/path/to');
$folder[] = 'folder'; 
echo $folder; //--> /some/path/to/folder

$user = eden('model')->setUserName('Chris');
echo $user['user_name']; //--> Chris

Event Driven

Another cool feature of Eden is the ability to call methods when an action is triggered. Applicable design for webites, server processes and the latter. All database calls and errors in Eden, for example, can invoke any custom action when triggered.

Figure 6. Email Me!
function mailme($event, $action, $email) {
	echo "mailing $email now";

$event = eden('event')->listen('error', 'mailme');
//... somewhere later ...
$event->trigger('error', 'your@email.com');


Routing in Eden is similar to page routing in typical MVC frameworks, however in this subject technically called Polymorphic Routing. Eden has adopted class naming conventions made popular from Zend Framework which is in relation to a cascading file system. One annoyance in this system is that class names can get really long. Long class names are harder to remember and ultimately increases the learning curve. Making virtual classes (or aliases to class names) not only makes it easier to remember, but allows developers to customize Eden in their own way.

Figure 7. Virtual Classes
//Make an alias for Eden_Session called Session
eden('route')->getClass()->route('My', 'My_Long_Class_Name');

//... some where later in your code ...

eden()->My(); // My_Long_Class_Name
Aliasing an alias will result in both aliases pointing to the same class.

In the example above, we first made an alias to My_Long_Class_Name called My. After that line, anytime that alias is called Eden will know to instantiate My_Long_Class_Name instead. This inherently also solves for a major flaw in CMS and framework design which we will get into in 2. Classes later. For now let's work with Virtual Methods.

Figure 8. Virtual Methods
//Make an alias for Eden_Tool->output called Eden->out
eden('route')->getMethod()->route('Eden', 'out', 'Eden_Tool', 'output');

//... some where later in your code ...

eden()->out('This method doesn\'t really exist'); //--> This method doesn't really exist

In Figure 8 above, we show how to make an alias for Eden_Tool->output() called Eden->out() and then calling that virtual method.

If there was a previously defined method called Eden->out() this method would be called instead.
Aliasing methods only work for classes that do not require inital arguments. Eden_Tool for example does not require inital arguments.

If we combine Figure 7 and Figure 8, it is possible to make virtual methods for virtual classes.

Figure 9. Virtual Class + Virtual Methods
//Make an alias for Eden_Session called Session
//Make an alias for Eden_Tool->output called Session->out
	->route('Session', 'Eden_Session')
	->route('Session', 'out', 'Eden_Tool', 'output');

//... some where later in your code ...

eden()->Session()->out('This class and method doesn\'t really exist'); 
	//--> This class and method doesn't really exist


We just covered some of the major features of Eden's core. Given the above knowledge, we open doors to more possibilities while changing the way we write code. It's important to know that all of Eden's classes can still be instantiated the traditional way. We wanted Eden to cover the interests of both novice and experienced developer, so depending on your understanding of PHP, either way is applicable. Head over to 2. Classes when you are ready to write your first class in Eden!

© 2012 Openovate Labs. All rights reserved.