Skip to content

Commit

Permalink
feat: return returned values from object
Browse files Browse the repository at this point in the history
  • Loading branch information
bennetgallein committed May 17, 2023
1 parent ec6ead6 commit ea5ff02
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions src/Engine/RouterEngine/Route.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Created by PhpStorm.
* User: bennet
Expand Down Expand Up @@ -65,12 +66,18 @@ class Route {
*/
private $config;

/**
* the return value of the function
*
* @var any
*/
private $output;

/**
* @param $resource
* @param array $config
*/
public function __construct($resource, array $config)
{
public function __construct($resource, array $config) {
$this->url = $resource;
$this->config = $config;
$this->methods = isset($config['methods']) ? (array) $config['methods'] : array();
Expand All @@ -81,13 +88,11 @@ public function __construct($resource, array $config)
$this->action = isset($action[1]) ? $action[1] : null;
}

public function getUrl()
{
public function getUrl() {
return $this->url;
}

public function setUrl($url)
{
public function setUrl($url) {
$url = (string)$url;

// make sure that the URL is suffixed with a forward slash
Expand All @@ -98,68 +103,64 @@ public function setUrl($url)
$this->url = $url;
}

public function getTarget()
{
public function setOutput($out) {
$this->output = $out;
}

public function getOutput() {
return $this->output;
}

public function getTarget() {
return $this->target;
}

public function setTarget($target)
{
public function setTarget($target) {
$this->target = $target;
}

public function getMethods()
{
public function getMethods() {
return $this->methods;
}

public function setMethods(array $methods)
{
public function setMethods(array $methods) {
$this->methods = $methods;
}

public function getName()
{
public function getName() {
return $this->name;
}

public function setName($name)
{
public function setName($name) {
$this->name = (string)$name;
}

public function setFilters(array $filters, $parametersByName = false)
{
public function setFilters(array $filters, $parametersByName = false) {
$this->filters = $filters;
$this->parametersByName = $parametersByName;
}

public function getRegex()
{
public function getRegex() {
return preg_replace_callback('/(:\w+)/', array(&$this, 'substituteFilter'), $this->url);
}

private function substituteFilter($matches)
{
private function substituteFilter($matches) {
if (isset($matches[1], $this->filters[$matches[1]])) {
return $this->filters[$matches[1]];
}

return '([\w\-%]+)';
}

public function getParameters()
{
public function getParameters() {
return $this->parameters;
}

public function setParameters(array $parameters)
{
public function setParameters(array $parameters) {
$this->parameters = array_merge($this->parameters, $parameters);
}

public function dispatch()
{
public function dispatch() {
$action = explode('::', $this->config['_controller']);
$instance = new $action[0];
$_SERVER['debug'] = ($this->parameters);
Expand All @@ -168,16 +169,14 @@ public function dispatch()
}

if (empty($action[1]) || trim($action[1]) === '') {
call_user_func_array($instance, $this->parameters);

return ;
$this->setOutput(call_user_func_array($instance, $this->parameters));
return;
}

call_user_func_array(array($instance, $action[1]), $this->parameters);
$this->setOutput(call_user_func_array(array($instance, $action[1]), $this->parameters));
}

public function getAction()
{
public function getAction() {
return $this->action;
}
}
}

0 comments on commit ea5ff02

Please sign in to comment.