-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from nicolasmure/event-dispatcher
Command execution events + subrequests support + volume_id setting
- Loading branch information
Showing
10 changed files
with
290 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace FM\ElfinderBundle\Event; | ||
|
||
use Symfony\Component\EventDispatcher\Event; | ||
|
||
abstract class ElFinderEvents extends Event | ||
{ | ||
/** | ||
* Event name to identify pre execution event. | ||
* @var string | ||
*/ | ||
const PRE_EXECUTION = 'fm_elfinder.event.pre_execution'; | ||
|
||
/** | ||
* Event name to identify post execution event. | ||
* @var string | ||
*/ | ||
const POST_EXECUTION = 'fm_elfinder.event.post_execution'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace FM\ElfinderBundle\Event; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
|
||
class ElFinderPostExecutionEvent extends ElFinderPreExecutionEvent | ||
{ | ||
/** | ||
* Command execution result. | ||
* @var array | ||
*/ | ||
protected $result; | ||
|
||
|
||
/** | ||
* Constructor. | ||
* @param Request $request | ||
* @param HttpKernelInterface $httpKernel | ||
* @param string $instance | ||
* @param string $homeFolder | ||
* @param array $result | ||
*/ | ||
public function __construct(Request $request, HttpKernelInterface $httpKernel, $instance, $homeFolder, array $result) | ||
{ | ||
parent::__construct($request, $httpKernel, $instance, $homeFolder); | ||
|
||
$this->result = $result; | ||
} | ||
|
||
/** | ||
* Tells if execution has encountered errors. | ||
* @return boolean | ||
*/ | ||
public function hasErrors() | ||
{ | ||
return isset($this->result['error']); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getResult() | ||
{ | ||
return $this->result; | ||
} | ||
|
||
/** | ||
* @param array $result | ||
*/ | ||
public function setResult(array $result) | ||
{ | ||
$this->result = $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace FM\ElfinderBundle\Event; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
|
||
class ElFinderPreExecutionEvent extends ElFinderEvents | ||
{ | ||
/** | ||
* Request object containing ElFinder command and parameters. | ||
* @var Request | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* Used to make sub requests. | ||
* @var HttpKernelInterface | ||
*/ | ||
private $httpKernel; | ||
|
||
/** | ||
* ElFinder instance. | ||
* @var string | ||
*/ | ||
protected $instance; | ||
|
||
/** | ||
* Home folder. | ||
* @var string | ||
*/ | ||
protected $homeFolder; | ||
|
||
|
||
/** | ||
* Constructor. | ||
* @param Request $request | ||
* @param HttpKernelInterface $httpKernel | ||
* @param string $instance | ||
* @param string $homeFolder | ||
*/ | ||
public function __construct(Request $request, HttpKernelInterface $httpKernel, $instance, $homeFolder) | ||
{ | ||
$this->request = $request; | ||
$this->httpKernel = $httpKernel; | ||
$this->instance = $instance; | ||
$this->homeFolder = $homeFolder; | ||
} | ||
|
||
/** | ||
* Makes a sub request to elFinder. | ||
* Function based on 'forward' function from Symfony controllers. | ||
* | ||
* @see https://github.com/symfony/symfony/blob/2.5/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php | ||
* | ||
* @param array $path An array of path parameters | ||
* @param array $query An array of query parameters | ||
* | ||
* @return Symfony\Component\HttpFoundation\Response A Response instance | ||
*/ | ||
public function subRequest(array $path, array $query) | ||
{ | ||
$path['_controller'] = 'FMElfinderBundle:ElFinder:load'; | ||
$subRequest = $this->request->duplicate($query, null, $path); | ||
|
||
return $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST); | ||
} | ||
|
||
/** | ||
* Returns executed command. | ||
* @return string | ||
*/ | ||
public function getCommand() | ||
{ | ||
return $this->request->get('cmd'); | ||
} | ||
|
||
/** | ||
* @return Request | ||
*/ | ||
public function getRequest() | ||
{ | ||
return $this->request; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getInstance() | ||
{ | ||
return $this->instance; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getHomeFolder() | ||
{ | ||
return $this->homeFolder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters