Skip to content

Commit

Permalink
[v0.0.1] module rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Calef committed Nov 5, 2021
0 parents commit 50ccd25
Show file tree
Hide file tree
Showing 30 changed files with 1,918 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Exception/ExternalException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* This file is part of Zepgram\Rest\Exception
*
* @package Zepgram\Rest\Exception
* @file ExternalException.php
* @date 04 11 2021 23:28
*
* @author Benjamin Calef <[email protected]>
* @copyright 2021 Zepgram Copyright (c) (https://github.com/zepgram)
* @license MIT License
**/

declare(strict_types=1);

namespace Zepgram\Rest\Exception;

class ExternalException extends RestException
{

}
21 changes: 21 additions & 0 deletions Exception/InternalException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* This file is part of Zepgram\Rest\Exception
*
* @package Zepgram\Rest\Exception
* @file InternalException.php
* @date 04 11 2021 23:28
*
* @author Benjamin Calef <[email protected]>
* @copyright 2021 Zepgram Copyright (c) (https://github.com/zepgram)
* @license MIT License
**/

declare(strict_types=1);

namespace Zepgram\Rest\Exception;

class InternalException extends RestException
{

}
23 changes: 23 additions & 0 deletions Exception/RestException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* This file is part of Zepgram\Rest\Exception
*
* @package Zepgram\Rest\Exception
* @file RestException.php
* @date 04 11 2021 23:28
*
* @author Benjamin Calef <[email protected]>
* @copyright 2021 Zepgram Copyright (c) (https://github.com/zepgram)
* @license MIT License
**/

declare(strict_types=1);

namespace Zepgram\Rest\Exception;

use Magento\Framework\Exception\LocalizedException;

class RestException extends LocalizedException
{

}
23 changes: 23 additions & 0 deletions Exception/Result/BusinessException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* This file is part of Zepgram\Rest\Exception\Result
*
* @package Zepgram\Rest\Exception\Result
* @file BusinessException.php
* @date 04 11 2021 23:22
*
* @author Benjamin Calef <[email protected]>
* @copyright 2021 Zepgram Copyright (c) (https://github.com/zepgram)
* @license MIT License
**/

declare(strict_types=1);

namespace Zepgram\Rest\Exception\Result;

use Zepgram\Rest\Exception\InternalException;

class BusinessException extends InternalException
{

}
36 changes: 36 additions & 0 deletions Exception/Result/HttpException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* This file is part of Zepgram\Rest\Exception\Result
*
* @package Zepgram\Rest\Exception\Result
* @file HttpException.php
* @date 04 11 2021 23:22
*
* @author Benjamin Calef <[email protected]>
* @copyright 2021 Zepgram Copyright (c) (https://github.com/zepgram)
* @license MIT License
**/

declare(strict_types=1);

namespace Zepgram\Rest\Exception\Result;

use Exception;
use Magento\Framework\Phrase;
use Zepgram\Rest\Exception\ExternalException;

class HttpException extends ExternalException
{
/**
* @throws ExternalException
*/
public function __construct(Phrase $phrase, Exception $cause = null, $code = 0)
{
parent::__construct($phrase, $cause, $code);
if ($cause && $cause->getCode() && ($code === 0 || $code === null)) {
$code = $cause->getCode();
}

throw new ExternalException(__($phrase), $cause, $code);
}
}
23 changes: 23 additions & 0 deletions Exception/Result/NotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* This file is part of Zepgram\Rest\Exception\Result
*
* @package Zepgram\Rest\Exception\Result
* @file NotFoundException.php
* @date 04 11 2021 23:22
*
* @author Benjamin Calef <[email protected]>
* @copyright 2021 Zepgram Copyright (c) (https://github.com/zepgram)
* @license MIT License
**/

declare(strict_types=1);

namespace Zepgram\Rest\Exception\Result;

use Zepgram\Rest\Exception\ExternalException;

class NotFoundException extends ExternalException
{

}
23 changes: 23 additions & 0 deletions Exception/Result/UnserializeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* This file is part of Zepgram\Rest\Exception\Result
*
* @package Zepgram\Rest\Exception\Result
* @file UnserializeException.php
* @date 04 11 2021 23:22
*
* @author Benjamin Calef <[email protected]>
* @copyright 2021 Zepgram Copyright (c) (https://github.com/zepgram)
* @license MIT License
**/

declare(strict_types=1);

namespace Zepgram\Rest\Exception\Result;

use Zepgram\Rest\Exception\ExternalException;

class UnserializeException extends ExternalException
{

}
23 changes: 23 additions & 0 deletions Exception/Technical/InvalidContractException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* This file is part of Zepgram\Rest\Exception\Technical
*
* @package Zepgram\Rest\Exception\Technical
* @file InvalidContractException.php
* @date 04 11 2021 23:22
*
* @author Benjamin Calef <[email protected]>
* @copyright 2021 Zepgram Copyright (c) (https://github.com/zepgram)
* @license MIT License
**/

declare(strict_types=1);

namespace Zepgram\Rest\Exception\Technical;

use Zepgram\Rest\Exception\RestException;

class InvalidContractException extends RestException
{

}
23 changes: 23 additions & 0 deletions Exception/Technical/LogicException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* This file is part of Zepgram\Rest\Exception\Technical
*
* @package Zepgram\Rest\Exception\Technical
* @file LogicException.php
* @date 04 11 2021 23:22
*
* @author Benjamin Calef <[email protected]>
* @copyright 2021 Zepgram Copyright (c) (https://github.com/zepgram)
* @license MIT License
**/

declare(strict_types=1);

namespace Zepgram\Rest\Exception\Technical;

use Zepgram\Rest\Exception\RestException;

class LogicException extends RestException
{

}
23 changes: 23 additions & 0 deletions Exception/Technical/MissingBaseUriException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* This file is part of Zepgram\Rest\Exception\Technical
*
* @package Zepgram\Rest\Exception\Technical
* @file LogicException.php
* @date 04 11 2021 23:22
*
* @author Benjamin Calef <[email protected]>
* @copyright 2021 Zepgram Copyright (c) (https://github.com/zepgram)
* @license MIT License
**/

declare(strict_types=1);

namespace Zepgram\Rest\Exception\Technical;

use Zepgram\Rest\Exception\RestException;

class MissingBaseUriException extends RestException
{

}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Zepgram - Benjamin Calef

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
52 changes: 52 additions & 0 deletions Model/Cache/Identifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* This file is part of Zepgram\Rest\Model\Cache
*
* @package Zepgram\Rest\Model\Cache
* @file Identifier.php
* @date 04 11 2021 23:28
*
* @author Benjamin Calef <[email protected]>
* @copyright 2021 Zepgram Copyright (c) (https://github.com/zepgram)
* @license MIT License
**/

declare(strict_types=1);

namespace Zepgram\Rest\Model\Cache;

use Magento\Framework\Encryption\Encryptor;
use Zepgram\Rest\Model\ParametersInterface;

class Identifier
{
/** @var Encryptor */
private $encryptor;

/**
* @param Encryptor $encryptor
*/
public function __construct(Encryptor $encryptor)
{
$this->encryptor = $encryptor;
}

/**
* @param ParametersInterface $parameters
* @return string
*/
public function getCacheKey(ParametersInterface $parameters): string
{
return $this->encryptor->hash($parameters->getServiceName() . '_' . $parameters->getCacheKey());
}

/**
* @param string $serviceName
* @param $data
* @return string
*/
public function getRegistryKey(string $serviceName, $data): string
{
return $this->encryptor->hash($serviceName . '_' . $data);
}
}
36 changes: 36 additions & 0 deletions Model/Cache/RestApiCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* This file is part of Zepgram\Rest\Model\Cache
*
* @package Zepgram\Rest\Model\Cache
* @file RestApiCache.php
* @date 04 11 2021 23:28
*
* @author Benjamin Calef <[email protected]>
* @copyright 2021 Zepgram Copyright (c) (https://github.com/zepgram)
* @license MIT License
**/

declare(strict_types=1);

namespace Zepgram\Rest\Model\Cache;

use Magento\Framework\App\Cache\Type\FrontendPool;
use Magento\Framework\Cache\Frontend\Decorator\TagScope;

class RestApiCache extends TagScope
{
/** @var string */
public const TYPE_IDENTIFIER = 'rest_api_result';

/** @var string */
public const CACHE_TAG = 'REST_API_RESULT';

/**
* @param FrontendPool $cacheFrontendPool
*/
public function __construct(FrontendPool $cacheFrontendPool)
{
parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG);
}
}
Loading

0 comments on commit 50ccd25

Please sign in to comment.