diff --git a/app/Action/Base.php b/app/Action/Base.php index 0d8bd565f..f29e9323d 100644 --- a/app/Action/Base.php +++ b/app/Action/Base.php @@ -10,17 +10,8 @@ use Pimple\Container; * * @package action * @author Frederic Guillot - * - * @property \Model\UserSession $userSession - * @property \Model\Comment $comment - * @property \Model\Task $task - * @property \Model\TaskCreation $taskCreation - * @property \Model\TaskModification $taskModification - * @property \Model\TaskDuplication $taskDuplication - * @property \Model\TaskFinder $taskFinder - * @property \Model\TaskStatus $taskStatus */ -abstract class Base +abstract class Base extends \Core\Base { /** * Flag for called listener @@ -135,18 +126,6 @@ abstract class Base return get_called_class(); } - /** - * Load automatically models - * - * @access public - * @param string $name Model name - * @return mixed - */ - public function __get($name) - { - return $this->container[$name]; - } - /** * Set an user defined parameter * diff --git a/app/Api/Base.php b/app/Api/Base.php index e9494b586..1b2258afe 100644 --- a/app/Api/Base.php +++ b/app/Api/Base.php @@ -2,7 +2,6 @@ namespace Api; -use Pimple\Container; use JsonRPC\AuthenticationFailure; use Symfony\Component\EventDispatcher\Event; @@ -11,56 +10,9 @@ use Symfony\Component\EventDispatcher\Event; * * @package api * @author Frederic Guillot - * - * @property \Model\Board $board - * @property \Model\Config $config - * @property \Model\Comment $comment - * @property \Model\LastLogin $lastLogin - * @property \Model\Notification $notification - * @property \Model\Project $project - * @property \Model\ProjectPermission $projectPermission - * @property \Model\ProjectActivity $projectActivity - * @property \Model\ProjectAnalytic $projectAnalytic - * @property \Model\ProjectDailySummary $projectDailySummary - * @property \Model\Subtask $subtask - * @property \Model\Task $task - * @property \Model\TaskDuplication $taskDuplication - * @property \Model\TaskExport $taskExport - * @property \Model\TaskFinder $taskFinder */ -abstract class Base +abstract class Base extends \Core\Base { - /** - * Container instance - * - * @access protected - * @var \Pimple\Container - */ - protected $container; - - /** - * Constructor - * - * @access public - * @param \Pimple\Container $container - */ - public function __construct(Container $container) - { - $this->container = $container; - } - - /** - * Load automatically models - * - * @access public - * @param string $name Model name - * @return mixed - */ - public function __get($name) - { - return $this->container[$name]; - } - /** * Check api credentials * diff --git a/app/Auth/Base.php b/app/Auth/Base.php index e2209e1ff..ebf6681bd 100644 --- a/app/Auth/Base.php +++ b/app/Auth/Base.php @@ -9,14 +9,8 @@ use Pimple\Container; * * @package auth * @author Frederic Guillot - * - * @property \Core\Session $session - * @property \Model\Acl $acl - * @property \Model\LastLogin $lastLogin - * @property \Model\User $user - * @property \Model\UserSession $userSession */ -abstract class Base +abstract class Base extends \Core\Base { /** * Database instance @@ -26,14 +20,6 @@ abstract class Base */ protected $db; - /** - * Container instance - * - * @access protected - * @var \Pimple\Container - */ - protected $container; - /** * Constructor * @@ -45,16 +31,4 @@ abstract class Base $this->container = $container; $this->db = $this->container['db']; } - - /** - * Load automatically models - * - * @access public - * @param string $name Model name - * @return mixed - */ - public function __get($name) - { - return $this->container[$name]; - } } diff --git a/app/Controller/App.php b/app/Controller/App.php index e4a97f8e0..8a97e8c74 100644 --- a/app/Controller/App.php +++ b/app/Controller/App.php @@ -90,7 +90,7 @@ class App extends Base $this->response->html('
'.t('Nothing to preview...').'
'); } - $this->response->html($this->template->markdown($payload['text'])); + $this->response->html($this->helper->text->markdown($payload['text'])); } /** diff --git a/app/Controller/Auth.php b/app/Controller/Auth.php index c1859304d..24e6e2428 100644 --- a/app/Controller/Auth.php +++ b/app/Controller/Auth.php @@ -18,7 +18,7 @@ class Auth extends Base public function login(array $values = array(), array $errors = array()) { if ($this->userSession->isLogged()) { - $this->response->redirect($this->helper->url('app', 'index')); + $this->response->redirect($this->helper->url->to('app', 'index')); } $this->response->html($this->template->layout('auth/index', array( @@ -47,7 +47,7 @@ class Auth extends Base $this->response->redirect('?'.urldecode($redirect_query)); } - $this->response->redirect($this->helper->url('app', 'index')); + $this->response->redirect($this->helper->url->to('app', 'index')); } $this->login($values, $errors); @@ -62,6 +62,6 @@ class Auth extends Base { $this->authentication->backend('rememberMe')->destroy($this->userSession->getId()); $this->session->close(); - $this->response->redirect($this->helper->url('auth', 'login')); + $this->response->redirect($this->helper->url->to('auth', 'login')); } } diff --git a/app/Controller/Base.php b/app/Controller/Base.php index 30d0b4e48..19de6a935 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -16,67 +16,8 @@ use Symfony\Component\EventDispatcher\Event; * * @package controller * @author Frederic Guillot - * - * @property \Core\Helper $helper - * @property \Core\Session $session - * @property \Core\Template $template - * @property \Core\Paginator $paginator - * @property \Integration\GithubWebhook $githubWebhook - * @property \Integration\GitlabWebhook $gitlabWebhook - * @property \Integration\BitbucketWebhook $bitbucketWebhook - * @property \Integration\PostmarkWebhook $postmarkWebhook - * @property \Integration\SendgridWebhook $sendgridWebhook - * @property \Integration\MailgunWebhook $mailgunWebhook - * @property \Model\Acl $acl - * @property \Model\Authentication $authentication - * @property \Model\Action $action - * @property \Model\Board $board - * @property \Model\Category $category - * @property \Model\Color $color - * @property \Model\Comment $comment - * @property \Model\Config $config - * @property \Model\DateParser $dateParser - * @property \Model\File $file - * @property \Model\HourlyRate $hourlyRate - * @property \Model\LastLogin $lastLogin - * @property \Model\Notification $notification - * @property \Model\Project $project - * @property \Model\ProjectPermission $projectPermission - * @property \Model\ProjectDuplication $projectDuplication - * @property \Model\ProjectAnalytic $projectAnalytic - * @property \Model\ProjectActivity $projectActivity - * @property \Model\ProjectDailySummary $projectDailySummary - * @property \Model\ProjectIntegration $projectIntegration - * @property \Model\Subtask $subtask - * @property \Model\SubtaskForecast $subtaskForecast - * @property \Model\Swimlane $swimlane - * @property \Model\Task $task - * @property \Model\Link $link - * @property \Model\TaskCreation $taskCreation - * @property \Model\TaskModification $taskModification - * @property \Model\TaskDuplication $taskDuplication - * @property \Model\TaskHistory $taskHistory - * @property \Model\TaskExport $taskExport - * @property \Model\TaskFinder $taskFinder - * @property \Model\TaskFilter $taskFilter - * @property \Model\TaskPosition $taskPosition - * @property \Model\TaskPermission $taskPermission - * @property \Model\TaskStatus $taskStatus - * @property \Model\Timetable $timetable - * @property \Model\TimetableDay $timetableDay - * @property \Model\TimetableWeek $timetableWeek - * @property \Model\TimetableExtra $timetableExtra - * @property \Model\TimetableOff $timetableOff - * @property \Model\TaskValidator $taskValidator - * @property \Model\TaskLink $taskLink - * @property \Model\CommentHistory $commentHistory - * @property \Model\SubtaskHistory $subtaskHistory - * @property \Model\SubtaskTimeTracking $subtaskTimeTracking - * @property \Model\User $user - * @property \Model\UserSession $userSession - * @property \Model\Webhook $webhook */ -abstract class Base +abstract class Base extends \Core\Base { /** * Request instance @@ -94,14 +35,6 @@ abstract class Base */ protected $response; - /** - * Container instance - * - * @access private - * @var \Pimple\Container - */ - private $container; - /** * Constructor * @@ -133,18 +66,6 @@ abstract class Base } } - /** - * Load automatically models - * - * @access public - * @param string $name Model name - * @return mixed - */ - public function __get($name) - { - return $this->container[$name]; - } - /** * Send HTTP headers * @@ -201,7 +122,7 @@ abstract class Base $this->response->text('Not Authorized', 401); } - $this->response->redirect($this->helper->url('auth', 'login', array('redirect_query' => urlencode($this->request->getQueryString())))); + $this->response->redirect($this->helper->url->to('auth', 'login', array('redirect_query' => urlencode($this->request->getQueryString())))); } } @@ -220,7 +141,7 @@ abstract class Base $this->response->text('Not Authorized', 401); } - $this->response->redirect($this->helper->url('twofactor', 'code')); + $this->response->redirect($this->helper->url->to('twofactor', 'code')); } } diff --git a/app/Controller/Board.php b/app/Controller/Board.php index 07c99a969..2b633d825 100644 --- a/app/Controller/Board.php +++ b/app/Controller/Board.php @@ -295,7 +295,7 @@ class Board extends Base $this->session->flashError(t('Unable to update your task.')); } - $this->response->redirect($this->helper->url('board', 'show', array('project_id' => $values['project_id']))); + $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $values['project_id']))); } /** @@ -333,7 +333,7 @@ class Board extends Base $this->session->flashError(t('Unable to update your task.')); } - $this->response->redirect($this->helper->url('board', 'show', array('project_id' => $values['project_id']))); + $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $values['project_id']))); } /** diff --git a/app/Controller/Budget.php b/app/Controller/Budget.php index 2c56c79df..45dad7fbb 100644 --- a/app/Controller/Budget.php +++ b/app/Controller/Budget.php @@ -88,7 +88,7 @@ class Budget extends Base if ($this->budget->create($values['project_id'], $values['amount'], $values['comment'], $values['date'])) { $this->session->flash(t('The budget line have been created successfully.')); - $this->response->redirect($this->helper->url('budget', 'create', array('project_id' => $project['id']))); + $this->response->redirect($this->helper->url->to('budget', 'create', array('project_id' => $project['id']))); } else { $this->session->flashError(t('Unable to create the budget line.')); @@ -130,6 +130,6 @@ class Budget extends Base $this->session->flashError(t('Unable to remove this budget line.')); } - $this->response->redirect($this->helper->url('budget', 'create', array('project_id' => $project['id']))); + $this->response->redirect($this->helper->url->to('budget', 'create', array('project_id' => $project['id']))); } } diff --git a/app/Controller/Column.php b/app/Controller/Column.php index 69ca5dd20..89c495a6e 100644 --- a/app/Controller/Column.php +++ b/app/Controller/Column.php @@ -57,7 +57,7 @@ class Column extends Base if ($this->board->addColumn($project['id'], $data['title'], $data['task_limit'], $data['description'])) { $this->session->flash(t('Board updated successfully.')); - $this->response->redirect($this->helper->url('column', 'index', array('project_id' => $project['id']))); + $this->response->redirect($this->helper->url->to('column', 'index', array('project_id' => $project['id']))); } else { $this->session->flashError(t('Unable to update this board.')); @@ -102,7 +102,7 @@ class Column extends Base if ($this->board->updateColumn($values['id'], $values['title'], $values['task_limit'], $values['description'])) { $this->session->flash(t('Board updated successfully.')); - $this->response->redirect($this->helper->url('column', 'index', array('project_id' => $project['id']))); + $this->response->redirect($this->helper->url->to('column', 'index', array('project_id' => $project['id']))); } else { $this->session->flashError(t('Unable to update this board.')); @@ -128,7 +128,7 @@ class Column extends Base $this->board->{'move'.$direction}($project['id'], $column_id); } - $this->response->redirect($this->helper->url('column', 'index', array('project_id' => $project['id']))); + $this->response->redirect($this->helper->url->to('column', 'index', array('project_id' => $project['id']))); } /** @@ -165,6 +165,6 @@ class Column extends Base $this->session->flashError(t('Unable to remove this column.')); } - $this->response->redirect($this->helper->url('column', 'index', array('project_id' => $project['id']))); + $this->response->redirect($this->helper->url->to('column', 'index', array('project_id' => $project['id']))); } } diff --git a/app/Controller/Currency.php b/app/Controller/Currency.php index fac34a301..10fb90da6 100644 --- a/app/Controller/Currency.php +++ b/app/Controller/Currency.php @@ -57,7 +57,7 @@ class Currency extends Base if ($this->currency->create($values['currency'], $values['rate'])) { $this->session->flash(t('The currency rate have been added successfully.')); - $this->response->redirect($this->helper->url('currency', 'index')); + $this->response->redirect($this->helper->url->to('currency', 'index')); } else { $this->session->flashError(t('Unable to add this currency rate.')); @@ -84,6 +84,6 @@ class Currency extends Base $this->session->flashError(t('Unable to save your settings.')); } - $this->response->redirect($this->helper->url('currency', 'index')); + $this->response->redirect($this->helper->url->to('currency', 'index')); } } diff --git a/app/Controller/File.php b/app/Controller/File.php index 39032abcc..f03675373 100644 --- a/app/Controller/File.php +++ b/app/Controller/File.php @@ -24,10 +24,10 @@ class File extends Base $this->session->flash(t('Screenshot uploaded successfully.')); if ($this->request->getStringParam('redirect') === 'board') { - $this->response->redirect($this->helper->url('board', 'show', array('project_id' => $task['project_id']))); + $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id']))); } - $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); } $this->response->html($this->taskLayout('file/screenshot', array( @@ -64,7 +64,7 @@ class File extends Base $this->session->flashError(t('Unable to upload the file.')); } - $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); } /** @@ -83,7 +83,7 @@ class File extends Base $this->response->binary(file_get_contents($filename)); } - $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); } /** @@ -164,7 +164,7 @@ class File extends Base $this->session->flashError(t('Unable to remove this file.')); } - $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); } /** diff --git a/app/Controller/Hourlyrate.php b/app/Controller/Hourlyrate.php index 8d96e5ca0..19650ede4 100644 --- a/app/Controller/Hourlyrate.php +++ b/app/Controller/Hourlyrate.php @@ -42,7 +42,7 @@ class Hourlyrate extends User if ($this->hourlyRate->create($values['user_id'], $values['rate'], $values['currency'], $values['date_effective'])) { $this->session->flash(t('Hourly rate created successfully.')); - $this->response->redirect($this->helper->url('hourlyrate', 'index', array('user_id' => $values['user_id']))); + $this->response->redirect($this->helper->url->to('hourlyrate', 'index', array('user_id' => $values['user_id']))); } else { $this->session->flashError(t('Unable to save the hourly rate.')); @@ -84,6 +84,6 @@ class Hourlyrate extends User $this->session->flash(t('Unable to remove this rate.')); } - $this->response->redirect($this->helper->url('hourlyrate', 'index', array('user_id' => $user['id']))); + $this->response->redirect($this->helper->url->to('hourlyrate', 'index', array('user_id' => $user['id']))); } } diff --git a/app/Controller/Link.php b/app/Controller/Link.php index 4a29a3e2c..8eac84941 100644 --- a/app/Controller/Link.php +++ b/app/Controller/Link.php @@ -73,7 +73,7 @@ class Link extends Base if ($this->link->create($values['label'], $values['opposite_label'])) { $this->session->flash(t('Link added successfully.')); - $this->response->redirect($this->helper->url('link', 'index')); + $this->response->redirect($this->helper->url->to('link', 'index')); } else { $this->session->flashError(t('Unable to create your link.')); @@ -115,7 +115,7 @@ class Link extends Base if ($valid) { if ($this->link->update($values)) { $this->session->flash(t('Link updated successfully.')); - $this->response->redirect($this->helper->url('link', 'index')); + $this->response->redirect($this->helper->url->to('link', 'index')); } else { $this->session->flashError(t('Unable to update your link.')); @@ -157,6 +157,6 @@ class Link extends Base $this->session->flashError(t('Unable to remove this link.')); } - $this->response->redirect($this->helper->url('link', 'index')); + $this->response->redirect($this->helper->url->to('link', 'index')); } } diff --git a/app/Controller/Subtask.php b/app/Controller/Subtask.php index 5eff1575b..5baa6004c 100644 --- a/app/Controller/Subtask.php +++ b/app/Controller/Subtask.php @@ -252,11 +252,11 @@ class Subtask extends Base { switch ($redirect) { case 'board': - $this->response->redirect($this->helper->url('board', 'show', array('project_id' => $task['project_id']))); + $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id']))); case 'dashboard': - $this->response->redirect($this->helper->url('app', 'index')); + $this->response->redirect($this->helper->url->to('app', 'index')); default: - $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); } } @@ -275,6 +275,6 @@ class Subtask extends Base $method = $direction === 'up' ? 'moveUp' : 'moveDown'; $this->subtask->$method($task_id, $subtask_id); - $this->response->redirect($this->helper->url('task', 'show', array('project_id' => $project_id, 'task_id' => $task_id)).'#subtasks'); + $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $project_id, 'task_id' => $task_id)).'#subtasks'); } } diff --git a/app/Controller/Task.php b/app/Controller/Task.php index c2e66245b..dc83f7b16 100644 --- a/app/Controller/Task.php +++ b/app/Controller/Task.php @@ -288,10 +288,10 @@ class Task extends Base } if ($redirect === 'board') { - $this->response->redirect($this->helper->url('board', 'show', array('project_id' => $task['project_id']))); + $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id']))); } - $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); } if ($this->request->isAjax()) { diff --git a/app/Controller/Tasklink.php b/app/Controller/Tasklink.php index eccf149f5..dd076802b 100644 --- a/app/Controller/Tasklink.php +++ b/app/Controller/Tasklink.php @@ -77,10 +77,10 @@ class Tasklink extends Base $this->session->flash(t('Link added successfully.')); if ($ajax) { - $this->response->redirect($this->helper->url('board', 'show', array('project_id' => $task['project_id']))); + $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id']))); } - $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links'); + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links'); } $errors = array('title' => array(t('The exact same link already exists'))); @@ -132,7 +132,7 @@ class Tasklink extends Base if ($this->taskLink->update($values['id'], $values['task_id'], $values['opposite_task_id'], $values['link_id'])) { $this->session->flash(t('Link updated successfully.')); - $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links'); + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links'); } $this->session->flashError(t('Unable to update your link.')); @@ -174,6 +174,6 @@ class Tasklink extends Base $this->session->flashError(t('Unable to remove this link.')); } - $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links'); + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links'); } } diff --git a/app/Controller/Timetableday.php b/app/Controller/Timetableday.php index eea44ae1b..c8f7ac8aa 100644 --- a/app/Controller/Timetableday.php +++ b/app/Controller/Timetableday.php @@ -41,7 +41,7 @@ class Timetableday extends User if ($this->timetableDay->create($values['user_id'], $values['start'], $values['end'])) { $this->session->flash(t('Time slot created successfully.')); - $this->response->redirect($this->helper->url('timetableday', 'index', array('user_id' => $values['user_id']))); + $this->response->redirect($this->helper->url->to('timetableday', 'index', array('user_id' => $values['user_id']))); } else { $this->session->flashError(t('Unable to save this time slot.')); @@ -83,6 +83,6 @@ class Timetableday extends User $this->session->flash(t('Unable to remove this time slot.')); } - $this->response->redirect($this->helper->url('timetableday', 'index', array('user_id' => $user['id']))); + $this->response->redirect($this->helper->url->to('timetableday', 'index', array('user_id' => $user['id']))); } } diff --git a/app/Controller/Timetableoff.php b/app/Controller/Timetableoff.php index 19a6fab10..585014a30 100644 --- a/app/Controller/Timetableoff.php +++ b/app/Controller/Timetableoff.php @@ -60,7 +60,7 @@ class Timetableoff extends User $values['comment'])) { $this->session->flash(t('Time slot created successfully.')); - $this->response->redirect($this->helper->url($this->controller_url, 'index', array('user_id' => $values['user_id']))); + $this->response->redirect($this->helper->url->to($this->controller_url, 'index', array('user_id' => $values['user_id']))); } else { $this->session->flashError(t('Unable to save this time slot.')); @@ -102,6 +102,6 @@ class Timetableoff extends User $this->session->flash(t('Unable to remove this time slot.')); } - $this->response->redirect($this->helper->url($this->controller_url, 'index', array('user_id' => $user['id']))); + $this->response->redirect($this->helper->url->to($this->controller_url, 'index', array('user_id' => $user['id']))); } } diff --git a/app/Controller/Timetableweek.php b/app/Controller/Timetableweek.php index 829f44028..b8ce00e77 100644 --- a/app/Controller/Timetableweek.php +++ b/app/Controller/Timetableweek.php @@ -52,7 +52,7 @@ class Timetableweek extends User if ($this->timetableWeek->create($values['user_id'], $values['day'], $values['start'], $values['end'])) { $this->session->flash(t('Time slot created successfully.')); - $this->response->redirect($this->helper->url('timetableweek', 'index', array('user_id' => $values['user_id']))); + $this->response->redirect($this->helper->url->to('timetableweek', 'index', array('user_id' => $values['user_id']))); } else { $this->session->flashError(t('Unable to save this time slot.')); @@ -94,6 +94,6 @@ class Timetableweek extends User $this->session->flash(t('Unable to remove this time slot.')); } - $this->response->redirect($this->helper->url('timetableweek', 'index', array('user_id' => $user['id']))); + $this->response->redirect($this->helper->url->to('timetableweek', 'index', array('user_id' => $user['id']))); } } diff --git a/app/Controller/Twofactor.php b/app/Controller/Twofactor.php index c21729bae..a8b0351f0 100644 --- a/app/Controller/Twofactor.php +++ b/app/Controller/Twofactor.php @@ -76,7 +76,7 @@ class Twofactor extends User $_SESSION['user']['twofactor_activated'] = false; $this->session->flash(t('User updated successfully.')); - $this->response->redirect($this->helper->url('twofactor', 'index', array('user_id' => $user['id']))); + $this->response->redirect($this->helper->url->to('twofactor', 'index', array('user_id' => $user['id']))); } /** @@ -99,7 +99,7 @@ class Twofactor extends User $this->session->flashError(t('The two factor authentication code is not valid.')); } - $this->response->redirect($this->helper->url('twofactor', 'index', array('user_id' => $user['id']))); + $this->response->redirect($this->helper->url->to('twofactor', 'index', array('user_id' => $user['id']))); } /** @@ -118,11 +118,11 @@ class Twofactor extends User if (! empty($values['code']) && $otp->checkTotp(Base32::decode($user['twofactor_secret']), $values['code'])) { $this->session['2fa_validated'] = true; $this->session->flash(t('The two factor authentication code is valid.')); - $this->response->redirect($this->helper->url('app', 'index')); + $this->response->redirect($this->helper->url->to('app', 'index')); } else { $this->session->flashError(t('The two factor authentication code is not valid.')); - $this->response->redirect($this->helper->url('twofactor', 'code')); + $this->response->redirect($this->helper->url->to('twofactor', 'code')); } } @@ -157,7 +157,7 @@ class Twofactor extends User 'twofactor_secret' => '', )); - $this->response->redirect($this->helper->url('user', 'show', array('user_id' => $user['id']))); + $this->response->redirect($this->helper->url->to('user', 'show', array('user_id' => $user['id']))); } $this->response->html($this->layout('twofactor/disable', array( diff --git a/app/Controller/User.php b/app/Controller/User.php index c8496418d..b049c9264 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -268,7 +268,7 @@ class User extends Base $this->session->flashError(t('Unable to update this user.')); } - $this->response->redirect($this->helper->url('user', 'share', array('user_id' => $user['id']))); + $this->response->redirect($this->helper->url->to('user', 'share', array('user_id' => $user['id']))); } $this->response->html($this->layout('user/share', array( diff --git a/app/Controller/Webhook.php b/app/Controller/Webhook.php index 667c50879..c79b4ed68 100644 --- a/app/Controller/Webhook.php +++ b/app/Controller/Webhook.php @@ -96,7 +96,7 @@ class Webhook extends Base $this->bitbucketWebhook->setProjectId($this->request->getIntegerParam('project_id')); - $result = $this->bitbucketWebhook->parsePayload(json_decode(@$_POST['payload'], true)); + $result = $this->bitbucketWebhook->parsePayload(json_decode(@$_POST['payload'], true) ?: array()); echo $result ? 'PARSED' : 'IGNORED'; } diff --git a/app/Core/Base.php b/app/Core/Base.php new file mode 100644 index 000000000..cb8e44871 --- /dev/null +++ b/app/Core/Base.php @@ -0,0 +1,110 @@ +container = $container; + } + + /** + * Load automatically models + * + * @access public + * @param string $name Model name + * @return mixed + */ + public function __get($name) + { + return $this->container[$name]; + } +} diff --git a/app/Core/FileCache.php b/app/Core/FileCache.php deleted file mode 100644 index 2037f2717..000000000 --- a/app/Core/FileCache.php +++ /dev/null @@ -1,41 +0,0 @@ -container = $container; - } - - /** - * Load automatically models - * - * @access public - * @param string $name Model name + * @param string $name Helper name * @return mixed */ public function __get($name) { - return $this->container[$name]; - } - - /** - * Get the age of an item in quasi human readable format. - * It's in this format: <1h , NNh, NNd - * - * @access public - * @param integer $timestamp Unix timestamp of the artifact for which age will be calculated - * @param integer $now Compare with this timestamp (Default value is the current unix timestamp) - * @return string - */ - public function getTaskAge($timestamp, $now = null) - { - if ($now === null) { - $now = time(); + if (! isset(self::$helpers[$name])) { + $class = '\Helper\\'.ucfirst($name); + self::$helpers[$name] = new $class($this->container); } - $diff = $now - $timestamp; - - if ($diff < 3600) { - return t('<1h'); - } - else if ($diff < 86400) { - return t('%dh', $diff / 3600); - } - - return t('%dd', ($now - $timestamp) / 86400); - } - - /** - * Proxy cache helper for acl::isManagerActionAllowed() - * - * @access public - * @param integer $project_id - * @return boolean - */ - public function isManager($project_id) - { - if ($this->userSession->isAdmin()) { - return true; - } - - return $this->container['memoryCache']->proxy('acl', 'isManagerActionAllowed', $project_id); - } - - /** - * Return the user full name - * - * @param array $user User properties - * @return string - */ - public function getFullname(array $user = array()) - { - return $this->user->getFullname(empty($user) ? $_SESSION['user'] : $user); + return self::$helpers[$name]; } /** @@ -113,688 +57,4 @@ class Helper { return htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false); } - - /** - * Add a Javascript asset - * - * @param string $filename Filename - * @return string - */ - public function js($filename) - { - return ''; - } - - /** - * Add a stylesheet asset - * - * @param string $filename Filename - * @param boolean $is_file Add file timestamp - * @param string $media Media - * @return string - */ - public function css($filename, $is_file = true, $media = 'screen') - { - return ''; - } - - /** - * Display the form error class - * - * @param array $errors Error list - * @param string $name Field name - * @return string - */ - public function errorClass(array $errors, $name) - { - return ! isset($errors[$name]) ? '' : ' form-error'; - } - - /** - * Display a list of form errors - * - * @param array $errors List of errors - * @param string $name Field name - * @return string - */ - public function errorList(array $errors, $name) - { - $html = ''; - - if (isset($errors[$name])) { - - $html .= '= t('Do you really want to remove this user: "%s"?', $user['name'] ?: $user['username']) ?>
Test
', $h->markdown('Test')); @@ -32,19 +31,34 @@ class HelperTest extends Base ); } - public function testGetCurrentBaseUrl() + public function testFormatBytes() { - $h = new Helper($this->container); + $h = new Text($this->container); - $_SERVER['PHP_SELF'] = '/'; - $_SERVER['SERVER_NAME'] = 'localhost'; - $_SERVER['SERVER_PORT'] = 1234; + $this->assertEquals('1k', $h->bytes(1024)); + $this->assertEquals('33.71k', $h->bytes(34520)); + } - $this->assertEquals('http://localhost:1234/', $h->getCurrentBaseUrl()); + public function testTruncate() + { + $h = new Text($this->container); - $c = new Config($this->container); - $c->save(array('application_url' => 'https://mykanboard/')); - $this->assertEquals('https://mykanboard/', $c->get('application_url')); - $this->assertEquals('https://mykanboard/', $h->getCurrentBaseUrl()); + $this->assertEquals('abc', $h->truncate('abc')); + $this->assertEquals(str_repeat('a', 85).' [...]', $h->truncate(str_repeat('a', 200))); + } + + public function testContains() + { + $h = new Text($this->container); + + $this->assertTrue($h->contains('abc', 'b')); + $this->assertFalse($h->contains('abc', 'd')); + } + + public function testInList() + { + $h = new Text($this->container); + $this->assertEquals('?', $h->in('a', array('b' => 'c'))); + $this->assertEquals('c', $h->in('b', array('b' => 'c'))); } } diff --git a/tests/units/UrlHelperTest.php b/tests/units/UrlHelperTest.php new file mode 100644 index 000000000..d70842aac --- /dev/null +++ b/tests/units/UrlHelperTest.php @@ -0,0 +1,64 @@ +container); + $this->assertEquals( + 'label', + $h->link('label', 'a', 'b', array('d' => 'e'), false, 'f', 'g', true) + ); + } + + public function testHref() + { + $h = new Url($this->container); + $this->assertEquals( + '?controller=a&action=b&d=e', + $h->href('a', 'b', array('d' => 'e')) + ); + } + + public function testTo() + { + $h = new Url($this->container); + $this->assertEquals( + '?controller=a&action=b&d=e', + $h->to('a', 'b', array('d' => 'e')) + ); + } + + public function testServer() + { + $h = new Url($this->container); + + $_SERVER['PHP_SELF'] = '/'; + $_SERVER['SERVER_NAME'] = 'localhost'; + $_SERVER['SERVER_PORT'] = 1234; + + $this->assertEquals('http://localhost:1234/', $h->server()); + } + + public function testBase() + { + $h = new Url($this->container); + + $_SERVER['PHP_SELF'] = '/'; + $_SERVER['SERVER_NAME'] = 'localhost'; + $_SERVER['SERVER_PORT'] = 1234; + + $this->assertEquals('http://localhost:1234/', $h->base()); + + $c = new Config($this->container); + $c->save(array('application_url' => 'https://mykanboard/')); + + $this->assertEquals('https://mykanboard/', $c->get('application_url')); + $this->assertEquals('https://mykanboard/', $h->base()); + } +}