-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from markhuot/craft5
WIP Craft 5 Compat
- Loading branch information
Showing
87 changed files
with
1,326 additions
and
261 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
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,5 @@ | ||
parameters: | ||
excludePaths: | ||
- src/actions/RenderCraft5CompiledClasses.php | ||
- src/factories/EntryType.php | ||
- src/factories/MatrixFieldEntries.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,6 @@ | ||
parameters: | ||
excludePaths: | ||
- src/actions/RenderCraft4CompiledClasses.php | ||
- src/factories/AddsMatrixBlocks.php | ||
- src/factories/BlockType.php | ||
- src/factories/MatrixFieldBlocks.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
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 | ||
|
||
use Composer\InstalledVersions; | ||
use Composer\Semver\VersionParser; | ||
|
||
$config = []; | ||
|
||
if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~4.0')) { | ||
$config['includes'][] = 'phpstan-craft4.neon'; | ||
} | ||
|
||
if (InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '~5.0')) { | ||
$config['includes'][] = 'phpstan-craft5.neon'; | ||
} | ||
|
||
return $config; |
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,58 @@ | ||
<?php | ||
|
||
namespace markhuot\craftpest\actions; | ||
|
||
use craft\helpers\FileHelper; | ||
use craft\helpers\StringHelper; | ||
use markhuot\craftpest\interfaces\RenderCompiledClassesInterface; | ||
|
||
class RenderCraft5CompiledClasses implements RenderCompiledClassesInterface | ||
{ | ||
public function handle(bool $forceRecreate = false) | ||
{ | ||
$this->render($forceRecreate); | ||
|
||
return true; | ||
} | ||
|
||
protected function render(bool $forceRecreate) | ||
{ | ||
$storedFieldVersion = \Craft::$app->getFields()->getFieldVersion(); | ||
$compiledClassesPath = \Craft::$app->getPath()->getCompiledClassesPath(); | ||
$fieldVersionExists = $storedFieldVersion !== null; | ||
if (! $fieldVersionExists) { | ||
$storedFieldVersion = StringHelper::randomString(12); | ||
} | ||
|
||
$compiledClassPath = $compiledClassesPath.DIRECTORY_SEPARATOR.'FactoryFields_'.$storedFieldVersion.'.php'; | ||
|
||
if (file_exists($compiledClassPath) && ! $forceRecreate) { | ||
return false; | ||
} | ||
|
||
$this->cleanupOldMixins('FactoryFields_'.$storedFieldVersion.'.php'); | ||
|
||
$template = file_get_contents(__DIR__.'/../../stubs/compiled_classes/FactoryFields.twig'); | ||
|
||
$compiledClass = \Craft::$app->view->renderString($template, [ | ||
'fields' => \Craft::$app->fields->getAllFields(), | ||
]); | ||
|
||
file_put_contents($compiledClassPath, $compiledClass); | ||
} | ||
|
||
protected function cleanupOldMixins(?string $except = null) | ||
{ | ||
$compiledClassesPath = __DIR__.'/../storage/'; | ||
|
||
FileHelper::clearDirectory($compiledClassesPath, [ | ||
'filter' => function (string $path) use ($except): bool { | ||
$b = basename($path); | ||
|
||
return | ||
str_starts_with($b, 'FactoryFields') && | ||
($except === null || $b !== $except); | ||
}, | ||
]); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.