Download the PHP package eden/core without Composer
On this page you can find all versions of the php package eden/core. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package core
Short Description Eden Core component full of secret sauce
License MIT
Homepage http://eden-php.com
Informations about the package core
Eden Core
- Install
- Introduction
- API
- Add Method
- Call Array
- Inspect
- Load State
- Loop
- Off
- On
- Save State
- Trigger
- When
- Contributing
====
Install
composer install eden/core
====
Enable Eden
The following documentation uses eden()
in its example reference. Enabling this function requires an extra step as descirbed in this section which is not required if you access this package using the following.
When using composer, there is not an easy way to access functions from packages. As a workaround, adding this constant in your code will allow eden()
to be available after.
For example:
====
Introduction
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.
Instantiating your PHP Classes
Eden has a mechanism for easily instantiating your classes ready to be used in a chainable manner.
You can pass arguments to you constructor in the following manner, where
123, array('foo' => 'bar'), 'abc'
is what you would like to pass on to
your __construct
.
Optional instantiation patterns can be expressed like this.
Notice how _
are replaced with \\
automatically. This also works for classes not using namespaces,
however the above pattern does not work when instantiating a mix of _
and \\
in the same class name.
Extending your PHP Classes
If you would like to utilize Eden's core features you may do so in the following manner.
Doing so will allow you to access features like when
and loop
within your class in
the following manner.
Eden uses a special pattern available in PHP 5.4 that allows class properties and methods to be accessed within the loop and when callback.
You can also instantiate other classes in your class in the following manner
instead of using the eden()
function.
====
API
Advanced examples can be found in the test
folder. It's recommended to review that folder as well.
Add Method
Add a virutal method to an existing instantiation.
Usage
Example
Parameters
string $name
- Required - The name of the method.
callable $callback
- Required - The method definition. If an array callable is passed,
the scope inside that method will be as defined in the callable array. Otherwise, the current
instance scope will be used.
Call Array
A chainable version of call_user_func_array(). Used for calling current methods vertically.
Usage
Example
Parameters
string $method
- Required - The name of the method.
array $args
- Optional - The argument array that will be passed to the specified method horizontally.
Inspect
For debug purposes, using this will output the raw values specified.
Usage
Example
Parameters
mixed $property
- Optional - if a string is provided and is really the name of a property in your
class the raw value will be outputted. If no value is provided, this method will output all the
properties in the current class.
Load State
Used in conjuction with eden()->saveState()
, this method will
recall a saved instance previously saved for further processing.
Usage
Example
Parameters
string $name
- Required - The name of the saved state.
Loop
A chainable for statement. It is possible to have an infinite loop with this method so test wisely.
Usage
Example
Parameters
callable $callback
- Required - The loop callback.
int $incrementor
- Optional - Default 0 - Used as an optional nice to have that auto
increments by 1 after each time the callback above is called.
Off
Used in conjunction with eden()->on()
and eden()->trigger()
, this removes event
listeners on a particular event. Events are stored in on a global scale.
Usage
Example
Parameters
string $event
- Optional - if a string is provided this will remove all events that match this string.
if no event is provided, all event handlers will be removed.
callable $handler
- Optional - Adding this will remove a particular handler from the specified event.
On
Used in conjunction with eden()->off()
and eden()->trigger()
, this adds an event
listener given the particular event. Events are stored in on a global scale.
Usage
Example
Parameters
string $event
- Required - The name of the event. This
can be any name you want so long that it's a valid string.
callable $handler
- Required - The handler that will be
called if the event is triggered.
Save State
Used in conjuction with eden()->loadState()
, this method will
save the current instance for further recall later.
Usage
Example
Parameters
string $name
- Required - The name of the saved state. This can be any name you
like so long as it's a valid string.
Trigger
Used in conjunction with eden()->off()
and eden()->on()
, this triggers the event passing
any arguments provided.
Usage
Example
Parameters
string $event
- Required - The name of the event. This
can be any name you want so long that it's a valid string.
mixed $arg
- Optional - any arguments you want passed to
all handlers that are listening to the specified event.
When
A chainable if/else statement.
Usage
Example
Parameters
bool|callable $condition
- Required - The conditional test
callable $success
- Required - This will be called if the conditional test evaluates to true.
callable $fail
- Optional - This will be called if the conditional test does not evaluates to true.
====
This is not a God Object
How many operation do you need on a simple iterator?
The question can be answered easily by looking at any Iterator API in a given language. You need 3 methods:
- Get the current value
- Move the iterator to the next element
- Check if the Iterator has more elements
That's all you need. If you can perform those 3 operations, you can go through any sequence of elements.
But that is not only what you usually want to do with a sequence of elements, is it? You usually have a much higher level goal to achieve. You may want to do something with every element, you may want to filter them according to some condition, or one of several other methods. See the IEnumerable interface in the LINQ library in .NET for more examples.
Do you see how many there are? And that is just a subset of all the methods they could have put on the IEnumerable interface, because you usually combine them to achieve even higher goals.
But here is the twist. Those methods are not on the IEnumerable interface. They are simple utility methods that actually take a IEnumerable as input and do something with it. So while in the C# language it feels like there are a bajillion methods on the IEnumerable interface, IEnumerable is not a god object.
Is jQuery a God Class?
Lets ask that question again, this time with class processes.
How many operation do you need on a DOM element?
Again the answer is pretty straightforward. All the methods you need are methods to read/modify the attributes and the child elements. That's about it. Everything else is only a combination of those basic operations.
But how much higher level stuff would you want to do with a DOM elements? Well, same as an Iterator: a bajillion different things. And that's where jQuery comes in. jQuery, in essence provide two things:
A very nice collections of utilities methods that you may want to call on a DOM element, and; Syntactic sugar so that using it is a much better experience than using the standard DOM API. If you take out the sugared form, you realise that jQuery could easily have been written as a bunch of functions that select/modify DOM elements. For example:
$("#body").html("<p>hello</p>");
...could have been written as:
html($("#body"), "<p>hello</p>");
Semantically it's the exact same thing. However the first form has the big advantage that the order left-to-right of the statements follow the order the operations will be executed. The second start in the middle, which makes for very hard to read code if you combine lots of operations together.
So what does it all mean? That jQuery (like LINQ) is not the God object anti-pattern. It's instead a case of a very respected pattern called the Decorator.
...
From (http://programmers.stackexchange.com/questions/179601/is-jquery-an-example-of-god-object-antipattern)
Back to Eden
Much like jQuery, Eden follows a similar decorator pattern. You can use classes in the Eden library
in the normal way of new Eden\Core\Event
or new Eden\Mysql\Factory
. Or use it this way eden('mysql')
====
Contributing to Eden
Contributions to Eden are following the Github work flow. Please read up before contributing.
Setting up your machine with the Eden repository and your fork
- Fork the repository
- Fire up your local terminal create a new branch from the
v4
branch of your fork with a branch name describing what your changes are. Possible branch name types:- bugfix
- feature
- improvement
- Make your changes. Always make sure to sign-off (-s) on all commits made (git commit -s -m "Commit message")
Making pull requests
- Please ensure to run
phpunit
before making a pull request. - Push your code to your remote forked version.
- Go back to your forked version on GitHub and submit a pull request.
- An Eden developer will review your code and merge it in when it has been classified as suitable.