-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6fc5a1c
commit 641d531
Showing
2 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
bundles/SystemBundle/Command/System/Compat/CompatCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters