Skip to content

Commit

Permalink
Revert the package name to avoid any conflicts with ARCANESOFT's modules
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Mar 4, 2017
1 parent 0ecaab5 commit d43f4ae
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 44 deletions.
File renamed without changes.
5 changes: 3 additions & 2 deletions src/Bases/Migration.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Arcanedev\LaravelSeo\Bases;

use Arcanedev\LaravelSeo\Seo;
use Arcanedev\Support\Bases\Migration as BaseMigration;

/**
Expand All @@ -19,7 +20,7 @@ abstract class Migration extends BaseMigration
*/
public function __construct()
{
$this->setConnection(config('seo.database.connection', null));
$this->setPrefix(config('seo.database.prefix', 'seo_'));
$this->setConnection(Seo::getConfig('database.connection', null));
$this->setPrefix(Seo::getConfig('database.prefix', 'seo_'));
}
}
6 changes: 5 additions & 1 deletion src/Entities/RedirectStatuses.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Arcanedev\LaravelSeo\Entities;

use Arcanedev\LaravelSeo\Seo;
use Symfony\Component\HttpFoundation\Response;

/**
Expand All @@ -17,6 +18,8 @@ class RedirectStatuses
/**
* Get the all status names.
*
* @param string|null $locale
*
* @return \Illuminate\Support\Collection
*/
public static function all($locale = null)
Expand All @@ -29,7 +32,7 @@ public static function all($locale = null)
];

return collect(array_combine($codes, $codes))->transform(function ($code) use ($locale) {
return trans("seo::redirections.statuses.{$code}", [], $locale);
return Seo::getTrans("redirections.statuses.{$code}", [], $locale);
});
}

Expand All @@ -48,6 +51,7 @@ public static function keys()
*
* @param int $key
* @param string|null $default
* @param string|null $locale
*
* @return string
*/
Expand Down
2 changes: 1 addition & 1 deletion src/LaravelSeoServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LaravelSeoServiceProvider extends PackageServiceProvider
*
* @var string
*/
protected $package = 'seo';
protected $package = 'laravel-seo';

/* ------------------------------------------------------------------------------------------------
| Main Functions
Expand Down
5 changes: 3 additions & 2 deletions src/Models/AbstractModel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Arcanedev\LaravelSeo\Models;

use Arcanedev\LaravelSeo\Seo;
use Arcanedev\Support\Bases\Model;

/**
Expand All @@ -23,7 +24,7 @@ public function __construct(array $attributes = [])
{
parent::__construct($attributes);

$this->setConnection(config('seo.database.connection', null));
$this->setPrefix(config('seo.database.prefix', 'seo_'));
$this->setConnection(Seo::getConfig('database.connection', null));
$this->setPrefix(Seo::getConfig('database.prefix', 'seo_'));
}
}
4 changes: 3 additions & 1 deletion src/Models/Meta.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace Arcanedev\LaravelSeo\Models;

use Arcanedev\LaravelSeo\Seo;

/**
* Class Meta
*
Expand Down Expand Up @@ -57,7 +59,7 @@ public function __construct(array $attributes = [])
{
parent::__construct($attributes);

$this->setTable(config('seo.metas.table', 'metas'));
$this->setTable(Seo::getConfig('metas.table', 'metas'));
}

/* -----------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/Models/Redirect.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Arcanedev\LaravelSeo\Models;

use Arcanedev\LaravelSeo\Seo;
use Symfony\Component\HttpFoundation\Response;

/**
Expand Down Expand Up @@ -50,7 +51,7 @@ public function __construct(array $attributes = [])
{
parent::__construct($attributes);

$this->setTable(config('seo.redirects.table', 'redirects'));
$this->setTable(Seo::getConfig('redirects.table', 'redirects'));
}

/* -----------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Arcanedev\LaravelSeo\Providers;

use Arcanedev\LaravelSeo\Http\Middleware\RedirectsMissingPages;
use Arcanedev\LaravelSeo\Seo;
use Arcanedev\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Contracts\Http\Kernel as HttpKernel;

Expand All @@ -18,7 +19,7 @@ class RouteServiceProvider extends ServiceProvider
*/
public function boot()
{
if (config('seo.redirector.enabled', false))
if (Seo::getConfig('redirector.enabled', false))
$this->app->make(HttpKernel::class)->pushMiddleware(RedirectsMissingPages::class);

parent::boot();
Expand Down
31 changes: 4 additions & 27 deletions src/RedirectorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,7 @@ class RedirectorManager extends Manager implements RedirectorFactory
*/
public function getDefaultDriver()
{
return $this->getConfig('redirector.default', 'config');
}

/**
* Get the config repository.
*
* @return \Illuminate\Contracts\Config\Repository
*/
protected function config()
{
return $this->app['config'];
return Seo::getConfig('redirector.default', 'config');
}

/* -----------------------------------------------------------------
Expand Down Expand Up @@ -69,7 +59,7 @@ public function createConfigDriver()
public function createEloquentDriver()
{
return $this->buildDriver('eloquent', [
'model' => $this->getConfig('redirects.model'),
'model' => Seo::getConfig('redirects.model'),
]);
}

Expand All @@ -88,22 +78,9 @@ public function createEloquentDriver()
private function buildDriver($driver, array $extra = [])
{
$router = $this->app->make(\Illuminate\Contracts\Routing\Registrar::class);
$class = $this->getConfig("redirector.drivers.$driver.class");
$options = $this->getConfig("redirector.drivers.$driver.options", []);
$class = Seo::getConfig("redirector.drivers.$driver.class");
$options = Seo::getConfig("redirector.drivers.$driver.options", []);

return new $class($router, array_merge($extra, $options));
}

/**
* Get the seo config.
*
* @param string $key
* @param mixed|null $default
*
* @return mixed
*/
private function getConfig($key, $default = null)
{
return $this->config()->get("seo.$key", $default);
}
}
47 changes: 47 additions & 0 deletions src/Seo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php namespace Arcanedev\LaravelSeo;

