MOON
Server: Apache
System: Linux server1.studioinfinity.com.br 2.6.32-954.3.5.lve1.4.90.el6.x86_64 #1 SMP Tue Feb 21 12:26:30 UTC 2023 x86_64
User: artinside (517)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/artinside/sites.artinside.com.br/paliar/vendor/aplus/database/src/Definition/DropSchema.php
<?php declare(strict_types=1);
/*
 * This file is part of Aplus Framework Database Library.
 *
 * (c) Natan Felles <natanfelles@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Framework\Database\Definition;

use Framework\Database\Statement;
use LogicException;

/**
 * Class DropSchema.
 *
 * @see https://mariadb.com/kb/en/drop-database/
 *
 * @package database
 */
class DropSchema extends Statement
{
    /**
     * @return static
     */
    public function ifExists() : static
    {
        $this->sql['if_exists'] = true;
        return $this;
    }

    protected function renderIfExists() : ?string
    {
        if (!isset($this->sql['if_exists'])) {
            return null;
        }
        return ' IF EXISTS';
    }

    /**
     * @param string $schemaName
     *
     * @return static
     */
    public function schema(string $schemaName) : static
    {
        $this->sql['schema'] = $schemaName;
        return $this;
    }

    protected function renderSchema() : string
    {
        if (isset($this->sql['schema'])) {
            return ' ' . $this->database->protectIdentifier($this->sql['schema']);
        }
        throw new LogicException('SCHEMA name must be set');
    }

    public function sql() : string
    {
        $sql = 'DROP SCHEMA' . $this->renderIfExists();
        $sql .= $this->renderSchema() . \PHP_EOL;
        return $sql;
    }

    /**
     * Runs the CREATE SCHEMA statement.
     *
     * @return int|string The number of affected rows
     */
    public function run() : int | string
    {
        return $this->database->exec($this->sql());
    }
}