From 3c79436378b2752a8a2ea9596c222a7f4ea914fc Mon Sep 17 00:00:00 2001 From: Ben Rutland Date: Sat, 13 Feb 2021 19:48:18 +0000 Subject: [PATCH] removed radiate package and updated composer json --- Radiate/Auth/AuthManager.php | 96 -- Radiate/Auth/AuthServiceProvider.php | 32 - Radiate/Auth/Middleware/Authenticate.php | 26 - Radiate/Console/Command.php | 192 ---- Radiate/Console/GeneratorCommand.php | 344 ------- Radiate/Console/Parser.php | 149 --- Radiate/Container/Container.php | 205 ---- Radiate/Container/ContainerException.php | 10 - Radiate/Container/NotFoundException.php | 9 - Radiate/Events/Console/MakeEvent.php | 51 - Radiate/Events/Console/MakeListener.php | 51 - Radiate/Events/Console/MakeSubscriber.php | 51 - Radiate/Events/Console/stubs/event.stub | 18 - Radiate/Events/Console/stubs/listener.stub | 24 - Radiate/Events/Console/stubs/subscriber.stub | 19 - Radiate/Events/Dispatchable.php | 19 - Radiate/Events/Dispatcher.php | 88 -- Radiate/Events/EventServiceProvider.php | 34 - .../Exceptions/FileNotFoundException.php | 9 - Radiate/Filesystem/Filesystem.php | 559 ----------- .../Filesystem/FilesystemServiceProvider.php | 20 - Radiate/Foundation/Application.php | 345 ------- Radiate/Foundation/Console/MakeProvider.php | 51 - Radiate/Foundation/Console/VendorPublish.php | 90 -- .../Foundation/Console/stubs/provider.stub | 18 - Radiate/Foundation/Exceptions/Handler.php | 39 - .../Http/Exceptions/HttpResponseException.php | 20 - .../Middleware/ConvertEmptyStringsToNull.php | 36 - .../Http/Middleware/TrimStrings.php | 36 - .../Providers/ConsoleServiceProvider.php | 21 - .../Providers/EventServiceProvider.php | 41 - .../Providers/RouteServiceProvider.php | 30 - Radiate/Http/Request.php | 407 -------- Radiate/Mail/Console/MakeMail.php | 51 - Radiate/Mail/Console/stubs/mail.stub | 28 - Radiate/Mail/MailServiceProvider.php | 36 - Radiate/Mail/Mailable.php | 424 -------- Radiate/Mail/Mailer.php | 170 ---- Radiate/Mail/PendingMail.php | 105 -- Radiate/Mail/resources/views/message.php | 10 - Radiate/Routing/AjaxRoute.php | 37 - Radiate/Routing/Console/MakeController.php | 56 -- Radiate/Routing/Console/MakeMiddleware.php | 51 - .../Console/stubs/controller.resource.stub | 67 -- Radiate/Routing/Console/stubs/controller.stub | 20 - Radiate/Routing/Console/stubs/middleware.stub | 21 - Radiate/Routing/Controller.php | 7 - Radiate/Routing/RestRoute.php | 53 - Radiate/Routing/Route.php | 210 ---- Radiate/Routing/Router.php | 384 ------- Radiate/Routing/RoutingServiceProvider.php | 33 - Radiate/Support/Collection.php | 792 --------------- Radiate/Support/Facades/App.php | 41 - Radiate/Support/Facades/Arr.php | 83 -- Radiate/Support/Facades/Event.php | 26 - Radiate/Support/Facades/Facade.php | 114 --- Radiate/Support/Facades/Route.php | 42 - Radiate/Support/Facades/Str.php | 97 -- Radiate/Support/Facades/View.php | 21 - Radiate/Support/Hash.php | 32 - Radiate/Support/Inflector.php | 350 ------- Radiate/Support/Pipeline.php | 134 --- Radiate/Support/Pluralizer.php | 57 -- Radiate/Support/ServiceProvider.php | 93 -- Radiate/Support/Stringable.php | 945 ------------------ Radiate/View/View.php | 43 - Radiate/View/ViewServiceProvider.php | 32 - Radiate/View/resources/views/404.php | 0 Radiate/View/resources/views/archive.php | 0 Radiate/View/resources/views/footer.php | 0 Radiate/View/resources/views/front-page.php | 0 Radiate/View/resources/views/header.php | 0 Radiate/View/resources/views/home.php | 0 Radiate/View/resources/views/index.php | 0 Radiate/View/resources/views/search.php | 0 Radiate/View/resources/views/searchform.php | 0 Radiate/View/resources/views/singular.php | 0 composer.json | 9 +- 78 files changed, 7 insertions(+), 7807 deletions(-) delete mode 100644 Radiate/Auth/AuthManager.php delete mode 100644 Radiate/Auth/AuthServiceProvider.php delete mode 100644 Radiate/Auth/Middleware/Authenticate.php delete mode 100644 Radiate/Console/Command.php delete mode 100644 Radiate/Console/GeneratorCommand.php delete mode 100644 Radiate/Console/Parser.php delete mode 100644 Radiate/Container/Container.php delete mode 100644 Radiate/Container/ContainerException.php delete mode 100644 Radiate/Container/NotFoundException.php delete mode 100644 Radiate/Events/Console/MakeEvent.php delete mode 100644 Radiate/Events/Console/MakeListener.php delete mode 100644 Radiate/Events/Console/MakeSubscriber.php delete mode 100644 Radiate/Events/Console/stubs/event.stub delete mode 100644 Radiate/Events/Console/stubs/listener.stub delete mode 100644 Radiate/Events/Console/stubs/subscriber.stub delete mode 100644 Radiate/Events/Dispatchable.php delete mode 100644 Radiate/Events/Dispatcher.php delete mode 100644 Radiate/Events/EventServiceProvider.php delete mode 100644 Radiate/Filesystem/Exceptions/FileNotFoundException.php delete mode 100644 Radiate/Filesystem/Filesystem.php delete mode 100644 Radiate/Filesystem/FilesystemServiceProvider.php delete mode 100644 Radiate/Foundation/Application.php delete mode 100644 Radiate/Foundation/Console/MakeProvider.php delete mode 100644 Radiate/Foundation/Console/VendorPublish.php delete mode 100644 Radiate/Foundation/Console/stubs/provider.stub delete mode 100644 Radiate/Foundation/Exceptions/Handler.php delete mode 100644 Radiate/Foundation/Http/Exceptions/HttpResponseException.php delete mode 100644 Radiate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php delete mode 100644 Radiate/Foundation/Http/Middleware/TrimStrings.php delete mode 100644 Radiate/Foundation/Providers/ConsoleServiceProvider.php delete mode 100644 Radiate/Foundation/Providers/EventServiceProvider.php delete mode 100644 Radiate/Foundation/Providers/RouteServiceProvider.php delete mode 100644 Radiate/Http/Request.php delete mode 100644 Radiate/Mail/Console/MakeMail.php delete mode 100644 Radiate/Mail/Console/stubs/mail.stub delete mode 100644 Radiate/Mail/MailServiceProvider.php delete mode 100644 Radiate/Mail/Mailable.php delete mode 100644 Radiate/Mail/Mailer.php delete mode 100644 Radiate/Mail/PendingMail.php delete mode 100644 Radiate/Mail/resources/views/message.php delete mode 100644 Radiate/Routing/AjaxRoute.php delete mode 100644 Radiate/Routing/Console/MakeController.php delete mode 100644 Radiate/Routing/Console/MakeMiddleware.php delete mode 100644 Radiate/Routing/Console/stubs/controller.resource.stub delete mode 100644 Radiate/Routing/Console/stubs/controller.stub delete mode 100644 Radiate/Routing/Console/stubs/middleware.stub delete mode 100644 Radiate/Routing/Controller.php delete mode 100644 Radiate/Routing/RestRoute.php delete mode 100644 Radiate/Routing/Route.php delete mode 100644 Radiate/Routing/Router.php delete mode 100644 Radiate/Routing/RoutingServiceProvider.php delete mode 100644 Radiate/Support/Collection.php delete mode 100644 Radiate/Support/Facades/App.php delete mode 100644 Radiate/Support/Facades/Arr.php delete mode 100644 Radiate/Support/Facades/Event.php delete mode 100644 Radiate/Support/Facades/Facade.php delete mode 100644 Radiate/Support/Facades/Route.php delete mode 100644 Radiate/Support/Facades/Str.php delete mode 100644 Radiate/Support/Facades/View.php delete mode 100644 Radiate/Support/Hash.php delete mode 100644 Radiate/Support/Inflector.php delete mode 100644 Radiate/Support/Pipeline.php delete mode 100644 Radiate/Support/Pluralizer.php delete mode 100644 Radiate/Support/ServiceProvider.php delete mode 100644 Radiate/Support/Stringable.php delete mode 100644 Radiate/View/View.php delete mode 100644 Radiate/View/ViewServiceProvider.php delete mode 100644 Radiate/View/resources/views/404.php delete mode 100644 Radiate/View/resources/views/archive.php delete mode 100644 Radiate/View/resources/views/footer.php delete mode 100644 Radiate/View/resources/views/front-page.php delete mode 100644 Radiate/View/resources/views/header.php delete mode 100644 Radiate/View/resources/views/home.php delete mode 100644 Radiate/View/resources/views/index.php delete mode 100644 Radiate/View/resources/views/search.php delete mode 100644 Radiate/View/resources/views/searchform.php delete mode 100644 Radiate/View/resources/views/singular.php diff --git a/Radiate/Auth/AuthManager.php b/Radiate/Auth/AuthManager.php deleted file mode 100644 index 4e4377c..0000000 --- a/Radiate/Auth/AuthManager.php +++ /dev/null @@ -1,96 +0,0 @@ -login($credentials, $remember); - } - - /** - * Log in - * - * @param array $credentials - * @param bool $remember - * @return bool - */ - public function login(array $credentials, bool $remember = false): bool - { - $user = wp_signon([ - 'user_login' => $credentials['username'], - 'user_password' => $credentials['password'], - 'rememberme' => $remember, - ]); - - return !is_wp_error($user); - } - - /** - * Log out - * - * @return void - */ - public function logout(): void - { - wp_logout(); - } - - /** - * Return the user - * - * @return \WP_User|false - */ - public function user() - { - return $this->check() ? wp_get_current_user() : false; - } - - /** - * Return the user id - * - * @return int|bool - */ - public function id() - { - return ($id = get_current_user_id()) !== 0 ? $id : false; - } - - /** - * Determine if the user is logged in - * - * @return boolean - */ - public function check(): bool - { - return is_user_logged_in(); - } - - /** - * Determine if the user is a guest - * - * @return bool - */ - public function guest(): bool - { - return !$this->check(); - } - - /** - * Return the auth guard - * - * @return self - */ - public function guard(): self - { - return $this; - } -} diff --git a/Radiate/Auth/AuthServiceProvider.php b/Radiate/Auth/AuthServiceProvider.php deleted file mode 100644 index 9f0b51f..0000000 --- a/Radiate/Auth/AuthServiceProvider.php +++ /dev/null @@ -1,32 +0,0 @@ -app->singleton('auth', function () { - return new AuthManager(); - }); - } - - /** - * Boot the services - * - * @return void - */ - public function boot() - { - $this->app['request']->setUserResolver(function () { - return $this->app['auth']->user(); - }); - } -} diff --git a/Radiate/Auth/Middleware/Authenticate.php b/Radiate/Auth/Middleware/Authenticate.php deleted file mode 100644 index 9a5da72..0000000 --- a/Radiate/Auth/Middleware/Authenticate.php +++ /dev/null @@ -1,26 +0,0 @@ -user()) { - return $next($request); - } - - throw new HttpResponseException('Unauthorised.', 401); - } -} diff --git a/Radiate/Console/Command.php b/Radiate/Console/Command.php deleted file mode 100644 index 4e931b0..0000000 --- a/Radiate/Console/Command.php +++ /dev/null @@ -1,192 +0,0 @@ -app = $app; - } - - /** - * Register a command - * - * @return void - */ - public function register() - { - $synopsis = $this->parseSignature(); - - WP_CLI::add_command('radiate ' . $this->name, $this, $synopsis); - } - - /** - * Parse the signature into the command name arguments, options and synopsis. - * - * @return array - */ - protected function parseSignature(): array - { - [$name, $arguments, $options] = Parser::parse($this->signature); - - $this->name = $name; - - $this->allowedArguments = $arguments; - - return [ - 'shortdesc' => $this->description, - 'synopsis' => array_merge($arguments, $options), - ]; - } - - /** - * Set up the command arguments and options. - * - * @param array $arguments The console arguments. - * @param array $options The console options and flags. - * @return void - */ - public function __invoke(array $arguments, array $options) - { - $this->arguments = $this->parseArguments($arguments); - - $this->options = $options; - - $this->handle(); - } - - /** - * Handle the command call. - * - * @return void - */ - abstract protected function handle(); - - /** - * Parse the arguments into a keyed array. - * - * @param array $args The arguments to parse. - * @return array - */ - protected function parseArguments(array $args) - { - $arguments = []; - - foreach ($this->allowedArguments as $index => $argument) { - $arguments[$argument['name']] = $args[$index]; - } - return $arguments; - } - - /** - * Display a success message - * - * @param string $message - * @return void - */ - protected function success(string $message) - { - WP_CLI::success($message); - } - - /** - * Display a message - * - * @param string $message - * @return void - */ - protected function line(string $message) - { - WP_CLI::log($message); - } - - /** - * Display an error message - * - * @param string $message - * @return void - */ - protected function error(string $message) - { - WP_CLI::error($message); - } - - /** - * Get a named argument. - * - * @param string $key The argument name. - * @return mixed - */ - protected function argument(string $key) - { - return $this->arguments[$key] ?? null; - } - - /** - * Get an option. - * - * @param string $key The option name. - * @return mixed - */ - protected function option(string $key) - { - return $this->options[$key] ?? null; - } -} diff --git a/Radiate/Console/GeneratorCommand.php b/Radiate/Console/GeneratorCommand.php deleted file mode 100644 index 3470d05..0000000 --- a/Radiate/Console/GeneratorCommand.php +++ /dev/null @@ -1,344 +0,0 @@ -files = $files; - - parent::__construct($app); - } - - /** - * Get the stub file for the generator. - * - * @return string - */ - abstract protected function getStub(); - - /** - * Execute the console command. - * - * @return void - */ - protected function handle() - { - // First we need to ensure that the given name is not a reserved word within the PHP - // language and that the class name will actually be valid. If it is not valid we - // can error now and prevent from polluting the filesystem using invalid files. - if ($this->isReservedName($this->getNameInput())) { - $this->error('The name "' . $this->getNameInput() . '" is reserved by PHP.'); - - return; - } - - $name = $this->qualifyClass($this->getNameInput()); - - $path = $this->getPath($name); - - // Next, We will check to see if the class already exists. If it does, we don't want - // to create the class and overwrite the user's code. So, we will bail out so the - // code is untouched. Otherwise, we will continue generating this class' files. - if (!$this->option('force') && $this->alreadyExists($this->getNameInput())) { - $this->error($this->type . ' already exists!'); - - return; - } - - // Next, we will generate the path to the location where this class' file should get - // written. Then, we will build the class and make the proper replacements on the - // stub files so that it gets the correctly formatted namespace and class name. - $this->makeDirectory($path); - - $this->files->put($path, $this->sortImports($this->buildClass($name))); - - $this->success($this->type . ' created successfully.'); - } - - /** - * Parse the class name and format according to the root namespace. - * - * @param string $name - * @return string - */ - protected function qualifyClass(string $name) - { - $name = ltrim($name, '\\/'); - - $name = str_replace('/', '\\', $name); - - $rootNamespace = $this->rootNamespace(); - - if (strpos($name, $rootNamespace) === 0) { - return $name; - } - - return $this->qualifyClass( - $this->getDefaultNamespace(trim($rootNamespace, '\\')) . '\\' . $name - ); - } - - /** - * Get the default namespace for the class. - * - * @param string $rootNamespace - * @return string - */ - protected function getDefaultNamespace(string $rootNamespace) - { - return $rootNamespace; - } - - /** - * Determine if the class already exists. - * - * @param string $rawName - * @return bool - */ - protected function alreadyExists(string $rawName) - { - return $this->files->exists($this->getPath($this->qualifyClass($rawName))); - } - - /** - * Get the destination class path. - * - * @param string $name - * @return string - */ - protected function getPath(string $name) - { - $position = strpos($name, $this->rootNamespace()); - - if ($position !== false) { - $name = substr_replace($name, '', $position, strlen($this->rootNamespace())); - } - - return $this->app->basePath('app/' . str_replace('\\', '/', $name) . '.php'); - } - - /** - * Build the directory for the class if necessary. - * - * @param string $path - * @return string - */ - protected function makeDirectory(string $path) - { - $directory = dirname($path); - - if (!$this->files->isDirectory($directory)) { - $this->files->makeDirectory($directory, 0777, true, true); - } - return $path; - } - - /** - * Build the class with the given name. - * - * @param string $name - * @return string - */ - protected function buildClass(string $name) - { - $stub = $this->files->get($this->getStub()); - - return $this->replaceNamespace($stub, $name)->replaceClass($stub, $name); - } - - /** - * Replace the namespace for the given stub. - * - * @param string $stub - * @param string $name - * @return self - */ - protected function replaceNamespace(string &$stub, string $name) - { - $stub = str_replace( - ['{{ namespace }}', '{{ rootNamespace }}'], - [$this->getNamespace($name), $this->rootNamespace()], - $stub - ); - - return $this; - } - - /** - * Get the full namespace for a given class, without the class name. - * - * @param string $name - * @return string - */ - protected function getNamespace(string $name) - { - return trim(implode('\\', array_slice(explode('\\', $name), 0, -1)), '\\'); - } - - /** - * Replace the class name for the given stub. - * - * @param string $stub - * @param string $name - * @return string - */ - protected function replaceClass(string $stub, string $name) - { - $class = str_replace($this->getNamespace($name) . '\\', '', $name); - - return str_replace('{{ class }}', $class, $stub); - } - - /** - * Alphabetically sorts the imports for the given stub. - * - * @param string $stub - * @return string - */ - protected function sortImports(string $stub) - { - if (preg_match('/(?P(?:use [^;]+;$\n?)+)/m', $stub, $match)) { - $imports = explode("\n", trim($match['imports'])); - - sort($imports); - - return str_replace(trim($match['imports']), implode("\n", $imports), $stub); - } - - return $stub; - } - - /** - * Get the desired class name from the input. - * - * @return string - */ - protected function getNameInput() - { - return trim($this->argument('name')); - } - - /** - * Get the root namespace for the class. - * - * @return string - */ - protected function rootNamespace() - { - return $this->app->getNamespace(); - } - - /** - * Checks whether the given name is reserved. - * - * @param string $name - * @return bool - */ - protected function isReservedName(string $name) - { - $name = strtolower($name); - - return in_array($name, $this->reservedNames); - } -} diff --git a/Radiate/Console/Parser.php b/Radiate/Console/Parser.php deleted file mode 100644 index 5c07087..0000000 --- a/Radiate/Console/Parser.php +++ /dev/null @@ -1,149 +0,0 @@ - 'positional', - 'name' => trim($token, '?'), - 'description' => $description, - 'optional' => true, - ]; - case preg_match('/(.+)\=(.+)/', $token, $matches): - return [ - 'type' => 'positional', - 'name' => $matches[1], - 'description' => $description, - 'default' => $matches[2], - ]; - default: - return [ - 'type' => 'positional', - 'name' => $token, - 'description' => $description, - ]; - } - } - - /** - * Parse an option expression. - * - * @param string $token - * @return array - */ - protected static function parseOption(string $token): array - { - [$token, $description] = static::extractDescription($token); - - switch (true) { - case Str::endsWith($token, '='): - return [ - 'type' => 'assoc', - 'name' => trim($token, '='), - 'description' => $description, - ]; - case preg_match('/(.+)\=(.+)/', $token, $matches): - return [ - 'type' => 'assoc', - 'name' => $matches[1], - 'description' => $description, - 'default' => $matches[2], - ]; - default: - return [ - 'type' => 'flag', - 'name' => $token, - 'description' => $description, - 'optional' => true, - ]; - } - } - - /** - * Parse the token into its token and description segments. - * - * @param string $token - * @return array - */ - protected static function extractDescription(string $token): array - { - $parts = preg_split('/\s+:\s+/', trim($token), 2); - - return count($parts) === 2 ? $parts : [$token, '']; - } -} diff --git a/Radiate/Container/Container.php b/Radiate/Container/Container.php deleted file mode 100644 index 5b2b49d..0000000 --- a/Radiate/Container/Container.php +++ /dev/null @@ -1,205 +0,0 @@ -instances[$abstract] = $concrete; - } - - /** - * Register a binding with the container. - * - * @param string $abstract - * @param \Closure $concrete - * @param bool $shared - * @return void - */ - public function bind(string $abstract, Closure $concrete, bool $shared = false) - { - $this->bindings[$abstract] = compact('concrete', 'shared'); - } - - /** - * Register a shared binding with the container. - * - * @param string $abstract - * @param \Closure $concrete - * @return void - */ - public function singleton(string $abstract, $concrete) - { - $this->bind($abstract, $concrete, true); - } - - /** - * Determine if the abstract is bound to the container - * - * @param string $abstract - * @return bool - */ - public function has($abstract) - { - return isset($this->instances[$abstract]) || isset($this->bindings[$abstract]); - } - - /** - * Resolve an instance - * - * @param string $abstract - * @return mixed - * - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface - */ - public function get($abstract) - { - try { - if (isset($this->instances[$abstract])) { - return $this->instances[$abstract]; - } - - if (isset($this->bindings[$abstract])) { - if ($this->bindings[$abstract]['shared']) { - return $this->instances[$abstract] = $this->bindings[$abstract]['concrete']($this); - } - - return $this->bindings[$abstract]['concrete']($this); - } - } catch (ContainerException $e) { - if ($this->has($abstract)) { - throw $e; - } - - throw new NotFoundException($abstract, $e->getCode(), $e); - } - } - - /** - * Get the container instance - * - * @return static - */ - public static function getInstance() - { - if (is_null(static::$instance)) { - static::$instance = new static; - } - - return static::$instance; - } - - /** - * Set the container instance - * - * @param \Radiate\Container\Container $container - * @return static - */ - public static function setInstance(Container $container = null) - { - return static::$instance = $container; - } - - /** - * Determine if an instance exists - * - * @param string $key - * @return bool - */ - public function offsetExists($key) - { - return $this->has($key); - } - - /** - * Get an instance - * - * @param string $key - * @return mixed - */ - public function offsetGet($key) - { - return $this->get($key); - } - - /** - * Set an instance - * - * @param string $key - * @param mixed $value - * @return void - */ - public function offsetSet($key, $value) - { - $this->bind($key, $value instanceof Closure ? $value : function () use ($value) { - return $value; - }); - } - - /** - * Unset any instances or bindings - * - * @param string $key - * @return void - */ - public function offsetUnset($key) - { - unset($this->bindings[$key], $this->instances[$key]); - } - - /** - * Get an instance - * - * @param string $key - * @return mixed - */ - public function __get(string $key) - { - return $this->get($key); - } - - /** - * Set an instance - * - * @param string $key - * @return mixed - */ - public function __set(string $key, $value) - { - $this[$key] = $value; - } -} diff --git a/Radiate/Container/ContainerException.php b/Radiate/Container/ContainerException.php deleted file mode 100644 index 05ec8a6..0000000 --- a/Radiate/Container/ContainerException.php +++ /dev/null @@ -1,10 +0,0 @@ -resolveListener($listener); - - foreach ((array) $events as $event) { - add_filter($event, $listener, $priority, $argCount); - } - } - - /** - * Determine if an event has listeners - * - * @param string $event - * @return bool - */ - public function hasListeners(string $event): bool - { - return (bool) has_filter($event); - } - - /** - * Undocumented function - * - * @param string $event - * @param mixed ...$payload - * @return mixed - */ - public function dispatch($event, ...$payload) - { - if (is_object($event)) { - return apply_filters(get_class($event), $event); - } - - return apply_filters($event, ...$payload); - } - - /** - * Forget the event listeners - * - * @param string $event - * @return void - */ - public function forget(string $event): void - { - remove_all_filters($event); - } - - /** - * Register an event subscriber with the dispatcher. - * - * @param string $subscriber - * @return void - */ - public function subscribe(string $subscriber): void - { - (new $subscriber)->subscribe($this); - } - - /** - * Resolve a listener - * - * @param mixed $listener - * @return mixed - */ - protected function resolveListener($listener) - { - if (is_string($listener) && class_exists($listener)) { - return [new $listener, 'handle']; - } - - return $listener; - } -} diff --git a/Radiate/Events/EventServiceProvider.php b/Radiate/Events/EventServiceProvider.php deleted file mode 100644 index 6d25368..0000000 --- a/Radiate/Events/EventServiceProvider.php +++ /dev/null @@ -1,34 +0,0 @@ -app->singleton('events', function () { - return new Dispatcher(); - }); - } - - /** - * Boot the provider - * - * @return void - */ - public function boot() - { - $this->commands([ - \Radiate\Events\Console\MakeEvent::class, - \Radiate\Events\Console\MakeListener::class, - \Radiate\Events\Console\MakeSubscriber::class, - ]); - } -} diff --git a/Radiate/Filesystem/Exceptions/FileNotFoundException.php b/Radiate/Filesystem/Exceptions/FileNotFoundException.php deleted file mode 100644 index 91dceeb..0000000 --- a/Radiate/Filesystem/Exceptions/FileNotFoundException.php +++ /dev/null @@ -1,9 +0,0 @@ -exists($path); - } - - /** - * Get the contents of a file. - * - * @param string $path - * @param bool $lock - * @return string - * - * @throws \Radiate\Filesystem\Exceptions\FileNotFoundException - */ - public function get(string $path, bool $lock = false): string - { - if ($this->isFile($path)) { - return $lock ? $this->sharedGet($path) : file_get_contents($path); - } - - throw new FileNotFoundException("File does not exist at path {$path}."); - } - - /** - * Get contents of a file with shared access. - * - * @param string $path - * @return string - */ - public function sharedGet(string $path): string - { - $contents = ''; - - $handle = fopen($path, 'rb'); - - if ($handle) { - try { - if (flock($handle, LOCK_SH)) { - clearstatcache(true, $path); - - $contents = fread($handle, $this->size($path) ?: 1); - - flock($handle, LOCK_UN); - } - } finally { - fclose($handle); - } - } - - return $contents; - } - - /** - * Get the returned value of a file. - * - * @param string $path - * @return mixed - * - * @throws \Radiate\Filesystem\Exceptions\FileNotFoundException - */ - public function getRequire(string $path) - { - if ($this->isFile($path)) { - return require $path; - } - - throw new FileNotFoundException("File does not exist at path {$path}."); - } - - /** - * Require the given file once. - * - * @param string $file - * @return mixed - */ - public function requireOnce(string $file) - { - require_once $file; - } - - /** - * Get the MD5 hash of the file at the given path. - * - * @param string $path - * @return string - */ - public function hash(string $path): string - { - return md5_file($path); - } - - /** - * Write the contents of a file. - * - * @param string $path - * @param string $contents - * @param bool $lock - * @return int|bool - */ - public function put(string $path, string $contents, bool $lock = false) - { - return file_put_contents($path, $contents, $lock ? LOCK_EX : 0); - } - - /** - * Write the contents of a file, replacing it automatically if it already exists. - * - * @param string $path - * @param string $content - * @return void - */ - public function replace(string $path, string $content): void - { - // If the path already exists and is a symlink, get the real path... - clearstatcache(true, $path); - - $path = realpath($path) ?: $path; - - $tempPath = tempnam(dirname($path), basename($path)); - - // Fix permissions of tempPath because `tempnam()` creates it with permissions set to 0600... - chmod($tempPath, 0777 - umask()); - - file_put_contents($tempPath, $content); - - rename($tempPath, $path); - } - - /** - * Prepend to a file. - * - * @param string $path - * @param string $data - * @return int - */ - public function prepend(string $path, string $data): int - { - if ($this->exists($path)) { - return $this->put($path, $data . $this->get($path)); - } - - return $this->put($path, $data); - } - - /** - * Append to a file. - * - * @param string $path - * @param string $data - * @return int - */ - public function append(string $path, string $data): int - { - return file_put_contents($path, $data, FILE_APPEND); - } - - /** - * Get or set UNIX mode of a file or directory. - * - * @param string $path - * @param int|null $mode - * @return mixed - */ - public function chmod(string $path, ?int $mode = null) - { - if ($mode) { - return chmod($path, $mode); - } - - return substr(sprintf('%o', fileperms($path)), -4); - } - - /** - * Delete the file at a given path. - * - * @param string|array $paths - * @return bool - */ - public function delete($paths): bool - { - $paths = is_array($paths) ? $paths : func_get_args(); - - $success = true; - - foreach ($paths as $path) { - try { - if (!@unlink($path)) { - $success = false; - } - } catch (ErrorException $e) { - $success = false; - } - } - - return $success; - } - - /** - * Move a file to a new location. - * - * @param string $path - * @param string $target - * @return bool - */ - public function move(string $path, string $target): bool - { - return rename($path, $target); - } - - /** - * Copy a file to a new location. - * - * @param string $path - * @param string $target - * @return bool - */ - public function copy(string $path, string $target): bool - { - return copy($path, $target); - } - - /** - * Create a symlink to the target file or directory. On Windows, a hard link is created if the target is a file. - * - * @param string $target - * @param string $link - * @return void - */ - public function link(string $target, string $link): void - { - if (!windows_os()) { - symlink($target, $link); - } - - $mode = $this->isDirectory($target) ? 'J' : 'H'; - - exec("mklink /{$mode} " . escapeshellarg($link) . ' ' . escapeshellarg($target)); - } - - /** - * Extract the file name from a file path. - * - * @param string $path - * @return string - */ - public function name(string $path): string - { - return pathinfo($path, PATHINFO_FILENAME); - } - - /** - * Extract the trailing name component from a file path. - * - * @param string $path - * @return string - */ - public function basename(string $path): string - { - return pathinfo($path, PATHINFO_BASENAME); - } - - /** - * Extract the parent directory from a file path. - * - * @param string $path - * @return string - */ - public function dirname(string $path): string - { - return pathinfo($path, PATHINFO_DIRNAME); - } - - /** - * Extract the file extension from a file path. - * - * @param string $path - * @return string - */ - public function extension(string $path): string - { - return pathinfo($path, PATHINFO_EXTENSION); - } - - /** - * Get the file type of a given file. - * - * @param string $path - * @return string - */ - public function type(string $path): string - { - return filetype($path); - } - - /** - * Get the mime-type of a given file. - * - * @param string $path - * @return string|false - */ - public function mimeType(string $path) - { - return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path); - } - - /** - * Get the file size of a given file. - * - * @param string $path - * @return int - */ - public function size(string $path): int - { - return filesize($path); - } - - /** - * Get the file's last modification time. - * - * @param string $path - * @return int - */ - public function lastModified(string $path): int - { - return filemtime($path); - } - - /** - * Determine if the given path is a directory. - * - * @param string $directory - * @return bool - */ - public function isDirectory(string $directory): bool - { - return is_dir($directory); - } - - /** - * Determine if the given path is readable. - * - * @param string $path - * @return bool - */ - public function isReadable(string $path): bool - { - return is_readable($path); - } - - /** - * Determine if the given path is writable. - * - * @param string $path - * @return bool - */ - public function isWritable(string $path): bool - { - return is_writable($path); - } - - /** - * Determine if the given path is a file. - * - * @param string $file - * @return bool - */ - public function isFile(string $file): bool - { - return is_file($file); - } - - /** - * Find path names matching a given pattern. - * - * @param string $pattern - * @param int $flags - * @return array - */ - public function glob(string $pattern, int $flags = 0): array - { - return glob($pattern, $flags); - } - - /** - * Ensure a directory exists. - * - * @param string $path - * @param int $mode - * @param bool $recursive - * @return void - */ - public function ensureDirectoryExists(string $path, int $mode = 0755, bool $recursive = true): void - { - if (!$this->isDirectory($path)) { - $this->makeDirectory($path, $mode, $recursive); - } - } - - /** - * Create a directory. - * - * @param string $path - * @param int $mode - * @param bool $recursive - * @param bool $force - * @return bool - */ - public function makeDirectory(string $path, int $mode = 0755, bool $recursive = false, bool $force = false): bool - { - if ($force) { - return @mkdir($path, $mode, $recursive); - } - - return mkdir($path, $mode, $recursive); - } - - /** - * Move a directory. - * - * @param string $from - * @param string $to - * @param bool $overwrite - * @return bool - */ - public function moveDirectory(string $from, string $to, bool $overwrite = false): bool - { - if ($overwrite && $this->isDirectory($to) && !$this->deleteDirectory($to)) { - return false; - } - - return @rename($from, $to) === true; - } - - /** - * Copy a directory from one location to another. - * - * @param string $directory - * @param string $destination - * @param int|null $options - * @return bool - */ - public function copyDirectory(string $directory, string $destination, ?int $options = null): bool - { - if (!$this->isDirectory($directory)) { - return false; - } - - $options = $options ?: FilesystemIterator::SKIP_DOTS; - - // If the destination directory does not actually exist, we will go ahead and - // create it recursively, which just gets the destination prepared to copy - // the files over. Once we make the directory we'll proceed the copying. - if (!$this->isDirectory($destination)) { - $this->makeDirectory($destination, 0777, true); - } - - $items = new FilesystemIterator($directory, $options); - - foreach ($items as $item) { - // As we spin through items, we will check to see if the current file is actually - // a directory or a file. When it is actually a directory we will need to call - // back into this function recursively to keep copying these nested folders. - $target = $destination . '/' . $item->getBasename(); - - if ($item->isDir()) { - $path = $item->getPathname(); - - if (!$this->copyDirectory($path, $target, $options)) { - return false; - } - } else { - // If the current items is just a regular file, we will just copy this to the new - // location and keep looping. If for some reason the copy fails we'll bail out - // and return false, so the developer is aware that the copy process failed. - if (!$this->copy($item->getPathname(), $target)) { - return false; - } - } - } - - return true; - } - - /** - * Recursively delete a directory. - * - * The directory itself may be optionally preserved. - * - * @param string $directory - * @param bool $preserve - * @return bool - */ - public function deleteDirectory(string $directory, bool $preserve = false): bool - { - if (!$this->isDirectory($directory)) { - return false; - } - - $items = new FilesystemIterator($directory); - - foreach ($items as $item) { - // If the item is a directory, we can just recurse into the function and - // delete that sub-directory otherwise we'll just delete the file and - // keep iterating through each file until the directory is cleaned. - if ($item->isDir() && !$item->isLink()) { - $this->deleteDirectory($item->getPathname()); - } else { - // If the item is just a file, we can go ahead and delete it since we're - // just looping through and waxing all of the files in this directory - // and calling directories recursively, so we delete the real path. - $this->delete($item->getPathname()); - } - } - - if (!$preserve) { - @rmdir($directory); - } - - return true; - } - - /** - * Empty the specified directory of all files and folders. - * - * @param string $directory - * @return bool - */ - public function cleanDirectory(string $directory): bool - { - return $this->deleteDirectory($directory, true); - } -} diff --git a/Radiate/Filesystem/FilesystemServiceProvider.php b/Radiate/Filesystem/FilesystemServiceProvider.php deleted file mode 100644 index 9eaf139..0000000 --- a/Radiate/Filesystem/FilesystemServiceProvider.php +++ /dev/null @@ -1,20 +0,0 @@ -app->singleton('files', function () { - return new Filesystem(); - }); - } -} diff --git a/Radiate/Foundation/Application.php b/Radiate/Foundation/Application.php deleted file mode 100644 index 52341a5..0000000 --- a/Radiate/Foundation/Application.php +++ /dev/null @@ -1,345 +0,0 @@ -basePath = $basePath; - } - - $this->registerBaseBindings(); - $this->registerCoreProviders(); - $this->setFacadeRoot(); - } - - /** - * Register the basic bindings into the container. - * - * @return void - */ - protected function registerBaseBindings() - { - static::setInstance($this); - - $this->instance('app', $this); - $this->instance(self::class, $this); - - $this->instance('env', wp_get_environment_type()); - - $this->singleton(ExceptionHandler::class, function ($app) { - return new ExceptionHandler($app); - }); - } - - /** - * Set the facade root - * - * @return void - */ - protected function setFacadeRoot() - { - Facade::setFacadeApplication($this); - } - - /** - * Register the core service providers - * - * @return void - */ - protected function registerCoreProviders() - { - $this->register(AuthServiceProvider::class); - $this->register(EventServiceProvider::class); - $this->register(FilesystemServiceProvider::class); - $this->register(RoutingServiceProvider::class); - $this->register(ViewServiceProvider::class); - - if ($this->runningInConsole()) { - $this->register(ConsoleServiceProvider::class); - } - } - - /** - * Get the app base path - * - * @return string - */ - public function basePath(string $path = null) - { - return $this->basePath . ($path ? DIRECTORY_SEPARATOR . $path : $path); - } - - /** - * Register a service provider - * - * @param string $provider - * @return void - */ - public function register(string $provider) - { - $provider = new $provider($this); - - $provider->register(); - - $this->providers[] = $provider; - } - - /** - * Boot the service providers - * - * @return void - */ - protected function bootProviders() - { - foreach ($this->providers as $provider) { - if (method_exists($provider, 'boot')) { - $provider->boot(); - } - } - } - - /** - * Capture the server request - * - * @return \Radiate\Http\Request - */ - protected function captureRequest() - { - $this->instance('request', $request = Request::capture()); - - return $request; - } - - /** - * Capture the server request - * - * @return void - */ - protected function runRequestThroughStack(Request $request) - { - try { - $response = (new Pipeline()) - ->send($request) - ->through($this->middleware) - ->then(function ($request) { - $this->instance('request', $request); - - return $request; - }); - } catch (Throwable $e) { - $response = $this->renderException($request, $e); - } - - return $response; - } - - /** - * Add a global middleware to the app - * - * @param array $middleware - * @return self - */ - public function middleware(array $middleware) - { - $this->middleware = array_unique(array_merge($this->middleware, $middleware)); - - return $this; - } - - /** - * Add a global middleware to the app - * - * @param array $middleware - * @return self - */ - public function routeMiddleware(array $middleware) - { - $this->routeMiddleware = array_merge($this->routeMiddleware, $middleware); - - return $this; - } - - /** - * Get the route middleware - * - * @return array - */ - public function getRouteMiddleware() - { - return $this->routeMiddleware; - } - - /** - * Boot the application - * - * @return void - */ - public function boot() - { - $request = $this->captureRequest(); - - $this->runRequestThroughStack($request); - - $this->bootProviders(); - } - - /** - * Get the app namespace - * - * @return string - * - * @throws \RuntimeException - */ - public function getNamespace() - { - if ($this->namespace) { - return $this->namespace; - } - - $composer = json_decode($this['files']->get($this->basePath('composer.json')), true); - - if ($composer['autoload'] && $loader = $composer['autoload']['psr-4']) { - foreach ($loader as $namespace => $path) { - if (realpath($this->basePath('app')) === realpath($this->basePath($path))) { - return $this->namespace = $namespace; - } - } - } - - throw new RuntimeException('Unable to detect application namespace.'); - } - - /** - * Determine if the app is running in the console - * - * @return bool - */ - public function runningInConsole() - { - return class_exists('WP_CLI'); - } - - /** - * Render an HTTP exception - * - * @param \Radiate\Http\Request $request - * @param \Throwable $e - * @return string - */ - public function renderException(Request $request, Throwable $e) - { - return $this[ExceptionHandler::class]->render($request, $e); - } - - /** - * Get or check the current application environment. - * - * @param string|array|null $environments - * @return string|bool - */ - public function environment($environments = null) - { - if ($environments) { - return in_array($this['env'], (array) $environments); - } - - return $this['env']; - } - - /** - * Determine if the app is in a local environment - * - * @return bool - */ - public function isLocal() - { - return $this['env'] == 'local'; - } - - /** - * Determine if the app is in a development environment - * - * @return bool - */ - public function isDevelopment() - { - return $this['env'] == 'development'; - } - - /** - * Determine if the app is in a staging environment - * - * @return bool - */ - public function isStaging() - { - return $this['env'] == 'staging'; - } - - /** - * Determine if the app is in a production environment - * - * @return bool - */ - public function isProduction() - { - return $this['env'] == 'production'; - } -} diff --git a/Radiate/Foundation/Console/MakeProvider.php b/Radiate/Foundation/Console/MakeProvider.php deleted file mode 100644 index 054cfec..0000000 --- a/Radiate/Foundation/Console/MakeProvider.php +++ /dev/null @@ -1,51 +0,0 @@ -files = $files; - - parent::__construct($app); - } - - /** - * Execute the console command. - * - * @return void - */ - public function handle() - { - $paths = ServiceProvider::pathsToPublish($this->option('provider'), $this->option('tag')); - - foreach ($paths as $from => $to) { - if ($this->files->copyDirectory($from, $to)) { - $this->status($from, $to, 'Directory'); - } - - if (!$this->files->exists($to) || $this->option('force')) { - $this->files->ensureDirectoryExists(dirname($to)); - - $this->files->copy($from, $to); - - $this->status($from, $to, 'File'); - } - } - - $this->success('Publishing complete.'); - } - - /** - * Write a status message to the console. - * - * @param string $from - * @param string $to - * @param string $type - * @return void - */ - protected function status(string $from, string $to, string $type): void - { - $from = str_replace($this->app->basePath(), '', realpath($from)); - - $to = str_replace($this->app->basePath(), '', realpath($to)); - - $this->line("Copied {$type} [{$from}] to [{$to}]"); - } -} diff --git a/Radiate/Foundation/Console/stubs/provider.stub b/Radiate/Foundation/Console/stubs/provider.stub deleted file mode 100644 index 150d465..0000000 --- a/Radiate/Foundation/Console/stubs/provider.stub +++ /dev/null @@ -1,18 +0,0 @@ -app = $app; - } - - /** - * Render an HTTP exception - * - * @param \Radiate\Http\Request $request - * @param \Throwable $e - * @return string - */ - public function render(Request $request, Throwable $e) - { - // run through the variations of exceptions to be thrown and handle them - // either from the exception itself or within the handler. - // the response should be a string with headers and status set. - if ($e instanceof HttpResponseException) { - return $e->getResponse(); - } - return $e->getMessage(); - } -} diff --git a/Radiate/Foundation/Http/Exceptions/HttpResponseException.php b/Radiate/Foundation/Http/Exceptions/HttpResponseException.php deleted file mode 100644 index 20cfc1d..0000000 --- a/Radiate/Foundation/Http/Exceptions/HttpResponseException.php +++ /dev/null @@ -1,20 +0,0 @@ -getCode(), $message = $this->getMessage()); - - return $message; - } -} diff --git a/Radiate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php b/Radiate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php deleted file mode 100644 index fcba96b..0000000 --- a/Radiate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php +++ /dev/null @@ -1,36 +0,0 @@ -transform($request)); - } - - /** - * Trim whitespace from the request strings - * - * @param \Radiate\Http\Request $request - * @return \Radiate\Http\Request - */ - protected function transform(Request $request) - { - foreach ($request->all() as $key => $value) { - $request[$key] = $value === '' ? null : $value; - } - - return $request; - } -} diff --git a/Radiate/Foundation/Http/Middleware/TrimStrings.php b/Radiate/Foundation/Http/Middleware/TrimStrings.php deleted file mode 100644 index 192aaa9..0000000 --- a/Radiate/Foundation/Http/Middleware/TrimStrings.php +++ /dev/null @@ -1,36 +0,0 @@ -transform($request)); - } - - /** - * Trim whitespace from the request strings - * - * @param \Radiate\Http\Request $request - * @return \Radiate\Http\Request - */ - protected function transform(Request $request) - { - foreach ($request->all() as $key => $value) { - $request[$key] = is_string($value) ? trim($value) : $value; - } - - return $request; - } -} diff --git a/Radiate/Foundation/Providers/ConsoleServiceProvider.php b/Radiate/Foundation/Providers/ConsoleServiceProvider.php deleted file mode 100644 index a39274b..0000000 --- a/Radiate/Foundation/Providers/ConsoleServiceProvider.php +++ /dev/null @@ -1,21 +0,0 @@ -commands([ - \Radiate\Foundation\Console\MakeProvider::class, - \Radiate\Foundation\Console\VendorPublish::class, - ]); - } -} diff --git a/Radiate/Foundation/Providers/EventServiceProvider.php b/Radiate/Foundation/Providers/EventServiceProvider.php deleted file mode 100644 index b5396c7..0000000 --- a/Radiate/Foundation/Providers/EventServiceProvider.php +++ /dev/null @@ -1,41 +0,0 @@ -listen as $event => $listeners) { - foreach (array_unique($listeners) as $listener) { - Event::listen($event, $listener); - } - } - - foreach ($this->subscribe as $subscriber) { - Event::subscribe($subscriber); - } - } -} diff --git a/Radiate/Foundation/Providers/RouteServiceProvider.php b/Radiate/Foundation/Providers/RouteServiceProvider.php deleted file mode 100644 index 196baff..0000000 --- a/Radiate/Foundation/Providers/RouteServiceProvider.php +++ /dev/null @@ -1,30 +0,0 @@ -map(); - - $this->app['router']->dispatch($this->app['request']); - } -} diff --git a/Radiate/Http/Request.php b/Radiate/Http/Request.php deleted file mode 100644 index 0c7ee91..0000000 --- a/Radiate/Http/Request.php +++ /dev/null @@ -1,407 +0,0 @@ -request = $request; - $this->cookies = $cookies; - $this->files = $files; - $this->server = $server; - $this->headers = $this->getHeaders($server); - } - - /** - * Capture the global request - * - * @return \Radiate\Http\Request - */ - public static function capture() - { - return new static($_REQUEST, $_COOKIE, $_FILES, $_SERVER); - } - - /** - * Get the headers from the server global - * - * @param array $server - * @return array - */ - protected function getHeaders(array $server): array - { - $headers = []; - - foreach ($server as $key => $value) { - if (strpos($key, 'HTTP_') === 0) { - $headers[substr($key, 5)] = $value; - } elseif (in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH', 'CONTENT_MD5'])) { - $headers[$key] = $value; - } - } - - return $headers; - } - - /** - * Get a server attribute - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function server(string $key, $default = null) - { - return $this->server[$key] ?? $default; - } - - /** - * Get a header - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function header(string $key, $default = null) - { - return $this->headers[$key] ?? $default; - } - - /** - * Determine if the method matches the given method - * - * @return bool - */ - public function isMethod(string $method): bool - { - return strtoupper($method) == $this->method(); - } - - /** - * Get the intended method - * - * @return string - */ - public function method() - { - return strtoupper($this->get('_method', $this->realMethod())); - } - - /** - * Get the real request method - * - * @return string - */ - public function realMethod() - { - return strtoupper($this->server('REQUEST_METHOD', 'GET')); - } - - /** - * Merge the attributes into the request - * - * @param array $attributes - * @return self - */ - public function merge(array $attributes) - { - $this->request = array_merge($this->request, $attributes); - - return $this; - } - - /** - * Determine if the request was made with AJAX - * - * @return bool - */ - public function ajax() - { - return $this->header('X_REQUESTED_WITH') == 'XMLHttpRequest'; - } - - /** - * Determine if the request can accept a JSON response - * - * @return bool - */ - public function wantsJson() - { - return strpos($this->header('ACCEPT', '*/*'), '/json') !== false; - } - - /** - * Determine if the request expects a JSON response - * - * @return bool - */ - public function expectsJson() - { - return $this->ajax() || $this->wantsJson(); - } - - /** - * Determine if the attribute exists - * - * @param string $key - * @return bool - */ - public function has(string $key) - { - return isset($this->request[$key]); - } - - /** - * Get an attribute or fallback - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function get(string $key, $default = null) - { - return $this->request[$key] ?? $default; - } - - /** - * Add an attribute to the request - * - * @param string $key - * @param mixed $value - * @return void - */ - public function add(string $key, $value) - { - $this->request[$key] = $value; - } - - /** - * Remove the attribute from the request - * - * @param string $key - * @return void - */ - public function remove(string $key) - { - unset($this->request[$key]); - } - - /** - * Get the request user - * - * @return mixed - */ - public function user() - { - return call_user_func($this->getUserResolver()); - } - - /** - * Set the user resolver - * - * @param \Closure $resolver - * @return self - */ - public function setUserResolver(Closure $resolver) - { - $this->userResolver = $resolver; - - return $this; - } - - /** - * Get the user resolver - * - * @return \Closure - */ - public function getUserResolver() - { - return $this->userResolver ?: function () { - // - }; - } - - /** - * Determine if an instance exists - * - * @param string $key - * @return bool - */ - public function offsetExists($key) - { - return $this->has($key); - } - - /** - * Get an instance - * - * @param string $key - * @return mixed - */ - public function offsetGet($key) - { - return $this->get($key); - } - - /** - * Set an instance - * - * @param string $key - * @param mixed $value - * @return void - */ - public function offsetSet($key, $value) - { - $this->add($key, $value); - } - - /** - * Unset any instances or bindings - * - * @param string $key - * @return void - */ - public function offsetUnset($key) - { - $this->remove($key); - } - - /** - * Return the object as an array - * - * @return array - */ - public function all(): array - { - return $this->toArray(); - } - - /** - * Return the object as an array - * - * @return array - */ - public function toArray(): array - { - return $this->request; - } - - /** - * Return the object as a json string - * - * @return string - */ - public function toJson(): string - { - return json_encode($this->request); - } - - /** - * Return the request to be encoded as json - * - * @return array - */ - public function jsonSerialize(): array - { - return $this->request; - } - - /** - * Return the request as a json string - * - * @return string - */ - public function __toString(): string - { - return $this->toJson(); - } - - /** - * Determine if the attribute exists - * - * @param string $key - * @return bool - */ - public function __isset(string $key) - { - return $this->has($key); - } - - /** - * Get an attribute or fallback - * - * @param string $key - * @return mixed - */ - public function __get(string $key) - { - return $this->get($key); - } - - /** - * Add an attribute to the request - * - * @param string $key - * @param mixed $value - * @return void - */ - public function __set(string $key, $value) - { - $this->add($key, $value); - } -} diff --git a/Radiate/Mail/Console/MakeMail.php b/Radiate/Mail/Console/MakeMail.php deleted file mode 100644 index 02cb3cb..0000000 --- a/Radiate/Mail/Console/MakeMail.php +++ /dev/null @@ -1,51 +0,0 @@ -markdown('emails.message'); - } -} diff --git a/Radiate/Mail/MailServiceProvider.php b/Radiate/Mail/MailServiceProvider.php deleted file mode 100644 index ed8377b..0000000 --- a/Radiate/Mail/MailServiceProvider.php +++ /dev/null @@ -1,36 +0,0 @@ -app->singleton('mailer', function ($app) { - return new Mailer($app['events']); - }); - } - - /** - * Boot the service provider - * - * @return void - */ - public function boot(): void - { - $this->commands([ - \Radiate\Mail\Console\MakeMail::class, - ]); - - $this->publishes([ - __DIR__ . '/resources/views' => $this->app->basePath('views/vendor/mail'), - ], 'mail'); - } -} diff --git a/Radiate/Mail/Mailable.php b/Radiate/Mail/Mailable.php deleted file mode 100644 index c1c3171..0000000 --- a/Radiate/Mail/Mailable.php +++ /dev/null @@ -1,424 +0,0 @@ -setAddress($address, $name, 'to'); - } - - /** - * Set a carbon copy address - * - * @param mixed $address - * @param string|null $name - * @return self - */ - public function cc($address, ?string $name = null): self - { - return $this->setAddress($address, $name, 'cc'); - } - - /** - * Set a blind carbon copy address - * - * @param mixed $address - * @param string|null $name - * @return self - */ - public function bcc($address, ?string $name = null): self - { - return $this->setAddress($address, $name, 'bcc'); - } - - /** - * Set a from address - * - * @param mixed $address - * @param string|null $name - * @return self - */ - public function from($address, ?string $name = null): self - { - return $this->setAddress($address, $name, 'from'); - } - - /** - * Set a reply-to address - * - * @param mixed $address - * @param string|null $name - * @return self - */ - public function replyTo($address, ?string $name = null): self - { - return $this->setAddress($address, $name, 'replyTo'); - } - - /** - * Unset the recipients - * - * @return self - */ - public function unsetRecipients(): self - { - foreach (['to', 'cc', 'bcc'] as $property) { - $this->{$property} = []; - } - return $this; - } - - /** - * Set the subject - * - * @param string $subject - * @return self - */ - public function subject(string $subject): self - { - $this->subject = $subject; - - return $this; - } - - /** - * Attach a file - * - * @param string $filepath - * @return self - */ - public function attach(string $filepath): self - { - $this->attachments[] = $filepath; - - return $this; - } - - /** - * Set the plain text body - * - * @param string $path - * @param array $data - * @return self - */ - public function text(string $path, array $data = []): self - { - $this->text = View::make($path, $this->buildViewData($data)); - - return $this; - } - - /** - * Set the HTML body - * - * @param string $path - * @param array $data - * @return self - */ - public function view(string $path, array $data = []): self - { - $this->html = View::make($path, $this->buildViewData($data)); - - return $this; - } - - /** - * Parse a markdown file and set the HTML and plain text bodies - * - * @param string $path - * @param array $data - * @return self - */ - public function markdown(string $path, array $data = []): self - { - $this->text($path, $data); - - $this->html = Str::markdown($this->text); - - return $this; - } - - /** - * Merge the data passed to the view with the instance public properties. - * - * @param array $data - * @return array - */ - protected function buildViewData(array $data): array - { - $properties = []; - - foreach ((new ReflectionClass($this))->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { - if ($property->getDeclaringClass()->getName() !== self::class) { - $properties[$property->getName()] = $property->getValue($this); - } - } - return array_merge($properties, $data); - } - - /** - * Set an address on the specified property - * - * @param mixed $address - * @param string|null $name - * @param string $property - * @return self - */ - protected function setAddress($address, ?string $name = null, string $property = 'to'): self - { - foreach ($this->addressesToArray($address, $name) as $recipient) { - $recipient = $this->normalizeRecipient($recipient); - - $this->{$property}[] = [ - 'name' => $recipient->name ?? null, - 'address' => $recipient->address, - ]; - } - - return $this; - } - - /** - * Transform the addresses into a useable format - * - * @param mixed $address - * @param string|null $name - * @return array - */ - protected function addressesToArray($address, ?string $name): array - { - if (!is_array($address)) { - $address = is_string($name) ? [['name' => $name, 'address' => $address]] : [$address]; - } - - return $address; - } - - /** - * Normalise a recipient - * - * @param mixed $recipient - * @return object - */ - protected function normalizeRecipient($recipient): object - { - if ($recipient instanceof WP_User) { - return (object) [ - 'address' => $recipient->user_email, - 'name' => $recipient->display_name ?? '', - ]; - } - if (is_array($recipient)) { - return (object) $recipient; - } elseif (is_string($recipient)) { - return (object) ['address' => $recipient]; - } - - return $recipient; - } - - /** - * Format an email address and optional name - * - * @param array $recipient - * @return string - */ - protected function format(array $recipient): string - { - return trim("{$recipient['name']} <{$recipient['address']}>"); - } - - /** - * Return an array of emails to send to - * - * @return array - */ - public function buildTo(): array - { - return array_unique(array_map(function (array $to) { - return $this->format($to); - }, $this->to)); - } - - /** - * Return the email subject or mailable classname - * - * @return string - */ - public function buildSubject(): string - { - if ($this->subject) { - return $this->subject; - } - return end(explode('\\', get_class($this))); - } - - /** - * Return a HTML message - * - * @return string - */ - public function buildHtml(): string - { - return $this->html ?? $this->text; - } - - /** - * Determine if there is HTML set - * - * @return bool - */ - public function hasHtml(): bool - { - return (bool) $this->html; - } - - /** - * Return a plain text message - * - * @return string - */ - public function buildText(): string - { - return $this->text ?? ''; - } - - /** - * Return an array of headers - * - * @return array - */ - public function buildHeaders(): array - { - $headers = []; - - if (!empty($this->from)) { - $headers[] = "From: {$this->format($this->from[0])}"; - } - foreach (['cc' => 'Cc', 'bcc' => 'Bcc', 'replyTo' => 'Reply-To'] as $type => $header) { - foreach ($this->{$type} as $recipient) { - $headers[] = "{$header}: {$this->format($recipient)}"; - } - } - - return array_unique($headers); - } - - /** - * Return an array of attachments - * - * @return array - */ - public function buildAttachments(): array - { - return $this->attachments; - } - - /** - * Build the email - * - * @return \Radiate\Mail\Mailable - */ - public function build(): self - { - return $this; - } - - /** - * Render the email - * - * @return string - */ - public function render(): string - { - return $this->build()->buildHtml(); - } - - /** - * Return the email render - * - * @return string - */ - public function __toString(): string - { - return $this->render(); - } -} diff --git a/Radiate/Mail/Mailer.php b/Radiate/Mail/Mailer.php deleted file mode 100644 index d2508e9..0000000 --- a/Radiate/Mail/Mailer.php +++ /dev/null @@ -1,170 +0,0 @@ -events = $events; - } - - /** - * Set the global from address and name. - * - * @param string $address - * @param string|null $name - * @return void - */ - public function alwaysFrom(string $address, ?string $name = null): void - { - $this->from = compact('address', 'name'); - } - - /** - * Set the global reply-to address and name. - * - * @param string $address - * @param string|null $name - * @return void - */ - public function alwaysReplyTo(string $address, ?string $name = null): void - { - $this->replyTo = compact('address', 'name'); - } - - /** - * Set the global to address and name. - * - * @param string $address - * @param string|null $name - * @return void - */ - public function alwaysTo(string $address, ?string $name = null): void - { - $this->to = compact('address', 'name'); - } - - /** - * Begin the process of mailing a mailable class instance. - * - * @param mixed $users - * @return \Radiate\Mail\PendingMail - */ - public function to($users): PendingMail - { - return (new PendingMail($this))->to($users); - } - - /** - * Begin the process of mailing a mailable class instance. - * - * @param mixed $users - * @return \Radiate\Mail\PendingMail - */ - public function cc($users): PendingMail - { - return (new PendingMail($this))->cc($users); - } - - /** - * Begin the process of mailing a mailable class instance. - * - * @param mixed $users - * @return \Radiate\Mail\PendingMail - */ - public function bcc($users): PendingMail - { - return (new PendingMail($this))->bcc($users); - } - - /** - * Render the given message as a view. - * - * @param \Radiate\Mail\Mailable $mailable - * @return string - */ - public function render(Mailable $mailable): string - { - return $mailable->render(); - } - - /** - * Send the mail - * - * @param \Radiate\Mail\Mailable $mailable - * @return void - */ - public function send(Mailable $mailable): void - { - $mailable->build(); - - $this->events->listen('phpmailer_init', function (PHPMailer $phpMailer) use ($mailable) { - if ($mailable->hasHtml()) { - $phpMailer->AltBody = $mailable->buildText(); - } - - $phpMailer->CharSet = 'UTF-8'; - $phpMailer->Encoding = 'base64'; - }); - - $this->events->listen('wp_loaded', function () use ($mailable) { - return wp_mail( - $mailable->buildTo(), - $mailable->buildSubject(), - $mailable->buildHtml(), - $mailable->buildHeaders(), - $mailable->buildAttachments() - ); - }); - } - - /** - * Set the global "to" address on the given message. - * - * @param \Radiate\Mail\PendingMail $mailable - * @return void - */ - protected function setGlobalToAndRemoveCcAndBcc(Mailable $mailable): void - { - $mailable->unsetRecipients() - ->to($this->to['address'], $this->to['name']); - } -} diff --git a/Radiate/Mail/PendingMail.php b/Radiate/Mail/PendingMail.php deleted file mode 100644 index 9dec031..0000000 --- a/Radiate/Mail/PendingMail.php +++ /dev/null @@ -1,105 +0,0 @@ -mailer = $mailer; - } - - /** - * Set the recipients of the message. - * - * @param mixed $users - * @return self - */ - public function to($users): self - { - $this->to = $users; - - return $this; - } - - /** - * Set the recipients of the message. - * - * @param mixed $users - * @return self - */ - public function cc($users): self - { - $this->cc = $users; - - return $this; - } - - /** - * Set the recipients of the message. - * - * @param mixed $users - * @return self - */ - public function bcc($users): self - { - $this->bcc = $users; - - return $this; - } - - /** - * Send a new mailable message instance. - * - * @param \Radiate\Mail\Mailable $mailable - * @return void - */ - public function send(Mailable $mailable) - { - return $this->mailer->send($this->fill($mailable)); - } - - /** - * Populate the mailable with the addresses. - * - * @param \Radiate\Mail\Mailable $mailable - * @return \Radiate\Mail\Mailable - */ - protected function fill(Mailable $mailable): Mailable - { - return $mailable->to($this->to)->cc($this->cc)->bcc($this->bcc); - } -} diff --git a/Radiate/Mail/resources/views/message.php b/Radiate/Mail/resources/views/message.php deleted file mode 100644 index d8676e9..0000000 --- a/Radiate/Mail/resources/views/message.php +++ /dev/null @@ -1,10 +0,0 @@ -# Introduction - ---- - -The body of your message. - ---- - -Thanks,
-uri(); - - $this->router->listen( - ['wp_ajax_' . $uri, 'wp_ajax_nopriv_' . $uri], - $this->handle($request) - ); - } - - /** - * Dispatch the route - * - * @param \Radiate\Http\Request $request - * @return void - */ - public function handle(Request $request) - { - return function () use ($request) { - die($this->runRequestThroughStack($request)); - }; - } -} diff --git a/Radiate/Routing/Console/MakeController.php b/Radiate/Routing/Console/MakeController.php deleted file mode 100644 index c923566..0000000 --- a/Radiate/Routing/Console/MakeController.php +++ /dev/null @@ -1,56 +0,0 @@ -option('resource')) { - return __DIR__ . '/stubs/controller.resource.stub'; - } - - return __DIR__ . '/stubs/controller.stub'; - } - - /** - * Get the default namespace for the class. - * - * @param string $rootNamespace - * @return string - */ - protected function getDefaultNamespace(string $rootNamespace) - { - return $rootNamespace . '\\Http\\Controllers'; - } -} diff --git a/Radiate/Routing/Console/MakeMiddleware.php b/Radiate/Routing/Console/MakeMiddleware.php deleted file mode 100644 index 2055fda..0000000 --- a/Radiate/Routing/Console/MakeMiddleware.php +++ /dev/null @@ -1,51 +0,0 @@ -router->listen('rest_api_init', function () use ($request) { - register_rest_route($this->namespace(), $this->parseUri($this->uri()), [ - 'methods' => $this->methods(), - 'callback' => $this->handle($request), - 'permission_callback' => '__return_true', - ]); - }); - } - - /** - * Dispatch the route - * - * @param \Radiate\Http\Request $request - * @return void - */ - public function handle(Request $request) - { - return function (WP_REST_Request $wpRequest) use ($request) { - die($this->runRequestThroughStack( - $request->merge($parameters = $wpRequest->get_url_params()), - array_values($parameters) - )); - }; - } - - /** - * Parse the uri into a WordPress compatible format. - * - * @param string $uri - * @return string - */ - protected function parseUri(string $uri): string - { - return preg_replace('@\/\{([\w]+?)(\?)?\}@', '\/?(?P<$1>[\w-]+)$2', $uri); - } -} diff --git a/Radiate/Routing/Route.php b/Radiate/Routing/Route.php deleted file mode 100644 index c02c1e5..0000000 --- a/Radiate/Routing/Route.php +++ /dev/null @@ -1,210 +0,0 @@ -methods = (array) $methods; - $this->uri = $uri; - $this->action = $action; - } - - /** - * Get the URI - * - * @return string - */ - public function uri() - { - return $this->prefix($this->uri); - } - - /** - * Get the route action - * - * @return mixed - */ - public function action() - { - if (is_callable($this->action)) { - return $this->action; - } - if (is_string($this->action) && class_exists($this->action)) { - return [new $this->action, '__invoke']; - } - } - - /** - * Return the route methods - * - * @return array - */ - public function methods() - { - return $this->methods; - } - - /** - * Get the route middleware - * - * @return array - */ - public function middleware() - { - return $this->attributes['middleware'] ?? []; - } - - /** - * Get the route prefix - * - * @param string $path - * @param string $sep - * @return string - */ - public function prefix(string $path = '') - { - return trim($this->attributes['prefix'] . ($path ? '/' . $path : $path), '/'); - } - - /** - * Get the route namespace - * - * @return string - */ - public function namespace() - { - return $this->attributes['namespace'] ?? 'api'; - } - - /** - * Set the group attributes - * - * @param array $attributes - * @return void - */ - public function setGroupAttributes(array $attributes) - { - $this->attributes = $attributes; - } - - /** - * Set the router - * - * @param Radiate\Routing\Router $router - * @return self - */ - public function setRouter(Router $router) - { - $this->router = $router; - - return $this; - } - - /** - * Set the container - * - * @param \Radiate\Routing\Application $app - * @return self - */ - public function setContainer(Application $app) - { - $this->app = $app; - - return $this; - } - - /** - * Handle the controller action - * - * @param \Radiate\Http\Request $request - * @param array $parameters - * @return mixed - */ - protected function runRequestThroughStack(Request $request, array $parameters = []) - { - try { - $response = (new Pipeline()) - ->send($request) - ->through($this->middleware()) - ->then(function ($request) use ($parameters) { - return call_user_func($this->action(), $request, ...$parameters); - }); - } catch (Throwable $e) { - $response = $this->app->renderException($request, $e); - } - - return $response; - } - - /** - * Dispatch the request to the route - * - * @param \Radiate\Http\Request $request - * @return void - */ - abstract public function dispatch(Request $request); - - /** - * Handle the route - * - * @param \Radiate\Http\Request $request - * @return void - */ - abstract public function handle(Request $request); -} diff --git a/Radiate/Routing/Router.php b/Radiate/Routing/Router.php deleted file mode 100644 index 0ea00b0..0000000 --- a/Radiate/Routing/Router.php +++ /dev/null @@ -1,384 +0,0 @@ -events = $events; - $this->app = $app; - } - - /** - * Create an ajax route - * - * @param string $uri - * @param mixed $action - * @return \Radiate\Routing\Route - */ - public function ajax(string $uri, $action) - { - return $this->addRoute(new AjaxRoute('AJAX', $uri, $action)); - } - - /** - * Create a GET route - * - * @param string $uri - * @param mixed $action - * @return \Radiate\Routing\Route - */ - public function get(string $uri, $action) - { - return $this->addRoute(new RestRoute(['GET', 'HEAD'], $uri, $action)); - } - - /** - * Create a POST route - * - * @param string $uri - * @param mixed $action - * @return \Radiate\Routing\Route - */ - public function post(string $uri, $action) - { - return $this->addRoute(new RestRoute('POST', $uri, $action)); - } - - /** - * Create a PUT route - * - * @param string $uri - * @param mixed $action - * @return \Radiate\Routing\Route - */ - public function put(string $uri, $action) - { - return $this->addRoute(new RestRoute('PUT', $uri, $action)); - } - - /** - * Create a PATCH route - * - * @param string $uri - * @param mixed $action - * @return \Radiate\Routing\Route - */ - public function patch(string $uri, $action) - { - return $this->addRoute(new RestRoute('PATCH', $uri, $action)); - } - - /** - * Create a DELETE route - * - * @param string $uri - * @param mixed $action - * @return \Radiate\Routing\Route - */ - public function delete(string $uri, $action) - { - return $this->addRoute(new RestRoute('DELETE', $uri, $action)); - } - - /** - * Create a route with any method - * - * @param string $uri - * @param mixed $action - * @return \Radiate\Routing\Route - */ - public function any(string $uri, $action) - { - return $this->addRoute(new RestRoute(['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], $uri, $action)); - } - - /** - * Create a route matching the given methods - * - * @param array $methods - * @param string $uri - * @param mixed $action - * @return \Radiate\Routing\Route - */ - public function matches(array $methods, string $uri, $action) - { - if (in_array('GET', $methods) && !in_array('HEAD', $methods)) { - $methods[] = 'HEAD'; - } - - return $this->addRoute(new RestRoute($methods, $uri, $action)); - } - - /** - * Create resource routes - * - * @param string $uri - * @param string $action - * @param array $methods - * @return void - */ - public function resource(string $uri, string $action, array $methods = ['index', 'show', 'store', 'update', 'destroy']) - { - $this->prefix($uri)->group(function () use ($action, $methods) { - if (in_array('index', $methods)) { - $this->get('/', [$action, 'index']); - } - if (in_array('show', $methods)) { - $this->get('{id}', [$action, 'show']); - } - if (in_array('store', $methods)) { - $this->post('/', [$action, 'store']); - } - if (in_array('update', $methods)) { - $this->matches(['PUT', 'PATCH'], '{id}', [$action, 'update']); - } - if (in_array('destroy', $methods)) { - $this->delete('{id}', [$action, 'destroy']); - } - }); - } - - /** - * Regsiter the route in the router - * - * @param \Radiate\Routing\Route $route - * @return \Radiate\Routing\Route - */ - public function addRoute(Route $route) - { - $this->routes[] = $route; - - if ($this->hasGroupStack()) { - $this->mergeGroupAttributesIntoRoute($route); - } - - return $route; - } - - /** - * Determine if the router currently has a group stack. - * - * @return bool - */ - public function hasGroupStack() - { - return !empty($this->groupStack); - } - - /** - * Merge the group stack with the controller action. - * - * @param \Radiate\Routing\Route $route - * @return void - */ - protected function mergeGroupAttributesIntoRoute($route) - { - $route->setGroupAttributes($this->getMergedGroupStack()); - } - - /** - * Return the merged group stack - * - * @return array - */ - public function getMergedGroupStack() - { - return [ - 'middleware' => $this->getMiddleware(), - 'prefix' => $this->getPrefix(), - 'namespace' => $this->getNamespace(), - ]; - } - - /** - * Set a group middleware - * - * @param string|array $middleware - * @return self - */ - public function middleware($middleware) - { - $this->currentGroup['middleware'] = (array) $middleware; - - return $this; - } - - /** - * Get the group middleware - * - * @return array - */ - public function getMiddleware() - { - $routeMiddleware = $this->app->getRouteMiddleware(); - - $middleware = []; - - foreach (array_column($this->groupStack, 'middleware') as $aliases) { - foreach ($aliases as $alias) { - if ($wares = $routeMiddleware[$alias]) { - foreach ((array) $wares as $ware) { - $middleware[] = $ware ?? null; - } - } - } - }; - - return array_unique($middleware); - } - - /** - * Set the group prefix - * - * @param string $prefix - * @return self - */ - public function prefix(string $prefix) - { - $this->currentGroup['prefix'] = trim($prefix, '/'); - - return $this; - } - - /** - * Get the group prefix - * - * @return string - */ - public function getPrefix() - { - return implode('/', array_column($this->groupStack, 'prefix')); - } - - /** - * Set the group namespace - * - * @param string $namespace - * @return self - */ - public function namespace(string $namespace) - { - $this->currentGroup['namespace'] = trim($namespace, '/'); - - return $this; - } - - /** - * Get the group namespace - * - * @return string - */ - public function getNamespace() - { - return implode('/', array_column($this->groupStack, 'namespace')); - } - - /** - * Define a group in the router - * - * @param \Closure|string $callback - * @return void - */ - public function group($routes) - { - $this->groupStack[] = $this->currentGroup; - $this->currentGroup = []; - - $this->loadRoutes($routes); - - array_pop($this->groupStack); - } - - /** - * Load the provided routes. - * - * @param \Closure|string $routes - * @return void - */ - protected function loadRoutes($routes) - { - if ($routes instanceof Closure) { - $routes($this); - } else { - $router = $this; - - require $routes; - } - } - - /** - * Dispatch the request to the routes - * - * @param \Radiate\Http\Request $request - * @return void - */ - public function dispatch(Request $request) - { - foreach ($this->routes as $route) { - $route->setRouter($this) - ->setContainer($this->app) - ->dispatch($request); - } - } - - /** - * Listen to an event - * - * @param string|string[] $events - * @param mixed $callback - * @return void - */ - public function listen($events, $callback) - { - $this->events->listen($events, $callback); - } -} diff --git a/Radiate/Routing/RoutingServiceProvider.php b/Radiate/Routing/RoutingServiceProvider.php deleted file mode 100644 index 804eba5..0000000 --- a/Radiate/Routing/RoutingServiceProvider.php +++ /dev/null @@ -1,33 +0,0 @@ -app->singleton('router', function ($app) { - return new Router($app['events'], $app); - }); - } - - /** - * Boot the provider - * - * @return void - */ - public function boot() - { - $this->commands([ - \Radiate\Routing\Console\MakeController::class, - \Radiate\Routing\Console\MakeMiddleware::class, - ]); - } -} diff --git a/Radiate/Support/Collection.php b/Radiate/Support/Collection.php deleted file mode 100644 index 5a10a85..0000000 --- a/Radiate/Support/Collection.php +++ /dev/null @@ -1,792 +0,0 @@ -items = $items; - } - - /** - * Create a collection instance - * - * @param array $items - * @return static - */ - public static function collect(array $items) - { - return new static($items); - } - - /** - * Add an item to the collection. - * - * @param mixed $item - * @return static - */ - public function add($item) - { - $this->items[] = $item; - - return $this; - } - - /** - * Get the collection items - * - * @return array - */ - public function all(): array - { - return $this->items; - } - - /** - * Split a collection into chunks - * - * @param int $size - * @return static - */ - public function chunk(int $size) - { - $results = new static(array_chunk($this->items, $size, true)); - - return $results->map(function ($chunk) { - return new static($chunk); - }); - } - - /** - * Create a collection by using this collection for keys and another for its - * values - * - * @param mixed $values - * @return static - */ - public function combine($values) - { - return new static( - array_combine($this->items, $this->getArrayableItems($values)) - ); - } - - /** - * Get the items in the collection that are not present in the given items - * - * @param mixed $items - * @return static - */ - public function diff($items) - { - return new static( - array_diff($this->items, $this->getArrayableItems($items)) - ); - } - - /** - * Execute a callback over each item - * - * @param callable $callback - * @return static - */ - public function each(callable $callback) - { - foreach ($this->items as $key => $item) { - if ($callback($item, $key) === false) { - break; - } - } - - return $this; - } - - /** - * Get all items except for those with the specified keys. - * - * @param string,... $keys - * @return static - */ - public function except(string ...$keys) - { - $new = clone $this; - - foreach ($keys as $key) { - $new->forget($key); - } - - return $new; - } - - /** - * Iterates over each item in the collection passing them to the callback - * function - * - * @param callable|null $callback - * @return static - */ - public function filter(?callable $callback = null) - { - return new static( - array_filter($this->items, $callback, ARRAY_FILTER_USE_BOTH) - ); - } - - /** - * Gets the first item of the collection - * - * @return mixed - */ - public function first() - { - return $this->items[$this->firstKey()]; - } - - /** - * Gets the first key of the collection - * - * @return string|int|null - */ - public function firstKey() - { - return array_key_first($this->items); - } - - /** - * Flatten a multi-dimensional array into a single level - * - * @return static - */ - public function flatten() - { - $new = clone $this; - - $results = []; - - array_walk_recursive($new->items, function ($value) use (&$results) { - $results[] = $value; - }); - - return new static($results); - } - - /** - * Exchanges all keys with their associated values in a collection - * - * @return static - */ - public function flip() - { - return new static(array_flip($this->items)); - } - - /** - * Unset an item in the collection - * - * @param string $key - * @return static - */ - public function forget(string $key) - { - unset($this->items[$key]); - - return $this; - } - - /** - * Get an item from the collection - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function get(string $key, $default) - { - return $this->items[$key] ?? $default; - } - - /** - * Determine if an item in the collection exists - * - * @param string $key - * @return bool - */ - public function has(string $key): bool - { - return isset($this->items[$key]); - } - - /** - * Determine if the given key or index exists in the collection - * - * @param string $key - * @return bool - */ - public function hasKey(string $key): bool - { - return array_key_exists($key, $this->items); - } - - /** - * Intersect the collection with the given items - * - * @param mixed $items - * @return static - */ - public function intersect($items) - { - return new static( - array_intersect($this->items, $this->getArrayableItems($items)) - ); - } - - /** - * Computes the intersection of the collection using keys for comparison - * - * @param mixed $items - * @return static - */ - public function intersectByKeys($items) - { - return new static( - array_intersect_key($this->items, $this->getArrayableItems($items)) - ); - } - - /** - * Determine if the collection is empty or not - * - * @return bool - */ - public function isEmpty(): bool - { - return empty($this->items); - } - - /** - * Determine if the collection is empty or not - * - * @return bool - */ - public function isNotEmpty(): bool - { - return !empty($this->items); - } - - /** - * Join all items from the collection using a string. - * - * @param string $glue - * @return string - */ - public function join(string $glue): string - { - return implode($glue, $this->items); - } - - /** - * Get the keys from the collection - * - * @return static - */ - public function keys() - { - return new static(array_keys($this->items)); - } - - /** - * Gets the last item of the collection - * - * @return mixed - */ - public function last() - { - return $this->items[$this->lastKey()]; - } - - /** - * Gets the last key of the collection - * - * @return string|int|null - */ - public function lastKey() - { - return array_key_last($this->items); - } - - /** - * Applies the callback to the elements of the collection - * - * @param callable $callback - * @return static - */ - public function map(callable $callback) - { - $items = array_map($callback, $this->items, $keys = array_keys($this->items)); - - return new static(array_combine($keys, $items)); - } - - /** - * Merge the collection with the given items - * - * @param mixed $array - * @return static - */ - public function merge($array) - { - return new static( - array_merge($this->items, $this->getArrayableItems($array)) - ); - } - - /** - * Recursively merge the collection with the given items - * - * @param mixed $array - * @return static - */ - public function mergeRecursive($array) - { - return new static( - array_merge_recursive($this->items, $this->getArrayableItems($array)) - ); - } - - /** - * Get the items with the specified keys - * - * @param string,... $keys - * @return static - */ - public function only(string ...$keys) - { - return new static($this->intersectByKeys(array_flip($keys))->all()); - } - - /** - * Pass the collection to the given callback and return the result - * - * @param callable $callback - * @return mixed - */ - public function pipe(callable $callback) - { - return $callback($this); - } - - /** - * Get and remove the last item from the collection - * - * @return mixed - */ - public function pop() - { - return array_pop($this->items); - } - - /** - * Push an item onto the beginning of the collection - * - * @param mixed $value - * @param string|int|null $key - * @return static - */ - public function prepend($value, $key = null) - { - if ($key) { - $this->items = [$key => $value] + $this->items; - } else { - array_unshift($this->items, $value); - } - - return $this; - } - - /** - * Push elements onto the end of the collection - * - * @param mixed,... $values - * @return static - */ - public function push(...$values) - { - foreach ($values as $value) { - $this->items[] = $value; - } - - return $this; - } - - /** - * Push keyed elements onto the end of the collection - * - * @param string $key - * @param mixed $value - * @return static - */ - public function put(string $key, $value) - { - $this->items[$key] = $value; - - return $this; - } - - /** - * Pick one or more random entries out of the collection - * - * @param int $number - * @param bool $preserveKeys - * @return mixed|static - * - * @throws \InvalidArgumentException - */ - public function random(int $number = 1, bool $preserveKeys = false) - { - if ($number == 1) { - return $this->items[array_rand($this->items)]; - } - - if ($number == 0) { - return new static(); - } - - if ($number > $count = $this->count()) { - throw new InvalidArgumentException( - "You requested {$number} items, but there are only {$count} items available." - ); - } - - $results = new static(); - - foreach (array_rand($this->items, $number) as $key) { - if ($preserveKeys) { - $results[$key] = $this->items[$key]; - } else { - $results[] = $this->items[$key]; - } - } - - return $results; - } - - /** - * Reduce the collection to a single value - * - * @param callable $callback - * @param mixed $initial - * @return mixed - */ - public function reduce(callable $callback, $initial = null) - { - return array_reduce($this->items, $callback, $initial); - } - - /** - * Replace the collection items with the given items - * - * @param mixed $items - * @return static - */ - public function replace($items) - { - return new static( - array_replace($this->items, $this->getArrayableItems($items)) - ); - } - - /** - * Recursively replace the collection items with the given items - * - * @param mixed $items - * @return static - */ - public function replaceRecursive($items) - { - return new static( - array_replace_recursive($this->items, $this->getArrayableItems($items)) - ); - } - - /** - * Return a collection with elements in reverse order - * - * @return static - */ - public function reverse() - { - return new static(array_reverse($this->items, true)); - } - - /** - * Searches the collection for a given value and returns the corresponding - * key if successful - * - * @param mixed $value - * @param boolean $strict - * @return int|string|false - */ - public function search($value, bool $strict = false) - { - return array_search($value, $this->items, $strict); - } - - /** - * Shift an element off the beginning of the collection - * - * @return mixed - */ - public function shift() - { - return array_shift($this->items); - } - - /** - * Shuffle the items in the collection - * - * @return static - */ - public function shuffle() - { - $keys = array_keys($this->items); - - $results = new static(); - - shuffle($keys); - - foreach ($keys as $key) { - $results[$key] = $this->items[$key]; - } - - return $results; - } - - /** - * Skip the first x number of items - * - * @param int $count - * @return static - */ - public function skip(int $count) - { - return $this->slice($count); - } - - /** - * Extract a slice of the collection - * - * @param int $offset - * @param int|null $length - * @return static - */ - public function slice(int $offset, ?int $length = null) - { - return new static(array_slice($this->items, $offset, $length, true)); - } - - /** - * Take the first or last x number of items from the collection - * - * @param int $limit - * @return static - */ - public function take(int $limit) - { - return $this->slice($limit < 0 ? $limit : 0, abs($limit)); - } - - /** - * Pass the collection to the given callback and then return it - * - * @param callable $callback - * @return static - */ - public function tap(callable $callback) - { - $callback(clone $this); - - return $this; - } - - /** - * Get the collection of items as an array - * - * @return array - */ - public function toArray(): array - { - return $this->map(function ($value) { - return $value instanceof Collection - ? $value->toArray() - : $value; - })->all(); - } - - /** - * Get the collection of items as JSON - * - * @param int $options - * @return string - */ - public function toJson(int $options = 0): string - { - return json_encode($this->items, $options); - } - - /** - * Return all the values of the collection - * - * @return static - */ - public function values() - { - return new static(array_values($this->items)); - } - - /** - * Return an array of items from Collection or Traversable - * - * @param mixed $items - * @return array - */ - protected function getArrayableItems($items): array - { - if (is_array($items)) { - return $items; - } elseif ($items instanceof Traversable) { - return iterator_to_array($items); - } - - return (array) $items; - } - - /** - * Determine if an item in the collection exists - * - * @param string $key - * @return bool - */ - public function offsetExists($key): bool - { - return isset($this->items[$key]); - } - - /** - * Get an item from the collection - * - * @param string $key - * @return mixed - */ - public function offsetGet($key) - { - return $this->items[$key]; - } - - /** - * Set an item in the collection - * - * @param string|null $key - * @param mixed $value - * @return void - */ - public function offsetSet($key, $value): void - { - if ($key) { - $this->items[$key] = $value; - } else { - $this->items[] = $value; - } - } - - /** - * Unset an item in the collection - * - * @param string $key - * @return void - */ - public function offsetUnset($key): void - { - unset($this->items[$key]); - } - - /** - * Get the collection items count - * - * @return int - */ - public function count(): int - { - return count($this->items); - } - - /** - * Implements \IteratorAggregate - * - * @return \ArrayIterator - */ - public function getIterator(): ArrayIterator - { - return new ArrayIterator($this->items); - } - - /** - * JSON serialise the collection - * - * @return array - */ - public function jsonSerialize(): array - { - return $this->all(); - } - - /** - * Dynamically get an item from the collection - * - * @param string $key - * @return mixed - */ - public function __get(string $key) - { - return $this->items[$key]; - } - - /** - * Dynamically set items in the collection - * - * @param string $key - * @param mixed $value - * @return void - */ - public function __set(string $key, $value): void - { - $this->items[$key] = $value; - } - - /** - * Return the collection as a JSON string - * - * @return string - */ - public function __toString(): string - { - return $this->toJson(); - } -} diff --git a/Radiate/Support/Facades/App.php b/Radiate/Support/Facades/App.php deleted file mode 100644 index 95a6d8e..0000000 --- a/Radiate/Support/Facades/App.php +++ /dev/null @@ -1,41 +0,0 @@ -$method(...$parameters); - - return $arr instanceof Collection ? $arr->toArray() : $arr; - } -} diff --git a/Radiate/Support/Facades/Event.php b/Radiate/Support/Facades/Event.php deleted file mode 100644 index 1ada4e6..0000000 --- a/Radiate/Support/Facades/Event.php +++ /dev/null @@ -1,26 +0,0 @@ -$method(...$parameters); - } -} diff --git a/Radiate/Support/Facades/Route.php b/Radiate/Support/Facades/Route.php deleted file mode 100644 index ef9edcc..0000000 --- a/Radiate/Support/Facades/Route.php +++ /dev/null @@ -1,42 +0,0 @@ -$method(...$parameters); - - return $str instanceof Stringable ? $str->toString() : $str; - } -} diff --git a/Radiate/Support/Facades/View.php b/Radiate/Support/Facades/View.php deleted file mode 100644 index dac6478..0000000 --- a/Radiate/Support/Facades/View.php +++ /dev/null @@ -1,21 +0,0 @@ - '\1tatuses', - '/(quiz)$/i' => '\1zes', - '/^(ox)$/i' => '\1\2en', - '/([m|l])ouse$/i' => '\1ice', - '/(matr|vert)(ix|ex)$/i' => '\1ices', - '/(x|ch|ss|sh)$/i' => '\1es', - '/([^aeiouy]|qu)y$/i' => '\1ies', - '/(hive)$/i' => '\1s', - '/(chef)$/i' => '\1s', - '/(?:([^f])fe|([lre])f)$/i' => '\1\2ves', - '/sis$/i' => 'ses', - '/([ti])um$/i' => '\1a', - '/(p)erson$/i' => '\1eople', - '/(? '\1en', - '/(c)hild$/i' => '\1hildren', - '/(buffal|tomat)o$/i' => '\1\2oes', - '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin)us$/i' => '\1i', - '/us$/i' => 'uses', - '/(alias)$/i' => '\1es', - '/(ax|cris|test)is$/i' => '\1es', - '/s$/' => 's', - '/^$/' => '', - '/$/' => 's', - ]; - - /** - * Singular inflector rules - * - * @var array - */ - protected static $singular = [ - '/(s)tatuses$/i' => '\1\2tatus', - '/^(.*)(menu)s$/i' => '\1\2', - '/(quiz)zes$/i' => '\\1', - '/(matr)ices$/i' => '\1ix', - '/(vert|ind)ices$/i' => '\1ex', - '/^(ox)en/i' => '\1', - '/(alias)(es)*$/i' => '\1', - '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|viri?)i$/i' => '\1us', - '/([ftw]ax)es/i' => '\1', - '/(cris|ax|test)es$/i' => '\1is', - '/(shoe)s$/i' => '\1', - '/(o)es$/i' => '\1', - '/ouses$/' => 'ouse', - '/([^a])uses$/' => '\1us', - '/([m|l])ice$/i' => '\1ouse', - '/(x|ch|ss|sh)es$/i' => '\1', - '/(m)ovies$/i' => '\1\2ovie', - '/(s)eries$/i' => '\1\2eries', - '/([^aeiouy]|qu)ies$/i' => '\1y', - '/(tive)s$/i' => '\1', - '/(hive)s$/i' => '\1', - '/(drive)s$/i' => '\1', - '/([le])ves$/i' => '\1f', - '/([^rfoa])ves$/i' => '\1fe', - '/(^analy)ses$/i' => '\1sis', - '/(analy|diagno|^ba|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', - '/([ti])a$/i' => '\1um', - '/(p)eople$/i' => '\1\2erson', - '/(m)en$/i' => '\1an', - '/(c)hildren$/i' => '\1\2hild', - '/(n)ews$/i' => '\1\2ews', - '/eaus$/' => 'eau', - '/^(.*us)$/' => '\\1', - '/s$/i' => '', - ]; - - /** - * Irregular rules - * - * @var array - */ - protected static $irregular = [ - 'atlas' => 'atlases', - 'beef' => 'beefs', - 'brief' => 'briefs', - 'brother' => 'brothers', - 'cafe' => 'cafes', - 'child' => 'children', - 'cookie' => 'cookies', - 'corpus' => 'corpuses', - 'cow' => 'cows', - 'criterion' => 'criteria', - 'ganglion' => 'ganglions', - 'genie' => 'genies', - 'genus' => 'genera', - 'graffito' => 'graffiti', - 'hoof' => 'hoofs', - 'loaf' => 'loaves', - 'man' => 'men', - 'money' => 'monies', - 'mongoose' => 'mongooses', - 'move' => 'moves', - 'mythos' => 'mythoi', - 'niche' => 'niches', - 'numen' => 'numina', - 'occiput' => 'occiputs', - 'octopus' => 'octopuses', - 'opus' => 'opuses', - 'ox' => 'oxen', - 'penis' => 'penises', - 'person' => 'people', - 'sex' => 'sexes', - 'soliloquy' => 'soliloquies', - 'testis' => 'testes', - 'trilby' => 'trilbys', - 'turf' => 'turfs', - 'potato' => 'potatoes', - 'hero' => 'heroes', - 'tooth' => 'teeth', - 'goose' => 'geese', - 'foot' => 'feet', - 'foe' => 'foes', - 'sieve' => 'sieves', - 'cache' => 'caches', - ]; - - /** - * Words that should not be inflected - * - * @var array - */ - protected static $uninflected = [ - '.*?media', '.*[nrlm]ese', '.*data', '.*deer', '.*fish', '.*measles', - '.*ois', '.*pox', '.*sheep', 'audio', 'bison', 'cattle', 'chassis', - 'chassis', 'clippers', 'compensation', 'coreopsis', 'debris', 'diabetes', - 'education', 'emoji', 'equipment', 'evidence', 'feedback', 'firmware', - 'furniture', 'gallows', 'gold', 'graffiti', 'hardware', 'headquarters', - 'information', 'innings', 'jedi', 'kin', 'knowledge', 'money', 'moose', - 'news', 'nexus', 'nutrition', 'offspring', 'people', 'plankton', - 'pokemon', 'police', 'proceedings', 'rain', 'recommended', 'related', - 'research', 'rice', 'sea[- ]bass', 'series', 'software', 'species', - 'stadia', 'swine', 'traffic', 'weather', 'wheat', - ]; - - /** - * Method cache array. - * - * @var array - */ - protected static $cache = []; - - /** - * The initial state of Inflector so reset() works. - * - * @var array - */ - protected static $initialState = []; - - /** - * Cache inflected values, and return if already available - * - * @param string $type Inflection type - * @param string $key Original value - * @param string|false $value Inflected value - * @return string|false Inflected value on cache hit or false on cache miss. - */ - protected static function cache(string $type, string $key, $value = false) - { - $key = '_' . $key; - $type = '_' . $type; - if ($value !== false) { - static::$cache[$type][$key] = $value; - - return $value; - } - if (!isset(static::$cache[$type][$key])) { - return false; - } - - return static::$cache[$type][$key]; - } - - /** - * Clears Inflectors inflected value caches. And resets the inflection - * rules to the initial values. - * - * @return void - */ - public static function reset(): void - { - if (empty(static::$initialState)) { - static::$initialState = get_class_vars(self::class); - - return; - } - foreach (static::$initialState as $key => $val) { - if ($key !== 'initialState') { - static::${$key} = $val; - } - } - } - - /** - * Adds custom inflection $rules, of either 'plural', 'singular', - * 'uninflected' or 'irregular' $type. - * - * ### Usage: - * - * ``` - * Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']); - * Inflector::rules('irregular', ['red' => 'redlings']); - * Inflector::rules('uninflected', ['dontinflectme']); - * ``` - * - * @param string $type The type of inflection, either 'plural', 'singular', - * or 'uninflected'. - * @param array $rules Array of rules to be added. - * @param bool $reset If true, will unset default inflections for all - * new rules that are being defined in $rules. - * @return void - */ - public static function rules(string $type, array $rules, bool $reset = false): void - { - $var = '_' . $type; - - if ($reset) { - static::${$var} = $rules; - } elseif ($type === 'uninflected') { - static::$uninflected = array_merge( - $rules, - static::$uninflected - ); - } else { - static::${$var} = $rules + static::${$var}; - } - - static::$cache = []; - } - - /** - * Return $word in plural form. - * - * @param string $word Word in singular - * @return string Word in plural - * @link https://book.cakephp.org/4/en/core-libraries/inflector.html#creating-plural-singular-forms - */ - public static function pluralize(string $word): string - { - if (isset(static::$cache['pluralize'][$word])) { - return static::$cache['pluralize'][$word]; - } - - if (!isset(static::$cache['irregular']['pluralize'])) { - $words = array_keys(static::$irregular); - static::$cache['irregular']['pluralize'] = '/(.*?(?:\\b|_))(' . implode('|', $words) . ')$/i'; - - $upperWords = array_map('ucfirst', $words); - static::$cache['irregular']['upperPluralize'] = '/(.*?(?:\\b|[a-z]))(' . implode('|', $upperWords) . ')$/'; - } - - if ( - preg_match(static::$cache['irregular']['pluralize'], $word, $regs) || - preg_match(static::$cache['irregular']['upperPluralize'], $word, $regs) - ) { - static::$cache['pluralize'][$word] = $regs[1] . substr($regs[2], 0, 1) . - substr(static::$irregular[strtolower($regs[2])], 1); - - return static::$cache['pluralize'][$word]; - } - - if (!isset(static::$cache['uninflected'])) { - static::$cache['uninflected'] = '/^(' . implode('|', static::$uninflected) . ')$/i'; - } - - if (preg_match(static::$cache['uninflected'], $word, $regs)) { - static::$cache['pluralize'][$word] = $word; - - return $word; - } - - foreach (static::$plural as $rule => $replacement) { - if (preg_match($rule, $word)) { - static::$cache['pluralize'][$word] = preg_replace($rule, $replacement, $word); - - return static::$cache['pluralize'][$word]; - } - } - - return $word; - } - - /** - * Return $word in singular form. - * - * @param string $word Word in plural - * @return string Word in singular - * @link https://book.cakephp.org/4/en/core-libraries/inflector.html#creating-plural-singular-forms - */ - public static function singularize(string $word): string - { - if (isset(static::$cache['singularize'][$word])) { - return static::$cache['singularize'][$word]; - } - - if (!isset(static::$cache['irregular']['singular'])) { - $wordList = array_values(static::$irregular); - static::$cache['irregular']['singular'] = '/(.*?(?:\\b|_))(' . implode('|', $wordList) . ')$/i'; - - $upperWordList = array_map('ucfirst', $wordList); - static::$cache['irregular']['singularUpper'] = '/(.*?(?:\\b|[a-z]))(' . - implode('|', $upperWordList) . - ')$/'; - } - - if ( - preg_match(static::$cache['irregular']['singular'], $word, $regs) || - preg_match(static::$cache['irregular']['singularUpper'], $word, $regs) - ) { - $suffix = array_search(strtolower($regs[2]), static::$irregular, true); - $suffix = $suffix ? substr($suffix, 1) : ''; - static::$cache['singularize'][$word] = $regs[1] . substr($regs[2], 0, 1) . $suffix; - - return static::$cache['singularize'][$word]; - } - - if (!isset(static::$cache['uninflected'])) { - static::$cache['uninflected'] = '/^(' . implode('|', static::$uninflected) . ')$/i'; - } - - if (preg_match(static::$cache['uninflected'], $word, $regs)) { - static::$cache['pluralize'][$word] = $word; - - return $word; - } - - foreach (static::$singular as $rule => $replacement) { - if (preg_match($rule, $word)) { - static::$cache['singularize'][$word] = preg_replace($rule, $replacement, $word); - - return static::$cache['singularize'][$word]; - } - } - static::$cache['singularize'][$word] = $word; - - return $word; - } -} diff --git a/Radiate/Support/Pipeline.php b/Radiate/Support/Pipeline.php deleted file mode 100644 index e58ff04..0000000 --- a/Radiate/Support/Pipeline.php +++ /dev/null @@ -1,134 +0,0 @@ -passable = $passable; - - return $this; - } - - /** - * Set the array of pipes. - * - * @param array|mixed $pipes - * @return $this - */ - public function through($pipes): self - { - $this->pipes = (array) $pipes; - - return $this; - } - - /** - * Set the method to call on the pipes. - * - * @param string $method - * @return $this - */ - public function via(string $method): self - { - $this->method = $method; - - return $this; - } - - /** - * Run the pipeline with a final destination callback. - * - * @param \Closure $destination - * @return mixed - */ - public function then(Closure $destination) - { - $pipeline = array_reduce( - array_reverse($this->pipes), - $this->carry(), - $this->prepareDestination($destination) - ); - - return $pipeline($this->passable); - } - - /** - * Run the pipeline and return the result. - * - * @return mixed - */ - public function thenReturn() - { - return $this->then(function ($passable) { - return $passable; - }); - } - - /** - * Get the final piece of the Closure onion. - * - * @param \Closure $destination - * @return \Closure - */ - protected function prepareDestination(Closure $destination): Closure - { - return function ($passable) use ($destination) { - return $destination($passable); - }; - } - - /** - * Get a Closure that represents a slice of the application onion. - * - * @return \Closure - */ - protected function carry(): Closure - { - return function ($stack, $pipe) { - return function ($passable) use ($stack, $pipe) { - - if (is_callable($pipe)) { - return $pipe($passable, $stack); - } - if (is_string($pipe) && class_exists($pipe)) { - $pipe = new $pipe; - - return method_exists($pipe, $this->method) - ? $pipe->{$this->method}($passable, $stack) - : $pipe($passable, $stack); - } - }; - }; - } -} diff --git a/Radiate/Support/Pluralizer.php b/Radiate/Support/Pluralizer.php deleted file mode 100644 index 9ebd76d..0000000 --- a/Radiate/Support/Pluralizer.php +++ /dev/null @@ -1,57 +0,0 @@ -app = $app; - } - - /** - * Register the provider - * - * @return void - */ - public function register() - { - // - } - - /** - * An array of files/directories to publish - * - * @param array $files - * @param string $tag - * @return void - */ - public function publishes(array $files, string $tag = 'all') - { - static::$publishes[$tag][static::class] = $files; - } - - /** - * Get the paths to publish - * - * @param string|null $provider - * @param string|null $tag - * @return array - */ - public static function pathsToPublish(?string $provider = null, ?string $tag = null) - { - if ($provider && $tag) { - return static::$publishes[$tag][$provider]; - } elseif ($provider) { - return array_merge(...array_column(static::$publishes, $provider)); - } elseif ($tag) { - return array_merge(...array_values(static::$publishes[$tag])); - } else { - return array_merge(...array_values(array_merge_recursive(...array_values(static::$publishes)))); - } - } - - /** - * Register the commands - * - * @param array $commands - * @return void - */ - public function commands(array $commands) - { - if ($this->app->runningInConsole()) { - foreach ($commands as $command) { - $this->app->singleton($command, function ($app) use ($command) { - return new $command($app, $app['files']); - }); - - $this->app[$command]->register(); - } - } - } -} diff --git a/Radiate/Support/Stringable.php b/Radiate/Support/Stringable.php deleted file mode 100644 index 2c901ab..0000000 --- a/Radiate/Support/Stringable.php +++ /dev/null @@ -1,945 +0,0 @@ -string = $string; - } - - /** - * Return a new instance - * - * @param string $string - * @return static - */ - public static function of(string $string) - { - return new static($string); - } - - /** - * Return the remainder of a string after the first occurrence of a given value. - * - * @param string $search - * @return static - */ - public function after(string $search) - { - if ($search === '') { - return $this; - } - - return new static(array_reverse(explode($search, $this->string, 2))[0]); - } - - /** - * Return the remainder of a string after the last occurrence of a given value. - * - * @param string $search - * @return static - */ - public function afterLast(string $search) - { - if ($search === '') { - return $this; - } - - $position = strrpos($this->string, $search); - - if ($position === false) { - return $this; - } - - return new static(substr($this->string, $position + strlen($search))); - } - - /** - * Append the given values to the string. - * - * @param string ...$values - * @return static - */ - public function append(string ...$values) - { - return new static($this->string . implode('', $values)); - } - - /** - * Get the trailing name component of the path. - * - * @param string $suffix - * @return static - */ - public function basename(string $suffix = '') - { - return new static(basename($this->string, $suffix)); - } - - /** - * Get the portion of a string before the first occurrence of a given value. - * - * @param string $search - * @return static - */ - public function before(string $search) - { - if ($search === '') { - return $this; - } - - $result = strstr($this->string, $search, true); - - return new static($result === false ? $this->string : $result); - } - - /** - * Get the portion of a string before the last occurrence of a given value. - * - * @param string $search - * @return static - */ - public function beforeLast(string $search) - { - if ($search === '') { - return $this; - } - - $pos = mb_strrpos($this->string, $search); - - if ($pos === false) { - return $this; - } - - return $this->substr(0, $pos); - } - - /** - * Get the portion of a string between two given values. - * - * @param string $from - * @param string $to - * @return static - */ - public function between(string $from, string $to) - { - if ($from === '' || $to === '') { - return $this; - } - - return $this->after($from)->beforeLast($to); - } - - /** - * Convert a value to camel case. - * - * @return static - */ - public function camel() - { - $key = $this->string; - - if (isset(static::$camelCache[$key])) { - return static::$camelCache[$key]; - } - - static::$camelCache[$key] = lcfirst($this->studly($key)); - - return new static(static::$camelCache[$key]); - } - - /** - * Determine if a given string contains a given substring. - * - * @param string|string[] $needles - * @return bool - */ - public function contains($needles) - { - foreach ((array) $needles as $needle) { - if ($needle !== '' && mb_strpos($this->string, $needle) !== false) { - return true; - } - } - - return false; - } - - /** - * Determine if a given string contains all array values. - * - * @param string[] $needles - * @return bool - */ - public function containsAll(array $needles) - { - foreach ($needles as $needle) { - if (!$this->contains($needle)) { - return false; - } - } - - return true; - } - - /** - * Get the parent directory's path. - * - * @param int $levels - * @return static - */ - public function dirname(int $levels = 1) - { - return new static(dirname($this->string, $levels)); - } - - /** - * Determine if a given string ends with a given substring. - * - * @param string|string[] $needles - * @return bool - */ - public function endsWith($needles) - { - foreach ((array) $needles as $needle) { - if ($needle !== '' && substr($this->string, -strlen($needle)) === (string) $needle) { - return true; - } - } - - return false; - } - - /** - * Determine if the string is an exact match with the given value. - * - * @param string $value - * @return bool - */ - public function exactly(string $value): bool - { - return $this->string === $value; - } - - /** - * Explode the string into an array. - * - * @param string $delimiter - * @param int $limit - * @return array - */ - public function explode(string $delimiter, int $limit = PHP_INT_MAX): array - { - return explode($delimiter, $this->string, $limit); - } - - /** - * Cap a string with a single instance of a given value. - * - * @param string $cap - * @return static - */ - public function finish(string $cap) - { - return new static(rtrim($this->string, $cap) . $cap); - } - - /** - * Determine if a given string matches a given pattern. - * - * @param string|array $pattern - * @return bool - */ - public function is($pattern): bool - { - $patterns = is_array($pattern) ? $pattern : [$pattern]; - - if (empty($patterns)) { - return false; - } - - foreach ($patterns as $pattern) { - if ($pattern === $this->string) { - return true; - } - - $pattern = preg_quote($pattern, '#'); - - $pattern = str_replace('\*', '.*', $pattern); - - if (preg_match('#^' . $pattern . '\z#u', $this->string) === 1) { - return true; - } - } - - return false; - } - - /** - * Determine if the given string is empty. - * - * @return bool - */ - public function isEmpty(): bool - { - return empty($this->string); - } - - /** - * Determine if the given string is not empty. - * - * @return bool - */ - public function isNotEmpty(): bool - { - return !$this->isEmpty(); - } - - /** - * Determine if a given string is a valid UUID. - * - * @return bool - */ - public function isUuid(): bool - { - return preg_match('/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iD', $this->string) > 0; - } - - /** - * Convert a string to kebab case. - * - * @return static - */ - public function kebab() - { - return $this->snake('-'); - } - - /** - * Return the length of the given string. - * - * @param string|null $encoding - * @return int - */ - public function length(?string $encoding = null): int - { - if ($encoding) { - return mb_strlen($this->string, $encoding); - } - - return mb_strlen($this->string); - } - - /** - * Limit the number of characters in a string. - * - * @param int $limit - * @param string $end - * @return static - */ - public function limit(int $limit = 100, string $end = '...') - { - if (mb_strwidth($this->string, 'UTF-8') <= $limit) { - return $this->string; - } - - return new static(rtrim(mb_strimwidth($this->string, 0, $limit, '', 'UTF-8')) . $end); - } - - /** - * Convert the given string to lower-case. - * - * @return static - */ - public function lower() - { - return new static(mb_strtolower($this->string, 'UTF-8')); - } - - /** - * Converts Markdown into HTML. - * - * @return string - */ - public function markdown() - { - return (new Parsedown)->text($this->string); - } - - /** - * Get the string matching the given pattern. - * - * @param string $pattern - * @return static|null - */ - public function match(string $pattern) - { - preg_match($pattern, $this->string, $matches); - - if (!$matches) { - return new static; - } - - return new static($matches[1] ?? $matches[0]); - } - - /** - * Get the string matching the given pattern. - * - * @param string $pattern - * @return array - */ - public function matchAll(string $pattern): array - { - preg_match_all($pattern, $this->string, $matches); - - if (empty($matches[0])) { - return []; - } - - return $matches[1] ?? $matches[0]; - } - - /** - * Pad both sides of a string with another. - * - * @param int $length - * @param string $pad - * @return static - */ - public function padBoth(int $length, string $pad = ' ') - { - return new static(str_pad($this->string, $length, $pad, STR_PAD_BOTH)); - } - - /** - * Pad the left side of a string with another. - * - * @param int $length - * @param string $pad - * @return static - */ - public function padLeft(int $length, string $pad = ' ') - { - return new static(str_pad($this->string, $length, $pad, STR_PAD_LEFT)); - } - - /** - * Pad the right side of a string with another. - * - * @param int $length - * @param string $pad - * @return static - */ - public function padRight(int $length, string $pad = ' ') - { - return new static(str_pad($this->string, $length, $pad, STR_PAD_RIGHT)); - } - - /** - * Call the given callback and return a new string. - * - * @param callable $callback - * @return static - */ - public function pipe(callable $callback) - { - return new static(call_user_func($callback, $this)); - } - - /** - * Get the plural form of an English word. - * - * @param int $count - * @return static - */ - public function plural(int $count = 2) - { - return new static(Pluralizer::plural($this->string, $count)); - } - - /** - * Pluralize the last word of an English, studly caps case string. - * - * @param int $count - * @return static - */ - public function pluralStudly(int $count = 2) - { - $parts = preg_split('/(.)(?=[A-Z])/u', $this->string, -1, PREG_SPLIT_DELIM_CAPTURE); - $lastWord = new static(array_pop($parts)); - - return new static(implode('', $parts) . $lastWord->plural($count)); - } - - /** - * Prepend the given values to the string. - * - * @param array ...$values - * @return static - */ - public function prepend(string ...$values) - { - return new static(implode('', $values) . $this->string); - } - - /** - * Generate a more truly "random" alpha-numeric string. - * - * @param int $length - * @return static - */ - public function random(int $length = 16) - { - $string = ''; - - while (($len = strlen($string)) < $length) { - $size = $length - $len; - - $bytes = random_bytes($size); - - $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); - } - - return new static($string); - } - - /** - * Replace the given value in the given string. - * - * @param string|string[] $search - * @param string|string[] $replace - * @return static - */ - public function replace($search, $replace) - { - return new static(str_replace($search, $replace, $this->string)); - } - - /** - * Replace a given value in the string sequentially with an array. - * - * @param string $search - * @param array $replace - * @return static - */ - public function replaceArray(string $search, array $replace) - { - $segments = explode($search, $this->string); - - $result = array_shift($segments); - - foreach ($segments as $segment) { - $result .= (array_shift($replace) ?? $search) . $segment; - } - - return new static($result); - } - - /** - * Replace the first occurrence of a given value in the string. - * - * @param string $search - * @param string $replace - * @return static - */ - public function replaceFirst(string $search, string $replace) - { - if ($search === '') { - return $this; - } - - $position = strpos($this->string, $search); - - if ($position !== false) { - return new static(substr_replace($this->string, $replace, $position, strlen($search))); - } - - return $this; - } - - /** - * Replace the last occurrence of a given value in the string. - * - * @param string $search - * @param string $replace - * @return static - */ - public function replaceLast(string $search, string $replace) - { - if ($search === '') { - return $this; - } - - $position = strrpos($this->string, $search); - - if ($position !== false) { - return new static(substr_replace($this->string, $replace, $position, strlen($search))); - } - - return $this; - } - - /** - * Replace the patterns matching the given regular expression. - * - * @param string $pattern - * @param \Closure|string $replace - * @param int $limit - * @return static - */ - public function replaceMatches(string $pattern, $replace, int $limit = -1) - { - if ($replace instanceof Closure) { - return new static(preg_replace_callback($pattern, $replace, $this->string, $limit)); - } - - return new static(preg_replace($pattern, $replace, $this->string, $limit)); - } - - /** - * Split a string using a regular expression or by length. - * - * @param string|int $pattern - * @param int $limit - * @param int $flags - * @return array - */ - public function split($pattern, int $limit = -1, int $flags = 0): array - { - if (filter_var($pattern, FILTER_VALIDATE_INT) !== false) { - return mb_str_split($this->string, $pattern); - } - - $segments = preg_split($pattern, $this->string, $limit, $flags); - - return !empty($segments) ? $segments : []; - } - - /** - * Begin a string with a single instance of a given value. - * - * @param string $prefix - * @return static - */ - public function start(string $prefix) - { - return new static($prefix . ltrim($this->string, $prefix)); - } - - /** - * Convert the given string to upper-case. - * - * @return static - */ - public function upper() - { - return new static(mb_strtoupper($this->string, 'UTF-8')); - } - - /** - * Convert the given string to title case. - * - * @return static - */ - public function title() - { - return new static(mb_convert_case($this->string, MB_CASE_TITLE, 'UTF-8')); - } - - /** - * Get the singular form of an English word. - * - * @return static - */ - public function singular() - { - return new static(Pluralizer::singular($this->string)); - } - - /** - * Generate a URL friendly "slug" from a given string. - * - * @return static - */ - public function slug() - { - return new static(sanitize_title_with_dashes(remove_accents($this->string))); - } - - /** - * Convert a string to snake case. - * - * @param string $delimiter - * @return static - */ - public function snake(string $delimiter = '_') - { - $key = $this->string; - - if (isset(static::$snakeCache[$key][$delimiter])) { - return static::$snakeCache[$key][$delimiter]; - } - - if (!ctype_lower($key)) { - $value = preg_replace('/\s+/u', '', ucwords($key)); - - $value = mb_strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value)); - } - - static::$snakeCache[$key][$delimiter] = $value; - - return new static(static::$snakeCache[$key][$delimiter]); - } - - /** - * Determine if a given string starts with a given substring. - * - * @param string|string[] $needles - * @return bool - */ - public function startsWith($needles) - { - foreach ((array) $needles as $needle) { - if ((string) $needle !== '' && strncmp($this->string, $needle, strlen($needle)) === 0) { - return true; - } - } - - return false; - } - - /** - * Convert a value to studly caps case. - * - * @return static - */ - public function studly() - { - $key = $this->string; - - if (isset(static::$studlyCache[$key])) { - return static::$studlyCache[$key]; - } - - $value = ucwords(str_replace(['-', '_'], ' ', $key)); - - static::$studlyCache[$key] = str_replace(' ', '', $value); - - return new static(static::$studlyCache[$key]); - } - - /** - * Returns the portion of string specified by the start and length parameters. - * - * @param int $start - * @param int|null $length - * @return static - */ - public function substr(int $start, ?int $length = null) - { - return new static(mb_substr($this->string, $start, $length, 'UTF-8')); - } - - /** - * Returns the number of substring occurrences. - * - * @param string $needle - * @param int $offset - * @param int|null $length - * @return int - */ - public function substrCount(string $needle, int $offset = 0, ?int $length = null): int - { - if (!is_null($length)) { - return substr_count($this->string, $needle, $offset, $length); - } else { - return substr_count($this->string, $needle, $offset); - } - } - - /** - * Trim the string of the given characters. - * - * @param string $characters - * @return static - */ - public function trim(?string $characters = " \t\n\r\0\x0B") - { - return new static(trim($this->string, $characters)); - } - - /** - * Left trim the string of the given characters. - * - * @param string $characters - * @return static - */ - public function ltrim(?string $characters = " \t\n\r\0\x0B") - { - return new static(ltrim($this->string, $characters)); - } - - /** - * Right trim the string of the given characters. - * - * @param string $characters - * @return static - */ - public function rtrim(?string $characters = " \t\n\r\0\x0B") - { - return new static(rtrim($this->string, $characters)); - } - - /** - * Call the given Closure with this instance then return the instance. - * - * @param callable $callback - * @return mixed - */ - public function tap(callable $callback) - { - $callback($this); - - return $this; - } - - /** - * Make a string's first character uppercase. - * - * @return static - */ - public function ucfirst() - { - return new static(ucfirst($this->string)); - } - - /** - * Execute the given callback if the string is empty. - * - * @param callable $callback - * @return static - */ - public function whenEmpty(callable $callback) - { - if ($this->isEmpty()) { - $result = $callback($this); - - return is_null($result) ? $this : $result; - } - - return $this; - } - - /** - * Limit the number of words in a string. - * - * @param int $words - * @param string $end - * @return static - */ - public function words(int $words = 100, string $end = '...') - { - preg_match('/^\s*+(?:\S++\s*+){1,' . $words . '}/u', $this->string, $matches); - - if (!isset($matches[0]) || mb_strlen($this->string) === mb_strlen($matches[0])) { - return $this; - } - - return new static(rtrim($matches[0]) . $end); - } - - /** - * Dump the string. - * - * @return static - */ - public function dump() - { - var_dump($this->string); - - return $this; - } - - /** - * Dump the string and end the script. - * - * @return void - */ - public function dd() - { - $this->dump(); - - die(1); - } - - /** - * Proxy dynamic properties onto methods. - * - * @param string $key - * @return mixed - */ - public function __get(string $key) - { - return $this->{$key}(); - } - - /** - * Get the underlying string - * - * @return string - */ - public function toString(): string - { - return $this->string; - } - - /** - * Get the underlying string - * - * @return string - */ - public function __toString(): string - { - return $this->string; - } -} diff --git a/Radiate/View/View.php b/Radiate/View/View.php deleted file mode 100644 index 828a3d1..0000000 --- a/Radiate/View/View.php +++ /dev/null @@ -1,43 +0,0 @@ -basePath = $basePath; - } - - /** - * Make a view - * - * @param string $path - * @param array $args - * @return string - */ - public function make(string $path, array $args = []): string - { - $path = str_replace('.', DIRECTORY_SEPARATOR, $path) . '.php'; - - ob_start(); - - extract($args); - - require $this->basePath . DIRECTORY_SEPARATOR . $path; - - return ob_get_clean(); - } -} diff --git a/Radiate/View/ViewServiceProvider.php b/Radiate/View/ViewServiceProvider.php deleted file mode 100644 index ba75761..0000000 --- a/Radiate/View/ViewServiceProvider.php +++ /dev/null @@ -1,32 +0,0 @@ -app->singleton('view', function ($app) { - return new View($app->basePath('views')); - }); - } - - /** - * Boot the provider - * - * @return void - */ - public function boot() - { - $this->publishes([ - __DIR__ . '/resources/views' => $this->app->basePath('views'), - ], 'views'); - } -} diff --git a/Radiate/View/resources/views/404.php b/Radiate/View/resources/views/404.php deleted file mode 100644 index e69de29..0000000 diff --git a/Radiate/View/resources/views/archive.php b/Radiate/View/resources/views/archive.php deleted file mode 100644 index e69de29..0000000 diff --git a/Radiate/View/resources/views/footer.php b/Radiate/View/resources/views/footer.php deleted file mode 100644 index e69de29..0000000 diff --git a/Radiate/View/resources/views/front-page.php b/Radiate/View/resources/views/front-page.php deleted file mode 100644 index e69de29..0000000 diff --git a/Radiate/View/resources/views/header.php b/Radiate/View/resources/views/header.php deleted file mode 100644 index e69de29..0000000 diff --git a/Radiate/View/resources/views/home.php b/Radiate/View/resources/views/home.php deleted file mode 100644 index e69de29..0000000 diff --git a/Radiate/View/resources/views/index.php b/Radiate/View/resources/views/index.php deleted file mode 100644 index e69de29..0000000 diff --git a/Radiate/View/resources/views/search.php b/Radiate/View/resources/views/search.php deleted file mode 100644 index e69de29..0000000 diff --git a/Radiate/View/resources/views/searchform.php b/Radiate/View/resources/views/searchform.php deleted file mode 100644 index e69de29..0000000 diff --git a/Radiate/View/resources/views/singular.php b/Radiate/View/resources/views/singular.php deleted file mode 100644 index e69de29..0000000 diff --git a/composer.json b/composer.json index 8fca7ed..0ea5376 100644 --- a/composer.json +++ b/composer.json @@ -22,9 +22,14 @@ }, "require": { "php": "^7.3", - "psr/container": "^1.0", - "erusev/parsedown": "^1.7" + "brw/radiate-framework": "@dev" }, + "repositories": [ + { + "type": "path", + "url": "../../vendor/brw/radiate-framework" + } + ], "scripts": { "post-create-project-cmd": [ "npm install"