Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
Boolean Class Reference
Inheritance diagram for Boolean:
DbDefinitionProcessorInterface

Public Member Functions

 __construct (Nullable $nullable, ResourceConnection $resourceConnection, Comment $comment)
 
 toDefinition (ElementInterface $column)
 
 fromDefinition (array $data)
 

Data Fields

const TYPE = 'BOOLEAN'
 
const INTEGER_TYPE = 'tinyint'
 
const INTEGER_PADDING = '1'
 

Detailed Description

As all MySQL aliases as BOOL or BOOLEAN are converted to TINYINT(1) proposed to processed tinyint as boolean.

Definition at line 19 of file Boolean.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Nullable  $nullable,
ResourceConnection  $resourceConnection,
Comment  $comment 
)

Constructor.

Parameters
Nullable$nullable
ResourceConnection$resourceConnection
Comment$comment

Definition at line 58 of file Boolean.php.

62  {
63  $this->nullable = $nullable;
64  $this->resourceConnection = $resourceConnection;
65  $this->comment = $comment;
66  }

Member Function Documentation

◆ fromDefinition()

fromDefinition ( array  $data)

Boolean is presented as tinyint(1).

Input always will be array of SQL definitions, like: 'type' => 'name VARCHAR(255)'\ 'nullable' => 'no'

Parameters
array$data
Returns
array

Implements DbDefinitionProcessorInterface.

Definition at line 90 of file Boolean.php.

91  {
92  if ($data['type'] === self::INTEGER_TYPE && $data['padding'] === self::INTEGER_PADDING) {
93  $data['type'] = strtolower(self::TYPE);
94  if (isset($data['default'])) {
95  $data['default'] = $data['default'] === null ? null : (bool) $data['default'];
96  }
97  $data['unsigned'] = false; //Not signed for boolean
98  unset($data['padding']);
99  }
100 
101  return $data;
102  }

◆ toDefinition()

toDefinition ( ElementInterface  $column)
Parameters
\Magento\Framework\Setup\Declaration\Schema\Dto\Columns\Boolean$columnOutput always will be SQL definition.

Implements DbDefinitionProcessorInterface.

Definition at line 72 of file Boolean.php.

73  {
74  return sprintf(
75  '%s %s %s %s %s',
76  $this->resourceConnection->getConnection()->quoteIdentifier($column->getName()),
77  self::TYPE,
78  $this->nullable->toDefinition($column),
79  $column->getDefault() !== null ?
80  sprintf('DEFAULT %s', $column->getDefault() ? 1 : 0) : '',
81  $this->comment->toDefinition($column)
82  );
83  }

Field Documentation

◆ INTEGER_PADDING

const INTEGER_PADDING = '1'

Padding for integer described below.

Definition at line 34 of file Boolean.php.

◆ INTEGER_TYPE

const INTEGER_TYPE = 'tinyint'

Type of integer that is used in MySQL for boolean.

Definition at line 29 of file Boolean.php.

◆ TYPE

const TYPE = 'BOOLEAN'

Type the column is persisted with.

Definition at line 24 of file Boolean.php.


The documentation for this class was generated from the following file: