simple serializer and deserializer with models, new architecture
This commit is contained in:
parent
1451d0c230
commit
923292a224
28 changed files with 4132 additions and 41 deletions
307
intaro.retailcrm/RetailcrmClasspathBuilder.php
Normal file
307
intaro.retailcrm/RetailcrmClasspathBuilder.php
Normal file
|
@ -0,0 +1,307 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Class RetailcrmClasspathBuilder.
|
||||
* Builds classpath for Bitrix autoloader. Contains some hardcoded things, which will go away when everything refactored.
|
||||
*/
|
||||
class RetailcrmClasspathBuilder
|
||||
{
|
||||
/**
|
||||
* File extension as a string. Defaults to ".php".
|
||||
* @var string
|
||||
*/
|
||||
protected $fileExt = 'php';
|
||||
|
||||
/**
|
||||
* @var string $moduleId
|
||||
*/
|
||||
protected $moduleId = 'intaro.retailcrm';
|
||||
|
||||
/**
|
||||
* The topmost directory where recursion should begin. Default: `classes/general`. Relative to the __DIR__.
|
||||
* @var string
|
||||
*/
|
||||
protected $path = 'classes/general';
|
||||
|
||||
/**
|
||||
* Do not include directory paths as namespaces.
|
||||
* @var bool
|
||||
*/
|
||||
protected $disableNamespaces;
|
||||
|
||||
/**
|
||||
* Bitrix document root
|
||||
* @var string
|
||||
*/
|
||||
protected $documentRoot;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $version;
|
||||
|
||||
/**
|
||||
* @var array $result
|
||||
*/
|
||||
protected $result = [];
|
||||
|
||||
/**
|
||||
* @var array $notIncluded
|
||||
*/
|
||||
protected $notIncluded = [];
|
||||
|
||||
/**
|
||||
* These classes can be customized, in which case they would be replaced with files from
|
||||
* directory <root>/bitrix/php_interface/retailcrm
|
||||
*
|
||||
* Array format:
|
||||
* [
|
||||
* 'class path with namespace' => 'file name'
|
||||
* ]
|
||||
*/
|
||||
protected static $customizableClasses = [
|
||||
'RestNormalizer' => 'RestNormalizer.php',
|
||||
'Logger' => 'Logger.php',
|
||||
'RetailCrm\ApiClient' => 'ApiClient_v5.php',
|
||||
'RetailCrm\Http\Client' => 'Client.php',
|
||||
'RCrmActions' => 'RCrmActions.php',
|
||||
'RetailCrmUser' => 'RetailCrmUser.php',
|
||||
'RetailCrmICML' => 'RetailCrmICML.php',
|
||||
'RetailCrmInventories' => 'RetailCrmInventories.php',
|
||||
'RetailCrmPrices' => 'RetailCrmPrices.php',
|
||||
'RetailCrmCollector' => 'RetailCrmCollector.php',
|
||||
'RetailCrmUa' => 'RetailCrmUa.php',
|
||||
'RetailCrmEvent' => 'RetailCrmEvent.php',
|
||||
'RetailCrmCorporateClient' => 'RetailCrmCorporateClient.php'
|
||||
];
|
||||
|
||||
/**
|
||||
* These classes can be customized, in which case they would be replaced with files from
|
||||
* directory <root>/bitrix/php_interface/retailcrm
|
||||
* Customized versions have fixed name, and original versions name depends on API version
|
||||
*
|
||||
* Array format:
|
||||
* [
|
||||
* 'class path with namespace' => ['customized file name', 'original file name with %s for API version']
|
||||
* ]
|
||||
*/
|
||||
protected static $versionedClasses = [
|
||||
'RetailCrm\ApiClient' => ['ApiClient.php', 'ApiClient_%s.php'],
|
||||
'RetailCrmOrder' => ['RetailCrmOrder.php', 'RetailCrmOrder_%s.php'],
|
||||
'RetailCrmHistory' => ['RetailCrmHistory.php', 'RetailCrmHistory_%s.php']
|
||||
];
|
||||
|
||||
/**
|
||||
* These classes will be ignored while loading from original files
|
||||
*/
|
||||
protected static $ignoredClasses = [
|
||||
'ApiClient_v4.php',
|
||||
'ApiClient_v5.php',
|
||||
'RetailCrmOrder_v4.php',
|
||||
'RetailCrmOrder_v5.php',
|
||||
'RetailCrmHistory_v4.php',
|
||||
'RetailCrmHistory_v5.php',
|
||||
];
|
||||
|
||||
/**
|
||||
* These namespaces are hardcoded.
|
||||
*/
|
||||
protected static $hardcodedNamespaces = [
|
||||
'RetailCrm\Response\ApiResponse' => 'ApiResponse.php',
|
||||
'RetailCrm\Exception\InvalidJsonException' => 'InvalidJsonException.php',
|
||||
'RetailCrm\Exception\CurlException' => 'CurlException.php'
|
||||
];
|
||||
|
||||
protected function buildCustomizableClasspath()
|
||||
{
|
||||
foreach (static::$customizableClasses as $className => $fileName) {
|
||||
$customizedFile = $this->documentRoot . '/bitrix/php_interface/retailcrm/' . $fileName;
|
||||
|
||||
if (file_exists($customizedFile)) {
|
||||
$this->result[$className] = $customizedFile;
|
||||
} else {
|
||||
$this->notIncluded[$className] = $fileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function buildVersionedClasspath()
|
||||
{
|
||||
foreach (static::$versionedClasses as $className => $fileNames) {
|
||||
$customizedFile = $this->documentRoot . '/bitrix/php_interface/retailcrm/' . $fileNames[0];
|
||||
|
||||
if (file_exists($customizedFile)) {
|
||||
$this->result[$className] = $customizedFile;
|
||||
} else {
|
||||
$this->notIncluded[$className] = sprintf($fileNames[1], $this->version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverse through directories, build include paths
|
||||
* @return $this
|
||||
*/
|
||||
public function build(): self
|
||||
{
|
||||
$directory = new RecursiveDirectoryIterator(
|
||||
$this->getSearchPath(),
|
||||
RecursiveDirectoryIterator::SKIP_DOTS
|
||||
);
|
||||
$fileIterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::LEAVES_ONLY);
|
||||
|
||||
$this->buildCustomizableClasspath();
|
||||
$this->buildVersionedClasspath();
|
||||
$notIncludedClasses = array_flip($this->notIncluded);
|
||||
$hardcodedNamespaces = array_flip(static::$hardcodedNamespaces);
|
||||
|
||||
/** @var \SplFileObject $file */
|
||||
foreach ($fileIterator as $file) {
|
||||
$fileNameWithoutExt = str_ireplace('.' . $this->fileExt, '', $file->getFilename());
|
||||
|
||||
if ($file->getExtension() !== $this->fileExt) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($file->getFilename(), static::$customizableClasses)
|
||||
|| in_array($file->getFilename(), static::$ignoredClasses)
|
||||
) {
|
||||
if (in_array($file->getFilename(), $this->notIncluded)) {
|
||||
$this->result[$notIncludedClasses[$file->getFilename()]] = $this->getImportPath($file->getPathname());
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($file->getFilename(), static::$hardcodedNamespaces)) {
|
||||
$this->result[$hardcodedNamespaces[$file->getFilename()]] = $this->getImportPath($file->getPathname());
|
||||
} else {
|
||||
$this->result[$this->getImportClass($fileNameWithoutExt, $file->getPath())] = $this->getImportPath($file->getPathname());
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the $fileExt property
|
||||
*
|
||||
* @param string $fileExt The file extension used for class files. Default is "php".
|
||||
*
|
||||
* @return \RetailcrmClasspathBuilder
|
||||
*/
|
||||
public function setFileExt($fileExt)
|
||||
{
|
||||
$this->fileExt = $fileExt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $documentRoot
|
||||
*
|
||||
* @return RetailcrmClasspathBuilder
|
||||
*/
|
||||
public function setDocumentRoot(string $documentRoot): RetailcrmClasspathBuilder
|
||||
{
|
||||
$this->documentRoot = $documentRoot;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the $path property
|
||||
*
|
||||
* @param string $path Top path to load files
|
||||
*
|
||||
* @return \RetailcrmClasspathBuilder
|
||||
*/
|
||||
public function setPath(string $path)
|
||||
{
|
||||
$this->path = $path;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $disableNamespaces
|
||||
*
|
||||
* @return RetailcrmClasspathBuilder
|
||||
*/
|
||||
public function setDisableNamespaces($disableNamespaces)
|
||||
{
|
||||
$this->disableNamespaces = $disableNamespaces;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $moduleId
|
||||
*
|
||||
* @return RetailcrmClasspathBuilder
|
||||
*/
|
||||
public function setModuleId(string $moduleId): RetailcrmClasspathBuilder
|
||||
{
|
||||
$this->moduleId = $moduleId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $version
|
||||
*
|
||||
* @return RetailcrmClasspathBuilder
|
||||
*/
|
||||
public function setVersion(string $version): RetailcrmClasspathBuilder
|
||||
{
|
||||
$this->version = $version;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getResult(): array
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getSearchPath(): string
|
||||
{
|
||||
return __DIR__ . DIRECTORY_SEPARATOR . $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filePath
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getImportPath(string $filePath): string
|
||||
{
|
||||
return (string) str_ireplace(implode(DIRECTORY_SEPARATOR, [
|
||||
$this->documentRoot,
|
||||
'bitrix',
|
||||
'modules',
|
||||
$this->moduleId
|
||||
]) . DIRECTORY_SEPARATOR, '', $filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fileNameWithoutExt
|
||||
* @param string $filePath
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getImportClass(string $fileNameWithoutExt, string $filePath): string
|
||||
{
|
||||
if ($this->disableNamespaces) {
|
||||
return $fileNameWithoutExt;
|
||||
}
|
||||
|
||||
$importClass = str_ireplace($this->getSearchPath(), '', $filePath). '\\' . $fileNameWithoutExt;
|
||||
|
||||
if (strlen($importClass) > 0 && $importClass[0] === '/') {
|
||||
$importClass = '\\' . substr($importClass, 1);
|
||||
}
|
||||
|
||||
return (string) str_replace(DIRECTORY_SEPARATOR, '\\', $importClass);
|
||||
}
|
||||
}
|
|
@ -1,43 +1,19 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . '/RetailcrmClasspathBuilder.php';
|
||||
|
||||
$retailcrmModuleId = 'intaro.retailcrm';
|
||||
$server = \Bitrix\Main\Context::getCurrent()->getServer()->getDocumentRoot();
|
||||
$version = COption::GetOptionString('intaro.retailcrm', 'api_version');
|
||||
|
||||
CModule::AddAutoloadClasses(
|
||||
'intaro.retailcrm', // module name
|
||||
array (
|
||||
'RetailcrmDependencyLoader' => 'classes/general/RetailcrmDependencyLoader.php',
|
||||
'RestNormalizer' => file_exists($server . '/bitrix/php_interface/retailcrm/RestNormalizer.php') ? '../../php_interface/retailcrm/RestNormalizer.php' : 'classes/general/RestNormalizer.php',
|
||||
'Logger' => file_exists($server . '/bitrix/php_interface/retailcrm/Logger.php') ? '../../php_interface/retailcrm/Logger.php' : 'classes/general/Logger.php',
|
||||
'RetailCrm\ApiClient' => file_exists($server . '/bitrix/php_interface/retailcrm/ApiClient.php') ? '../../php_interface/retailcrm/ApiClient.php' : 'classes/general/ApiClient_' . $version . '.php',
|
||||
'RetailCrm\Http\Client' => file_exists($server . '/bitrix/php_interface/retailcrm/Client.php') ? '../../php_interface/retailcrm/Client.php' : 'classes/general/Http/Client.php',
|
||||
'RCrmActions' => file_exists($server . '/bitrix/php_interface/retailcrm/RCrmActions.php') ? '../../php_interface/retailcrm/RCrmActions.php' : 'classes/general/RCrmActions.php',
|
||||
'RetailCrmUser' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmUser.php') ? '../../php_interface/retailcrm/RetailCrmUser.php' : 'classes/general/user/RetailCrmUser.php',
|
||||
'RetailCrmOrder' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmOrder.php') ? '../../php_interface/retailcrm/RetailCrmOrder.php' : 'classes/general/order/RetailCrmOrder_' . $version . '.php',
|
||||
'RetailCrmHistory' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmHistory.php') ? '../../php_interface/retailcrm/RetailCrmHistory.php' : 'classes/general/history/RetailCrmHistory_' . $version . '.php',
|
||||
'RetailCrmICML' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmICML.php') ? '../../php_interface/retailcrm/RetailCrmICML.php' : 'classes/general/icml/RetailCrmICML.php',
|
||||
'RetailCrmInventories' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmInventories.php') ? '../../php_interface/retailcrm/RetailCrmInventories.php' : 'classes/general/inventories/RetailCrmInventories.php',
|
||||
'RetailCrmPrices' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmPrices.php') ? '../../php_interface/retailcrm/RetailCrmPrices.php' : 'classes/general/prices/RetailCrmPrices.php',
|
||||
'RetailCrmCollector' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmCollector.php') ? '../../php_interface/retailcrm/RetailCrmCollector.php' : 'classes/general/collector/RetailCrmCollector.php',
|
||||
'RetailCrmUa' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmUa.php') ? '../../php_interface/retailcrm/RetailCrmUa.php' : 'classes/general/ua/RetailCrmUa.php',
|
||||
'RetailCrmEvent' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmEvent.php') ? '../../php_interface/retailcrm/RetailCrmEvent.php' : 'classes/general/events/RetailCrmEvent.php',
|
||||
'RetailCrm\Response\ApiResponse' => 'classes/general/Response/ApiResponse.php',
|
||||
'RetailCrm\Exception\InvalidJsonException' => 'classes/general/Exception/InvalidJsonException.php',
|
||||
'RetailCrm\Exception\CurlException' => 'classes/general/Exception/CurlException.php',
|
||||
'RetailCrmCorporateClient' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmCorporateClient.php') ? '../../php_interface/retailcrm/RetailCrmCorporateClient.php' : 'classes/general/user/RetailCrmCorporateClient.php',
|
||||
'RetailcrmConfigProvider' => 'classes/general/RetailcrmConfigProvider.php',
|
||||
'RetailcrmConstants' => 'classes/general/RetailcrmConstants.php',
|
||||
'RetailcrmBuilderInterface' => 'classes/general/RetailcrmBuilderInterface.php',
|
||||
'CustomerBuilder' => 'classes/general/CustomerBuilder.php',
|
||||
'CorporateCustomerBuilder' => 'classes/general/CorporateCustomerBuilder.php',
|
||||
'Customer' => 'classes/general/Model/Customer.php',
|
||||
'CustomerAddress' => 'classes/general/Model/CustomerAddress.php',
|
||||
'CustomerContragent' => 'classes/general/Model/CustomerContragent.php',
|
||||
'BuyerProfile' => 'classes/general/Model/BuyerProfile.php',
|
||||
'AdressBuilder' => 'classes/general/AdressBuilder.php',
|
||||
'BuilderBase' => 'classes/general/BuilderBase.php',
|
||||
'AddressBuilder' => 'classes/general/AddressBuilder.php',
|
||||
'AbstractBuilder' => 'classes/general/AbstractBuilder.php',
|
||||
'BaseModel' => 'classes/general/Model/BaseModel.php',
|
||||
'RetailCrmService' => 'classes/general/services/RetailCrmService.php',
|
||||
)
|
||||
);
|
||||
$builder = new RetailcrmClasspathBuilder();
|
||||
$builder->setDisableNamespaces(true)
|
||||
->setDocumentRoot($server)
|
||||
->setModuleId($retailcrmModuleId)
|
||||
->setPath('classes')
|
||||
->setVersion($version)
|
||||
->build();
|
||||
|
||||
\Bitrix\Main\Loader::switchAutoLoad(true);
|
||||
\Bitrix\Main\Loader::registerAutoLoadClasses('intaro.retailcrm', $builder->getResult());
|
||||
\Intaro\RetailCrm\Component\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Component\Builder\API
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component\Builder\Api;
|
||||
|
||||
use Intaro\RetailCrm\Component\Builder\BuilderInterface;
|
||||
|
||||
/**
|
||||
* Class CorporateCustomerBuilder
|
||||
*
|
||||
* @package Intaro\RetailCrm\Component\Builder\Api
|
||||
*/
|
||||
class CorporateCustomerBuilder implements BuilderInterface
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function build(): BuilderInterface
|
||||
{
|
||||
// TODO: Implement build() method.
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getResult()
|
||||
{
|
||||
// TODO: Implement getResult() method.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Component\Builder\API
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component\Builder\Api;
|
||||
|
||||
use Intaro\RetailCrm\Component\Builder\BuilderInterface;
|
||||
|
||||
/**
|
||||
* Class CustomerBuilder
|
||||
*
|
||||
* @package Intaro\RetailCrm\Component\Builder\Api
|
||||
*/
|
||||
class CustomerBuilder implements BuilderInterface
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function build(): BuilderInterface
|
||||
{
|
||||
// TODO: Implement build() method.
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getResult()
|
||||
{
|
||||
// TODO: Implement getResult() method.
|
||||
}
|
||||
}
|
35
intaro.retailcrm/lib/component/builder/builderinterface.php
Normal file
35
intaro.retailcrm/lib/component/builder/builderinterface.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Component\Builder
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component\Builder;
|
||||
|
||||
/**
|
||||
* Interface BuilderInterface
|
||||
*
|
||||
* @package Intaro\RetailCrm\Component\Builder
|
||||
*/
|
||||
interface BuilderInterface
|
||||
{
|
||||
/**
|
||||
* Builds result
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function build(): BuilderInterface;
|
||||
|
||||
/**
|
||||
* Returns builder result
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResult();
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
|
||||
|
||||
/**
|
||||
* Annotations class.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class Annotation
|
||||
{
|
||||
/**
|
||||
* Value property. Common among all derived classes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data Key-value for properties to be defined in this class.
|
||||
*/
|
||||
public final function __construct(array $data)
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error handler for unknown property accessor in Annotation class.
|
||||
*
|
||||
* @param string $name Unknown property name.
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
throw new \BadMethodCallException(
|
||||
sprintf("Unknown property '%s' on annotation '%s'.", $name, get_class($this))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error handler for unknown property mutator in Annotation class.
|
||||
*
|
||||
* @param string $name Unknown property name.
|
||||
* @param mixed $value Property value.
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
throw new \BadMethodCallException(
|
||||
sprintf("Unknown property '%s' on annotation '%s'.", $name, get_class($this))
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check the attribute type during the parsing process.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
final class Attribute
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
public $required = false;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check the types of all declared attributes during the parsing process.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
final class Attributes
|
||||
{
|
||||
/**
|
||||
* @var array<Doctrine\Common\Annotations\Annotation\Attribute>
|
||||
*/
|
||||
public $value;
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check the available values during the parsing process.
|
||||
*
|
||||
* @since 2.4
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*
|
||||
* @Annotation
|
||||
* @Attributes({
|
||||
* @Attribute("value", required = true, type = "array"),
|
||||
* @Attribute("literal", required = false, type = "array")
|
||||
* })
|
||||
*/
|
||||
final class Enum
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Literal target declaration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $literal;
|
||||
|
||||
/**
|
||||
* Annotation constructor.
|
||||
*
|
||||
* @param array $values
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct(array $values)
|
||||
{
|
||||
if ( ! isset($values['literal'])) {
|
||||
$values['literal'] = [];
|
||||
}
|
||||
|
||||
foreach ($values['value'] as $var) {
|
||||
if( ! is_scalar($var)) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'@Enum supports only scalar values "%s" given.',
|
||||
is_object($var) ? get_class($var) : gettype($var)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($values['literal'] as $key => $var) {
|
||||
if( ! in_array($key, $values['value'])) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'Undefined enumerator value "%s" for literal "%s".',
|
||||
$key , $var
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$this->value = $values['value'];
|
||||
$this->literal = $values['literal'];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser to ignore specific
|
||||
* annotations during the parsing process.
|
||||
*
|
||||
* @Annotation
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
final class IgnoreAnnotation
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $names;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $values
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function __construct(array $values)
|
||||
{
|
||||
if (is_string($values['value'])) {
|
||||
$values['value'] = [$values['value']];
|
||||
}
|
||||
if (!is_array($values['value'])) {
|
||||
throw new \RuntimeException(sprintf('@IgnoreAnnotation expects either a string name, or an array of strings, but got %s.', json_encode($values['value'])));
|
||||
}
|
||||
|
||||
$this->names = $values['value'];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check if that attribute is required during the parsing process.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
final class Required
|
||||
{
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check the annotation target during the parsing process.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
final class Target
|
||||
{
|
||||
const TARGET_CLASS = 1;
|
||||
const TARGET_METHOD = 2;
|
||||
const TARGET_PROPERTY = 4;
|
||||
const TARGET_ANNOTATION = 8;
|
||||
const TARGET_ALL = 15;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $map = [
|
||||
'ALL' => self::TARGET_ALL,
|
||||
'CLASS' => self::TARGET_CLASS,
|
||||
'METHOD' => self::TARGET_METHOD,
|
||||
'PROPERTY' => self::TARGET_PROPERTY,
|
||||
'ANNOTATION' => self::TARGET_ANNOTATION,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Targets as bitmask.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $targets;
|
||||
|
||||
/**
|
||||
* Literal target declaration.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $literal;
|
||||
|
||||
/**
|
||||
* Annotation constructor.
|
||||
*
|
||||
* @param array $values
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct(array $values)
|
||||
{
|
||||
if (!isset($values['value'])){
|
||||
$values['value'] = null;
|
||||
}
|
||||
if (is_string($values['value'])){
|
||||
$values['value'] = [$values['value']];
|
||||
}
|
||||
if (!is_array($values['value'])){
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('@Target expects either a string value, or an array of strings, "%s" given.',
|
||||
is_object($values['value']) ? get_class($values['value']) : gettype($values['value'])
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$bitmask = 0;
|
||||
foreach ($values['value'] as $literal) {
|
||||
if(!isset(self::$map[$literal])){
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('Invalid Target "%s". Available targets: [%s]',
|
||||
$literal, implode(', ', array_keys(self::$map)))
|
||||
);
|
||||
}
|
||||
$bitmask |= self::$map[$literal];
|
||||
}
|
||||
|
||||
$this->targets = $bitmask;
|
||||
$this->value = $values['value'];
|
||||
$this->literal = implode(', ', $this->value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,197 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
|
||||
|
||||
/**
|
||||
* Description of AnnotationException
|
||||
*
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class AnnotationException extends \Exception
|
||||
{
|
||||
/**
|
||||
* Creates a new AnnotationException describing a Syntax error.
|
||||
*
|
||||
* @param string $message Exception message
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function syntaxError($message)
|
||||
{
|
||||
return new self('[Syntax Error] ' . $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing a Semantical error.
|
||||
*
|
||||
* @param string $message Exception message
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function semanticalError($message)
|
||||
{
|
||||
return new self('[Semantical Error] ' . $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing an error which occurred during
|
||||
* the creation of the annotation.
|
||||
*
|
||||
* @since 2.2
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function creationError($message)
|
||||
{
|
||||
return new self('[Creation Error] ' . $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing a type error.
|
||||
*
|
||||
* @since 1.1
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function typeError($message)
|
||||
{
|
||||
return new self('[Type Error] ' . $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing a constant semantical error.
|
||||
*
|
||||
* @since 2.3
|
||||
*
|
||||
* @param string $identifier
|
||||
* @param string $context
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function semanticalErrorConstants($identifier, $context = null)
|
||||
{
|
||||
return self::semanticalError(sprintf(
|
||||
"Couldn't find constant %s%s.",
|
||||
$identifier,
|
||||
$context ? ', ' . $context : ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing an type error of an attribute.
|
||||
*
|
||||
* @since 2.2
|
||||
*
|
||||
* @param string $attributeName
|
||||
* @param string $annotationName
|
||||
* @param string $context
|
||||
* @param string $expected
|
||||
* @param mixed $actual
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function attributeTypeError($attributeName, $annotationName, $context, $expected, $actual)
|
||||
{
|
||||
return self::typeError(sprintf(
|
||||
'Attribute "%s" of @%s declared on %s expects %s, but got %s.',
|
||||
$attributeName,
|
||||
$annotationName,
|
||||
$context,
|
||||
$expected,
|
||||
is_object($actual) ? 'an instance of ' . get_class($actual) : gettype($actual)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing an required error of an attribute.
|
||||
*
|
||||
* @since 2.2
|
||||
*
|
||||
* @param string $attributeName
|
||||
* @param string $annotationName
|
||||
* @param string $context
|
||||
* @param string $expected
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function requiredError($attributeName, $annotationName, $context, $expected)
|
||||
{
|
||||
return self::typeError(sprintf(
|
||||
'Attribute "%s" of @%s declared on %s expects %s. This value should not be null.',
|
||||
$attributeName,
|
||||
$annotationName,
|
||||
$context,
|
||||
$expected
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing a invalid enummerator.
|
||||
*
|
||||
* @since 2.4
|
||||
*
|
||||
* @param string $attributeName
|
||||
* @param string $annotationName
|
||||
* @param string $context
|
||||
* @param array $available
|
||||
* @param mixed $given
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function enumeratorError($attributeName, $annotationName, $context, $available, $given)
|
||||
{
|
||||
return new self(sprintf(
|
||||
'[Enum Error] Attribute "%s" of @%s declared on %s accept only [%s], but got %s.',
|
||||
$attributeName,
|
||||
$annotationName,
|
||||
$context,
|
||||
implode(', ', $available),
|
||||
is_object($given) ? get_class($given) : $given
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function optimizerPlusSaveComments()
|
||||
{
|
||||
return new self(
|
||||
"You have to enable opcache.save_comments=1 or zend_optimizerplus.save_comments=1."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function optimizerPlusLoadComments()
|
||||
{
|
||||
return new self(
|
||||
"You have to enable opcache.load_comments=1 or zend_optimizerplus.load_comments=1."
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,418 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
|
||||
|
||||
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
|
||||
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* A reader for docblock annotations.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class AnnotationReader implements Reader
|
||||
{
|
||||
/**
|
||||
* Global map for imports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $globalImports = [
|
||||
'ignoreannotation' => 'Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\IgnoreAnnotation',
|
||||
];
|
||||
|
||||
/**
|
||||
* A list with annotations that are not causing exceptions when not resolved to an annotation class.
|
||||
*
|
||||
* The names are case sensitive.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $globalIgnoredNames = [
|
||||
// Annotation tags
|
||||
'Annotation' => true, 'Attribute' => true, 'Attributes' => true,
|
||||
/* Can we enable this? 'Enum' => true, */
|
||||
'Required' => true,
|
||||
'Target' => true,
|
||||
// Widely used tags (but not existent in phpdoc)
|
||||
'fix' => true , 'fixme' => true,
|
||||
'override' => true,
|
||||
// PHPDocumentor 1 tags
|
||||
'abstract'=> true, 'access'=> true,
|
||||
'code' => true,
|
||||
'deprec'=> true,
|
||||
'endcode' => true, 'exception'=> true,
|
||||
'final'=> true,
|
||||
'ingroup' => true, 'inheritdoc'=> true, 'inheritDoc'=> true,
|
||||
'magic' => true,
|
||||
'name'=> true,
|
||||
'toc' => true, 'tutorial'=> true,
|
||||
'private' => true,
|
||||
'static'=> true, 'staticvar'=> true, 'staticVar'=> true,
|
||||
'throw' => true,
|
||||
// PHPDocumentor 2 tags.
|
||||
'api' => true, 'author'=> true,
|
||||
'category'=> true, 'copyright'=> true,
|
||||
'deprecated'=> true,
|
||||
'example'=> true,
|
||||
'filesource'=> true,
|
||||
'global'=> true,
|
||||
'ignore'=> true, /* Can we enable this? 'index' => true, */ 'internal'=> true,
|
||||
'license'=> true, 'link'=> true,
|
||||
'method' => true,
|
||||
'package'=> true, 'param'=> true, 'property' => true, 'property-read' => true, 'property-write' => true,
|
||||
'return'=> true,
|
||||
'see'=> true, 'since'=> true, 'source' => true, 'subpackage'=> true,
|
||||
'throws'=> true, 'todo'=> true, 'TODO'=> true,
|
||||
'usedby'=> true, 'uses' => true,
|
||||
'var'=> true, 'version'=> true,
|
||||
// PHPUnit tags
|
||||
'codeCoverageIgnore' => true, 'codeCoverageIgnoreStart' => true, 'codeCoverageIgnoreEnd' => true,
|
||||
// PHPCheckStyle
|
||||
'SuppressWarnings' => true,
|
||||
// PHPStorm
|
||||
'noinspection' => true,
|
||||
// PEAR
|
||||
'package_version' => true,
|
||||
// PlantUML
|
||||
'startuml' => true, 'enduml' => true,
|
||||
// Symfony 3.3 Cache Adapter
|
||||
'experimental' => true,
|
||||
// Slevomat Coding Standard
|
||||
'phpcsSuppress' => true,
|
||||
// PHP CodeSniffer
|
||||
'codingStandardsIgnoreStart' => true,
|
||||
'codingStandardsIgnoreEnd' => true,
|
||||
// PHPStan
|
||||
'template' => true, 'implements' => true, 'extends' => true, 'use' => true,
|
||||
];
|
||||
|
||||
/**
|
||||
* A list with annotations that are not causing exceptions when not resolved to an annotation class.
|
||||
*
|
||||
* The names are case sensitive.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $globalIgnoredNamespaces = [];
|
||||
|
||||
/**
|
||||
* Add a new annotation to the globally ignored annotation names with regard to exception handling.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
static public function addGlobalIgnoredName($name)
|
||||
{
|
||||
self::$globalIgnoredNames[$name] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new annotation to the globally ignored annotation namespaces with regard to exception handling.
|
||||
*
|
||||
* @param string $namespace
|
||||
*/
|
||||
static public function addGlobalIgnoredNamespace($namespace)
|
||||
{
|
||||
self::$globalIgnoredNamespaces[$namespace] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotations parser.
|
||||
*
|
||||
* @var \Intaro\RetailCrm\Component\Doctrine\Common\Annotations\DocParser
|
||||
*/
|
||||
private $parser;
|
||||
|
||||
/**
|
||||
* Annotations parser used to collect parsing metadata.
|
||||
*
|
||||
* @var \Intaro\RetailCrm\Component\Doctrine\Common\Annotations\DocParser
|
||||
*/
|
||||
private $preParser;
|
||||
|
||||
/**
|
||||
* PHP parser used to collect imports.
|
||||
*
|
||||
* @var \Intaro\RetailCrm\Component\Doctrine\Common\Annotations\PhpParser
|
||||
*/
|
||||
private $phpParser;
|
||||
|
||||
/**
|
||||
* In-memory cache mechanism to store imported annotations per class.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $imports = [];
|
||||
|
||||
/**
|
||||
* In-memory cache mechanism to store ignored annotations per class.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $ignoredAnnotationNames = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Initializes a new AnnotationReader.
|
||||
*
|
||||
* @param DocParser $parser
|
||||
*
|
||||
* @throws AnnotationException
|
||||
*/
|
||||
public function __construct(DocParser $parser = null)
|
||||
{
|
||||
if (extension_loaded('Zend Optimizer+') && (ini_get('zend_optimizerplus.save_comments') === "0" || ini_get('opcache.save_comments') === "0")) {
|
||||
throw AnnotationException::optimizerPlusSaveComments();
|
||||
}
|
||||
|
||||
if (extension_loaded('Zend OPcache') && ini_get('opcache.save_comments') == 0) {
|
||||
throw AnnotationException::optimizerPlusSaveComments();
|
||||
}
|
||||
|
||||
// Make sure that the IgnoreAnnotation annotation is loaded
|
||||
class_exists(IgnoreAnnotation::class);
|
||||
|
||||
$this->parser = $parser ?: new DocParser();
|
||||
|
||||
$this->preParser = new DocParser;
|
||||
|
||||
$this->preParser->setImports(self::$globalImports);
|
||||
$this->preParser->setIgnoreNotImportedAnnotations(true);
|
||||
$this->preParser->setIgnoredAnnotationNames(self::$globalIgnoredNames);
|
||||
|
||||
$this->phpParser = new PhpParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotations(ReflectionClass $class)
|
||||
{
|
||||
$this->parser->setTarget(Target::TARGET_CLASS);
|
||||
$this->parser->setImports($this->getClassImports($class));
|
||||
$this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
|
||||
$this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);
|
||||
|
||||
return $this->parser->parse($class->getDocComment(), 'class ' . $class->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotation(ReflectionClass $class, $annotationName)
|
||||
{
|
||||
$annotations = $this->getClassAnnotations($class);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotations(ReflectionProperty $property)
|
||||
{
|
||||
$class = $property->getDeclaringClass();
|
||||
$context = 'property ' . $class->getName() . "::\$" . $property->getName();
|
||||
|
||||
$this->parser->setTarget(Target::TARGET_PROPERTY);
|
||||
$this->parser->setImports($this->getPropertyImports($property));
|
||||
$this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
|
||||
$this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);
|
||||
|
||||
return $this->parser->parse($property->getDocComment(), $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotation(ReflectionProperty $property, $annotationName)
|
||||
{
|
||||
$annotations = $this->getPropertyAnnotations($property);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotations(ReflectionMethod $method)
|
||||
{
|
||||
$class = $method->getDeclaringClass();
|
||||
$context = 'method ' . $class->getName() . '::' . $method->getName() . '()';
|
||||
|
||||
$this->parser->setTarget(Target::TARGET_METHOD);
|
||||
$this->parser->setImports($this->getMethodImports($method));
|
||||
$this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
|
||||
$this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);
|
||||
|
||||
return $this->parser->parse($method->getDocComment(), $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotation(ReflectionMethod $method, $annotationName)
|
||||
{
|
||||
$annotations = $this->getMethodAnnotations($method);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ignored annotations for the given class.
|
||||
*
|
||||
* @param \ReflectionClass $class
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getIgnoredAnnotationNames(ReflectionClass $class)
|
||||
{
|
||||
$name = $class->getName();
|
||||
if (isset($this->ignoredAnnotationNames[$name])) {
|
||||
return $this->ignoredAnnotationNames[$name];
|
||||
}
|
||||
|
||||
$this->collectParsingMetadata($class);
|
||||
|
||||
return $this->ignoredAnnotationNames[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves imports.
|
||||
*
|
||||
* @param \ReflectionClass $class
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getClassImports(ReflectionClass $class)
|
||||
{
|
||||
$name = $class->getName();
|
||||
if (isset($this->imports[$name])) {
|
||||
return $this->imports[$name];
|
||||
}
|
||||
|
||||
$this->collectParsingMetadata($class);
|
||||
|
||||
return $this->imports[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves imports for methods.
|
||||
*
|
||||
* @param \ReflectionMethod $method
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getMethodImports(ReflectionMethod $method)
|
||||
{
|
||||
$class = $method->getDeclaringClass();
|
||||
$classImports = $this->getClassImports($class);
|
||||
|
||||
$traitImports = [];
|
||||
|
||||
foreach ($class->getTraits() as $trait) {
|
||||
if ($trait->hasMethod($method->getName())
|
||||
&& $trait->getFileName() === $method->getFileName()
|
||||
) {
|
||||
$traitImports = array_merge($traitImports, $this->phpParser->parseClass($trait));
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge($classImports, $traitImports);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves imports for properties.
|
||||
*
|
||||
* @param \ReflectionProperty $property
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getPropertyImports(ReflectionProperty $property)
|
||||
{
|
||||
$class = $property->getDeclaringClass();
|
||||
$classImports = $this->getClassImports($class);
|
||||
|
||||
$traitImports = [];
|
||||
|
||||
foreach ($class->getTraits() as $trait) {
|
||||
if ($trait->hasProperty($property->getName())) {
|
||||
$traitImports = array_merge($traitImports, $this->phpParser->parseClass($trait));
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge($classImports, $traitImports);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects parsing metadata for a given class.
|
||||
*
|
||||
* @param \ReflectionClass $class
|
||||
*/
|
||||
private function collectParsingMetadata(ReflectionClass $class)
|
||||
{
|
||||
$ignoredAnnotationNames = self::$globalIgnoredNames;
|
||||
$annotations = $this->preParser->parse($class->getDocComment(), 'class ' . $class->name);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof IgnoreAnnotation) {
|
||||
foreach ($annotation->names AS $annot) {
|
||||
$ignoredAnnotationNames[$annot] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$name = $class->getName();
|
||||
|
||||
$this->imports[$name] = array_merge(
|
||||
self::$globalImports,
|
||||
$this->phpParser->parseClass($class),
|
||||
['__NAMESPACE__' => $class->getNamespaceName()]
|
||||
);
|
||||
|
||||
$this->ignoredAnnotationNames[$name] = $ignoredAnnotationNames;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
|
||||
|
||||
final class AnnotationRegistry
|
||||
{
|
||||
/**
|
||||
* A map of namespaces to use for autoloading purposes based on a PSR-0 convention.
|
||||
*
|
||||
* Contains the namespace as key and an array of directories as value. If the value is NULL
|
||||
* the include path is used for checking for the corresponding file.
|
||||
*
|
||||
* This autoloading mechanism does not utilize the PHP autoloading but implements autoloading on its own.
|
||||
*
|
||||
* @var string[][]|string[]|null[]
|
||||
*/
|
||||
static private $autoloadNamespaces = [];
|
||||
|
||||
/**
|
||||
* A map of autoloader callables.
|
||||
*
|
||||
* @var callable[]
|
||||
*/
|
||||
static private $loaders = [];
|
||||
|
||||
/**
|
||||
* An array of classes which cannot be found
|
||||
*
|
||||
* @var null[] indexed by class name
|
||||
*/
|
||||
static private $failedToAutoload = [];
|
||||
|
||||
/**
|
||||
* Whenever registerFile() was used. Disables use of standard autoloader.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
static private $registerFileUsed = false;
|
||||
|
||||
public static function reset() : void
|
||||
{
|
||||
self::$autoloadNamespaces = [];
|
||||
self::$loaders = [];
|
||||
self::$failedToAutoload = [];
|
||||
self::$registerFileUsed = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers file.
|
||||
*
|
||||
* @deprecated This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
|
||||
*/
|
||||
public static function registerFile(string $file) : void
|
||||
{
|
||||
self::$registerFileUsed = true;
|
||||
|
||||
require_once $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a namespace with one or many directories to look for files or null for the include path.
|
||||
*
|
||||
* Loading of this namespaces will be done with a PSR-0 namespace loading algorithm.
|
||||
*
|
||||
* @param string $namespace
|
||||
* @param string|array|null $dirs
|
||||
*
|
||||
* @deprecated This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
|
||||
*/
|
||||
public static function registerAutoloadNamespace(string $namespace, $dirs = null) : void
|
||||
{
|
||||
self::$autoloadNamespaces[$namespace] = $dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers multiple namespaces.
|
||||
*
|
||||
* Loading of this namespaces will be done with a PSR-0 namespace loading algorithm.
|
||||
*
|
||||
* @param string[][]|string[]|null[] $namespaces indexed by namespace name
|
||||
*
|
||||
* @deprecated This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
|
||||
*/
|
||||
public static function registerAutoloadNamespaces(array $namespaces) : void
|
||||
{
|
||||
self::$autoloadNamespaces = \array_merge(self::$autoloadNamespaces, $namespaces);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an autoloading callable for annotations, much like spl_autoload_register().
|
||||
*
|
||||
* NOTE: These class loaders HAVE to be silent when a class was not found!
|
||||
* IMPORTANT: Loaders have to return true if they loaded a class that could contain the searched annotation class.
|
||||
*
|
||||
* @deprecated This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
|
||||
*/
|
||||
public static function registerLoader(callable $callable) : void
|
||||
{
|
||||
// Reset our static cache now that we have a new loader to work with
|
||||
self::$failedToAutoload = [];
|
||||
self::$loaders[] = $callable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an autoloading callable for annotations, if it is not already registered
|
||||
*
|
||||
* @deprecated This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
|
||||
*/
|
||||
public static function registerUniqueLoader(callable $callable) : void
|
||||
{
|
||||
if ( ! in_array($callable, self::$loaders, true) ) {
|
||||
self::registerLoader($callable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoloads an annotation class silently.
|
||||
*/
|
||||
public static function loadAnnotationClass(string $class) : bool
|
||||
{
|
||||
if (\class_exists($class, false)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (\array_key_exists($class, self::$failedToAutoload)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (self::$autoloadNamespaces AS $namespace => $dirs) {
|
||||
if (\strpos($class, $namespace) === 0) {
|
||||
$file = \str_replace('\\', \DIRECTORY_SEPARATOR, $class) . '.php';
|
||||
|
||||
if ($dirs === null) {
|
||||
if ($path = stream_resolve_include_path($file)) {
|
||||
require $path;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
foreach((array) $dirs AS $dir) {
|
||||
if (is_file($dir . \DIRECTORY_SEPARATOR . $file)) {
|
||||
require $dir . \DIRECTORY_SEPARATOR . $file;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (self::$loaders AS $loader) {
|
||||
if ($loader($class) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (self::$loaders === [] && self::$autoloadNamespaces === [] && self::$registerFileUsed === false && \class_exists($class)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
self::$failedToAutoload[$class] = null;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
|
||||
|
||||
use Intaro\RetailCrm\Component\Doctrine\Common\Lexer\AbstractLexer;
|
||||
|
||||
/**
|
||||
* Simple lexer for docblock annotations.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
final class DocLexer extends AbstractLexer
|
||||
{
|
||||
const T_NONE = 1;
|
||||
const T_INTEGER = 2;
|
||||
const T_STRING = 3;
|
||||
const T_FLOAT = 4;
|
||||
|
||||
// All tokens that are also identifiers should be >= 100
|
||||
const T_IDENTIFIER = 100;
|
||||
const T_AT = 101;
|
||||
const T_CLOSE_CURLY_BRACES = 102;
|
||||
const T_CLOSE_PARENTHESIS = 103;
|
||||
const T_COMMA = 104;
|
||||
const T_EQUALS = 105;
|
||||
const T_FALSE = 106;
|
||||
const T_NAMESPACE_SEPARATOR = 107;
|
||||
const T_OPEN_CURLY_BRACES = 108;
|
||||
const T_OPEN_PARENTHESIS = 109;
|
||||
const T_TRUE = 110;
|
||||
const T_NULL = 111;
|
||||
const T_COLON = 112;
|
||||
const T_MINUS = 113;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $noCase = [
|
||||
'@' => self::T_AT,
|
||||
',' => self::T_COMMA,
|
||||
'(' => self::T_OPEN_PARENTHESIS,
|
||||
')' => self::T_CLOSE_PARENTHESIS,
|
||||
'{' => self::T_OPEN_CURLY_BRACES,
|
||||
'}' => self::T_CLOSE_CURLY_BRACES,
|
||||
'=' => self::T_EQUALS,
|
||||
':' => self::T_COLON,
|
||||
'-' => self::T_MINUS,
|
||||
'\\' => self::T_NAMESPACE_SEPARATOR
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $withCase = [
|
||||
'true' => self::T_TRUE,
|
||||
'false' => self::T_FALSE,
|
||||
'null' => self::T_NULL
|
||||
];
|
||||
|
||||
/**
|
||||
* Whether the next token starts immediately, or if there were
|
||||
* non-captured symbols before that
|
||||
*/
|
||||
public function nextTokenIsAdjacent() : bool
|
||||
{
|
||||
return $this->token === null
|
||||
|| ($this->lookahead !== null
|
||||
&& ($this->lookahead['position'] - $this->token['position']) === strlen($this->token['value']));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getCatchablePatterns()
|
||||
{
|
||||
return [
|
||||
'[a-z_\\\][a-z0-9_\:\\\]*[a-z_][a-z0-9_]*',
|
||||
'(?:[+-]?[0-9]+(?:[\.][0-9]+)*)(?:[eE][+-]?[0-9]+)?',
|
||||
'"(?:""|[^"])*+"',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNonCatchablePatterns()
|
||||
{
|
||||
return ['\s+', '\*+', '(.)'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getType(&$value)
|
||||
{
|
||||
$type = self::T_NONE;
|
||||
|
||||
if ($value[0] === '"') {
|
||||
$value = str_replace('""', '"', substr($value, 1, strlen($value) - 2));
|
||||
|
||||
return self::T_STRING;
|
||||
}
|
||||
|
||||
if (isset($this->noCase[$value])) {
|
||||
return $this->noCase[$value];
|
||||
}
|
||||
|
||||
if ($value[0] === '_' || $value[0] === '\\' || ctype_alpha($value[0])) {
|
||||
return self::T_IDENTIFIER;
|
||||
}
|
||||
|
||||
$lowerValue = strtolower($value);
|
||||
|
||||
if (isset($this->withCase[$lowerValue])) {
|
||||
return $this->withCase[$lowerValue];
|
||||
}
|
||||
|
||||
// Checking numeric value
|
||||
if (is_numeric($value)) {
|
||||
return (strpos($value, '.') !== false || stripos($value, 'e') !== false)
|
||||
? self::T_FLOAT : self::T_INTEGER;
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
|
||||
|
||||
use SplFileObject;
|
||||
|
||||
/**
|
||||
* Parses a file for namespaces/use/class declarations.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Christian Kaps <christian.kaps@mohiva.com>
|
||||
*/
|
||||
final class PhpParser
|
||||
{
|
||||
/**
|
||||
* Parses a class.
|
||||
*
|
||||
* @param \ReflectionClass $class A <code>ReflectionClass</code> object.
|
||||
*
|
||||
* @return array A list with use statements in the form (Alias => FQN).
|
||||
*/
|
||||
public function parseClass(\ReflectionClass $class)
|
||||
{
|
||||
if (method_exists($class, 'getUseStatements')) {
|
||||
return $class->getUseStatements();
|
||||
}
|
||||
|
||||
if (false === $filename = $class->getFileName()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$content = $this->getFileContent($filename, $class->getStartLine());
|
||||
|
||||
if (null === $content) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$namespace = preg_quote($class->getNamespaceName());
|
||||
$content = preg_replace('/^.*?(\bnamespace\s+' . $namespace . '\s*[;{].*)$/s', '\\1', $content);
|
||||
$tokenizer = new TokenParser('<?php ' . $content);
|
||||
|
||||
$statements = $tokenizer->parseUseStatements($class->getNamespaceName());
|
||||
|
||||
return $statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content of the file right up to the given line number.
|
||||
*
|
||||
* @param string $filename The name of the file to load.
|
||||
* @param integer $lineNumber The number of lines to read from file.
|
||||
*
|
||||
* @return string|null The content of the file or null if the file does not exist.
|
||||
*/
|
||||
private function getFileContent($filename, $lineNumber)
|
||||
{
|
||||
if ( ! is_file($filename)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$content = '';
|
||||
$lineCnt = 0;
|
||||
$file = new SplFileObject($filename);
|
||||
while (!$file->eof()) {
|
||||
if ($lineCnt++ == $lineNumber) {
|
||||
break;
|
||||
}
|
||||
|
||||
$content .= $file->fgets();
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
|
||||
|
||||
/**
|
||||
* Interface for annotation readers.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
interface Reader
|
||||
{
|
||||
/**
|
||||
* Gets the annotations applied to a class.
|
||||
*
|
||||
* @param \ReflectionClass $class The ReflectionClass of the class from which
|
||||
* the class annotations should be read.
|
||||
*
|
||||
* @return array An array of Annotations.
|
||||
*/
|
||||
function getClassAnnotations(\ReflectionClass $class);
|
||||
|
||||
/**
|
||||
* Gets a class annotation.
|
||||
*
|
||||
* @param \ReflectionClass $class The ReflectionClass of the class from which
|
||||
* the class annotations should be read.
|
||||
* @param string $annotationName The name of the annotation.
|
||||
*
|
||||
* @return object|null The Annotation or NULL, if the requested annotation does not exist.
|
||||
*/
|
||||
function getClassAnnotation(\ReflectionClass $class, $annotationName);
|
||||
|
||||
/**
|
||||
* Gets the annotations applied to a method.
|
||||
*
|
||||
* @param \ReflectionMethod $method The ReflectionMethod of the method from which
|
||||
* the annotations should be read.
|
||||
*
|
||||
* @return array An array of Annotations.
|
||||
*/
|
||||
function getMethodAnnotations(\ReflectionMethod $method);
|
||||
|
||||
/**
|
||||
* Gets a method annotation.
|
||||
*
|
||||
* @param \ReflectionMethod $method The ReflectionMethod to read the annotations from.
|
||||
* @param string $annotationName The name of the annotation.
|
||||
*
|
||||
* @return object|null The Annotation or NULL, if the requested annotation does not exist.
|
||||
*/
|
||||
function getMethodAnnotation(\ReflectionMethod $method, $annotationName);
|
||||
|
||||
/**
|
||||
* Gets the annotations applied to a property.
|
||||
*
|
||||
* @param \ReflectionProperty $property The ReflectionProperty of the property
|
||||
* from which the annotations should be read.
|
||||
*
|
||||
* @return array An array of Annotations.
|
||||
*/
|
||||
function getPropertyAnnotations(\ReflectionProperty $property);
|
||||
|
||||
/**
|
||||
* Gets a property annotation.
|
||||
*
|
||||
* @param \ReflectionProperty $property The ReflectionProperty to read the annotations from.
|
||||
* @param string $annotationName The name of the annotation.
|
||||
*
|
||||
* @return object|null The Annotation or NULL, if the requested annotation does not exist.
|
||||
*/
|
||||
function getPropertyAnnotation(\ReflectionProperty $property, $annotationName);
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
|
||||
|
||||
/**
|
||||
* Parses a file for namespaces/use/class declarations.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Christian Kaps <christian.kaps@mohiva.com>
|
||||
*/
|
||||
class TokenParser
|
||||
{
|
||||
/**
|
||||
* The token list.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $tokens;
|
||||
|
||||
/**
|
||||
* The number of tokens.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $numTokens;
|
||||
|
||||
/**
|
||||
* The current array pointer.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $pointer = 0;
|
||||
|
||||
/**
|
||||
* @param string $contents
|
||||
*/
|
||||
public function __construct($contents)
|
||||
{
|
||||
$this->tokens = token_get_all($contents);
|
||||
|
||||
// The PHP parser sets internal compiler globals for certain things. Annoyingly, the last docblock comment it
|
||||
// saw gets stored in doc_comment. When it comes to compile the next thing to be include()d this stored
|
||||
// doc_comment becomes owned by the first thing the compiler sees in the file that it considers might have a
|
||||
// docblock. If the first thing in the file is a class without a doc block this would cause calls to
|
||||
// getDocBlock() on said class to return our long lost doc_comment. Argh.
|
||||
// To workaround, cause the parser to parse an empty docblock. Sure getDocBlock() will return this, but at least
|
||||
// it's harmless to us.
|
||||
token_get_all("<?php\n/**\n *\n */");
|
||||
|
||||
$this->numTokens = count($this->tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next non whitespace and non comment token.
|
||||
*
|
||||
* @param boolean $docCommentIsComment If TRUE then a doc comment is considered a comment and skipped.
|
||||
* If FALSE then only whitespace and normal comments are skipped.
|
||||
*
|
||||
* @return array|null The token if exists, null otherwise.
|
||||
*/
|
||||
public function next($docCommentIsComment = TRUE)
|
||||
{
|
||||
for ($i = $this->pointer; $i < $this->numTokens; $i++) {
|
||||
$this->pointer++;
|
||||
if ($this->tokens[$i][0] === T_WHITESPACE ||
|
||||
$this->tokens[$i][0] === T_COMMENT ||
|
||||
($docCommentIsComment && $this->tokens[$i][0] === T_DOC_COMMENT)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
return $this->tokens[$i];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a single use statement.
|
||||
*
|
||||
* @return array A list with all found class names for a use statement.
|
||||
*/
|
||||
public function parseUseStatement()
|
||||
{
|
||||
|
||||
$groupRoot = '';
|
||||
$class = '';
|
||||
$alias = '';
|
||||
$statements = [];
|
||||
$explicitAlias = false;
|
||||
while (($token = $this->next())) {
|
||||
$isNameToken = $token[0] === T_STRING || $token[0] === T_NS_SEPARATOR;
|
||||
if (!$explicitAlias && $isNameToken) {
|
||||
$class .= $token[1];
|
||||
$alias = $token[1];
|
||||
} else if ($explicitAlias && $isNameToken) {
|
||||
$alias .= $token[1];
|
||||
} else if ($token[0] === T_AS) {
|
||||
$explicitAlias = true;
|
||||
$alias = '';
|
||||
} else if ($token === ',') {
|
||||
$statements[strtolower($alias)] = $groupRoot . $class;
|
||||
$class = '';
|
||||
$alias = '';
|
||||
$explicitAlias = false;
|
||||
} else if ($token === ';') {
|
||||
$statements[strtolower($alias)] = $groupRoot . $class;
|
||||
break;
|
||||
} else if ($token === '{' ) {
|
||||
$groupRoot = $class;
|
||||
$class = '';
|
||||
} else if ($token === '}' ) {
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all use statements.
|
||||
*
|
||||
* @param string $namespaceName The namespace name of the reflected class.
|
||||
*
|
||||
* @return array A list with all found use statements.
|
||||
*/
|
||||
public function parseUseStatements($namespaceName)
|
||||
{
|
||||
$statements = [];
|
||||
while (($token = $this->next())) {
|
||||
if ($token[0] === T_USE) {
|
||||
$statements = array_merge($statements, $this->parseUseStatement());
|
||||
continue;
|
||||
}
|
||||
if ($token[0] !== T_NAMESPACE || $this->parseNamespace() != $namespaceName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get fresh array for new namespace. This is to prevent the parser to collect the use statements
|
||||
// for a previous namespace with the same name. This is the case if a namespace is defined twice
|
||||
// or if a namespace with the same name is commented out.
|
||||
$statements = [];
|
||||
}
|
||||
|
||||
return $statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the namespace.
|
||||
*
|
||||
* @return string The found namespace.
|
||||
*/
|
||||
public function parseNamespace()
|
||||
{
|
||||
$name = '';
|
||||
while (($token = $this->next()) && ($token[0] === T_STRING || $token[0] === T_NS_SEPARATOR)) {
|
||||
$name .= $token[1];
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the class name.
|
||||
*
|
||||
* @return string The found class name.
|
||||
*/
|
||||
public function parseClass()
|
||||
{
|
||||
// Namespaces and class names are tokenized the same: T_STRINGs
|
||||
// separated by T_NS_SEPARATOR so we can use one function to provide
|
||||
// both.
|
||||
return $this->parseNamespace();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,349 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Copyright (c) 2006-2018 Doctrine Project
|
||||
|
||||
* 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.
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component\Doctrine\Common\Lexer;
|
||||
|
||||
use ReflectionClass;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function preg_split;
|
||||
use function sprintf;
|
||||
use function substr;
|
||||
use const PREG_SPLIT_DELIM_CAPTURE;
|
||||
use const PREG_SPLIT_NO_EMPTY;
|
||||
use const PREG_SPLIT_OFFSET_CAPTURE;
|
||||
|
||||
/**
|
||||
* Base class for writing simple lexers, i.e. for creating small DSLs.
|
||||
*/
|
||||
abstract class AbstractLexer
|
||||
{
|
||||
/**
|
||||
* Lexer original input string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $input;
|
||||
|
||||
/**
|
||||
* Array of scanned tokens.
|
||||
*
|
||||
* Each token is an associative array containing three items:
|
||||
* - 'value' : the string value of the token in the input string
|
||||
* - 'type' : the type of the token (identifier, numeric, string, input
|
||||
* parameter, none)
|
||||
* - 'position' : the position of the token in the input string
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $tokens = [];
|
||||
|
||||
/**
|
||||
* Current lexer position in input string.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $position = 0;
|
||||
|
||||
/**
|
||||
* Current peek of current lexer position.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $peek = 0;
|
||||
|
||||
/**
|
||||
* The next token in the input.
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
public $lookahead;
|
||||
|
||||
/**
|
||||
* The last matched/seen token.
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
public $token;
|
||||
|
||||
/**
|
||||
* Composed regex for input parsing.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $regex;
|
||||
|
||||
/**
|
||||
* Sets the input data to be tokenized.
|
||||
*
|
||||
* The Lexer is immediately reset and the new input tokenized.
|
||||
* Any unprocessed tokens from any previous input are lost.
|
||||
*
|
||||
* @param string $input The input to be tokenized.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setInput($input)
|
||||
{
|
||||
$this->input = $input;
|
||||
$this->tokens = [];
|
||||
|
||||
$this->reset();
|
||||
$this->scan($input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the lexer.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
$this->lookahead = null;
|
||||
$this->token = null;
|
||||
$this->peek = 0;
|
||||
$this->position = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the peek pointer to 0.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resetPeek()
|
||||
{
|
||||
$this->peek = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the lexer position on the input to the given position.
|
||||
*
|
||||
* @param int $position Position to place the lexical scanner.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resetPosition($position = 0)
|
||||
{
|
||||
$this->position = $position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the original lexer's input until a given position.
|
||||
*
|
||||
* @param int $position
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInputUntilPosition($position)
|
||||
{
|
||||
return substr($this->input, 0, $position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given token matches the current lookahead.
|
||||
*
|
||||
* @param int|string $token
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isNextToken($token)
|
||||
{
|
||||
return $this->lookahead !== null && $this->lookahead['type'] === $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether any of the given tokens matches the current lookahead.
|
||||
*
|
||||
* @param array $tokens
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isNextTokenAny(array $tokens)
|
||||
{
|
||||
return $this->lookahead !== null && in_array($this->lookahead['type'], $tokens, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves to the next token in the input string.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function moveNext()
|
||||
{
|
||||
$this->peek = 0;
|
||||
$this->token = $this->lookahead;
|
||||
$this->lookahead = isset($this->tokens[$this->position])
|
||||
? $this->tokens[$this->position++] : null;
|
||||
|
||||
return $this->lookahead !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the lexer to skip input tokens until it sees a token with the given value.
|
||||
*
|
||||
* @param string $type The token type to skip until.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function skipUntil($type)
|
||||
{
|
||||
while ($this->lookahead !== null && $this->lookahead['type'] !== $type) {
|
||||
$this->moveNext();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if given value is identical to the given token.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param int|string $token
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isA($value, $token)
|
||||
{
|
||||
return $this->getType($value) === $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the lookahead token forward.
|
||||
*
|
||||
* @return array|null The next token or NULL if there are no more tokens ahead.
|
||||
*/
|
||||
public function peek()
|
||||
{
|
||||
if (isset($this->tokens[$this->position + $this->peek])) {
|
||||
return $this->tokens[$this->position + $this->peek++];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Peeks at the next token, returns it and immediately resets the peek.
|
||||
*
|
||||
* @return array|null The next token or NULL if there are no more tokens ahead.
|
||||
*/
|
||||
public function glimpse()
|
||||
{
|
||||
$peek = $this->peek();
|
||||
$this->peek = 0;
|
||||
|
||||
return $peek;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans the input string for tokens.
|
||||
*
|
||||
* @param string $input A query string.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function scan($input)
|
||||
{
|
||||
if (! isset($this->regex)) {
|
||||
$this->regex = sprintf(
|
||||
'/(%s)|%s/%s',
|
||||
implode(')|(', $this->getCatchablePatterns()),
|
||||
implode('|', $this->getNonCatchablePatterns()),
|
||||
$this->getModifiers()
|
||||
);
|
||||
}
|
||||
|
||||
$flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE;
|
||||
$matches = preg_split($this->regex, $input, -1, $flags);
|
||||
|
||||
if ($matches === false) {
|
||||
// Work around https://bugs.php.net/78122
|
||||
$matches = [[$input, 0]];
|
||||
}
|
||||
|
||||
foreach ($matches as $match) {
|
||||
// Must remain before 'value' assignment since it can change content
|
||||
$type = $this->getType($match[0]);
|
||||
|
||||
$this->tokens[] = [
|
||||
'value' => $match[0],
|
||||
'type' => $type,
|
||||
'position' => $match[1],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the literal for a given token.
|
||||
*
|
||||
* @param int|string $token
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
public function getLiteral($token)
|
||||
{
|
||||
$className = static::class;
|
||||
$reflClass = new ReflectionClass($className);
|
||||
$constants = $reflClass->getConstants();
|
||||
|
||||
foreach ($constants as $name => $value) {
|
||||
if ($value === $token) {
|
||||
return $className . '::' . $name;
|
||||
}
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Regex modifiers
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getModifiers()
|
||||
{
|
||||
return 'iu';
|
||||
}
|
||||
|
||||
/**
|
||||
* Lexical catchable patterns.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getCatchablePatterns();
|
||||
|
||||
/**
|
||||
* Lexical non-catchable patterns.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getNonCatchablePatterns();
|
||||
|
||||
/**
|
||||
* Retrieve token type. Also processes the token value if necessary.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return int|string|null
|
||||
*/
|
||||
abstract protected function getType(&$value);
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Component\Json
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component\Json;
|
||||
|
||||
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\AnnotationReader;
|
||||
|
||||
/**
|
||||
* Trait AnnotationReaderTrait
|
||||
*
|
||||
* @package Intaro\RetailCrm\Component\Json
|
||||
*/
|
||||
trait AnnotationReaderTrait
|
||||
{
|
||||
/** @var \Intaro\RetailCrm\Component\Doctrine\Common\Annotations\AnnotationReader */
|
||||
private static $_annotationReader;
|
||||
|
||||
/**
|
||||
* @return \Intaro\RetailCrm\Component\Doctrine\Common\Annotations\AnnotationReader
|
||||
*/
|
||||
private static function annotationReader(): AnnotationReader
|
||||
{
|
||||
if (empty(static::$_annotationReader)) {
|
||||
static::$_annotationReader = new AnnotationReader();
|
||||
}
|
||||
|
||||
return static::$_annotationReader;
|
||||
}
|
||||
}
|
91
intaro.retailcrm/lib/component/json/deserializer.php
Normal file
91
intaro.retailcrm/lib/component/json/deserializer.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Component\Json
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component\Json;
|
||||
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\JsonProperty;
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\Name;
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\Type;
|
||||
use RetailCrm\Exception\InvalidJsonException;
|
||||
|
||||
/**
|
||||
* Class Deserializer
|
||||
*
|
||||
* @package Intaro\RetailCrm\Component\Json
|
||||
*/
|
||||
class Deserializer
|
||||
{
|
||||
use AnnotationReaderTrait;
|
||||
|
||||
/**
|
||||
* @param string $json
|
||||
* @param string $className
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public static function deserialize(string $json, string $className)
|
||||
{
|
||||
return static::deserializeArray(json_decode($json, true), $className);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param string $className
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public static function deserializeArray(array $data, string $className)
|
||||
{
|
||||
$reflection = new \ReflectionClass($className);
|
||||
$instance = new $className();
|
||||
|
||||
foreach ($reflection->getProperties() as $property) {
|
||||
static::deserializeProperty($instance, $property, $data);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $object
|
||||
* @param \ReflectionProperty $property
|
||||
* @param array $data
|
||||
*
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected static function deserializeProperty($object, \ReflectionProperty $property, array $data)
|
||||
{
|
||||
$property->setAccessible(true);
|
||||
|
||||
$name = $property->getName();
|
||||
$fqcn = '';
|
||||
|
||||
$nameData = static::annotationReader()->getPropertyAnnotation($property, Name::class);
|
||||
$fqcnData = static::annotationReader()->getPropertyAnnotation($property, Type::class);
|
||||
|
||||
if ($nameData instanceof Name) {
|
||||
$name = !empty($nameData->name) ? $nameData->name : $name;
|
||||
}
|
||||
|
||||
if ($fqcnData instanceof Type) {
|
||||
$fqcn = $fqcnData->type;
|
||||
}
|
||||
|
||||
if (empty($fqcn)) {
|
||||
$property->setValue($object, $data[$name]);
|
||||
} else {
|
||||
$property->setValue($object, static::deserializeArray($data[$name], $fqcn));
|
||||
}
|
||||
}
|
||||
}
|
38
intaro.retailcrm/lib/component/json/mapping/name.php
Normal file
38
intaro.retailcrm/lib/component/json/mapping/name.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Component\Json\Mapping
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component\Json\Mapping;
|
||||
|
||||
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
|
||||
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Target;
|
||||
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attribute;
|
||||
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attributes;
|
||||
|
||||
/**
|
||||
* Class Name
|
||||
*
|
||||
* @package Intaro\RetailCrm\Component\Json\Mapping
|
||||
* @Annotation
|
||||
* @Attributes(
|
||||
* @Attribute("name", required=true, type="string")
|
||||
* )
|
||||
* @Target({"PROPERTY","ANNOTATION"})
|
||||
*/
|
||||
final class Name
|
||||
{
|
||||
/**
|
||||
* Property name in result JSON
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
}
|
38
intaro.retailcrm/lib/component/json/mapping/type.php
Normal file
38
intaro.retailcrm/lib/component/json/mapping/type.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Component\Json\Mapping
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component\Json\Mapping;
|
||||
|
||||
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
|
||||
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Target;
|
||||
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attribute;
|
||||
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attributes;
|
||||
|
||||
/**
|
||||
* Class Type
|
||||
*
|
||||
* @package Intaro\RetailCrm\Component\Json\Mapping
|
||||
* @Annotation
|
||||
* @Attributes(
|
||||
* @Attribute("type", required=false, type="string")
|
||||
* )
|
||||
* @Target({"PROPERTY","ANNOTATION"})
|
||||
*/
|
||||
final class Type
|
||||
{
|
||||
/**
|
||||
* Property type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type;
|
||||
}
|
89
intaro.retailcrm/lib/component/json/serializer.php
Normal file
89
intaro.retailcrm/lib/component/json/serializer.php
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Component\Json
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component\Json;
|
||||
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\JsonProperty;
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\Name;
|
||||
use Intaro\RetailCrm\Model\Customer;
|
||||
use RetailCrm\Exception\InvalidJsonException;
|
||||
|
||||
/**
|
||||
* Class Serializer
|
||||
*
|
||||
* @package Intaro\RetailCrm\Component\Json
|
||||
*/
|
||||
class Serializer
|
||||
{
|
||||
use AnnotationReaderTrait;
|
||||
|
||||
/**
|
||||
* @param object $object
|
||||
*
|
||||
* @return string
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public static function serialize($object): string
|
||||
{
|
||||
$result = json_encode(static::serializeArray($object));
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new InvalidJsonException(json_last_error_msg(), json_last_error());
|
||||
}
|
||||
|
||||
return (string) $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $object
|
||||
*
|
||||
* @return array
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public static function serializeArray($object): array
|
||||
{
|
||||
$result = [];
|
||||
$ref = new \ReflectionClass(get_class($object));
|
||||
|
||||
foreach ($ref->getProperties() as $property) {
|
||||
static::serializeProperty($object, $property, $result);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $object
|
||||
* @param \ReflectionProperty $property
|
||||
* @param array $result
|
||||
*
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected static function serializeProperty($object, \ReflectionProperty $property, array &$result)
|
||||
{
|
||||
$property->setAccessible(true);
|
||||
|
||||
$name = $property->getName();
|
||||
$value = $property->getValue($object);
|
||||
$annotation = static::annotationReader()->getPropertyAnnotation($property, Name::class);
|
||||
|
||||
if ($annotation instanceof Name) {
|
||||
$name = !empty($annotation->name) ? $annotation->name : $name;
|
||||
}
|
||||
|
||||
if (is_object($value)) {
|
||||
$result[$name] = static::serializeArray($value);
|
||||
} else {
|
||||
$result[$name] = $value;
|
||||
}
|
||||
}
|
||||
}
|
72
intaro.retailcrm/lib/model/customer.php
Normal file
72
intaro.retailcrm/lib/model/customer.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Model
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Model;
|
||||
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\Name;
|
||||
|
||||
/**
|
||||
* Class Customer
|
||||
* TODO: Create necessary models for retailCRM entities
|
||||
*
|
||||
* @package Intaro\RetailCrm\Model
|
||||
*/
|
||||
class Customer
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $externalId;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isContact = false;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return Customer
|
||||
*/
|
||||
public function setId(int $id): Customer
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $externalId
|
||||
*
|
||||
* @return Customer
|
||||
*/
|
||||
public function setExternalId(string $externalId): Customer
|
||||
{
|
||||
$this->externalId = $externalId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $isContact
|
||||
*
|
||||
* @return Customer
|
||||
*/
|
||||
public function setIsContact(bool $isContact): Customer
|
||||
{
|
||||
$this->isContact = $isContact;
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -9,8 +9,8 @@
|
|||
* @see http://help.retailcrm.ru
|
||||
*/
|
||||
|
||||
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
if (file_exists(__DIR__ . '/../vendor/RetailcrmClasspathBuilder.php')) {
|
||||
require_once __DIR__ . '/../vendor/RetailcrmClasspathBuilder.php';
|
||||
}
|
||||
|
||||
if (file_exists(__DIR__ . '/../.env')) {
|
||||
|
|
Loading…
Add table
Reference in a new issue