summaryrefslogtreecommitdiff
path: root/app/Api/Base.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-05-23 21:44:33 -0400
committerFrederic Guillot <fred@kanboard.net>2015-05-23 21:44:33 -0400
commite32f26d048249b84166542d6442efdf202ff44fd (patch)
tree1868c5e83cec5ea8b821ad8a2036543aa37e5adb /app/Api/Base.php
parentc9ba525bab06eff76b1d5fb8701848d0e3990122 (diff)
API refactoring
Diffstat (limited to 'app/Api/Base.php')
-rw-r--r--app/Api/Base.php81
1 files changed, 81 insertions, 0 deletions
diff --git a/app/Api/Base.php b/app/Api/Base.php
new file mode 100644
index 00000000..e9494b58
--- /dev/null
+++ b/app/Api/Base.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace Api;
+
+use Pimple\Container;
+use JsonRPC\AuthenticationFailure;
+use Symfony\Component\EventDispatcher\Event;
+
+/**
+ * Base class
+ *
+ * @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
+{
+ /**
+ * 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
+ *
+ * @access public
+ * @param string $username
+ * @param string $password
+ * @param string $class
+ * @param string $method
+ */
+ public function authentication($username, $password, $class, $method)
+ {
+ $this->container['dispatcher']->dispatch('api.bootstrap', new Event);
+
+ if (! ($username === 'jsonrpc' && $password === $this->config->get('api_token'))) {
+ throw new AuthenticationFailure('Wrond credentials');
+ }
+ }
+}