Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Packages" directory, deprecate "Illuminate" directory #6

Merged
merged 4 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,16 @@ Access the generator commands through `vendor/bin/weasley` in the terminal/comma

**NOTE**: In other PHP frameworks, this is also known as `Controllers`.

### Integrations
### Packages

| Integration | Description |
| ----------- | ----------- |
| [SessionIntegration](https://github.com/rougin/weasley/blob/master/src/Session/SessionIntegration.php) | An implementation of [SessionHandlerInterface](https://secure.php.net/manual/en/class.sessionhandlerinterface.php). |

#### Illuminate (Laravel's individual components)
The following classes below are using the [`IntegrationInterface`](https://github.com/rougin/slytherin/wiki/IntegrationInterface-Implementation) from Slytherin:

| Integration | Description |
| Package | Description |
| ----------- | ----------- |
| [DatabaseIntegration](https://github.com/rougin/weasley/blob/master/src/Illuminate/DatabaseIntegration.php) | Based on [illuminate/database](https://github.com/illuminate/database) ([Eloquent](https://laravel.com/docs/5.4/eloquent)). |
| [PaginationIntegration](https://github.com/rougin/weasley/blob/master/src/Illuminate/PaginationIntegration.php) | Based on [illuminate/pagination](https://github.com/illuminate/pagination). |
| [ViewIntegration](https://github.com/rougin/weasley/blob/master/src/Illuminate/ViewIntegration.php) | Based on [illuminate/view](https://github.com/illuminate/view) ([Blade](https://laravel.com/docs/5.4/blade)). |
| [Laravel/Eloquent](https://github.com/rougin/weasley/blob/master/src/Packages/Laravel/Eloquent.php) | Based on the [illuminate/database](https://github.com/illuminate/database) ([Eloquent](https://laravel.com/docs/11.x/eloquent)). |
| [Laravel/Blade](https://github.com/rougin/weasley/blob/master/src/Packages/Laravel/Blade.php) | Based on the [illuminate/view](https://github.com/illuminate/view) ([Blade](https://laravel.com/docs/11.x/blade)). |
| [Laravel/Paginate](https://github.com/rougin/weasley/blob/master/src/Packages/Laravel/Paginate.php) | Based on the [illuminate/pagination](https://github.com/illuminate/pagination). |
| [SessionIntegration](https://github.com/rougin/weasley/blob/master/src/Packages/Session.php) | A simple implementation of the [SessionHandlerInterface](https://secure.php.net/manual/en/class.sessionhandlerinterface.php). |

**NOTE**: The mentioned integrations above needs to include their required dependencies first.

Expand Down
46 changes: 46 additions & 0 deletions src/Contract/Session.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Rougin\Weasley\Contract;

/**
* Session Interface
*
* @package Weasley
* @author Rougin Gutib <rougingutib@gmail.com>
*/
interface Session
{
/**
* Returns the value from the specified key.
*
* @param string $key
* @return boolean
*/
public function delete($key);

/**
* Returns the value from the specified key.
*
* @param string $key
* @param mixed|null $default
* @return mixed
*/
public function get($key, $default = null);

/**
* Updates the current session ID with a newly generated one.
*
* @param boolean $delete
* @return boolean
*/
public function regenerate($delete = false);

/**
* Sets the value to the specified key.
*
* @param string $key
* @param mixed $value
* @return self
*/
public function set($key, $value);
}
60 changes: 4 additions & 56 deletions src/Illuminate/DatabaseIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,16 @@

namespace Rougin\Weasley\Illuminate;

use Rougin\Slytherin\Container\ContainerInterface;
use Rougin\Slytherin\Integration\Configuration;
use Rougin\Slytherin\Integration\IntegrationInterface;
use Rougin\Weasley\Packages\Laravel\Eloquent;

/**
* Illuminate's Database Integration
* @deprecated since ~0.7, use "Packages/Laravel/Eloquent" instead.
*
* An integration for Laravel's Eloquent package (illuminate/database).
* Illuminate's Database Integration
*
* @package Weasley
* @author Rougin Gutib <rougingutib@gmail.com>
*/
class DatabaseIntegration implements IntegrationInterface
class DatabaseIntegration extends Eloquent
{
/**
* Defines the specified integration.
*
* @param \Rougin\Slytherin\Container\ContainerInterface $container
* @param \Rougin\Slytherin\Integration\Configuration $config
* @return \Rougin\Slytherin\Container\ContainerInterface
*/
public function define(ContainerInterface $container, Configuration $config)
{
$capsule = new \Illuminate\Database\Capsule\Manager;

$connections = $config->get('database', array());

foreach ((array) $connections as $key => $value)
{
if (is_array($value) === true)
{
$this->connection($config, $key, $value);

$capsule->addConnection($value, $key);
}
}

$capsule->setAsGlobal();

$capsule->bootEloquent();

return $container->set(get_class($capsule), $capsule);
}

/**
* Updates the parameters of the current connection.
*
* @param \Rougin\Slytherin\Integration\Configuration $config
* @param string $key
* @param array<string, string> $value
* @return void
*/
protected function connection(Configuration $config, &$key, &$value)
{
$collation = 'database.' . $key . '.collation';

$value['collation'] = $config->get($collation, 'utf8_unicode_ci');

$prefix = 'database.' . $key . '.prefix';

$value['prefix'] = $config->get($prefix, '');

$key === $config->get('database.default') && $key = 'default';
}
}
60 changes: 4 additions & 56 deletions src/Illuminate/PaginationIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,16 @@

namespace Rougin\Weasley\Illuminate;

use Illuminate\Pagination\Paginator;
use Rougin\Slytherin\Container\ContainerInterface;
use Rougin\Slytherin\Integration\Configuration;
use Rougin\Slytherin\Integration\IntegrationInterface;
use Rougin\Weasley\Packages\Laravel\Paginate;

/**
* Illuminate's Pagination Integration
* @deprecated since ~0.7, use "Packages/Laravel/Paginate" instead.
*
* An integration for Laravel's Pagination package (illuminate/pagination).
* Illuminate's Pagination Integration
*
* @package Weasley
* @author Rougin Gutib <rougingutib@gmail.com>
*/
class PaginationIntegration implements IntegrationInterface
class PaginationIntegration extends Paginate
{
const REQUEST = 'Psr\Http\Message\ServerRequestInterface';

/**
* Defines the specified integration.
*
* @param \Rougin\Slytherin\Container\ContainerInterface $container
* @param \Rougin\Slytherin\Integration\Configuration $config
* @return \Rougin\Slytherin\Container\ContainerInterface
*/
public function define(ContainerInterface $container, Configuration $config)
{
/** @var \Psr\Http\Message\ServerRequestInterface */
$request = $container->get(self::REQUEST);

$query = $request->getQueryParams();

$page = function ($name = null) use ($query)
{
$name = $name === null ? 'page' : $name;

return isset($query[$name]) ? $query[$name] : 1;
};

$path = function () use ($request)
{
/** @var string|null */
$uri = $request->getAttribute('REQUEST_URI');

return $uri ? strtok($uri, '?') : '/';
};

$this->resolve($page, $path);

return $container;
}

/**
* Sets current page and path resolvers.
*
* @param \Closure $page
* @param \Closure $path
* @return void
*/
protected function resolve($page, $path)
{
Paginator::currentPageResolver($page);

Paginator::currentPathResolver($path);
}
}
114 changes: 4 additions & 110 deletions src/Illuminate/ViewIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,122 +2,16 @@

namespace Rougin\Weasley\Illuminate;

use Illuminate\Container\Container;
use Illuminate\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Engines\CompilerEngine;
use Illuminate\View\Engines\EngineResolver;
use Illuminate\View\Factory;
use Illuminate\View\FileViewFinder;
use Rougin\Slytherin\Container\ContainerInterface;
use Rougin\Slytherin\Integration\Configuration;
use Rougin\Slytherin\Integration\IntegrationInterface;
use Rougin\Weasley\Renderers\BladeRenderer;
use Rougin\Weasley\Packages\Laravel\Blade;

/**
* Illuminate's View Integration
* @deprecated since ~0.7, use "Packages/Laravel/Blade" instead.
*
* An integration for Laravel's View package (illuminate/view).
* Illuminate's View Integration
*
* @package Weasley
* @author Rougin Gutib <rougingutib@gmail.com>
*/
class ViewIntegration implements IntegrationInterface
class ViewIntegration extends Blade
{
const RENDERER = 'Rougin\Slytherin\Template\RendererInterface';

const VIEW_FACTORY = 'Illuminate\Contracts\View\Factory';

/**
* @var string
*/
protected $interface = 'Rougin\Slytherin\Template\RendererInterface';

/**
* Defines the specified integration.
*
* @param \Rougin\Slytherin\Container\ContainerInterface $container
* @param \Rougin\Slytherin\Integration\Configuration $config
* @return \Rougin\Slytherin\Container\ContainerInterface
*/
public function define(ContainerInterface $container, Configuration $config)
{
$filesystem = new Filesystem;

$result = $this->locations($config);

/** @var string */
$compiled = $result['compiled'];

/** @var string[] */
$templates = $result['templates'];

$resolver = $this->resolver($compiled, $filesystem);

$dispatcher = new Dispatcher(new Container);

$finder = new FileViewFinder($filesystem, $templates);

$factory = new Factory($resolver, $finder, $dispatcher);

$container->set(self::VIEW_FACTORY, $factory);

$renderer = new BladeRenderer($factory);

return $container->set(self::RENDERER, $renderer);
}

/**
* Returns the EngineResolver instance.
*
* @param string $compiled
* @param \Illuminate\Filesystem\Filesystem $filesystem
* @return \Illuminate\View\Engines\EngineResolver
*/
protected function resolver($compiled, $filesystem)
{
$resolver = new EngineResolver;

$callback = function () use ($compiled, $filesystem)
{
$blade = new BladeCompiler($filesystem, $compiled);

return new CompilerEngine($blade);
};

$resolver->register('blade', $callback);

return $resolver;
}

/**
* Returns the compiled and template locations.
*
* @param \Rougin\Slytherin\Integration\Configuration $config
* @return array<string, string[]|string>
*/
protected function locations(Configuration $config)
{
$view = 'illuminate.view';

/** @var string|string[] */
$templates = $config->get($view . '.templates', array());

/** @var string */
$compiled = $config->get($view . '.compiled', '');

if (is_string($templates))
{
$templates = array($templates);
}

$result = array();

$result['compiled'] = $compiled;

$result['templates'] = $templates;

return $result;
}
}
5 changes: 2 additions & 3 deletions src/Integrations/Illuminate/DatabaseIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
use Rougin\Weasley\Illuminate\DatabaseIntegration as Integration;

/**
* Illuminate's Database Integration
* @deprecated since ~0.6, use "Illuminate/DatabaseIntegration" instead.
*
* An integration for Laravel's Eloquent package (illuminate/database).
* NOTE: To be removed in v1.0.0. Use Rougin\Weasley\Illuminate instead.
* Illuminate's Database Integration
*
* @package Weasley
* @author Rougin Gutib <rougingutib@gmail.com>
Expand Down
5 changes: 2 additions & 3 deletions src/Integrations/Illuminate/PaginationIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
use Rougin\Weasley\Illuminate\PaginationIntegration as Integration;

/**
* Illuminate's Pagination Integration
* @deprecated since ~0.6, use "Illuminate/PaginationIntegration" instead.
*
* An integration for Laravel's Pagination package (illuminate/pagination).
* NOTE: To be removed in v1.0.0. Use Rougin\Weasley\Illuminate instead.
* Illuminate's Pagination Integration
*
* @package Weasley
* @author Rougin Gutib <rougingutib@gmail.com>
Expand Down
5 changes: 2 additions & 3 deletions src/Integrations/Illuminate/ViewIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
use Rougin\Weasley\Illuminate\ViewIntegration as Integration;

/**
* Illuminate's View Integration
* @deprecated since ~0.6, use "Illuminate/ViewIntegration" instead.
*
* An integration for Laravel's View package (illuminate/view).
* NOTE: To be removed in v1.0.0. Use Rougin\Weasley\Illuminate instead.
* Illuminate's View Integration
*
* @package Weasley
* @author Rougin Gutib <rougingutib@gmail.com>
Expand Down