Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* version constraint syntax * Add CI job for satis repo update * tried to make postinstall work with a event handlers * Initial draft of writing config to var/config and symlinking to old locations * Add trailing semicolon (syntax) * Add quotation marks for app fileroot * Move static dir out of horde dir * Stub of a horde-specific command * Add missing getCapabilities * Flesh out stub of HordeReconfigureCommand * Add phpstan action * Fix issues found by phpstan * Raise to phpstan level 3 * Fix issues found by phpstan * Move to phpstan level 5 * horde-reconfigure command can now rebuild js and config symlinks * Fix phpstan detected issues * Write horde.local.php files during horde-reconfigure command * Handle copying presets and linking themes * Add type hints suggested by phpstan level 6 * Ensure always returning a string, not false * Handle doc/registry.d snippets Co-authored-by: Koch, Corbinian <koch@b1-systems.de> Co-authored-by: Midah Pasche <midahannep@gmail.com>
- Loading branch information
1 parent
21127f6
commit afd3e4a
Showing
13 changed files
with
561 additions
and
24 deletions.
There are no files selected for viewing
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,18 @@ | ||
name: PHPStan | ||
on: | ||
push: | ||
workflow_dispatch: | ||
pull_request: | ||
|
||
jobs: | ||
phpstan: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: php-actions/composer@v5 | ||
|
||
- name: PHPStan Static Analysis | ||
uses: php-actions/phpstan@v3 | ||
with: | ||
path: src/ | ||
level: 5 |
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,16 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
namespace Horde\Composer; | ||
|
||
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Composer\Command\BaseCommand; | ||
|
||
class CommandProvider implements CommandProviderCapability | ||
{ | ||
public function getCommands() | ||
{ | ||
return [new HordeReconfigureCommand]; | ||
} | ||
} |
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,69 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
namespace Horde\Composer; | ||
use \DirectoryIterator; | ||
use \RecursiveDirectoryIterator; | ||
use \RecursiveIteratorIterator; | ||
|
||
class ConfigLinker | ||
{ | ||
private string $baseDir; | ||
private string $configDir; | ||
private string $vendorDir; | ||
private string $webDir; | ||
|
||
public function __construct(string $baseDir) | ||
{ | ||
$this->baseDir = $baseDir; | ||
$this->vendorDir = $baseDir . '/vendor'; | ||
$this->webDir= $baseDir . '/web'; | ||
$this->configDir = $this->baseDir . '/var/config'; | ||
} | ||
/** | ||
* Symlink contents of var/config | ||
* | ||
* We always check the whole tree even though this may happen | ||
* multiple times in installations with many apps | ||
* | ||
* @return void | ||
*/ | ||
public function run(): void | ||
{ | ||
// Abort unless var/config exists and is readable | ||
if (!is_dir($this->configDir) || !is_readable($this->configDir)) { | ||
return; | ||
} | ||
// Iterate through subdirs | ||
foreach (new DirectoryIterator($this->configDir) as $appFileInfo) { | ||
if (!$appFileInfo->isDir()) { | ||
continue; | ||
} | ||
if ($appFileInfo->isDot()) { | ||
continue; | ||
} | ||
$app = $appFileInfo->getFilename(); | ||
// Next if no corresponding web/$app/config dir exists | ||
$appConfigDir = $appFileInfo->getPathname(); | ||
$targetDir = $this->webDir . '/' . $app . '/config/'; | ||
if (!is_dir($targetDir)) { | ||
continue; | ||
} | ||
// Iterate recursively | ||
$contentInfo = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($appConfigDir)); | ||
foreach ($contentInfo as $contentItem) { | ||
// Don't symlink dirs | ||
if ($contentItem->isDir()) { | ||
continue; | ||
} | ||
$relativeName = $contentInfo->getSubPathname(); | ||
$linkName = $targetDir . '/' . $relativeName; | ||
$sourceName = $appConfigDir . '/' . $relativeName; | ||
if (file_exists($linkName)) { | ||
continue; | ||
} | ||
symlink($sourceName, $linkName); | ||
} | ||
// Do not overwrite existing files or links | ||
} | ||
} | ||
} |
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
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
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,83 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
namespace Horde\Composer; | ||
use \Composer\Util\Filesystem; | ||
|
||
class HordeLocalFileWriter | ||
{ | ||
/** | ||
* List of apps | ||
* | ||
* @var string[] | ||
*/ | ||
private array $apps; | ||
private string $baseDir; | ||
private string $configDir; | ||
private string $vendorDir; | ||
private string $webDir; | ||
|
||
private Filesystem $filesystem; | ||
|
||
/** | ||
* Undocumented function | ||
* | ||
* @param Filesystem $filesystem | ||
* @param string $baseDir | ||
* @param string[] $apps | ||
*/ | ||
public function __construct(Filesystem $filesystem, string $baseDir, array $apps) | ||
{ | ||
$this->filesystem = $filesystem; | ||
$this->baseDir = $baseDir; | ||
$this->configDir = $baseDir . '/var/config'; | ||
$this->vendorDir = $baseDir . '/vendor'; | ||
$this->webDir = $baseDir . '/web'; | ||
$this->apps = $apps; | ||
} | ||
|
||
public function run(): void | ||
{ | ||
foreach ($this->apps as $app) { | ||
$this->processApp($app); | ||
} | ||
} | ||
|
||
private function processApp(string $app): void | ||
{ | ||
$hordeWebDir = $this->webDir . '/horde'; | ||
list($vendor, $name) = explode('/', $app, 2); | ||
$this->filesystem->ensureDirectoryExists($this->configDir . "/$name"); | ||
$path = $this->configDir . "/$name/horde.local.php"; | ||
$hordeLocalFileContent = sprintf( | ||
"<?php if (!defined('HORDE_BASE')) define('HORDE_BASE', '%s');\n", | ||
$hordeWebDir | ||
); | ||
// special case horde/horde needs to require the composer autoloader | ||
if ($app == 'horde/horde') { | ||
$hordeLocalFileContent .= $this->_legacyWorkaround(realpath($this->vendorDir)); | ||
$hordeLocalFileContent .= "require_once('" . $this->vendorDir ."/autoload.php');"; | ||
} | ||
$this->filesystem->filePutContentsIfModified($path, $hordeLocalFileContent); | ||
} | ||
/** | ||
* Legacy support | ||
* | ||
* Work around case inconsistencies | ||
* hard requires etc until they are resolved in code | ||
* | ||
* @param string $path Path to vendor dir | ||
* @return string | ||
*/ | ||
protected function _legacyWorkaround(string $path): string | ||
{ | ||
return sprintf("ini_set('include_path', '%s/horde/autoloader/lib%s%s/horde/form/lib/%s' . ini_get('include_path')); | ||
require_once('%s/horde/core/lib/Horde/Core/Nosql.php'); | ||
", | ||
$path, | ||
PATH_SEPARATOR, | ||
$path, | ||
PATH_SEPARATOR, | ||
$path | ||
); | ||
} | ||
} |
Oops, something went wrong.