Skip to content

Commit

Permalink
FRW-9645 Enable feature development. (#11264)
Browse files Browse the repository at this point in the history
FRW-9645 Enable feature development.
  • Loading branch information
annakotiuk authored Jan 7, 2025
1 parent 2123aa9 commit 6e85228
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 7 deletions.
1 change: 1 addition & 0 deletions config/Shared/config_default.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
];
$config[KernelConstants::CORE_NAMESPACES] = [
'SprykerShop',
'SprykerFeature',
'SprykerEco',
'Spryker',
'SprykerSdk',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function find(): array
$modules = [];
$modules[] = $this->loadProjectModules();
$modules[] = $this->loadCoreDevelopmentModules();
$modules[] = $this->loadFeaturesDevelopmentModules();
$modules[] = $this->loadOtherCoreModules();

return $this->addApplication(array_merge(...$modules));
Expand Down Expand Up @@ -87,6 +88,21 @@ protected function loadCoreDevelopmentModules(): array
return array_merge(...$modules);
}

/**
* @return array
*/
protected function loadFeaturesDevelopmentModules(): array
{
$modules = [];

foreach (range('A', 'Z') as $letter) {
$path = sprintf('%s/spryker/%s/Features/%s*/src/*/*', APPLICATION_VENDOR_DIR, 'spryker', $letter);
$modules[] = $this->findModules($path, $this->developmentConfig->getSprykerFeatureNamespace());
}

return array_merge(...$modules);
}

/**
* @return array
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ protected function getOrganizationFromComposerJsonFile(SplFileInfo $composerJson
return $matches[1];
}

if (preg_match('/vendor\/spryker\/spryker\/Features\/\w+\/composer.json$/', $realPath, $matches)) {
return 'spryker-feature';
}

if (preg_match('/vendor\/([a-z_-]+)\/[a-z_-]+\/composer.json$/', $realPath, $matches)) {
return $matches[1];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ class AutoloadUpdater implements UpdaterInterface
*/
public const SPRYKER_NAMESPACE = 'Spryker';

/**
* @var string
*/
public const SPRYKER_FEATURE_NAMESPACE = 'SprykerFeature';

