forked from symfony/ux
-
Notifications
You must be signed in to change notification settings - Fork 0
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
52dc225
commit 05bcb98
Showing
37 changed files
with
558 additions
and
125 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
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
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,72 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\StimulusBundle\AssetMapper; | ||
|
||
use Symfony\Component\AssetMapper\AssetMapperInterface; | ||
use Symfony\Component\AssetMapper\ImportMap\ImportMapConfigReader; | ||
use Symfony\Component\AssetMapper\MappedAsset; | ||
use Symfony\UX\StimulusBundle\Ux\UxPackageMetadata; | ||
|
||
/** | ||
* Finds the MappedAsset for an "autoimport" string. | ||
*/ | ||
class AutoImportLocator | ||
{ | ||
public function __construct( | ||
private ImportMapConfigReader $importMapConfigReader, | ||
private AssetMapperInterface $assetMapper, | ||
) { | ||
} | ||
|
||
// parts of this method are duplicated & adapted from UxControllersTwigRuntime | ||
public function locateAutoImport(string $path, UxPackageMetadata $packageMetadata): MappedControllerAutoImport | ||
{ | ||
// see if this is a mapped asset path | ||
if ($asset = $this->assetMapper->getAsset($path)) { | ||
return new MappedControllerAutoImport($asset->sourcePath, false); | ||
} | ||
|
||
$slashPosition = strpos($path, '/'); | ||
if (false === $slashPosition) { | ||
throw new \LogicException(sprintf('The autoimport "%s" is not valid.', $path)); | ||
} | ||
|
||
$parts = explode('/', ltrim($path, '@')); | ||
if (2 > \count($parts)) { | ||
throw new \LogicException(sprintf('The autoimport "%s" is not valid.', $path)); | ||
} | ||
$package = implode('/', \array_slice($parts, 0, 2)); | ||
$file = implode('/', \array_slice($parts, 2)); | ||
|
||
if ($package === $packageMetadata->packageName) { | ||
// this is a file local to the ux package | ||
$filePath = $packageMetadata->packageDirectory.'/'.$file; | ||
if (!is_file($filePath)) { | ||
throw new \LogicException(sprintf('An "autoimport" in "controllers.json" refers to "%s". This path could not be found in the asset mapper and the file "%s" does not exist in the package path "%s". And so, the file cannot be loaded.', $path, $filePath, $packageMetadata->packageDirectory)); | ||
} | ||
|
||
$asset = $this->assetMapper->getAssetFromSourcePath($filePath); | ||
if (!$asset) { | ||
throw new \LogicException(sprintf('An "autoimport" in "controllers.json" refers to "%s". This file was found, but the path is not in the asset mapper. And so, the file cannot be loaded. This is a misconfiguration with the bundle providing this.', $path)); | ||
} | ||
|
||
return new MappedControllerAutoImport($asset->sourcePath, false); | ||
} | ||
|
||
$entry = $this->importMapConfigReader->findRootImportMapEntry($path); | ||
if (!$entry) { | ||
throw new \LogicException(sprintf('The autoimport "%s" could not be found in importmap.php. Try running "importmap:require %s".', $path, $path)); | ||
} | ||
|
||
return new MappedControllerAutoImport($path, true); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/StimulusBundle/src/AssetMapper/MappedControllerAutoImport.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,26 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\StimulusBundle\AssetMapper; | ||
|
||
/** | ||
* @experimental | ||
* | ||
* @author Ryan Weaver <[email protected]> | ||
*/ | ||
class MappedControllerAutoImport | ||
{ | ||
public function __construct( | ||
public string $path, | ||
public bool $isBareImport | ||
) { | ||
} | ||
} |
Oops, something went wrong.