Skip to content

Commit

Permalink
Add combat command
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Oct 20, 2017
1 parent 6fc5a1c commit 641d531
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
112 changes: 112 additions & 0 deletions bundles/SystemBundle/Command/System/Compat/CompatCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace SystemBundle\Command\System\Compat;

use Windwalker\Console\Command\Command;
use Windwalker\Filesystem\Folder;

class CompatCommand extends Command
{
/**
* An enabled flag.
*
* @var bool
*/
public static $isEnabled = true;

/**
* Property name.
*
* @var string
*/
protected $name = 'compat';

/**
* Property description.
*
* @var string
*/
protected $description = 'Add compat helper file for IDE after Joomla 3.8.';

/**
* Property usage.
*
* @var string
*/
protected $usage = 'compat <cmd><folder></cmd> <option>[option]</option>';

/**
* Property offline.
*
* @var int
*/
protected $offline = 0;

/**
* doExecute
*
* @return void
*/
protected function doExecute()
{
$folder = $this->getArgument(0, 'tmp');

$path = JPATH_BASE . '/' . trim($folder, '/\\');

$path = realpath($path);

if (!$path)
{
Folder::create($path);
}

$this->out('Creating helper file...');

$aliases = \JLoader::getDeprecatedAliases();

$placeholders = [];

foreach ($aliases as $alias)
{
$version = $alias['version'];

if (version_compare(JVERSION, $version, '>='))
{
continue;
}

$placeholders[] = $this->getTemplate($alias['old'], $alias['new']);
}

$placeholders = "<?php\n\n" . implode("\n\n", $placeholders);

file_put_contents($path . '/compat.php', $placeholders);

$this->out(sprintf('File: %s created.', $path . '/compat.php'));

return;
}

/**
* getTemplate
*
* @param string $class
* @param string $targetClass
*
* @return string
*/
protected function getTemplate($class, $targetClass)
{
$class = ucfirst($class);

return <<<PHP
if (!class_exists('$class'))
{
/**
* @deprecated This class is only a placeholder.
*/
class $class extends $targetClass {}
}
PHP;
}
}
2 changes: 2 additions & 0 deletions bundles/SystemBundle/Command/System/SystemCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SystemBundle\Command\System;

use SystemBundle\Command\System\CleanCache\ClearCacheCommand;
use SystemBundle\Command\System\Compat\CompatCommand;
use SystemBundle\Command\System\Off\OffCommand;
use SystemBundle\Command\System\On\OnCommand;
use Windwalker\Console\Command\Command;
Expand Down Expand Up @@ -42,5 +43,6 @@ protected function initialise()
$this->addCommand(new ClearCacheCommand);
$this->addCommand(new OnCommand);
$this->addCommand(new OffCommand);
$this->addCommand(new CompatCommand);
}
}

0 comments on commit 641d531

Please sign in to comment.