-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-6276: JSON fields support #25479
- Loading branch information
Showing
7 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/MySQL/Definition/Columns/Json.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\Setup\Declaration\Schema\Db\MySQL\Definition\Columns; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Framework\Setup\Declaration\Schema\Db\DbDefinitionProcessorInterface; | ||
use Magento\Framework\Setup\Declaration\Schema\Dto\ElementInterface; | ||
|
||
/** | ||
* Process json data type. | ||
*/ | ||
class Json implements DbDefinitionProcessorInterface | ||
{ | ||
/** | ||
* @var Nullable | ||
*/ | ||
private $nullable; | ||
|
||
/** | ||
* @var ResourceConnection | ||
*/ | ||
private $resourceConnection; | ||
|
||
/** | ||
* @var Comment | ||
*/ | ||
private $comment; | ||
|
||
/** | ||
* Blob constructor. | ||
* | ||
* @param Nullable $nullable | ||
* @param Comment $comment | ||
* @param ResourceConnection $resourceConnection | ||
*/ | ||
public function __construct( | ||
Nullable $nullable, | ||
Comment $comment, | ||
ResourceConnection $resourceConnection | ||
) { | ||
$this->nullable = $nullable; | ||
$this->resourceConnection = $resourceConnection; | ||
$this->comment = $comment; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function toDefinition(ElementInterface $column) | ||
{ | ||
return sprintf( | ||
'%s %s %s %s', | ||
$this->resourceConnection->getConnection()->quoteIdentifier($column->getName()), | ||
$column->getType(), | ||
$this->nullable->toDefinition($column), | ||
$this->comment->toDefinition($column) | ||
); | ||
} | ||
|
||
/** | ||
* Returns an array of column definitions | ||
* | ||
* @param array $data | ||
* @return array | ||
*/ | ||
public function fromDefinition(array $data) | ||
{ | ||
return $data; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Columns/Json.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\Setup\Declaration\Schema\Dto\Columns; | ||
|
||
use Magento\Framework\Setup\Declaration\Schema\Dto\Column; | ||
use Magento\Framework\Setup\Declaration\Schema\Dto\ElementDiffAwareInterface; | ||
use Magento\Framework\Setup\Declaration\Schema\Dto\Table; | ||
|
||
/** | ||
* Json | ||
* | ||
* Text column. | ||
* Declared in SQL, like: JSON | ||
*/ | ||
class Json extends Column implements ElementDiffAwareInterface, ColumnNullableAwareInterface | ||
{ | ||
/** | ||
* @var bool | ||
*/ | ||
private $nullable; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param string $name | ||
* @param string $type | ||
* @param Table $table | ||
* @param bool $nullable | ||
* @param string|null $comment | ||
* @param string|null $onCreate | ||
*/ | ||
public function __construct( | ||
string $name, | ||
string $type, | ||
Table $table, | ||
bool $nullable = true, | ||
string $comment = null, | ||
string $onCreate = null | ||
) { | ||
parent::__construct($name, $type, $table, $comment, $onCreate); | ||
$this->nullable = $nullable; | ||
} | ||
|
||
/** | ||
* Check whether column can be nullable. | ||
* | ||
* @return bool | ||
*/ | ||
public function isNullable() | ||
{ | ||
return $this->nullable; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getDiffSensitiveParams() | ||
{ | ||
return [ | ||
'type' => $this->getType(), | ||
'nullable' => $this->isNullable(), | ||
'comment' => $this->getComment() | ||
]; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Factories/Json.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\Setup\Declaration\Schema\Dto\Factories; | ||
|
||
use Magento\Framework\ObjectManagerInterface; | ||
|
||
/** | ||
* Class Json | ||
*/ | ||
class Json implements FactoryInterface | ||
{ | ||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $className; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param ObjectManagerInterface $objectManager | ||
* @param string $className | ||
*/ | ||
public function __construct( | ||
ObjectManagerInterface $objectManager, | ||
$className = \Magento\Framework\Setup\Declaration\Schema\Dto\Columns\Blob::class | ||
) { | ||
$this->objectManager = $objectManager; | ||
$this->className = $className; | ||
} | ||
|
||
/** | ||
* Create element using definition data array. | ||
* | ||
* @param array $data | ||
* @return \Magento\Framework\Setup\Declaration\Schema\Dto\ElementInterface|mixed | ||
*/ | ||
public function create(array $data) | ||
{ | ||
return $this->objectManager->create($this->className, $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
lib/internal/Magento/Framework/Setup/Declaration/Schema/etc/types/texts/json.xsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> | ||
<xs:include schemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/types/column.xsd"/> | ||
|
||
<xs:complexType name="json"> | ||
<xs:complexContent> | ||
<xs:extension base="abstractColumnType"> | ||
<xs:annotation> | ||
<xs:documentation> | ||
Well formatted Json object | ||
</xs:documentation> | ||
</xs:annotation> | ||
<xs:attribute name="nullable" type="xs:boolean" /> | ||
</xs:extension> | ||
</xs:complexContent> | ||
</xs:complexType> | ||
</xs:schema> |
25 changes: 25 additions & 0 deletions
25
lib/internal/Magento/Framework/Setup/SchemaListenerDefinition/JsonDefinition.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\Setup\SchemaListenerDefinition; | ||
|
||
/** | ||
* Json type definition. | ||
*/ | ||
class JsonDefinition implements DefinitionConverterInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function convertToDefinition(array $definition) | ||
{ | ||
return [ | ||
'xsi:type' => $definition['type'], | ||
'name' => $definition['name'], | ||
'nullable' => $definition['nullable'] ?? true | ||
]; | ||
} | ||
} |