/**
* @var string
*/
Expand Down Expand Up @@ -169,6 +174,7 @@ class AutoloadUpdater implements UpdaterInterface
*/
protected $autoloadPSR4Whitelist = [
self::SPRYKER_NAMESPACE,
self::SPRYKER_FEATURE_NAMESPACE,
self::SPRYKER_SHOP_NAMESPACE,
self::SPRYKER_ECO_NAMESPACE,
self::BASE_HELPER_DIRECTORY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
use Spryker\Zed\Development\Business\Module\PathBuilder\PathBuilderComposite;
use Spryker\Zed\Development\Business\Module\PathBuilder\PathBuilderInterface;
use Spryker\Zed\Development\Business\Module\PathBuilder\SprykerEcoModulePathBuilder;
use Spryker\Zed\Development\Business\Module\PathBuilder\SprykerFeatureModulePathBuilder;
use Spryker\Zed\Development\Business\Module\PathBuilder\SprykerMerchantPortalModulePathBuilder;
use Spryker\Zed\Development\Business\Module\PathBuilder\SprykerModulePathBuilder;
use Spryker\Zed\Development\Business\Module\PathBuilder\SprykerSdkModulePathBuilder;
Expand Down Expand Up @@ -337,6 +338,7 @@ public function createPathBuilder(): PathBuilderInterface
return new PathBuilderComposite([
$this->createSprykerStandaloneModuleFilePathBuilder(),
$this->createSprykerModuleFilePathBuilder(),
$this->createSprykerFeatureModuleFilePathBuilder(),
$this->createSprykerShopModuleFilePathBuilder(),
$this->createSprykerEcoModuleFilePathBuilder(),
$this->createSprykerSdkModulePathBuilder(),
Expand All @@ -362,6 +364,16 @@ public function createSprykerModuleFilePathBuilder(): PathBuilderInterface
);
}

/**
* @return \Spryker\Zed\Development\Business\Module\PathBuilder\PathBuilderInterface
*/
public function createSprykerFeatureModuleFilePathBuilder(): PathBuilderInterface
{
return new SprykerFeatureModulePathBuilder(
$this->getConfig(),
);
}

/**
* @return \Spryker\Zed\Development\Business\Module\PathBuilder\PathBuilderInterface
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Zed\Development\Business\Module\PathBuilder;

class SprykerFeatureModulePathBuilder extends AbstractPathBuilder
{
/**
* @var string
*/
protected const ORGANIZATION = 'SprykerFeature';
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ protected function validateModules(OutputInterface $output): bool
protected function getModuleNames(): array
{
$finder = new Finder();
$finder->directories()->in(APPLICATION_VENDOR_DIR . '/spryker/spryker/Bundles/')->depth('< 1');
$finder->directories()->in([
APPLICATION_VENDOR_DIR . '/spryker/spryker/Bundles/',
APPLICATION_VENDOR_DIR . '/spryker/spryker/Features/',
])->depth('< 1');

$modules = [];

Expand Down Expand Up @@ -127,7 +130,10 @@ protected function getModuleSchemaFileFinder(string $module)
*/
protected function getPathToModuleSchemas(string $module): string
{
return sprintf('%1$s/spryker/spryker/Bundles/%2$s/src/Spryker/Zed/%2$s/Persistence/Propel/Schema/', APPLICATION_VENDOR_DIR, $module);
$bundlePath = sprintf('%1$s/spryker/spryker/Bundles/%2$s/src/Spryker/Zed/%2$s/Persistence/Propel/Schema/', APPLICATION_VENDOR_DIR, $module);
$featurePath = sprintf('%1$s/spryker/spryker/Features/%2$s/src/SprykerFeature/Zed/%2$s/Persistence/Propel/Schema/', APPLICATION_VENDOR_DIR, $module);

return is_dir($featurePath) ? $featurePath : $bundlePath;
}

/**
Expand Down Expand Up @@ -195,16 +201,18 @@ protected function abstractClassesForTableExists(array $simpleXmlTableElements,
$tableName = $this->getTableNameFromSimpleXmlTableElement($simpleXmlTableElement);

$abstractEntityClass = sprintf('Spryker\\Zed\\%s\\Persistence\\Propel\\Abstract%s', $module, $phpName);
if (!class_exists($abstractEntityClass)) {
$abstractFeatureEntityClass = sprintf('SprykerFeature\\Zed\\%s\\Persistence\\Propel\\Abstract%s', $module, $phpName);
if (!class_exists($abstractEntityClass) && !class_exists($abstractFeatureEntityClass)) {
$isValid = false;
$output->writeln(sprintf('<fg=yellow>%s</> <fg=red>does not exists, please create one.</>', $abstractEntityClass));
$output->writeln(sprintf('<fg=red>Neither %s nor %s</> <fg=red>does not exists, please create one.</>', $abstractEntityClass, $abstractFeatureEntityClass));
$output->writeln(sprintf('<fg=green>vendor/bin/console spryk:run AddZedPersistencePropelAbstractEntity --module=\'%1$s\' --targetModule=\'%1$s\' --tableName=\'%2$s\' -n</>', $module, $tableName));
}

$abstractQueryClass = sprintf('Spryker\\Zed\\%s\\Persistence\\Propel\\Abstract%sQuery', $module, $phpName);
if (!class_exists($abstractQueryClass)) {
$abstractFeatureQueryClass = sprintf('SprykerFeature\\Zed\\%s\\Persistence\\Propel\\Abstract%sQuery', $module, $phpName);
if (!class_exists($abstractQueryClass) && !class_exists($abstractFeatureQueryClass)) {
$isValid = false;
$output->writeln(sprintf('<fg=red>%s does not exists, please create one.</>', $abstractQueryClass));
$output->writeln(sprintf('<fg=red>Neither %s nor %s does not exists, please create one.</>', $abstractQueryClass, $abstractFeatureQueryClass));
$output->writeln(sprintf('<fg=green>vendor/bin/console spryk:run AddZedPersistencePropelAbstractQuery --module=\'%1$s\' --targetModule=\'%1$s\' --tableName=\'%2$s\' -n</>', $module, $tableName));
}
}
Expand Down
25 changes: 24 additions & 1 deletion src/Spryker/Zed/Development/DevelopmentConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class DevelopmentConfig extends AbstractBundleConfig
*/
protected const GROUP_SPRYKER_TEST = 'SprykerTest';

/**
* @var string
*/
protected const NAMESPACE_SPRYKER_FEATURE = 'SprykerFeature';

/**
* @var array<string>
*/
Expand Down Expand Up @@ -96,6 +101,7 @@ class DevelopmentConfig extends AbstractBundleConfig
*/
protected const INTERNAL_NAMESPACES_LIST = [
self::NAMESPACE_SPRYKER,
self::NAMESPACE_SPRYKER_FEATURE,
self::NAMESPACE_SPRYKER_SHOP,
self::NAMESPACE_SPRYKER_MERCHANT_PORTAL,
];
Expand All @@ -105,6 +111,7 @@ class DevelopmentConfig extends AbstractBundleConfig
*/
protected const INTERNAL_NAMESPACES_TO_PATH_MAPPING = [
self::NAMESPACE_SPRYKER => APPLICATION_ROOT_DIR . DIRECTORY_SEPARATOR . 'vendor/spryker/',
self::NAMESPACE_SPRYKER_FEATURE => APPLICATION_ROOT_DIR . DIRECTORY_SEPARATOR . 'vendor/spryker/',
self::NAMESPACE_SPRYKER_SHOP => APPLICATION_ROOT_DIR . DIRECTORY_SEPARATOR . 'vendor/spryker-shop/',
self::NAMESPACE_SPRYKER_ECO => APPLICATION_ROOT_DIR . DIRECTORY_SEPARATOR . 'vendor/spryker-eco/',
self::NAMESPACE_SPRYKER_SDK => APPLICATION_ROOT_DIR . DIRECTORY_SEPARATOR . 'vendor/spryker-sdk/',
Expand Down Expand Up @@ -139,7 +146,7 @@ public function getPermissionMode(): int
*/
public function getInternalNamespaces(): array
{
return ['Spryker', 'SprykerEco', 'SprykerSdk', 'SprykerShop', 'Orm'];
return ['Spryker', 'SprykerFeature', 'SprykerEco', 'SprykerSdk', 'SprykerShop', 'Orm'];
}

/**
Expand All @@ -153,6 +160,8 @@ public function getTwigPathPatterns(): array
$this->getPathToCore() . '%1$s/src/Spryker/Zed/%1$s/Presentation/',
$this->getPathToCore() . '%1$s/src/Spryker/Yves/%1$s/Theme/',
$this->getPathToShop() . '%1$s/src/SprykerShop/Yves/%1$s/Theme/',
$this->getPathToCore() . '%1$s/src/SprykerFeature/Zed/%1$s/Presentation/',
$this->getPathToCore() . '%1$s/src/SprykerFeature/Yves/%1$s/Theme/',
];
}

Expand Down Expand Up @@ -276,6 +285,7 @@ public function getOrganizationPathMap(): array
{
return [
'Spryker' => $this->getPathToCore(),
'SprykerFeature' => $this->getPathToCore(),
'SprykerEco' => $this->getPathToEco(),
];
}
Expand Down Expand Up @@ -890,4 +900,17 @@ public function isStandaloneMode(): bool
{
return (bool)getenv('DEVELOPMENT_STANDALONE_MODE');
}

/**
* Specification:
* - Returns Spryker Feature namespace.
*
* @api
*
* @return string
*/
public function getSprykerFeatureNamespace(): string
{
return static::NAMESPACE_SPRYKER_FEATURE;
}
}

0 comments on commit 6e85228

Please sign in to comment.