JRA, PHP cAPI interface
  • Namespace
  • Class
  • Tree

Namespaces

  • JRA
    • Abstracts
    • Commands
      • Invokers
      • Methods
        • Content
        • Token
        • User
      • Routes
    • ComposerHandler
    • Config
      • Helper
    • Exceptions
    • Facades
    • Factories
    • Interfaces
    • Objects
      • Response
        • Data
    • Responsibilities
      • Handlers
      • Responsible
        • Login
        • Logout

Classes

  • JRA\Abstracts\AbstractCommand
  • JRA\Abstracts\AbstractMethod
  • JRA\Commands\ContentCommand
  • JRA\Commands\Invokers\CommandInvoker
  • JRA\Commands\Methods\Content\DeleteContentId
  • JRA\Commands\Methods\Content\GetCategoryFields
  • JRA\Commands\Methods\Content\GetCategoryListAll
  • JRA\Commands\Methods\Content\GetCategoryListIdCategories
  • JRA\Commands\Methods\Content\GetCategoryListIdContent
  • JRA\Commands\Methods\Content\GetCategorySingleId
  • JRA\Commands\Methods\Content\GetContentFields
  • JRA\Commands\Methods\Content\GetContentListAll
  • JRA\Commands\Methods\Content\GetContentSingleId
  • JRA\Commands\Methods\Content\PostContentCreate
  • JRA\Commands\Methods\Content\PostContentUpdateId
  • JRA\Commands\Methods\Token\GetTokenToken
  • JRA\Commands\Methods\User\GetUser
  • JRA\Commands\Methods\User\GetUserLoginUsernamePassword
  • JRA\Commands\Methods\User\GetUserLogoutUserSession
  • JRA\Commands\Methods\User\GetUserSessions
  • JRA\Commands\Methods\User\PutUserProfile
  • JRA\Commands\Methods\User\PutUserProfileId
  • JRA\Commands\Routes\ContentRoutes
  • JRA\Commands\Routes\TokenRoutes
  • JRA\Commands\Routes\UserRoutes
  • JRA\Commands\TokenCommand
  • JRA\Commands\UserCommand
  • JRA\ComposerHandler\GuzzleHandler
  • JRA\Config\ARSAnnatech
  • JRA\Config\Authenticate
  • JRA\Config\Helper\APIRoutes
  • JRA\Config\Helper\Versions
  • JRA\Config\Server
  • JRA\Config\Version
  • JRA\Facades\APIFacade
  • JRA\Facades\ConfigFacade
  • JRA\Factories\ChainFactory
  • JRA\Factories\CommandFactory
  • JRA\Factories\ConfigFactory
  • JRA\Factories\GuzzleFactory
  • JRA\Factories\InternalFactory
  • JRA\FrontFactory
  • JRA\Objects\CreateContentObject
  • JRA\Objects\Response\CategoryFieldsResponseObject
  • JRA\Objects\Response\CategoryListResponseObject
  • JRA\Objects\Response\CategoryResponseObject
  • JRA\Objects\Response\ContentDeleteResponseObject
  • JRA\Objects\Response\ContentFieldsResponseObject
  • JRA\Objects\Response\ContentListResponseObject
  • JRA\Objects\Response\ContentResponseObject
  • JRA\Objects\Response\Data\CategoryObject
  • JRA\Objects\Response\Data\ContentObject
  • JRA\Objects\Response\Data\DatabaseFieldObject
  • JRA\Objects\Response\Data\SessionObject
  • JRA\Objects\Response\JResponseObject
  • JRA\Objects\Response\MsgResponseObject
  • JRA\Objects\Response\SessionResponseObject
  • JRA\Objects\Response\UserLoginResponseObject
  • JRA\Objects\Response\UserLogoutResponseObject
  • JRA\Objects\StateObject
  • JRA\Objects\UpdateContentObject
  • JRA\Objects\UpdateUserProfileObject
  • JRA\Responsibilities\Handlers\AbstractLoginHandler
  • JRA\Responsibilities\Handlers\AbstractLogoutHandler
  • JRA\Responsibilities\Responsible\Login\HeaderTokenLogin
  • JRA\Responsibilities\Responsible\Login\TokenLogin
  • JRA\Responsibilities\Responsible\Login\UserCredentialsLogin
  • JRA\Responsibilities\Responsible\Logout\TokenLogout
  • JRA\Responsibilities\Responsible\Logout\UserCredentialsLogout

Interfaces

  • JRA\Interfaces\ConfigInterface

Exceptions

  • JRA\Exceptions\APIException
  • JRA\Exceptions\AuthenticationConfigException
  • JRA\Exceptions\CommandException
  • JRA\Exceptions\JRAException
  • JRA\Exceptions\ServerConfigException
  • JRA\Exceptions\TokenConfigException
  • JRA\Exceptions\UserAPIException
  • JRA\Exceptions\UserCredentialsConfigException
  • JRA\Exceptions\VersionException
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 
<?php
/**
 * Created by PhpStorm.
 * Copyright: Bertschi AG, 2016
 * User: jbaumann
 * File: APIFacade.php
 * Date: 05.01.2016
 * Time: 13:25
 */

namespace JRA\Facades;


use JRA\Commands\Routes\ContentRoutes;
use JRA\Commands\Routes\TokenRoutes;
use JRA\Commands\Routes\UserRoutes;
use JRA\Exceptions\UserAPIException;
use JRA\Factories\InternalFactory;
use JRA\Interfaces\ConfigInterface;
use JRA\Objects\CreateContentObject;
use JRA\Objects\Response\CategoryFieldsResponseObject;
use JRA\Objects\Response\CategoryListResponseObject;
use JRA\Objects\Response\CategoryResponseObject;
use JRA\Objects\Response\ContentDeleteResponseObject;
use JRA\Objects\Response\ContentFieldsResponseObject;
use JRA\Objects\Response\ContentListResponseObject;
use JRA\Objects\Response\ContentResponseObject;
use JRA\Objects\Response\JResponseObject;
use JRA\Objects\Response\MsgResponseObject;
use JRA\Objects\Response\SessionResponseObject;
use JRA\Objects\Response\UserLoginResponseObject;
use JRA\Objects\Response\UserLogoutResponseObject;
use JRA\Objects\UpdateContentObject;
use stdClass;

class APIFacade
{

    /**
     * The configuration for the requests.
     *
     * @var ConfigInterface
     */
    private $_config;

    /**
     * The internal factory for all internal object creations.
     *
     * @var InternalFactory
     */
    private $_internalFactory;

    /**
     * APIFacade constructor.
     *
     * @param ConfigInterface $pConfig The configuration of the request.
     * @param InternalFactory $pInternalFactory The factory which is used internal for creating objects.
     */
    public function __construct(ConfigInterface $pConfig, InternalFactory $pInternalFactory)
    {
        $this->_config = $pConfig;
        $this->_internalFactory = $pInternalFactory;
    }

    /**
     * Login on the website, without depending on an authentication method.
     *
     * @return bool|stdClass Returns false on failure or json decoded response object as stdClass.
     */
    public function login()
    {
        $loginChain = $this->_internalFactory
            ->getChainFactory()
            ->getLoginChain();
        return $loginChain->handle($this->_config, $this->_internalFactory);
    }

    /**
     * Logout on the website, without depending on an authentication method.
     *
     * @return bool|stdClass Returns false on failure or json decoded response object as stdClass.
     */
    public function logout()
    {
        $logoutChain = $this->_internalFactory
            ->getChainFactory()
            ->getLogoutChain();
        return $logoutChain->handle($this->_config, $this->_internalFactory);
    }

    /**
     * Get all active sessions.
     *
     * @return SessionResponseObject Returns the response in an functionality providing object.
     */
    public function getSessions()
    {
        $userCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getUserCommand($this->_config, UserRoutes::GET_USER_SESSIONS);
        $userCommand->run();
        return new SessionResponseObject($userCommand->getContents());
    }

    /**
     * Update the own user profile.
     *
     * @throws UserAPIException This functionality is not supported yet.
     */
    public function updateProfile()
    {
        throw new UserAPIException('Not supported yet!');
    }

    /**
     * Update user profile of other users by id.
     *
     * @throws UserAPIException This functionality is not supported yet.
     */
    public function updateProfileById()
    {
        throw new UserAPIException('Not supported yet!');
    }

    /**
     * Get all categories from joomla.
     *
     * @return CategoryListResponseObject Returns the response in an functionality providing object.
     */
    public function getAllCategories()
    {
        $contentCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getContentCommand($this->_config, ContentRoutes::GET_CATEGORY_LIST_ALL);
        $contentCommand->run();
        return new CategoryListResponseObject($contentCommand->getContents());
    }

    /**
     * Get all categories which are a subcategory an parent category, which is selected by id.
     *
     * @param int $pId The parent id if for selecting all child categories.
     * @return CategoryListResponseObject Returns the response in an functionality providing object.
     */
    public function getAllSubCategoriesByParentId($pId)
    {
        $contentCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getContentCommand($this->_config, ContentRoutes::GET_CATEGORY_LIST_ID_CATEGORIES, ['id' => $pId]);
        $contentCommand->run();
        return new CategoryListResponseObject($contentCommand->getContents());
    }

    /**
     * Get all content from joomla.
     *
     * @return ContentListResponseObject Returns the response in an functionality providing object.
     */
    public function getAllContents()
    {
        $contentCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getContentCommand($this->_config, ContentRoutes::GET_CONTENT_LIST_ALL);
        $contentCommand->run();
        return new ContentListResponseObject($contentCommand->getContents());
    }

    /**
     * Get all database fields with the field configuration from an category.
     *
     * @return CategoryFieldsResponseObject Returns the response in an functionality providing object.
     */
    public function getAllCategoryFields()
    {
        $contentCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getContentCommand($this->_config, ContentRoutes::GET_CATEGORY_FIELDS);
        $contentCommand->run();
        return new CategoryFieldsResponseObject($contentCommand->getContents());
    }

    /**
     * Get all content which is under one category by id.
     *
     * @param int $pId The category id for selecting all contents under this category.
     * @return ContentListResponseObject Returns the response in an functionality providing object.
     */
    public function getAllContentsByCategoryId($pId)
    {
        $contentCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getContentCommand($this->_config, ContentRoutes::GET_CATEGORY_LIST_ID_CONTENT, ['id' => $pId]);
        $contentCommand->run();
        return new ContentListResponseObject($contentCommand->getContents());
    }

    /**
     * Get an single category by id.
     *
     * @param int $pId The category id to select this record.
     * @return CategoryListResponseObject Returns the response in an functionality providing object.
     */
    public function getCategoryById($pId)
    {
        $contentCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getContentCommand($this->_config, ContentRoutes::GET_CATEGORY_SINGLE_ID, ['id' => $pId]);
        $contentCommand->run();
        return new CategoryResponseObject($contentCommand->getContents());
    }

    /**
     * Get all database fields with the field configuration from an content.
     *
     * @return ContentFieldsResponseObject Returns the response in an functionality providing object.
     */
    public function getAllContentFields()
    {
        $contentCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getContentCommand($this->_config, ContentRoutes::GET_CONTENT_FIELDS);
        $contentCommand->run();
        return new ContentFieldsResponseObject($contentCommand->getContents());
    }

    /**
     * Delete an content by id.
     *
     * @param int $pId The content id to delete this record.
     * @return ContentResponseObject Returns the response in an functionality providing object.
     */
    public function deleteContentById($pId)
    {
        $contentCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getContentCommand($this->_config, ContentRoutes::GET_CONTENT_DELETE_ID, ['id' => $pId]);
        $contentCommand->run();
        return new ContentDeleteResponseObject($contentCommand->getContents());
    }

    /**
     * Get an single content by id.
     *
     * @param int $pId The content id to select this record.
     * @return ContentResponseObject Returns the response in an functionality providing object.
     */
    public function getContentById($pId)
    {
        $contentCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getContentCommand($this->_config, ContentRoutes::GET_CONTENT_SINGLE_ID, ['id' => $pId]);
        $contentCommand->run();
        return new ContentResponseObject($contentCommand->getContents());
    }

    /**
     * Create an content from an create content object.
     *
     * @param CreateContentObject $pContent The object with all information in it to create a content.
     * @return MsgResponseObject Returns the response in an functionality providing object.
     */
    public function createContent(CreateContentObject $pContent)
    {
        $params = $pContent->getRequestParams();

        $contentCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getContentCommand($this->_config, ContentRoutes::POST_CONTENT_CREATE, $params);
        $contentCommand->run();
        return new MsgResponseObject($contentCommand->getContents());
    }

    /**
     * Update an content by an update content object.
     * The id for updating the right content is inside the update content object.
     *
     * @param UpdateContentObject $pContent The object with all information in it to update a content.
     * @param int $pId The content id of the content which should be updated.
     * @return MsgResponseObject Returns the response in an functionality providing object.
     */
    public function updateContentById(UpdateContentObject $pContent, $pId)
    {
        $params = $pContent->getRequestParams();
        $params['id'] = $pId;

        $contentCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getContentCommand($this->_config, ContentRoutes::POST_CONTENT_UPDATE_ID, $params);
        $contentCommand->run();
        return new MsgResponseObject($contentCommand->getContents());
    }

    /**
     * Make an login request with an token.
     *
     * @param string $pToken The token for login at the cAPI.
     * @return JResponseObject Returns the response in an functionality providing object.
     */
    public function loginToken($pToken)
    {
        $tokenCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getTokenCommand($this->_config, TokenRoutes::GET_TOKEN_TOKEN, ['token' => $pToken]);
        $tokenCommand->run();
        return new JResponseObject($tokenCommand->getContents());
    }

    /**
     * Login with the user credentials.
     *
     * @param string $pUsername The username which is used to login at the cAPI.
     * @param string $pPassword The password which is used to login at the cAPI.
     * @return UserLoginResponseObject Returns the response in an functionality providing object.
     */
    public function loginUserCredentials($pUsername, $pPassword)
    {
        $params = [
            'username' => $pUsername,
            'password' => $pPassword
        ];

        $userCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getUserCommand($this->_config, UserRoutes::GET_USER_LOGIN_USERNAME_PASSWORD, $params);
        $userCommand->run();
        return new UserLoginResponseObject($userCommand->getContents());
    }

    /**
     * Logout an specified user session.
     *
     * @param string $pUsername The username which is used to get the correct session.
     * @param string $pSession The password which is used to get the correct session.
     * @return UserLogoutResponseObject Returns the response in an functionality providing object.
     */
    public function logoutUserSession($pUsername, $pSession)
    {
        $params = [
            'username' => $pUsername,
            'session' => $pSession
        ];

        $userCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getUserCommand($this->_config, UserRoutes::GET_USER_LOGOUT_USER_SESSION, $params);
        $userCommand->run();
        return new UserLogoutResponseObject($userCommand->getContents());
    }

    /**
     * Get the current logged in user.
     *
     * @return UserLogoutResponseObject Returns the response in an functionality providing object.
     */
    public function getCurrentUser()
    {
        $userCommand = $this->_internalFactory
            ->getCommandFactory()
            ->getUserCommand($this->_config, UserRoutes::GET_USER);
        $userCommand->run();
        return new MsgResponseObject($userCommand->getContents());
    }
}
JRA, PHP cAPI interface API documentation generated by ApiGen