2023-01-03 17:31:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Helpers;
|
|
|
|
|
|
|
|
class ExtensionHelper
|
|
|
|
{
|
2023-01-21 00:03:33 +00:00
|
|
|
/**
|
|
|
|
* Get a config of an extension by its name
|
|
|
|
* @param string $extensionName
|
|
|
|
* @param string $configname
|
|
|
|
*/
|
|
|
|
public static function getExtensionConfig(string $extensionName, string $configname)
|
2023-01-03 17:31:21 +00:00
|
|
|
{
|
2023-01-21 00:03:33 +00:00
|
|
|
$extensions = ExtensionHelper::getAllExtensions();
|
2023-01-03 17:31:21 +00:00
|
|
|
|
2023-01-21 00:03:33 +00:00
|
|
|
// call the getConfig function of the config file of the extension like that
|
|
|
|
// call_user_func("App\\Extensions\\PaymentGateways\\Stripe" . "\\getConfig");
|
|
|
|
foreach ($extensions as $extension) {
|
|
|
|
if (!(basename($extension) == $extensionName)) {
|
|
|
|
continue;
|
|
|
|
}
|
2023-01-03 17:31:21 +00:00
|
|
|
|
2023-01-21 00:03:33 +00:00
|
|
|
$configFile = $extension . '/config.php';
|
|
|
|
if (file_exists($configFile)) {
|
|
|
|
include_once $configFile;
|
|
|
|
$config = call_user_func('App\\Extensions\\' . basename(dirname($extension)) . '\\' . basename($extension) . "\\getConfig");
|
|
|
|
}
|
2023-01-03 17:31:21 +00:00
|
|
|
|
|
|
|
|
2023-01-21 00:03:33 +00:00
|
|
|
if (isset($config[$configname])) {
|
|
|
|
return $config[$configname];
|
|
|
|
}
|
2023-01-03 17:31:21 +00:00
|
|
|
}
|
|
|
|
|
2023-01-21 00:03:33 +00:00
|
|
|
return null;
|
2023-01-03 17:31:21 +00:00
|
|
|
}
|
2023-01-14 22:33:30 +00:00
|
|
|
|
2023-01-21 00:03:33 +00:00
|
|
|
public static function getAllCsrfIgnoredRoutes()
|
2023-01-14 22:33:30 +00:00
|
|
|
{
|
2023-01-21 00:03:33 +00:00
|
|
|
$extensions = ExtensionHelper::getAllExtensions();
|
|
|
|
|
|
|
|
$routes = [];
|
|
|
|
foreach ($extensions as $extension) {
|
|
|
|
$configFile = $extension . '/config.php';
|
|
|
|
if (file_exists($configFile)) {
|
|
|
|
include_once $configFile;
|
|
|
|
$config = call_user_func('App\\Extensions\\' . basename(dirname($extension)) . '\\' . basename($extension) . "\\getConfig");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($config['RoutesIgnoreCsrf'])) {
|
|
|
|
$routes = array_merge($routes, $config['RoutesIgnoreCsrf']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add extension/ infront of every route
|
|
|
|
foreach ($routes as $key => $route) {
|
|
|
|
$routes[$key] = 'extensions/' . $route;
|
|
|
|
}
|
|
|
|
}
|
2023-01-14 22:33:30 +00:00
|
|
|
|
2023-01-21 00:03:33 +00:00
|
|
|
return $routes;
|
|
|
|
}
|
2023-01-14 22:33:30 +00:00
|
|
|
|
2023-01-21 00:03:33 +00:00
|
|
|
/**
|
|
|
|
* Get all extensions
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getAllExtensions()
|
|
|
|
{
|
|
|
|
$extensionNamespaces = glob(app_path() . '/Extensions/*', GLOB_ONLYDIR);
|
|
|
|
$extensions = [];
|
|
|
|
foreach ($extensionNamespaces as $extensionNamespace) {
|
|
|
|
$extensions = array_merge($extensions, glob($extensionNamespace . '/*', GLOB_ONLYDIR));
|
2023-01-14 22:33:30 +00:00
|
|
|
}
|
|
|
|
|
2023-01-21 00:03:33 +00:00
|
|
|
return $extensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getAllExtensionsByNamespace(string $namespace)
|
|
|
|
{
|
|
|
|
$extensions = glob(app_path() . '/Extensions/' . $namespace . '/*', GLOB_ONLYDIR);
|
|
|
|
|
|
|
|
return $extensions;
|
2023-01-14 22:33:30 +00:00
|
|
|
}
|
2023-01-15 00:39:38 +00:00
|
|
|
}
|