Skip to content

Commit

Permalink
Updated plugin docs with namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
electerious committed Feb 6, 2016
1 parent 34f8736 commit 8735044
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions docs/Plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,41 @@ The plugin-system of Lychee allows you to execute scripts, when a certain action
```php
<?php

if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
namespace ExamplePlugin;

use SplObserver;
use SplSubject;

class ExamplePlugin implements SplObserver {

public function __construct() {

# Add code here if wanted
# __construct() will be called every time Lychee gets called
# Make sure this part is performant
/**
* Add code here if wanted
* __construct() will be called every time Lychee gets called
* Make sure this part is performant
*/

return true;

}

public function update(\SplSubject $subject) {
public function update(SplSubject $subject) {

/**
* Check if the called hook is the hook you are waiting for
* A list of all hooks is available online
*/

# Check if the called hook is the hook you are waiting for
# A list of all hooks is available online
if ($subject->action!=='Photo::add:before') return false;

# Do something when Photo::add:before gets called
# Database::get() => Database connection of Lychee
# Settings::get() => Settings of Lychee
# $subject->action => Called hook
# $subject->args => Params passed to the original function
/**
* Do something when Photo::add:before gets called
* Database::get() => Database connection of Lychee
* Settings::get() => Settings of Lychee
* $subject->action => Called hook
* $subject->args => Params passed to the original function
*/

return true;

Expand All @@ -54,9 +64,9 @@ class ExamplePlugin implements SplObserver {

3. Add the class name to the database of Lychee

Select the table `lychee_settings` and add the name of the class to the value of `plugins` (e.g. `ExamplePlugin`). Please ensure that the folder has the same name as the class and as the file.
Select the table `lychee_settings` and add the [external fully qualified name](http://php.net/manual/en/language.namespaces.importing.php) to the value of `plugins` (e.g. `ExamplePlugin\ExamplePlugin`). Please ensure that the folder has the same name as the namespace and the file the same name as the class.

Divide multiple plugins with semicolons: `ExamplePlugin;ExampleTwoPlugin`.
Divide multiple plugins with semicolons: `ExamplePlugin\ExamplePlugin;ExampleTwoPlugin\ExampleTwoPlugin`.

### Available hooks

Expand Down

0 comments on commit 8735044

Please sign in to comment.