Skip to content
Snippets Groups Projects
Commit 2af34655 authored by Florian Weber's avatar Florian Weber
Browse files

Merge branch '3245516-cs' into '8.x-1.x'

Fix CS

See merge request !10
parents 4223a831 9caa90ce
No related branches found
No related tags found
No related merge requests found
Pipeline #306761 passed
<?php <?php
/**
* @file
* Install, update and uninstall functions for the composer_deploy module.
*/
/** /**
* Really remove vendor_dir from composer_deploy config. * Really remove vendor_dir from composer_deploy config.
*/ */
function composer_deploy_update_8101() { function composer_deploy_update_8101(): void {
\Drupal::configFactory() \Drupal::configFactory()
->getEditable('composer_deploy.settings') ->getEditable('composer_deploy.settings')
->clear('vendor_dir') ->clear('vendor_dir')
......
<?php <?php
use Drupal\composer_deploy\ComposerDeployHandler; /**
* @file
* Provides metadata from composer lockfile to Drupal.
*/
use Drupal\Core\Extension\Extension; use Drupal\Core\Extension\Extension;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\composer_deploy\ComposerDeployHandler;
use DrupalFinder\DrupalFinderComposerRuntime; use DrupalFinder\DrupalFinderComposerRuntime;
/** /**
* @param array $info * Implements hook_system_info_alter().
* @param \Drupal\Core\Extension\Extension $file
* @param $type
*/ */
function composer_deploy_system_info_alter(array &$info, Extension $file, $type) { function composer_deploy_system_info_alter(array &$info, Extension $file, string $type): void {
$handler = &drupal_static(__FUNCTION__); $handler = &drupal_static(__FUNCTION__);
if (!isset($handler)) { if (!isset($handler)) {
...@@ -34,19 +37,20 @@ function composer_deploy_system_info_alter(array &$info, Extension $file, $type) ...@@ -34,19 +37,20 @@ function composer_deploy_system_info_alter(array &$info, Extension $file, $type)
if (empty($info['version']) && $handler) { if (empty($info['version']) && $handler) {
$extensionName = basename($file->getFilename(), '.info.yml'); $extensionName = basename($file->getFilename(), '.info.yml');
$package = $handler->getPackageByPath(DRUPAL_ROOT. '/' . $file->getPath()); $package = $handler->getPackageByPath(DRUPAL_ROOT . '/' . $file->getPath());
if (!$package) { if (!$package) {
$package = $handler->getPackage($extensionName); $package = $handler->getPackage($extensionName);
} }
if ($package) { if ($package) {
// Skip processing for Drupal submodules. Submodules (e.g. ldap_authentication ldap) are shipped as metapackages. // Skip processing for Drupal submodules.
// Submodules (e.g. ldap_authentication ldap) are shipped as metapackages.
if ($package['type'] == 'metapackage') { if ($package['type'] == 'metapackage') {
return; return;
} }
[$vendor, $project] = explode('/', $package['name']); [$vendor, $project] = explode('/', $package['name']);
$info['project'] = $project; $info['project'] = $project;
$info['composer_deploy_git_hash'] = isset($package['source']['reference']) ? $package['source']['reference'] : NULL; $info['composer_deploy_git_hash'] = $package['source']['reference'] ?? NULL;
if (isset($package['extra']['drupal']['version'])) { if (isset($package['extra']['drupal']['version'])) {
$info['version'] = $package['extra']['drupal']['version']; $info['version'] = $package['extra']['drupal']['version'];
...@@ -55,7 +59,7 @@ function composer_deploy_system_info_alter(array &$info, Extension $file, $type) ...@@ -55,7 +59,7 @@ function composer_deploy_system_info_alter(array &$info, Extension $file, $type)
$info['datestamp'] = $package['extra']['drupal']['datestamp']; $info['datestamp'] = $package['extra']['drupal']['datestamp'];
} }
// Fallback to other composer metadata // Fallback to other composer metadata.
if (empty($info['datestamp']) && isset($package['time'])) { if (empty($info['datestamp']) && isset($package['time'])) {
$info['datestamp'] = strtotime($package['time']); $info['datestamp'] = strtotime($package['time']);
} }
...@@ -63,9 +67,7 @@ function composer_deploy_system_info_alter(array &$info, Extension $file, $type) ...@@ -63,9 +67,7 @@ function composer_deploy_system_info_alter(array &$info, Extension $file, $type)
$info['version'] = substr($package['version'], 4) . '-dev'; $info['version'] = substr($package['version'], 4) . '-dev';
} }
elseif (empty($info['version'])) { elseif (empty($info['version'])) {
/** // @todo Handle mode version constraints.
* @todo: Handle mode version constraints.
*/
$info['version'] = 'dev'; $info['version'] = 'dev';
} }
} }
......
<?php <?php
/**
* @file
* Contains \Drupal\composer_deploy\ComposerDeployHandler.
*/
namespace Drupal\composer_deploy; namespace Drupal\composer_deploy;
use DrupalFinder\DrupalFinderComposerRuntime; use DrupalFinder\DrupalFinderComposerRuntime;
use Symfony\Component\Filesystem\Path; use Symfony\Component\Filesystem\Path;
/** /**
* Load package metadata from composers installed.json file.
*
* @internal * @internal
*/ */
class ComposerDeployHandler { class ComposerDeployHandler {
protected $packages = [];
/** /**
* List of package prefixes. * Installed composer packages.
* *
* @var string[] * @var array
*/ */
protected $prefixes = ['drupal']; protected array $packages = [];
/** /**
* @var \DrupalFinder\DrupalFinder * List of package prefixes.
*
* @var string[]
*/ */
protected $drupalFinder; protected array $prefixes = ['drupal'];
public function __construct(DrupalFinderComposerRuntime $drupalFinder) {
$this->drupalFinder = $drupalFinder;
public function __construct(protected DrupalFinderComposerRuntime $drupalFinder) {
$packages = json_decode(file_get_contents($this->drupalFinder->getVendorDir() . '/composer/installed.json'), TRUE); $packages = json_decode(file_get_contents($this->drupalFinder->getVendorDir() . '/composer/installed.json'), TRUE);
// Composer 2.0 compatibility. // Composer 2.0 compatibility.
// @see https://getcomposer.org/upgrade/UPGRADE-2.0.md // @see https://getcomposer.org/upgrade/UPGRADE-2.0.md
...@@ -40,9 +35,11 @@ class ComposerDeployHandler { ...@@ -40,9 +35,11 @@ class ComposerDeployHandler {
} }
/** /**
* Lookup package metadata by project name.
*
* @deprecated. Use \Drupal\composer_deploy\ComposerDeployHandler::getPackageByPath instead. * @deprecated. Use \Drupal\composer_deploy\ComposerDeployHandler::getPackageByPath instead.
*/ */
public function getPackage($projectName) { public function getPackage(string $projectName): ?array {
foreach ($this->packages as $package) { foreach ($this->packages as $package) {
foreach ($this->prefixes as $prefix) { foreach ($this->prefixes as $prefix) {
if ($package['name'] == $prefix . '/' . $projectName) { if ($package['name'] == $prefix . '/' . $projectName) {
...@@ -50,10 +47,13 @@ class ComposerDeployHandler { ...@@ -50,10 +47,13 @@ class ComposerDeployHandler {
} }
} }
} }
return FALSE; return NULL;
} }
public function getPackageByPath($path) { /**
* Lookup package metadata by path.
*/
public function getPackageByPath(string $path): ?array {
foreach ($this->packages as $package) { foreach ($this->packages as $package) {
if (isset($package['install-path'])) { if (isset($package['install-path'])) {
$packagePath = $this->drupalFinder->getVendorDir() . '/composer/' . $package['install-path']; $packagePath = $this->drupalFinder->getVendorDir() . '/composer/' . $package['install-path'];
...@@ -62,15 +62,16 @@ class ComposerDeployHandler { ...@@ -62,15 +62,16 @@ class ComposerDeployHandler {
} }
} }
} }
return FALSE; return NULL;
} }
/** /**
* Set the package prefixes to check against. * Set the package prefixes to check against.
* *
* @param string[] $prefixes * @param string[] $prefixes
* Composer vendor prefixes.
*/ */
public function setPrefixes(array $prefixes) { public function setPrefixes(array $prefixes): void {
$this->prefixes = $prefixes; $this->prefixes = $prefixes;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment