forked from pimcore/pimcore
-
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.
Opcache Preloading Integration (pimcore#8192)
* Preload.php Generator: Data Object / Field Collection / Object Bricks class files - see pimcore#5387 * models & lib classes
- Loading branch information
1 parent
3fec8d3
commit a9676c9
Showing
2 changed files
with
125 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Enterprise License (PEL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PEL | ||
*/ | ||
|
||
namespace Pimcore\HttpKernel\CacheWarmer; | ||
|
||
use Pimcore\Bootstrap; | ||
use Pimcore\Model\Asset; | ||
use Pimcore\Model\DataObject; | ||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; | ||
|
||
class PimcoreCoreCacheWarmer implements CacheWarmerInterface | ||
{ | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function isOptional() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function warmUp($cacheDir) | ||
{ | ||
$classes = []; | ||
|
||
$this->libraryClasses($classes); | ||
$this->modelClasses($classes); | ||
$this->dataObjectClasses($classes); | ||
|
||
return $classes; | ||
} | ||
|
||
private function libraryClasses(array &$classes): void | ||
{ | ||
$excludePattern = '@/lib/(Migrations|Maintenance|Sitemap|Workflow|Console|Composer|Translation/(Import|Export)|Image/Optimizer|DataObject/(GridColumnConfig|Import)|Test|Tool/Transliteration|(Pimcore|simple_html_dom)\.php)@'; | ||
|
||
$reflection = new \ReflectionClass(Bootstrap::class); | ||
$dir = dirname($reflection->getFileName()); | ||
|
||
$this->getClassesFromDirectory($dir, $excludePattern, 'Pimcore', $classes); | ||
} | ||
|
||
private function modelClasses(array &$classes): void | ||
{ | ||
$excludePattern = '@/models/(GridConfig|ImportConfig|Notification|Schedule|Tool/CustomReport|User|Workflow)@'; | ||
|
||
$reflection = new \ReflectionClass(Asset::class); | ||
$dir = dirname($reflection->getFileName()); | ||
|
||
$this->getClassesFromDirectory($dir, $excludePattern, 'Pimcore\Model', $classes); | ||
} | ||
|
||
private function getClassesFromDirectory(string $dir, string $excludePattern, string $NSPrefix, array &$classes): void | ||
{ | ||
$files = rscandir($dir); | ||
|
||
foreach($files as $file) { | ||
$file = str_replace(DIRECTORY_SEPARATOR, '/', $file); | ||
if(is_file($file) && !preg_match($excludePattern, $file)) { | ||
$className = preg_replace('@^' . preg_quote($dir, '@') . '@', $NSPrefix, $file); | ||
$className = preg_replace('@\.php$@', '', $className); | ||
$className = str_replace(DIRECTORY_SEPARATOR, '\\', $className); | ||
|
||
if(class_exists($className)) { | ||
$classes[] = $className; | ||
} | ||
} | ||
} | ||
} | ||
|
||
private function dataObjectClasses(array &$classes): void | ||
{ | ||
|
||
// load all data object classes | ||
$list = new DataObject\ClassDefinition\Listing(); | ||
$list = $list->load(); | ||
|
||
foreach ($list as $classDefinition) { | ||
$className = DataObject::class . '\\' . ucfirst($classDefinition->getName()); | ||
$listingClass = $className . '\\Listing'; | ||
|
||
$classes[] = $className; | ||
$classes[] = $listingClass; | ||
} | ||
|
||
|
||
$list = new DataObject\Objectbrick\Definition\Listing(); | ||
$list = $list->load(); | ||
|
||
foreach ($list as $brickDefinition) { | ||
$className = 'Pimcore\\Model\\DataObject\\Objectbrick\\Data' . ucfirst($brickDefinition->getKey()); | ||
|
||
$classes[] = $className; | ||
} | ||
|
||
$list = new DataObject\Fieldcollection\Definition\Listing(); | ||
$list = $list->load(); | ||
|
||
foreach ($list as $fcDefinition) { | ||
$className = 'Pimcore\\Model\\DataObject\\Fieldcollection\\Data' . ucfirst($fcDefinition->getKey()); | ||
|
||
$classes[] = $className; | ||
} | ||
|
||
} | ||
} |