/**
* Class Seo
*
* @package Arcanedev\LaravelSeo
* @author ARCANEDEV <arcanedev.maroc@gmail.com>
*/
class Seo
{
/* -----------------------------------------------------------------
| Constants
| -----------------------------------------------------------------
*/
const KEY = 'laravel-seo';

/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
/**
* Get the seo config.
*
* @param string $key
* @param mixed|null $default
*
* @return mixed
*/
public static function getConfig($key, $default = null)
{
return config(self::KEY.'.'.$key, $default);
}

/**
* Get the seo translation.
*
* @param string $key
* @param array $replace
* @param string $locale
*
* @return string
*/
public static function getTrans($key = null, $replace = [], $locale = null)
{
return trans(self::KEY.'::'.$key, $replace, $locale);
}
}
23 changes: 16 additions & 7 deletions tests/RedirectorManagerTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Arcanedev\LaravelSeo\Tests;

use Arcanedev\LaravelSeo\Models\Redirect;
use Arcanedev\LaravelSeo\Seo;
use Symfony\Component\HttpFoundation\Response;

/**
Expand Down Expand Up @@ -103,8 +104,8 @@ public function it_can_build_eloquent_driver()
$this->assertCount(2, $redirects);

$expected = [
'/non-existing-page-url' => ['/existing-page-url', 301],
'/old-blog/{slug}' => ['/new-blog/{slug}', 301],
'/non-existing-page-url' => ['/existing-page-url', Response::HTTP_MOVED_PERMANENTLY],
'/old-blog/{slug}' => ['/new-blog/{slug}', Response::HTTP_MOVED_PERMANENTLY],
];

$this->assertSame($expected, $redirects);
Expand Down Expand Up @@ -171,14 +172,13 @@ public function it_can_use_multiple_named_parameters_in_one_segment()
public function it_can_optionally_set_the_redirect_status_code()
{
$this->setRedirectUrl([
'temporarily-moved' => ['just-for-now', 302],
'temporarily-moved' => ['just-for-now', Response::HTTP_FOUND],
]);

$this->get('temporarily-moved');

$this->assertRedirectedTo('just-for-now');

$this->assertResponseStatus(302);
$this->assertResponseStatus(Response::HTTP_FOUND);
}

/** @test */
Expand Down Expand Up @@ -209,8 +209,17 @@ public function it_will_not_redirect_requests_that_are_not_404s()
$this->assertResponseStatus(500);
}

private function setRedirectUrl($urls)
/* -----------------------------------------------------------------
| Other Methods
| -----------------------------------------------------------------
*/
/**
* Set the redirect URL.
*
* @param array $urls
*/
private function setRedirectUrl(array $urls)
{
$this->app['config']->set('seo.redirector.drivers.config.options.redirects', $urls);
$this->app['config']->set(Seo::KEY.'.redirector.drivers.config.options.redirects', $urls);
}
}
3 changes: 2 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Arcanedev\LaravelSeo\Tests;

use Arcanedev\LaravelSeo\Seo;
use Orchestra\Testbench\BrowserKit\TestCase as BaseTestCase;

/**
Expand Down Expand Up @@ -67,7 +68,7 @@ protected function getEnvironmentSetUp($app)
'prefix' => '',
]);

$app['config']->set('seo.redirector.drivers.config.options.redirects', [
$app['config']->set(Seo::KEY.'.redirector.drivers.config.options.redirects', [
'/non-existing-page-url' => '/existing-page-url',
'/old-blog/{slug}' => '/new-blog/{slug}',
]);
Expand Down

0 comments on commit d43f4ae

Please sign in to comment.