| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- /**
- * @author Open Mind
- * @date 26/04/2018
- * @time 11:11
- */
- namespace OpenMind\System;
- use FilesystemIterator;
- use OpenMind\Web\Web;
- use RecursiveDirectoryIterator;
- use RecursiveIteratorIterator;
- class OMUtils
- {
- public static function getInstance()
- {
- static $instance = null;
- if ($instance === null) {
- $instance = new static(); // PHP 5+ lazy state building
- }
- return $instance;
- }
- /**
- * Load all modules in <$path> folder
- * @param string $path
- */
- public function PluginLoader(string $path)
- {
- // <class priority>
- //TODO , if is necessary to give a priority to some classes before other, initialize here
- Global $System, $Web;
- $System = new System(); // we need System Base class first, so will force to load as first
- $Web = new Web();
- // </class priority>
- $Directory = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
- $Iterator = new RecursiveIteratorIterator($Directory, RecursiveIteratorIterator::CHILD_FIRST);
- foreach($Iterator as $item) {
- if (is_file($item->getPathname()))
- continue;
- $moduleName = $item->getFilename();
- $moduleInitPath = "{$item->getPathname()}/{$moduleName}.php";
- $className = str_replace('/', '\\', ltrim("{$item->getPathname()}/{$moduleName}", $path));
- if (file_exists($moduleInitPath)) { // If already imported, skip
- if (!isset($$moduleName)) {
- Global $$moduleName; // Declare visibility to Global
- $$moduleName = new $className(); // Instantiate the Module, all init procedure must reside in __constructor() method
- }
- }
- }
- }
- /**
- * Use F3 template resolve() to parse string like "{{@BASESITE}}"
- *
- * @param string $strTemplate the F3 original string
- * @return string converted string
- */
- public function getStringFromTemplate(string $strTemplate)
- {
- return \Template::instance()->resolve($strTemplate);
- }
- /**
- * Load an encrypted file with the method "base64_encode(gzcompress(<path to config.ini>))", save it in a temporary file in temp folder of system and load with F3::config()
- *
- * @param string $path
- */
- public function LoadEncryptedConfig(string $path)
- {
- $tmpFilepath = tempnam(sys_get_temp_dir(), 'om');
- $config = gzuncompress(base64_decode(file_get_contents($path)));
- file_put_contents($tmpFilepath, $config);
- \F3::config($tmpFilepath, true);
- unlink($tmpFilepath);
- }
- public function DieByOldPhpVersion()
- {
- if (version_compare(PHP_VERSION, '7.2') != 1)
- die('PHP 7.2+ is need to run the project');
- }
- }
|