Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement namespace #3

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
460 changes: 460 additions & 0 deletions Classes/Controller/DatabaseController.php

Large diffs are not rendered by default.

155 changes: 155 additions & 0 deletions Classes/Dispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?php
namespace Aoe\T3deploy;

/***************************************************************
* Copyright notice
*
* (c) 2018 AOE GmbH <[email protected]>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

use TYPO3\CMS\Core\Controller\CommandLineController;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* General CLI dispatcher for the t3deploy extension.
*
* @package t3deploy
*/
class Dispatcher extends CommandLineController
{
const ExtKey = 't3deploy';
const Mask_ClassName = 'Aoe\\T3deploy\\Controller\\%sController';
const Mask_Action = '%sAction';

/**
* @var array
*/
protected $classInstances = [];

/**
* Creates this object.
*/
public function __construct()
{
parent::__construct();

$this->setCliOptions();

$this->cli_help = array_merge($this->cli_help, [
'name' => __CLASS__,
'synopsis' => self::ExtKey . ' controller action ###OPTIONS###',
'description' => 'TYPO3 dispatcher for database related operations.',
'examples' => 'typo3/cli_dispatch.phpsh ' . self::ExtKey . ' database updateStructure',
'author' => '(c) 2012 - 2018 AOE GmbH <[email protected]>',
]);
}

/**
* Sets the CLI arguments.
*
* @param array $arguments
* @return void
*/
public function setCliArguments(array $arguments)
{
$this->cli_args = $arguments;
}

/**
* Gets or generates an instance of the given class name.
*
* @param string $className
* @return object
*/
public function getClassInstance($className)
{
if (!isset($this->classInstances[$className])) {
$this->classInstances[$className] = GeneralUtility::makeInstance($className);
}
return $this->classInstances[$className];
}

/**
* Sets an instance for the given class name.
*
* @param string $className
* @param object $classInstance
* @return void
*/
public function setClassInstance($className, $classInstance)
{
$this->classInstances[$className] = $classInstance;
}

/**
* Dispatches the requested actions to the accordant controller.
*
* @return mixed
* @throws \Exception
*/
public function dispatch()
{
$controller = (string)$this->cli_args['_DEFAULT'][1];
$action = (string)$this->cli_args['_DEFAULT'][2];

if (!$controller || !$action) {
$this->cli_validateArgs();
$this->cli_help();
exit(1);
}

$className = sprintf(self::Mask_ClassName, ucfirst($controller));
$actionName = sprintf(self::Mask_Action, $action);

$instance = $this->getClassInstance($className);

if (!is_callable([$instance, $actionName])) {
throw new \Exception('The action ' . $action . ' is not implemented in controller ' . $controller);
}

$result = call_user_func_array(
[$instance, $actionName],
[$this->cli_args]
);

return $result;
}

/**
* Sets the CLI options for help.
*
* @return void
*/
protected function setCliOptions()
{
$this->cli_options = [
['--verbose', 'Report changes'],
['-v', 'Same as --verbose'],
['--execute', 'Execute changes (updates, removals)'],
['-e', 'Same as --execute'],
['--remove', 'Include structure differences for removal'],
['-r', 'Same as --remove'],
['--drop-keys', 'Removes key modifications that will cause errors'],
['--dump-file', 'Dump changes to file'],
['--excludes', 'Exclude update types (add,change,create_table,change_table,drop,drop_table,clear_table)']
];
}
}
Loading