Skip to content

Commit

Permalink
Merge pull request #17 from MekDrop/fix/for-older-php
Browse files Browse the repository at this point in the history
This probably would fix running on older PHP versions than 8.0 when installing with ImpressCMS
  • Loading branch information
fiammybe authored Oct 14, 2021
2 parents 27e34d2 + 2e0ab12 commit 9f4ba67
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 12 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"class": "ImpressCMS\\Composer\\AddonInstaller\\ComposerPlugin"
},
"require": {
"symfony/polyfill-php80": ">=1.21",
"composer-plugin-api": "^1.0 || ^2.0",
"phpexperts/laravel-env-polyfill": ">=1.0",
"vlucas/phpdotenv": ">=3.3.3"
Expand Down
7 changes: 4 additions & 3 deletions src/LibraryInstaller/ModuleInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Composer\Installer\LibraryInstaller;
use Composer\Package\PackageInterface;
use ImpressCMS\Composer\AddonInstaller\Utils\ImpressCMSConstantsReader;
use ImpressCMS\Composer\AddonInstaller\Utils\StrHelper;

/**
* Custom installer to install impresscms supported modules
Expand All @@ -20,11 +21,11 @@ public function getInstallPath(PackageInterface $package)
{
list($vendor, $dir) = explode('/', $package->getName());

if (str_starts_with($dir, 'impresscms-module-')) {
if (StrHelper::str_starts_with($dir, 'impresscms-module-')) {
$dir = substr($dir, strlen('impresscms-module-'));
} elseif (str_starts_with($dir, 'module-')) {
} elseif (StrHelper::str_starts_with($dir, 'module-')) {
$dir = substr($dir, strlen('module-'));
} elseif (str_ends_with($dir, '-module')) {
} elseif (StrHelper::str_ends_with($dir, '-module')) {
$dir = substr($dir, 0, -strlen('-module'));
}

Expand Down
7 changes: 4 additions & 3 deletions src/LibraryInstaller/ThemeInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Composer\Installer\LibraryInstaller;
use Composer\Package\PackageInterface;
use ImpressCMS\Composer\AddonInstaller\Utils\ImpressCMSConstantsReader;
use ImpressCMS\Composer\AddonInstaller\Utils\StrHelper;

/**
* Custom installer to install impresscms supported themes
Expand All @@ -21,11 +22,11 @@ public function getInstallPath(PackageInterface $package)
{
list($vendor, $dir) = explode('/', $package->getName());

if (str_starts_with($dir, 'impresscms-theme-')) {
if (StrHelper::str_starts_with($dir, 'impresscms-theme-')) {
$dir = substr($dir, strlen('impresscms-theme-'));
} elseif (str_starts_with($dir, 'theme-')) {
} elseif (StrHelper::str_starts_with($dir, 'theme-')) {
$dir = substr($dir, strlen('theme-'));
} elseif (str_ends_with($dir, '-theme')) {
} elseif (StrHelper::str_ends_with($dir, '-theme')) {
$dir = substr($dir, 0, -strlen('-theme'));
}

Expand Down
6 changes: 3 additions & 3 deletions src/Listeners/AutoloadDumpListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public function postAutoloadDump(Event $event)
*/
protected function clearCaches(ProcessExecutor $executor, IOInterface $IO)
{
$IO->info("Clearing caches...");
$IO->write("<info>Clearing caches...</info>");
if ($executor->executeImpressCMSCommand("cache:clear") > 0) {
$IO->warning(' Clearing system cache failed');
$IO->write(' <warning>Clearing system cache failed</warning>');
} else {
$IO->write(' System cache cleared successfully');
}
if ($executor->executeImpressCMSCommand("templates:cache:clear") > 0) {
$IO->warning(' Clearing template cache failed');
$IO->write(' <warning>Clearing template cache failed</warning>');
} else {
$IO->write(' Template cache cleared successfully');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/ImpressCMSConstantsReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public function getConstant(string $constantName, $defaultValue)
public function load()
{
if ($this->exists()) {
$this->IO->debug('Loading ImpressCMS constants file...');
$this->IO->write('Loading ImpressCMS constants file...');
/** @noinspection PhpIncludeInspection */
require_once $this->getFilename();
} else {
$this->IO->debug('Np ImpressCMS constants file was found or composer plugin can\'t load it.');
$this->IO->write('Np ImpressCMS constants file was found or composer plugin can\'t load it.');
}
self::$loaded = true;
}
Expand Down
47 changes: 47 additions & 0 deletions src/Utils/StrHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace ImpressCMS\Composer\AddonInstaller\Utils;

/**
* Few string malipulation related functions
*
* @package ImpressCMS\Composer\AddonInstaller\Utils
*/
final class StrHelper
{

/**
* StrHelper disabled constructor.
*/
private function __construct()
{
}

/**
* Checks if string starts with another string
*
* @param string $str String where to look
* @param string $needle String to look for
*
* @return bool
*/
public static function str_starts_with(string $str, string $needle): bool
{
return strpos($str, $needle) === 0;
}

/**
* Checks if string ends with such string
*
* @param string $str Where to look
* @param string $needle What to look
*
* @return bool
*/
public static function str_ends_with(string $str, string $needle): bool
{
return substr($str, -strlen($needle)) === $needle;
}


}

0 comments on commit 9f4ba67

Please sign in to comment.