diff --git a/app/Common/Option.php b/app/Common/Option.php index 77df699..b8c00bf 100644 --- a/app/Common/Option.php +++ b/app/Common/Option.php @@ -2,7 +2,7 @@ namespace App\Common; -use App\Core\Helper; +use Jackal\Jackal\Helper; use App\Exceptions\ClassNotFoundException; use ReflectionClass; diff --git a/app/Constracts/Assets/AssetConstract.php b/app/Constracts/Assets/AssetConstract.php index 73a6c02..2498ade 100644 --- a/app/Constracts/Assets/AssetConstract.php +++ b/app/Constracts/Assets/AssetConstract.php @@ -3,7 +3,7 @@ namespace App\Constracts\Assets; use App\Constracts\AssetTypeEnum; -use App\Core\Assets\AssetOptions; +use Jackal\Jackal\Assets\AssetOptions; interface AssetConstract { diff --git a/app/Constracts/Assets/AssetExternalConstract.php b/app/Constracts/Assets/AssetExternalConstract.php index ff69345..12d47a1 100644 --- a/app/Constracts/Assets/AssetExternalConstract.php +++ b/app/Constracts/Assets/AssetExternalConstract.php @@ -2,7 +2,7 @@ namespace App\Constracts\Assets; -use App\Core\Assets\AssetUrl; +use Jackal\Jackal\Assets\AssetUrl; interface AssetExternalConstract extends AssetConstract { diff --git a/app/Constracts/ExtensionConstract.php b/app/Constracts/ExtensionConstract.php index d8fed00..a9c2f22 100644 --- a/app/Constracts/ExtensionConstract.php +++ b/app/Constracts/ExtensionConstract.php @@ -2,7 +2,7 @@ namespace App\Constracts; -use App\Core\Application; +use Jackal\Jackal\Application; use DI\Container; interface ExtensionConstract diff --git a/app/Core/Application.php b/app/Core/Application.php deleted file mode 100644 index c71cd10..0000000 --- a/app/Core/Application.php +++ /dev/null @@ -1,391 +0,0 @@ -responseFactory = $responseFactory; - $this->callableResolver = $callableResolver; - $this->container = $container; - $this->routeCollector = $routeCollector; - $this->groupPattern = ''; - - $this->routeResolver = $routeResolver ?? new RouteResolver($this->routeCollector); - $routeRunner = new RouteRunner($this->routeResolver, $this->routeCollector->getRouteParser(), $this); - - if (!$middlewareDispatcher) { - $middlewareDispatcher = new MiddlewareDispatcher($routeRunner, $this->callableResolver, $container); - } else { - $middlewareDispatcher->seedMiddlewareStack($routeRunner); - } - - $this->middlewareDispatcher = $middlewareDispatcher; - - if (is_null(static::$instance)) { - static::$instance = &$this; - } - - // Register base providers - $this->registerBaseServiceProviders(); - } - - public function booted() - { - $this->isBooted = true; - } - - public function isBooted() - { - return $this->isBooted; - } - - /** - * @return RouteResolverInterface - */ - public function getRouteResolver(): RouteResolverInterface - { - return $this->routeResolver; - } - - /** - * @return MiddlewareDispatcherInterface - */ - public function getMiddlewareDispatcher(): MiddlewareDispatcherInterface - { - return $this->middlewareDispatcher; - } - - /** - * @param MiddlewareInterface|string|callable $middleware - */ - public function add($middleware): self - { - $this->middlewareDispatcher->add($middleware); - return $this; - } - - /** - * @param MiddlewareInterface $middleware - */ - public function addMiddleware(MiddlewareInterface $middleware): self - { - $this->middlewareDispatcher->addMiddleware($middleware); - return $this; - } - - /** - * Add the Slim built-in routing middleware to the app middleware stack - * - * This method can be used to control middleware order and is not required for default routing operation. - * - * @return RoutingMiddleware - */ - public function addRoutingMiddleware(): RoutingMiddleware - { - $routingMiddleware = new RoutingMiddleware( - $this->getRouteResolver(), - $this->getRouteCollector()->getRouteParser() - ); - $this->add($routingMiddleware); - return $routingMiddleware; - } - - /** - * Add the Slim built-in error middleware to the app middleware stack - * - * @param bool $displayErrorDetails - * @param bool $logErrors - * @param bool $logErrorDetails - * @param LoggerInterface|null $logger - * - * @return ErrorMiddleware - */ - public function addErrorMiddleware( - bool $displayErrorDetails, - bool $logErrors, - bool $logErrorDetails, - ?LoggerInterface $logger = null - ): ErrorMiddleware { - $errorMiddleware = new ErrorMiddleware( - $this->getCallableResolver(), - $this->getResponseFactory(), - $displayErrorDetails, - $logErrors, - $logErrorDetails, - $logger - ); - $this->add($errorMiddleware); - return $errorMiddleware; - } - - /** - * Add the Slim body parsing middleware to the app middleware stack - * - * @param callable[] $bodyParsers - * - * @return BodyParsingMiddleware - */ - public function addBodyParsingMiddleware(array $bodyParsers = []): BodyParsingMiddleware - { - $bodyParsingMiddleware = new BodyParsingMiddleware($bodyParsers); - $this->add($bodyParsingMiddleware); - return $bodyParsingMiddleware; - } - - /** - * Run application - * - * This method traverses the application middleware stack and then sends the - * resultant Response object to the HTTP client. - * - * @param ServerRequestInterface|null $request - * @return void - */ - public function run(?ServerRequestInterface $request = null): void - { - if (!$request) { - $serverRequestCreator = ServerRequestCreatorFactory::create(); - $request = $serverRequestCreator->createServerRequestFromGlobals(); - } - - $response = $this->handle($request); - $responseEmitter = new ResponseEmitter(); - $responseEmitter->emit($response); - } - - /** - * Handle a request - * - * This method traverses the application middleware stack and then returns the - * resultant Response object. - * - * @param ServerRequestInterface $request - * @return ResponseInterface - */ - public function handle(ServerRequestInterface $request): ResponseInterface - { - $response = $this->middlewareDispatcher->handle($request); - - /** - * This is to be in compliance with RFC 2616, Section 9. - * If the incoming request method is HEAD, we need to ensure that the response body - * is empty as the request may fall back on a GET route handler due to FastRoute's - * routing logic which could potentially append content to the response body - * https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 - */ - $method = strtoupper($request->getMethod()); - if ($method === 'HEAD') { - $emptyBody = $this->responseFactory->createResponse()->getBody(); - return $response->withBody($emptyBody); - } - - return $response; - } - - public static function getInstance() - { - if (is_null(static::$instance)) { - throw new InvalidApplicationException('The application is not initialized'); - } - return static::$instance; - } - - - /** - * Get the registered service provider instances if any exist. - * - * @param \App\Providers\ServiceProvider|string $provider - * @return array - */ - public function getProviders($provider) - { - $name = is_string($provider) ? $provider : get_class($provider); - - return Arr::where($this->serviceProviders, function ($value) use ($name) { - return $value instanceof $name; - }); - } - - /** - * Resolve a service provider instance from the class name. - * - * @param string $provider - * @return \App\Providers\ServiceProvider - */ - public function resolveProvider($provider) - { - return new $provider($this); - } - - /** - * Mark the given provider as registered. - * - * @param \App\Providers\ServiceProvider $provider - * @return void - */ - protected function markAsRegistered($provider) - { - $this->serviceProviders[] = $provider; - - $this->loadedProviders[get_class($provider)] = true; - } - - /** - * Get the registered service provider instance if it exists. - * - * @param \App\Providers\ServiceProvider|string $provider - * @return \App\Providers\ServiceProvider|null - */ - public function getProvider($provider) - { - return array_values($this->getProviders($provider))[0] ?? null; - } - - - /** - * Boot the given service provider. - * - * @param \App\Providers\ServiceProvider $provider - * @return mixed - */ - protected function bootProvider(ServiceProvider $provider) - { - if (method_exists($provider, 'boot')) { - return call_user_func([$provider, 'boot']); - } - } - - /** - * Register a service provider with the application. - * - * @param \App\Providers\ServiceProvider|string $provider - * @param bool $force - * @return \App\Providers\ServiceProvider - */ - public function register($provider, $force = false) - { - if (($registered = $this->getProvider($provider)) && ! $force) { - return $registered; - } - - // If the given "provider" is a string, we will resolve it, passing in the - // application instance automatically for the developer. This is simply - // a more convenient way of specifying your service provider classes. - if (is_string($provider)) { - $provider = $this->resolveProvider($provider); - } - - $provider->register(); - - $this->markAsRegistered($provider); - - // If the application has already booted, we will call this boot method on - // the provider class so it has an opportunity to do its boot logic and - // will be ready for any usage by this developer's application logic. - if ($this->isBooted()) { - $this->bootProvider($provider); - } - - return $provider; - } - - /** - * Register all of the base service providers. - * - * @return void - */ - protected function registerBaseServiceProviders() - { - $this->register(new LogServiceProvider($this)); - - // Create Request object from globals - $serverRequestCreator = ServerRequestCreatorFactory::create(); - $request = $serverRequestCreator->createServerRequestFromGlobals(); - - $this->container->set('request', $request); - } - - public function terminate() - { - } -} diff --git a/app/Core/Asset.php b/app/Core/Asset.php deleted file mode 100644 index bde2138..0000000 --- a/app/Core/Asset.php +++ /dev/null @@ -1,111 +0,0 @@ -id = $id; - } - - public function isValid(): bool - { - return !empty($this->id); - } - - public function setAssetType(AssetTypeEnum $assetType): AssetConstract - { - $this->assetType = $assetType; - - return $this; - } - - public function getAssetType(): AssetTypeEnum - { - return $this->assetType; - } - - public function setDeps($deps): AssetConstract - { - if (is_array($deps)) { - $this->deps = $deps; - } - return $this; - } - - public function getDeps(): array - { - return $this->deps ?? []; - } - - public function setOptions(AssetOptionsConstract $assetOptions): AssetConstract - { - $this->options = $assetOptions; - - return $this; - } - - public function setVersion($version): AssetConstract - { - $this->version = $version; - - return $this; - } - - public function getId() - { - return $this->id; - } - - public function enqueue(): self - { - $this->isEnqueue = true; - - return $this; - } - - public function isEnqueue(): bool - { - return $this->isEnqueue; - } - - public function isRendered(): bool - { - return $this->isRendered; - } - - public function renderTabCharacter($size = 1) - { - echo str_repeat("\t", $size); - } - - public function renderHtml() - { - echo PHP_EOL; - $this->isRendered = true; - } - - public function getVersion() - { - return $this->version; - } -} diff --git a/app/Core/AssetManager.php b/app/Core/AssetManager.php deleted file mode 100644 index 37f2632..0000000 --- a/app/Core/AssetManager.php +++ /dev/null @@ -1,310 +0,0 @@ -frontendBucket = new Bucket(); - $this->backendBucket = new Bucket(); - } - - public static function getInstance() - { - if (is_null(static::$instance)) { - static::$instance = new self(); - } - return static::$instance; - } - - public static function create( - $id, - AssetUrl $url, - AssetTypeEnum $assetType, - $deps = [], - $version = null, - AssetOptions $assetOptions = null - ): AssetConstract { - $asset = Helper::createAssetByAssetType($id, $assetType); - if ($asset instanceof AssetExternalConstract) { - $asset->setUrl($url); - } - $asset->setDeps($deps); - $asset->setOptions($assetOptions); - $asset->setVersion($version); - - return $asset; - } - - public static function registerAsset( - $id, - AssetUrl $url, - AssetTypeEnum $assetType, - $deps = [], - $version = null, - AssetOptions $assetOptions = null - ): AssetConstract { - $asset = static::create( - (string) $id, - $url, - $assetType, - $deps, - $version, - $assetOptions - ); - $instance = static::getInstance(); - $instance->getFrontendBucket() - ->addAsset($asset); - - return $asset; - } - - public static function registerBackendAsset( - $id, - AssetUrl $url, - AssetTypeEnum $assetType, - $deps = [], - $version = null, - AssetOptions $assetOptions = null - ): AssetConstract { - /** - * @var \App\Core\Assets\JavaScript - */ - $asset = static::create($id, $url, $assetType, $deps, $version, $assetOptions); - $instance = static::getInstance(); - $instance->getBackendBucket() - ->addAsset($asset); - - return $asset; - } - - public function getFrontendBucket(): Bucket - { - return $this->frontendBucket; - } - - public function getBackendBucket(): Bucket - { - return $this->backendBucket; - } - - protected function getActiveBucket(): Bucket - { - return !Helper::isDashboard() - ? $this->getFrontendBucket() - : $this->getBackendBucket(); - } - - protected function getAssetTypeFromStringType($type): ?AssetTypeEnum - { - switch ($type) { - case AssetTypeEnum::CSS()->getType(): - return AssetTypeEnum::CSS(); - case AssetTypeEnum::JS()->getType(): - return AssetTypeEnum::JS(); - case AssetTypeEnum::FONT()->getType(): - return AssetTypeEnum::FONT(); - case AssetTypeEnum::ICON()->getType(): - return AssetTypeEnum::ICON(); - case AssetTypeEnum::STYLE()->getType(): - return AssetTypeEnum::STYLE(); - case AssetTypeEnum::EXECUTE_SCRIPT()->getType(): - return AssetTypeEnum::EXECUTE_SCRIPT(); - } - } - - protected function resolve(AssetConstract $asset, StringSort &$resolver) - { - $bucket = $this->getActiveBucket(); - $resolver->add($asset->getId(), $asset->getDeps()); - foreach ($asset->getDeps() as $assetId) { - $assetDep = $bucket->getAsset($assetId, $asset->getAssetType()); - if (is_null($assetDep)) { - error_log('Asset ID #' . $assetId . ' is not exists'); - continue; - } - $assetDep->enqueue(); - - $this->resolve($assetDep, $resolver); - } - } - - /** - * @param \App\Constracts\Assets\AssetConstract[] $assets - * @param AssetTypeEnum $assetType - * @return void - */ - protected function resolveDependences($assets, AssetTypeEnum $assetType) - { - $bucket = $this->getActiveBucket(); - $resolver = new StringSort(); - - foreach ($assets as $asset) { - $this->resolve($asset, $resolver); - } - $sortedAssets = $resolver->sort(); - foreach ($sortedAssets as $assetId) { - $asset = $bucket->getAsset($assetId, $assetType); - if (is_null($asset)) { - error_log('Asset ID #' . $assetId . ' is not exists'); - continue; - } - if (!isset($this->resolvedAssets[$assetType->getType()])) { - $this->resolvedAssets[$assetType->getType()] = []; - } - $this->resolvedAssets[$assetType->getType()][] = $asset; - } - } - - public function resolveAllDependences() - { - $bucket = $this->getActiveBucket(); - foreach ($bucket->getAssets() as $type => $assets) { - $assetType = $this->getAssetTypeFromStringType($type); - if (is_null($assetType)) { - continue; - } - $this->resolveDependences(array_filter($assets, function (AssetConstract $item) { - return $item->isEnqueue() === true; - }), $assetType); - } - } - - protected function getEnqueueAssetsByType(AssetTypeEnum $assetType, $filter = null) - { - if (!isset($this->resolvedAssets[$assetType->getType()])) { - return []; - } - - return is_null($filter) - ? $this->resolvedAssets[$assetType->getType()] - : array_filter($this->resolvedAssets[$assetType->getType()], $filter); - } - - public function printInitHeadScripts() - { - $headInitScripts = $this->getEnqueueAssetsByType( - AssetTypeEnum::INIT_SCRIPT(), - function (AssetScriptConstract $item) { - return $item->isFooterScript() === false; - } - ); - - foreach ($headInitScripts as $initScript) { - if ($initScript->isRendered()) { - continue; - } - $initScript->renderTabCharacter(2); - $initScript->renderHtml(); - } - } - - public function printHeadAssets() - { - foreach ($this->getEnqueueAssetsByType(AssetTypeEnum::CSS()) as $css) { - if ($css->isRendered()) { - continue; - } - $css->renderTabCharacter(2); - $css->renderHtml(); - } - - foreach ($this->getActiveBucket()->getJs(false, true) as $js) { - if ($js->isRendered()) { - continue; - } - $js->renderTabCharacter(2); - $js->renderHtml(); - } - } - - public function printExecuteHeadScripts() - { - foreach ($this->getEnqueueAssetsByType(AssetTypeEnum::STYLE()) as $interalStyle) { - if ($interalStyle->isRendered()) { - continue; - } - $interalStyle->renderTabCharacter(2); - $interalStyle->renderHtml(); - } - $headExecScripts = $this->getEnqueueAssetsByType( - AssetTypeEnum::EXECUTE_SCRIPT(), - function (AssetScriptConstract $item) { - return $item->isFooterScript() === false; - } - ); - - foreach ($headExecScripts as $executeScript) { - if ($executeScript->isRendered()) { - continue; - } - $executeScript->renderTabCharacter(2); - $executeScript->renderHtml(); - } - } - - public function printFooterInitScripts() - { - $footerInitScripts = $this->getEnqueueAssetsByType( - AssetTypeEnum::INIT_SCRIPT(), - function (AssetScriptConstract $item) { - return $item->isFooterScript() === true; - } - ); - - foreach ($footerInitScripts as $initScript) { - if ($initScript->isRendered()) { - continue; - } - $initScript->renderTabCharacter(2); - $initScript->renderHtml(); - } - } - - public function printFooterAssets() - { - foreach ($this->getActiveBucket()->getJs(true, true) as $js) { - if ($js->isRendered()) { - continue; - } - $js->renderTabCharacter(2); - $js->renderHtml(); - } - } - - public function executeFooterScripts() - { - $footerExecScripts = $this->getEnqueueAssetsByType( - AssetTypeEnum::INIT_SCRIPT(), - function (AssetScriptConstract $item) { - return $item->isFooterScript() === true; - } - ); - - foreach ($footerExecScripts as $executeScript) { - if ($executeScript->isRendered()) { - continue; - } - $executeScript->renderTabCharacter(2); - $executeScript->renderHtml(); - } - } -} diff --git a/app/Core/Assets/AssetOptions.php b/app/Core/Assets/AssetOptions.php deleted file mode 100644 index 376fd1a..0000000 --- a/app/Core/Assets/AssetOptions.php +++ /dev/null @@ -1,32 +0,0 @@ -$name; - } - } - - public function __call($name, $arguments) - { - if (property_exists($this, $name)) { - return $this->$name; - } - return array_get($arguments, 0, null); - } -} diff --git a/app/Core/Assets/AssetScriptOptions.php b/app/Core/Assets/AssetScriptOptions.php deleted file mode 100644 index ded27e2..0000000 --- a/app/Core/Assets/AssetScriptOptions.php +++ /dev/null @@ -1,8 +0,0 @@ -url = $url; - if (!is_null($minUrl)) { - $this->minUrl = $minUrl; - } - } - - public function getUrl($supportMinUrl = false): string - { - if (!$supportMinUrl || empty($this->minUrl)) { - return $this->url; - } - return $this->minUrl; - } - - public function __toString() - { - return $this->getUrl(); - } -} diff --git a/app/Core/Assets/Bucket.php b/app/Core/Assets/Bucket.php deleted file mode 100644 index cfa13ee..0000000 --- a/app/Core/Assets/Bucket.php +++ /dev/null @@ -1,127 +0,0 @@ -isValid()) { - return $this; - } - $this->assets[$asset->getAssetType()->getType()][$asset->getId()] = $asset; - return $this; - } - - public function getAssets() - { - return $this->assets ?? []; - } - - public function getAsset($id, AssetTypeEnum $assetType): ?AssetConstract - { - if (!empty($this->assets[$assetType->getType()])) { - $assets = &$this->assets[$assetType->getType()]; - if (isset($assets[$id])) { - return $assets[$id]; - } - } - return null; - } - - public function getStylesheets($enqueueScripts = null): array - { - $assets = &$this->assets; - if (!isset($assets[AssetTypeEnum::CSS()->getType()])) { - return []; - } - return is_null($enqueueScripts) - ? $assets[AssetTypeEnum::CSS()->getType()] - : array_filter( - $assets[AssetTypeEnum::CSS()->getType()], - function (CascadingStyleSheets $item) use ($enqueueScripts) { - return $item->isEnqueue() === $enqueueScripts; - } - ); - } - - /** - * @param boolean $isFooter - * - * @return \App\Constracts\Assets\AssetConstract[] - */ - public function getJs($isFooter = false, $enqueueScripts = null): array - { - $assets = &$this->assets; - if (!isset($assets[AssetTypeEnum::JS()->getType()])) { - return []; - } - - return array_filter( - $assets[AssetTypeEnum::JS()->getType()], - function (JavaScript $item) use ($isFooter, $enqueueScripts) { - if (is_null($enqueueScripts)) { - return $item->isFooterScript() === $isFooter; - } - return $item->isFooterScript() === $isFooter && $item->isEnqueue() && $enqueueScripts; - } - ); - } - - /** - * @param boolean $isFooter - * - * @return \App\Constracts\Assets\AssetConstract[] - */ - public function getInitScripts($isFooter = false, $enqueueScripts = null): array - { - $assets = &$this->assets; - if (!isset($assets[AssetTypeEnum::INIT_SCRIPT()->getType()])) { - return []; - } - - return array_filter( - $assets[AssetTypeEnum::INIT_SCRIPT()->getType()], - function (Script $item) use ($isFooter, $enqueueScripts) { - if (is_null($enqueueScripts)) { - return $item->isFooterScript() === $isFooter; - } - return $item->isFooterScript() === $isFooter && $item->isEnqueue() && $enqueueScripts; - } - ); - } - - /** - * @param boolean $isFooter - * - * @return \App\Constracts\Assets\AssetConstract[] - */ - public function getExecuteScripts($isFooter = false, $enqueueScripts = null): array - { - $assets = &$this->assets; - if (!isset($assets[AssetTypeEnum::EXECUTE_SCRIPT()->getType()])) { - return []; - } - - return array_filter( - $assets[AssetTypeEnum::EXECUTE_SCRIPT()->getType()], - function (Script $item) use ($isFooter, $enqueueScripts) { - if (is_null($enqueueScripts)) { - return $item->isFooterScript() === $isFooter; - } - return $item->isFooterScript() === $isFooter && $item->isEnqueue() && $enqueueScripts; - } - ); - } -} diff --git a/app/Core/Assets/CascadingStyleSheets.php b/app/Core/Assets/CascadingStyleSheets.php deleted file mode 100644 index 0aad286..0000000 --- a/app/Core/Assets/CascadingStyleSheets.php +++ /dev/null @@ -1,28 +0,0 @@ -', - HookManager::applyFilters("asset_css_url", $this->getUrl( - Env::get("COMPRESSED_ASSETS", Env::get("DEBUG") === false) - ), $this->id, $this), - $this->id - ), - $this->getId(), - $this - ); - - parent::renderHtml(); - } -} diff --git a/app/Core/Assets/Font.php b/app/Core/Assets/Font.php deleted file mode 100644 index 294c9e7..0000000 --- a/app/Core/Assets/Font.php +++ /dev/null @@ -1,13 +0,0 @@ -', - HookManager::applyFilters("asset_js_url", $this->getUrl( - Env::get("COMPRESSED_ASSETS", Env::get("DEBUG") === false) - ), $this->id, $this), - $this->id - ), - $this->getId(), - $this - ); - - parent::renderHtml(); - } -} diff --git a/app/Core/Assets/Script.php b/app/Core/Assets/Script.php deleted file mode 100644 index a4d4cd2..0000000 --- a/app/Core/Assets/Script.php +++ /dev/null @@ -1,19 +0,0 @@ -createUserProvider($config['provider'] ?? null); - - $guard = new SessionGuard($name, $provider, $this->app['session.store']); - - // When using the remember me functionality of the authentication services we - // will need to be set the encryption instance of the guard, which allows - // secure, encrypted cookie values to get generated for those cookies. - if (method_exists($guard, 'setCookieJar')) { - $guard->setCookieJar($this->app['cookie']); - } - - if (method_exists($guard, 'setDispatcher')) { - $guard->setDispatcher($this->app['events']); - } - - if (method_exists($guard, 'setRequest')) { - $guard->setRequest($this->app->refresh('request', $guard, 'setRequest')); - } - - return $guard; - } - - protected function getDefaultDriver() - { - } - - public function setDefaultDriver($name) - { - $this->app['config']['auth.defaults.guard'] = $name; - } - - public function shouldUse($name) - { - $name = $name ?: $this->getDefaultDriver(); - - $this->setDefaultDriver($name); - - $this->userResolver = function ($name = null) { - return $this->guard($name)->user(); - }; - } -} diff --git a/app/Core/Auth/AuthServiceProvider.php b/app/Core/Auth/AuthServiceProvider.php deleted file mode 100644 index 8d1c0b0..0000000 --- a/app/Core/Auth/AuthServiceProvider.php +++ /dev/null @@ -1,13 +0,0 @@ -name = trim($name); - } - - public function getExtensionName() - { - return $this->name; - } - - public function isBuiltIn(): bool - { - return boolval($this->isBuiltIn); - } - - public function setApp(Application &$app) - { - $this->app = $app; - } - - public function setContainer(Container &$container) - { - $this->container = $container; - } - - public function setExtensionDir($extensionDir) - { - $this->extensionDir = $extensionDir; - } - - public function addDependencyExtension($extensionName, $version = "*") - { - $this->deps[$extensionName] = $version; - } - - public function getExtensionDir() - { - return $this->extensionDir; - } - - public function getPriority(): int - { - return $this->priority; - } - - public function bootstrap() - { - // - } - - public function setup() - { - // - } - - public function registerRoutes() - { - $routeConfig = implode(DIRECTORY_SEPARATOR, [$this->getExtensionDir(), 'routes.php']); - if (file_exists($routeConfig)) { - $routes = require $routeConfig; - if (is_callable($routes)) { - call_user_func_array( - $routes, - [$this->app, $this->container] - ); - } - } - } - - public function registerMiddlewares() - { - // - } - - public function run() - { - // - } - - public function getResponeCallback(): ?callable - { - return null; - } -} diff --git a/app/Core/Extension/ExtensionInfo.php b/app/Core/Extension/ExtensionInfo.php deleted file mode 100644 index 7b4fe7c..0000000 --- a/app/Core/Extension/ExtensionInfo.php +++ /dev/null @@ -1,103 +0,0 @@ -name = trim($name); - } - - public function setDescription($description) - { - $this->description = $description; - } - - public function setVersion($version) - { - $this->version = $version; - } - - public function getVersion() - { - return $this->version; - } - - public function getExtensionName() - { - return $this->name; - } - - public function setRootDir($rootDir) - { - $this->rootDir = $rootDir; - } - - public function setVendorDirectory($vendorDirectory) - { - $this->vendorDirectory = $vendorDirectory; - } - - public function setExtensionClass($extensionClass) - { - $this->extensionClass = $extensionClass; - } - - public function getExtension(): ?ExtensionConstract - { - if ($this->isValid()) { - /** - * @var \App\Constracts\ExtensionConstract - */ - $extension = new $this->extensionClass(); - $extension->setExtensionDir($this->rootDir); - $extension->setExtensionName($this->getExtensionName()); - - return $extension; - } - return null; - } - - public function isValid(): bool - { - return !empty($this->extensionClass) && class_exists($this->extensionClass, true); - } - - public function loadVendor() - { - $autoloader = implode(DIRECTORY_SEPARATOR, [$this->rootDir, $this->vendorDirectory, 'autoload.php']); - if (file_exists($autoloader)) { - require_once $autoloader; - } - } - - public function setDeps(array $deps = null) - { - if (is_array($deps)) { - $this->deps = $deps; - } - } - - /** - * @return array - */ - public function getDeps(): array - { - return $this->deps; - } -} diff --git a/app/Core/Extension/Resolver.php b/app/Core/Extension/Resolver.php deleted file mode 100644 index 327d42b..0000000 --- a/app/Core/Extension/Resolver.php +++ /dev/null @@ -1,90 +0,0 @@ -app = $app; - $this->container = $container; - - if (is_null($extensions) || !is_array($extensions)) { - $extensions = ExtensionManager::getAllExtensions(); - } - $this->extensions = $extensions; - - $this->cmsVersion = $container->get('version'); - } - - protected function createResolver(): StringSort - { - $resolver = new StringSort(); - - foreach ($this->extensions as $extensionName => $extensionInfo) { - $resolver->add($extensionName, array_keys($extensionInfo->getDeps())); - } - return $resolver; - } - - - protected function resolveExtensions($extensions) - { - $resolver = $this->createResolver(); - - $resolvedExtensions = $resolver->sort(); - usort($extensions, function ($a, $b) use ($resolvedExtensions) { - $aIndex = intval(array_search($a->getExtensionName(), $resolvedExtensions)); - $bIndex = intval(array_search($b->getExtensionName(), $resolvedExtensions)); - - return $aIndex - $bIndex; - }); - - - - return $extensions; - } - - protected function getActiveExtensions() - { - $extensions = []; - foreach ($this->extensions as $extensionInfo) { - /** - * @var \App\Core\Extension - */ - $extension = $extensionInfo->getExtension(); - if ($extension instanceof ExtensionConstract) { - $extension->setApp($this->app); - $extension->setContainer($this->container); - } - $extensions[$extensionInfo->getExtensionName()] = $extension; - } - return $extensions; - } - - /** - * Resolve the extensions - * - * @return \App\Core\Extension[] - */ - public function resolve(): array - { - return $this->resolveExtensions($this->getActiveExtensions()); - } -} diff --git a/app/Core/ExtensionManager.php b/app/Core/ExtensionManager.php deleted file mode 100644 index 5e18443..0000000 --- a/app/Core/ExtensionManager.php +++ /dev/null @@ -1,168 +0,0 @@ - 'admin', - ]; - - protected $activeExtensions = []; - - protected static $instance; - - protected function __construct() - { - } - - public static function getInstance() - { - if (is_null(static::$instance)) { - static::$instance = new self(); - } - return static::$instance; - } - - public static function __callStatic($name, $arguments) - { - $instance = static::getInstance(); - $callable = [$instance, $name]; - - if (!is_callable($callable)) { - throw new RuntimeException(sprintf("The method %s::%s() is not defined", __CLASS__, $name)); - } - return call_user_func_array($callable, $arguments); - } - - /** - * Get all extensions - * - * @return \App\Core\Extension\ExtensionInfo[] - */ - public static function getAllExtensions(): array - { - $extensions = []; - $extensionFiles = glob(EXTENSIONS_DIR . DIRECTORY_SEPARATOR . '{*/composer,composer}.json', GLOB_BRACE); - - foreach ($extensionFiles as $extensionFile) { - $jsonStr = file_exists($extensionFile) ? file_get_contents($extensionFile) : ''; - $json = json_decode($jsonStr, true); - $extensionInfo = static::parseExtensionInfo($json); - - $extensionInfo->setRootDir(dirname($extensionFile)); - $extensionInfo->loadVendor(); - - if ($extensionInfo->isValid()) { - $extensions[$extensionInfo->getExtensionName()] = $extensionInfo; - } - } - - return $extensions; - } - - /** - * Parse extension info from composer.json - * - * @return ExtensionInfo - */ - protected static function parseExtensionInfo($json): ExtensionInfo - { - $extInfo = new ExtensionInfo(); - - if (isset($json['extension-class'])) { - $extInfo->setExtensionClass($json['extension-class']); - } - if (isset($json['name'])) { - $extInfo->setExtensionName($json['name']); - } - if (isset($json['description'])) { - $extInfo->setDescription($json['description']); - } - if (isset($json['version'])) { - $extInfo->setVersion($json['version']); - } - - $extInfo->setVendorDirectory(array_get($json, 'config.vendor-dir', 'vendor')); - $extInfo->setDeps(array_get($json, 'require-extensions', [])); - - return $extInfo; - } - - public function addActiveExtension(ExtensionConstract $extension) - { - $this->activeExtensions[$extension->getExtensionName()] = $extension; - } - - public function init(&$app, &$container) - { - $instance = static::getInstance(); - $extensionResolver = new ExtensionResolver($app, $container); - - foreach ($extensionResolver->resolve() as $extension) { - $instance->addActiveExtension($extension); - - // Call the bootstrap - $extension->bootstrap(); - - $extension->registerRoutes(); - - $callable = $extension->getResponeCallback(); - if (!is_null($callable)) { - HookManager::addFilter('response', $callable); - } - } - } - - /** - * @return \App\Constracts\ExtensionConstract[] - */ - public function getActiveExtensions() - { - if (is_null($this->activeExtensions)) { - return []; - } - return $this->activeExtensions; - } - - /** - * Run active extensions - * - * @return void - */ - public function runActiveExtensions() - { - foreach ($this->getActiveExtensions() as $extension) { - $extension->run(); - } - } - - public static function getExtension($extensionName, $throwException = true) - { - $instance = static::getInstance(); - if (isset($instance->activeExtensions[$extensionName])) { - return $instance->activeExtensions[$extensionName]; - } - if ($throwException) { - throw new NotFoundExtensionException($extensionName); - } - } - - protected function hasExtension($extensionName) - { - return isset($this->activeExtensions[$extensionName]); - } -} diff --git a/app/Core/ExternalAsset.php b/app/Core/ExternalAsset.php deleted file mode 100644 index 515be0b..0000000 --- a/app/Core/ExternalAsset.php +++ /dev/null @@ -1,40 +0,0 @@ -url = $url; - - return $this; - } - - public function getUrl($supportMinUrl = null) - { - if (empty($this->url)) { - return ""; - } - - if (is_null($supportMinUrl)) { - $supportMinUrl = Env::get('COMPRESSED_ASSETS', !Env::get('DEBUG', false)); - } - - $asetUrl = $this->url->getUrl($supportMinUrl); - if (empty($this->getVersion())) { - return $asetUrl; - } - - $queryJoinCharacter = '?'; - if (strpos($asetUrl, '?')) { - $queryJoinCharacter = '&'; - } - return $asetUrl . $queryJoinCharacter . 'v=' . $this->getVersion(); - } -} diff --git a/app/Core/Factory/AppFactory.php b/app/Core/Factory/AppFactory.php deleted file mode 100644 index 73f9f96..0000000 --- a/app/Core/Factory/AppFactory.php +++ /dev/null @@ -1,34 +0,0 @@ - $routeArguments - */ - public function resolve( - callable $callable, - ServerRequestInterface $request, - ResponseInterface $response, - array $routeArguments, - ContainerInterface $container - ): ResponseInterface { - $this->container = $container; - - foreach ($routeArguments as $k => $v) { - $request = $request->withAttribute($k, $v); - } - - // Resolved params order - $params = $this->resolveParams( - $callable, - $request, - $response, - $routeArguments - ); - - return call_user_func_array($callable, $params); - } - - protected function resolveTheParamValue(?ReflectionType $type, string $namedParam) - { - if (!is_null($type) && $type instanceof ReflectionNamedType && $this->container->has($type->getName())) { - return $this->container->get($type->getName()); - } - if ($this->container->has($namedParam)) { - return $this->container->get($namedParam); - } - throw new CanNotResolveParamException(); - } - - protected function checkParamIsRouteArgs(ReflectionParameter $param): bool - { - if (in_array($param->getName(), ['args', 'routeArgs', 'routeArguments'])) { - return true; - } - if (is_null($param->getType())) { - return true; - } - - return !is_null($param->getType()) && $param->getType()->getName() === 'array'; - } - - - protected function resolveParamsForClosure($callable) - { - $params = []; - $methodRefl = new ReflectionClosure($callable); - - if ($methodRefl->getNumberOfParameters() > 0) { - $maxParamIndex = $methodRefl->getNumberOfParameters() - 1; - foreach ($methodRefl->getParameters() as $index => $param) { - $isRouteArgs = $index === $maxParamIndex && $this->checkParamIsRouteArgs($param); - - $params[] = $this->resolveTheParamValue( - $param->getType(), - $isRouteArgs ? 'args' : $param->getName() - ); - } - } - - return $params; - } - - protected function resolveParamsForStaticMethod($callable): array - { - $params = []; - $funcRefl = new ReflectionFunction($callable); - - if ($funcRefl->getNumberOfParameters() > 0) { - $maxParamIndex = $funcRefl->getNumberOfParameters() - 1; - foreach ($funcRefl->getParameters() as $index => $param) { - $isRouteArgs = $maxParamIndex && $this->checkParamIsRouteArgs($param); - - $params[] = $this->resolveTheParamValue( - $param->getType(), - $isRouteArgs ? 'args' : $param->getName() - ); - } - } - - return $params; - } - - protected function resolveParamsForMethod($callable): array - { - $params = []; - if (count($callable) === 2) { - $methodRefl = new ReflectionMethod($callable[0], $callable[1]); - if ($methodRefl->getNumberOfParameters() > 0) { - $maxParamIndex = $methodRefl->getNumberOfParameters() - 1; - foreach ($methodRefl->getParameters() as $index => $param) { - $isRouteArgs = $index === $maxParamIndex && $this->checkParamIsRouteArgs($param); - $params[] = $this->resolveTheParamValue( - $param->getType(), - $isRouteArgs ? 'args' : $param->getName() - ); - } - } - } - - return $params; - } - - protected function resolveParams($callable, $request, $response, $args): array - { - try { - if ($callable instanceof Closure) { - return $this->resolveParamsForClosure($callable); - } elseif (is_string($callable)) { - return $this->resolveParamsForStaticMethod($callable); - } elseif (is_array($callable) && is_object($callable[0])) { - $reflectCls = new ReflectionClass($callable[0]); - if (!$reflectCls->isAnonymous()) { - return $this->resolveParamsForMethod($callable); - } - } - } catch (CanNotResolveParamException $e) { - // Ignore this case - } catch (Throwable $e) { - // Send PHP error logs to debug - error_log($e->getMessage()); - } - return [$request, $response, $args]; - } -} diff --git a/app/Core/Helper.php b/app/Core/Helper.php deleted file mode 100644 index bbe531b..0000000 --- a/app/Core/Helper.php +++ /dev/null @@ -1,173 +0,0 @@ -getType()) { - case AssetTypeEnum::CSS(): - return (new CascadingStyleSheets($id)) - ->setAssetType($assetType); - case AssetTypeEnum::FONT(): - return (new Font($id)) - ->setAssetType($assetType); - case AssetTypeEnum::ICON(): - return (new Icon($id)) - ->setAssetType($assetType); - case AssetTypeEnum::JS(): - return (new JavaScript($id)) - ->setAssetType($assetType); - case AssetTypeEnum::INIT_SCRIPT(): - return (new Script($id)) - ->setAssetType($assetType); - case AssetTypeEnum::STYLE(): - return (new Style($id)) - ->setAssetType($assetType); - } - throw new InvalidAssetTypeException($assetType); - } - - - /** - * @param \ReflectionProperty[] $objectProperties - * @return array - */ - protected static function extractPropertyNames($objectProperties): array - { - $properties = []; - foreach ($objectProperties as $objectProperty) { - array_push($properties, $objectProperty->getName()); - } - return $properties; - } - - protected static function filterInvalidProperties($valueKeys, $propertyNames): array - { - $invalueProperties = []; - foreach ($valueKeys as $valueKey) { - if (!in_array($valueKey, $propertyNames)) { - array_push($invalueProperties, $valueKey); - } - } - return $invalueProperties; - } - - protected static function convertKeyToCamel($key) - { - return preg_replace_callback('/_(\w)/', function ($matches) { - return strtoupper($matches[1]); - }, $key); - } - - public static function convertArrayValuesToObject($rawValue, $className = null) - { - if (is_null($className) || !is_array($rawValue)) { - return $rawValue; - } - if (!class_exists($className, true)) { - throw new ClassNotFoundException($className); - } - $reflectClass = new ReflectionClass($className); - $object = $reflectClass->newInstance(); - $properties = static::extractPropertyNames($reflectClass->getProperties()); - $inValidProperies = static::filterInvalidProperties(array_keys($rawValue), $properties); - - foreach ($rawValue as $rawKey => $value) { - $keys = array_unique([$rawKey, self::convertKeyToCamel($rawKey)]); - foreach ($keys as $key) { - if (in_array($key, $inValidProperies)) { - continue; - } - $property = $reflectClass->getProperty($key); - $property->setAccessible(true); - $propertyType = $property->getType(); - if (is_array($value) && !empty($propertyType) && class_exists($propertyType->getName())) { - $property->setValue( - $object, - static::convertArrayValuesToObject($value, $propertyType->getName()) - ); - } else { - $property->setValue($object, $value); - } - $property->setAccessible(false); - break; - } - } - - return $object; - } - - public static function getContainer(): ContainerInterface - { - return Application::getInstance()->getContainer(); - } - - public static function isDashboard() - { - return self::$isDashboard; - } - - protected static function convertArrayToString($arr, $joinCharacter = ',') - { - $ret = ''; - if (is_array($arr)) { - foreach ($arr as $index => $value) { - if (is_array($value)) { - $ret .= self::convertArrayToString($value, $joinCharacter); - } else { - $ret .= ($index > 0 ? ' ' : '') . $value; - } - } - return $ret; - } - return $arr; - } - - public static function generateHtmlAttributes($attributes, $skipEmpty = false) - { - $ret = ''; - foreach ($attributes as $attributeName => $attributeValue) { - if (empty($attributeValue)) { - if (!empty($attributeName) && !$skipEmpty) { - $ret = $attributeName; - } - continue; - } - $ret .= sprintf('%s="%s"', $attributeName, static::convertArrayToString($attributeValue, ' ')); - } - - return $ret; - } -} diff --git a/app/Core/Hook.php b/app/Core/Hook.php deleted file mode 100644 index 08db144..0000000 --- a/app/Core/Hook.php +++ /dev/null @@ -1,48 +0,0 @@ -priority = $priority; - } - - public function setCallable($callable) - { - if (!is_callable($callable)) { - throw new NotCallableException(var_export($callable, true)); - } - $this->callable = $callable; - } - - public function setParamsQuantity(int $quantity) - { - $this->paramsQuantity = $quantity; - } - - public function getPriority(): int - { - return $this->priority; - } - - public function getCallable() - { - return $this->callable; - } - - public function getParamsQuantity(): int - { - return $this->paramsQuantity; - } -} diff --git a/app/Core/HookManager.php b/app/Core/HookManager.php deleted file mode 100644 index 96eed7f..0000000 --- a/app/Core/HookManager.php +++ /dev/null @@ -1,154 +0,0 @@ -actions[$hookName])) { - $instance->actions[$hookName] = []; - } - - $instance->actions[$hookName][] = ActionHook::create($fn, $priority, $paramsQuantity); - } - - public static function addFilter($hookName, $fn, $priority = 10, $paramsQuantity = 1) - { - if (!is_callable($fn)) { - throw new NotCallableException(var_export($fn, true) . " is can not callable"); - } - $instance = static::getInstance(); - if (!isset($instance->filters[$hookName])) { - $instance->filters[$hookName] = []; - } - - $instance->filters[$hookName][] = FilterHook::create($fn, $priority, $paramsQuantity); - } - - /** - * Undocumented function - * - * @param \App\Constracts\HookConstract[] $hooks - * @return void - */ - protected function sortHookByPriority(array $hooks) - { - usort($hooks, function (HookConstract $hook1, HookConstract $hook2) { - return $hook1->getPriority() - $hook2->getPriority(); - }); - return $hooks; - } - - /** - * @param string $hookName - * - * @return \App\Core\Hooks\ActionHook[] - */ - public function getActionsByHook($hookName) - { - if (isset($this->actions[$hookName])) { - return $this->sortHookByPriority($this->actions[$hookName]); - } - return []; - } - - /** - * @param string $hookName - * - * @return \App\Core\Hooks\FilterHook[] - */ - public function getFiltersByHook($hookName): array - { - if (isset($this->filters[$hookName])) { - return $this->sortHookByPriority($this->filters[$hookName]); - } - return []; - } - - public static function executeAction($hookName, ...$params) - { - $instance = static::getInstance(); - $hooks = $instance->getActionsByHook($hookName); - - foreach ($hooks as $hook) { - $args = array_splice($params, 0, $hook->getParamsQuantity()); - call_user_func_array( - $hook->getCallable(), - $args - ); - } - } - - public static function applyFilters($hookName, ...$params) - { - $instance = static::getInstance(); - $value = count($params) > 0 ? $params[0] : null; - $hooks = $instance->getFiltersByHook($hookName); - foreach ($hooks as $hook) { - $value = call_user_func_array( - $hook->getCallable(), - array_splice( - $params, - 0, - $hook->getParamsQuantity() - ) - ); - } - - return $value; - } - - public static function removeAllActionsByHook($hookName) - { - $instance = static::getInstance(); - if (isset($instance->actions[$hookName])) { - unset($instance->actions[$hookName]); - } - } - - public static function removeAllFiltersByHook($hookName) - { - $instance = static::getInstance(); - if (isset($instance->filters[$hookName])) { - unset($instance->filters[$hookName]); - } - } -} diff --git a/app/Core/Hooks/ActionHook.php b/app/Core/Hooks/ActionHook.php deleted file mode 100644 index 63cbaac..0000000 --- a/app/Core/Hooks/ActionHook.php +++ /dev/null @@ -1,19 +0,0 @@ -setCallable($fn); - $hook->setPriority($priority); - $hook->setParamsQuantity($paramsQuantity); - - return $hook; - } -} diff --git a/app/Core/Hooks/FilterHook.php b/app/Core/Hooks/FilterHook.php deleted file mode 100644 index 1fb3c46..0000000 --- a/app/Core/Hooks/FilterHook.php +++ /dev/null @@ -1,19 +0,0 @@ -setCallable($fn); - $hook->setPriority($priority); - $hook->setParamsQuantity($paramsQuantity); - - return $hook; - } -} diff --git a/app/Core/Log/LogServiceProvider.php b/app/Core/Log/LogServiceProvider.php deleted file mode 100644 index 26a3325..0000000 --- a/app/Core/Log/LogServiceProvider.php +++ /dev/null @@ -1,94 +0,0 @@ -getProperty('isDashboard'); - $isDashboardProperty->setAccessible(true); - $isDashboardProperty->setValue($isDashboardProperty, $isDashboard); - $isDashboardProperty->setAccessible(false); - } - - protected function setupHttpErrorHandle() - { - /** - * @var ContainerInterface - */ - $container = $this->app->getContainer(); - - /** @var SettingsInterface $settings */ - $settings = $container->get(SettingsInterface::class); - - $displayErrorDetails = $settings->get('displayErrorDetails'); - - $request = $container->has('request') - ? $container->get('request') - : null; - - if (is_null($request)) { - // Create Request object from globals - $serverRequestCreator = ServerRequestCreatorFactory::create(); - $request = $serverRequestCreator->createServerRequestFromGlobals(); - } - - $requestPath = $request->getUri() != null ? $request->getUri()->getPath() : '/'; - $isDashboard = $requestPath === $settings->get('admin_prefix', '/dashboard') - || strpos($requestPath, $settings->get('admin_prefix', '/dashboard') . '/') === 0; - - $container->set('is_dashboard', $isDashboard); - - $this->setupDashboardEnvironment($isDashboard); - - $responseFactory = $this->app->getResponseFactory(); - $callableResolver = $this->app->getCallableResolver(); - $errorHandler = new HttpErrorHandler($callableResolver, $responseFactory); - - // Create Shutdown Handler - $shutdownHandler = new ShutdownHandler($request, $errorHandler, $displayErrorDetails); - register_shutdown_function($shutdownHandler); - - return $errorHandler; - } - - protected function writeErrorLogs(HttpErrorHandler $errorHandler) - { - /** - * @var ContainerInterface - */ - $container = $this->app->getContainer(); - $settings = $container->get(SettingsInterface::class); - - $displayErrorDetails = $settings->get('displayErrorDetails'); - $logError = $settings->get('logError'); - $logErrorDetails = $settings->get('logErrorDetails'); - - // Add Error Middleware - $errorMiddleware = $this->app->addErrorMiddleware($displayErrorDetails, $logError, $logErrorDetails); - $errorMiddleware->setDefaultErrorHandler($errorHandler); - } - - public function register() - { - $this->writeErrorLogs( - $this->setupHttpErrorHandle() - ); - } - - public function boot() - { - die('zo'); - } -} diff --git a/app/Core/MiddlewareDispatcher.php b/app/Core/MiddlewareDispatcher.php deleted file mode 100644 index cb0cda1..0000000 --- a/app/Core/MiddlewareDispatcher.php +++ /dev/null @@ -1,29 +0,0 @@ -seedMiddlewareStack($kernel); - $this->callableResolver = $callableResolver; - $this->container = $container; - } -} diff --git a/app/Core/Routing/Route.php b/app/Core/Routing/Route.php deleted file mode 100644 index 8377cd0..0000000 --- a/app/Core/Routing/Route.php +++ /dev/null @@ -1,106 +0,0 @@ -methods = $methods; - $this->pattern = $pattern; - $this->callable = $callable; - $this->responseFactory = $responseFactory; - $this->callableResolver = $callableResolver; - $this->container = $container; - $this->invocationStrategy = $invocationStrategy ?? new RequestResponse(); - $this->groups = $groups; - $this->identifier = 'route' . $identifier; - $this->middlewareDispatcher = new MiddlewareDispatcher($this, $callableResolver, $container); - } - - /** - * {@inheritdoc} - */ - public function handle(ServerRequestInterface $request): ResponseInterface - { - if ($this->callableResolver instanceof AdvancedCallableResolverInterface) { - $callable = $this->callableResolver->resolveRoute($this->callable); - } else { - $callable = $this->callableResolver->resolve($this->callable); - } - /** - * @var \App\Core\Handlers\Strategies\RequestResponse - */ - $strategy = $this->invocationStrategy; - - /** @var string[] $strategyImplements */ - $strategyImplements = class_implements($strategy); - - if ( - is_array($callable) - && $callable[0] instanceof RequestHandlerInterface - && !in_array(RequestHandlerInvocationStrategyInterface::class, $strategyImplements) - ) { - /** - * @var \Slim\Handlers\Strategies\RequestHandler; - */ - $strategy = new RequestHandler(); - } - - $response = $this->responseFactory->createResponse(); - - /** - * @var \DI\Container - */ - $container = $this->container; - - $container->set(RequestInterface::class, $request); - $container->set(ServerRequestInterface::class, $request); - $container->set('request', $request); - - $container->set(ResponseInterface::class, $response); - $container->set('response', $response); - - $container->set('args', $this->arguments); - - // Auto resolve params - if (is_a($strategy, RequestResponse::class)) { - return $strategy->resolve($callable, $request, $response, $this->arguments, $container); - } - return $strategy($callable, $request, $response, $this->arguments); - } -} diff --git a/app/Core/Routing/RouteCollector.php b/app/Core/Routing/RouteCollector.php deleted file mode 100644 index 8078a09..0000000 --- a/app/Core/Routing/RouteCollector.php +++ /dev/null @@ -1,54 +0,0 @@ -responseFactory = $responseFactory; - $this->callableResolver = $callableResolver; - $this->container = $container; - $this->defaultInvocationStrategy = $defaultInvocationStrategy ?? new RequestResponse(); - $this->routeParser = $routeParser ?? new RouteParser($this); - - if ($cacheFile) { - $this->setCacheFile($cacheFile); - } - } - - /** - * @param string[] $methods - * @param callable|string $callable - */ - protected function createRoute(array $methods, string $pattern, $callable): RouteInterface - { - return new Route( - $methods, - $pattern, - $callable, - $this->responseFactory, - $this->callableResolver, - $this->container, - $this->defaultInvocationStrategy, - $this->routeGroups, - $this->routeCounter - ); - } -} diff --git a/app/Core/Routing/RouteCollectorProxy.php b/app/Core/Routing/RouteCollectorProxy.php deleted file mode 100644 index 75dd152..0000000 --- a/app/Core/Routing/RouteCollectorProxy.php +++ /dev/null @@ -1,26 +0,0 @@ -responseFactory = $responseFactory; - $this->callableResolver = $callableResolver; - $this->container = $container; - $this->routeCollector = $routeCollector ?? new RouteCollector($responseFactory, $callableResolver, $container); - $this->groupPattern = $groupPattern; - } -} diff --git a/app/Core/Settings/Settings.php b/app/Core/Settings/Settings.php deleted file mode 100644 index 4e2ec6e..0000000 --- a/app/Core/Settings/Settings.php +++ /dev/null @@ -1,55 +0,0 @@ -settings = $this->init($settings); - } - - private function init($settings, $prefix = null, &$ret = []): array - { - // Reset data type - if (!is_array($ret)) { - $ret = []; - } - - foreach ($settings as $key => $subSettings) { - $settingKey = empty($prefix) ? $key : sprintf('%s.%s', $prefix, $key); - if (is_array($subSettings)) { - $this->init($subSettings, $settingKey, $ret); - } else { - $ret[$settingKey] = $subSettings; - } - } - - return $ret; - } - - /** - * @return mixed - */ - public function get(string $key = '', $defaultValue = null) - { - if (empty($key)) { - return $this->settings; - } - - if (isset($this->settings[$key])) { - return $this->settings[$key]; - } - return $defaultValue; - } - - public function isBuiltInExtension(string $extensionName) - { - return in_array($extensionName, $this->builtInExtensions); - } -} diff --git a/app/Core/Settings/SettingsInterface.php b/app/Core/Settings/SettingsInterface.php deleted file mode 100644 index b776428..0000000 --- a/app/Core/Settings/SettingsInterface.php +++ /dev/null @@ -1,14 +0,0 @@ - - */ -class Twig implements ArrayAccess -{ - /** - * Twig loader - */ - protected LoaderInterface $loader; - - /** - * Twig environment - */ - protected Environment $environment; - - /** - * Default view variables - * - * @var array - */ - protected array $defaultVariables = []; - - /** - * @param ServerRequestInterface $request - * @param string $attributeName - * - * @return Twig - */ - public static function fromRequest(ServerRequestInterface $request, string $attributeName = 'view'): self - { - $twig = $request->getAttribute($attributeName); - if (!($twig instanceof self)) { - throw new RuntimeException( - 'Twig could not be found in the server request attributes using the key "' . $attributeName . '".' - ); - } - - return $twig; - } - - /** - * @param string|string[] $path Path(s) to templates directory - * @param array $settings Twig environment settings - * - * @throws LoaderError When the template cannot be found - * - * @return Twig - */ - public static function create($path, array $settings = []): self - { - $loader = new FilesystemLoader(); - - $paths = is_array($path) ? $path : [$path]; - foreach ($paths as $namespace => $path) { - if (is_string($namespace)) { - $loader->setPaths($path, $namespace); - } else { - $loader->addPath($path); - } - } - - return new self($loader, $settings); - } - - /** - * @param LoaderInterface $loader Twig loader - * @param array $settings Twig environment settings - */ - public function __construct(LoaderInterface $loader, array $settings = []) - { - $this->loader = $loader; - $this->environment = new Environment($this->loader, $settings); - $extension = new TwigExtension(); - $this->addExtension($extension); - } - - /** - * Proxy method to add an extension to the Twig environment - * - * @param ExtensionInterface $extension A single extension instance or an array of instances - */ - public function addExtension(ExtensionInterface $extension): void - { - $this->environment->addExtension($extension); - } - - /** - * Proxy method to add a runtime loader to the Twig environment - * - * @param RuntimeLoaderInterface $runtimeLoader - */ - public function addRuntimeLoader(RuntimeLoaderInterface $runtimeLoader): void - { - $this->environment->addRuntimeLoader($runtimeLoader); - } - - /** - * Fetch rendered template - * - * @param string $template Template pathname relative to templates directory - * @param array $data Associative array of template variables - * - * @throws LoaderError When the template cannot be found - * @throws SyntaxError When an error occurred during compilation - * @throws RuntimeError When an error occurred during rendering - * - * @return string - */ - public function fetch(string $template, array $data = []): string - { - $data = array_merge($this->defaultVariables, $data); - - return $this->environment->render($template, $data); - } - - /** - * Fetch rendered block - * - * @param string $template Template pathname relative to templates directory - * @param string $block Name of the block within the template - * @param array $data Associative array of template variables - * - * @throws Throwable When an error occurred during rendering - * @throws LoaderError When the template cannot be found - * @throws SyntaxError When an error occurred during compilation - * - * @return string - */ - public function fetchBlock(string $template, string $block, array $data = []): string - { - $data = HookManager::applyFilters( - $template . '_data', - array_merge($this->defaultVariables, $data), - $template, - $block - ); - - return $this->environment->resolveTemplate($template)->renderBlock($block, $data); - } - - /** - * Fetch rendered string - * - * @param string $string String - * @param array $data Associative array of template variables - * - * @throws LoaderError When the template cannot be found - * @throws SyntaxError When an error occurred during compilation - * - * @return string - */ - public function fetchFromString(string $string = '', array $data = []): string - { - $data = array_merge($this->defaultVariables, $data); - - return $this->environment->createTemplate($string)->render($data); - } - - /** - * Output rendered template - * - * @param ResponseInterface $response - * @param string $template Template pathname relative to templates directory - * @param array $data Associative array of template variables - * - * @throws LoaderError When the template cannot be found - * @throws SyntaxError When an error occurred during compilation - * @throws RuntimeError When an error occurred during rendering - * - * @return ResponseInterface - */ - public function render(ResponseInterface $response, string $template, array $data = []): ResponseInterface - { - $response->getBody()->write($this->fetch($template, $data)); - - return $response; - } - - /** - * Return Twig loader - * - * @return LoaderInterface - */ - public function getLoader(): LoaderInterface - { - return $this->loader; - } - - /** - * Return Twig environment - * - * @return Environment - */ - public function getEnvironment(): Environment - { - return $this->environment; - } - - /** - * Does this collection have a given key? - * - * @param string $key The data key - * - * @return bool - */ - public function offsetExists($key): bool - { - return array_key_exists($key, $this->defaultVariables); - } - - /** - * Get collection item for key - * - * @param string $key The data key - * - * @return mixed The key's value, or the default value - */ - #[ReturnTypeWillChange] - public function offsetGet($key) - { - if (!$this->offsetExists($key)) { - return null; - } - return $this->defaultVariables[$key]; - } - - /** - * Set collection item - * - * @param string $key The data key - * @param mixed $value The data value - */ - public function offsetSet($key, $value): void - { - $this->defaultVariables[$key] = $value; - } - - /** - * Remove item from collection - * - * @param string $key The data key - */ - public function offsetUnset($key): void - { - unset($this->defaultVariables[$key]); - } - - /** - * Get number of items in collection - * - * @return int - */ - public function count(): int - { - return count($this->defaultVariables); - } - - /** - * Get collection iterator - * - * @return ArrayIterator - */ - public function getIterator(): ArrayIterator - { - return new ArrayIterator($this->defaultVariables); - } -} diff --git a/app/Http/Controllers/GlobalController.php b/app/Http/Controllers/GlobalController.php index ffec526..8823c33 100644 --- a/app/Http/Controllers/GlobalController.php +++ b/app/Http/Controllers/GlobalController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\Core\HookManager; +use Jackal\Jackal\HookManager; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 08cdbbd..6924608 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\Core\HookManager; +use Jackal\Jackal\HookManager; use Psr\Http\Message\ResponseInterface; class HomeController extends Controller diff --git a/app/Http/Middleware/AssetsMiddleware.php b/app/Http/Middleware/AssetsMiddleware.php index 41c751b..e0ff324 100644 --- a/app/Http/Middleware/AssetsMiddleware.php +++ b/app/Http/Middleware/AssetsMiddleware.php @@ -3,9 +3,9 @@ namespace App\Http\Middleware; use App\Constracts\MiddlewareConstract; -use App\Core\AssetManager; -use App\Core\Helper; -use App\Core\HookManager; +use Jackal\Jackal\AssetManager; +use Jackal\Jackal\Helper; +use Jackal\Jackal\HookManager; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Message\ResponseInterface; diff --git a/app/Providers/ServiceProvider.php b/app/Providers/ServiceProvider.php index 9de9e07..c5d8a98 100644 --- a/app/Providers/ServiceProvider.php +++ b/app/Providers/ServiceProvider.php @@ -2,14 +2,14 @@ namespace App\Providers; -use App\Core\Application; +use Jackal\Jackal\Application; abstract class ServiceProvider { /** * The application instance. * - * @var \App\Core\Application + * @var \Jackal\Jackal\Application */ protected $app; diff --git a/app/Traits/AssetBaseTrait.php b/app/Traits/AssetBaseTrait.php index 46dd160..79e371a 100644 --- a/app/Traits/AssetBaseTrait.php +++ b/app/Traits/AssetBaseTrait.php @@ -3,8 +3,8 @@ namespace App\Traits; use App\Constracts\Assets\AssetOptionsConstract; -use App\Core\Assets\AssetOptions; -use App\Core\Helper; +use Jackal\Jackal\Assets\AssetOptions; +use Jackal\Jackal\Helper; trait AssetBaseTrait { diff --git a/app/bootstrap.php b/app/bootstrap.php index 3339dfe..3aa643f 100644 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -4,16 +4,16 @@ use App\Common\Option; use App\Constracts\AssetTypeEnum; -use App\Core\AssetManager; -use App\Core\Assets\AssetStylesheetOptions; -use App\Core\Assets\AssetUrl; +use Jackal\Jackal\AssetManager; +use Jackal\Jackal\Assets\AssetStylesheetOptions; +use Jackal\Jackal\Assets\AssetUrl; use App\Http\Controllers\GlobalController; use App\Http\Kernel; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -use App\Core\ExtensionManager; -use App\Core\Factory\AppFactory; -use App\Core\HookManager; +use Jackal\Jackal\ExtensionManager; +use Jackal\Jackal\Factory\AppFactory; +use Jackal\Jackal\HookManager; use App\Http\ResponseEmitter\ResponseEmitter; use DI\ContainerBuilder; use Dotenv\Dotenv; diff --git a/app/helpers.php b/app/helpers.php index 2e5a9e2..460ebe9 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -2,10 +2,10 @@ use App\Common\Constants; use App\Common\Option; -use App\Core\Application; -use App\Core\Env; -use App\Core\Helper; -use App\Core\HookManager; +use Jackal\Jackal\Application; +use Jackal\Jackal\Env; +use Jackal\Jackal\Helper; +use Jackal\Jackal\HookManager; use Psr\Container\ContainerInterface; if (!function_exists('array_get')) { diff --git a/composer.json b/composer.json index 59f6a00..6e37691 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "router", "psr7" ], + "minimum-stability": "dev", "homepage": "http://github.com/slimphp/Slim-Skeleton", "license": "MIT", "authors": [ @@ -30,6 +31,7 @@ "require": { "php": "^7.4 || ^8.0", "ext-json": "*", + "jackal-cms/framework": "dev-master", "davedevelopment/phpmig": "^1.7", "laravel/serializable-closure": "^1.3", "marcj/topsort": "^2.0", @@ -52,7 +54,7 @@ "jangregor/phpstan-prophecy": "^1.0.0", "phpspec/prophecy-phpunit": "^2.1", "phpstan/extension-installer": "^1.3.1", - "phpstan/phpstan": "^1.10", + "phpstan/phpstan": "1.10.62", "phpunit/phpunit": "^9.6.17", "squizlabs/php_codesniffer": "^3.9" }, diff --git a/configs/dependencies.php b/configs/dependencies.php index cfbe960..13482df 100644 --- a/configs/dependencies.php +++ b/configs/dependencies.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use App\Core\Settings\SettingsInterface; +use Jackal\Jackal\Settings\SettingsInterface; use DI\ContainerBuilder; use Monolog\Handler\StreamHandler; use Monolog\Logger; diff --git a/configs/middleware.php b/configs/middleware.php index a6d841d..99f1bce 100644 --- a/configs/middleware.php +++ b/configs/middleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use App\Core\Application; +use Jackal\Jackal\Application; use App\Http\Middleware\AssetsMiddleware; use App\Http\Middleware\SessionMiddleware; diff --git a/configs/routes.php b/configs/routes.php index 10194a5..aa6d66f 100644 --- a/configs/routes.php +++ b/configs/routes.php @@ -3,11 +3,11 @@ declare(strict_types=1); use Slim\Interfaces\RouteCollectorProxyInterface as Group; -use App\Core\Application; +use Jackal\Jackal\Application; use App\Application\Actions\User\ListUsersAction; use App\Application\Actions\User\ViewUserAction; use App\Http\Controllers\StaticFileController; -use App\Core\HookManager; +use Jackal\Jackal\HookManager; use App\Http\Controllers\HomeController; return function (Application $app) { diff --git a/configs/settings.php b/configs/settings.php index a4f3460..1b369e2 100644 --- a/configs/settings.php +++ b/configs/settings.php @@ -2,8 +2,8 @@ declare(strict_types=1); -use App\Core\Settings\Settings; -use App\Core\Settings\SettingsInterface; +use Jackal\Jackal\Settings\Settings; +use Jackal\Jackal\Settings\SettingsInterface; use DI\ContainerBuilder; use Monolog\Logger; diff --git a/extensions/common/src/CommonExtension.php b/extensions/common/src/CommonExtension.php index 67e2ce1..20cc001 100644 --- a/extensions/common/src/CommonExtension.php +++ b/extensions/common/src/CommonExtension.php @@ -1,7 +1,7 @@