Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
eusonlito committed Sep 28, 2017
1 parent 050e2d5 commit 6889702
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 59 deletions.
85 changes: 33 additions & 52 deletions src/CrudModuleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,8 @@ public function boot()

$this->loadTranslationsFrom(__DIR__.'/../lang', 'anavel-crud');

$this->publishes([
__DIR__.'/../public/' => public_path('vendor/anavel-crud/'),
], 'assets');

$this->publishes([
__DIR__.'/../config/anavel-crud.php' => config_path('anavel-crud.php'),
], 'config');
$this->publishes([__DIR__.'/../public/' => public_path('vendor/anavel-crud/')], 'assets');
$this->publishes([__DIR__.'/../config/anavel-crud.php' => config_path('anavel-crud.php')], 'config');
}

/**
Expand All @@ -59,48 +54,36 @@ public function register()
if (!self::isAnavel()) {
return;
}

$this->mergeConfigFrom(__DIR__.'/../config/anavel-crud.php', 'anavel-crud');

$this->app->register('ANavallaSuiza\Laravel\Database\Manager\ModelManagerServiceProvider');

$this->app->bind(
'Anavel\Crud\Contracts\Abstractor\FieldFactory',
function () {
return new FieldAbstractorFactory(new FormFactory());
}
);

$this->app->bind(
'Anavel\Crud\Contracts\Abstractor\RelationFactory',
function () {
return new RelationAbstractorFactory(
$this->app['ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'],
$this->app['Anavel\Crud\Contracts\Abstractor\FieldFactory']
);
}
);

$this->app->bind(
'Anavel\Crud\Contracts\Abstractor\ModelFactory',
function () {
return new ModelAbstractorFactory(
config('anavel-crud.models'),
$this->app['ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'],
$this->app['Anavel\Crud\Contracts\Abstractor\RelationFactory'],
$this->app['Anavel\Crud\Contracts\Abstractor\FieldFactory'],
$this->app['Anavel\Crud\Contracts\Form\Generator'],
$this->app['Anavel\Foundation\Contracts\Anavel']
);
}
);

$this->app->bind(
'Anavel\Crud\Contracts\Form\Generator',
function () {
return new FormGenerator(new FormFactory());
}
);
$this->app->bind('Anavel\Crud\Contracts\Abstractor\FieldFactory', function () {
return new FieldAbstractorFactory(new FormFactory());
});

$this->app->bind('Anavel\Crud\Contracts\Abstractor\RelationFactory', function () {
return new RelationAbstractorFactory(
$this->app['ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'],
$this->app['Anavel\Crud\Contracts\Abstractor\FieldFactory']
);
});

$this->app->bind('Anavel\Crud\Contracts\Abstractor\ModelFactory', function () {
return new ModelAbstractorFactory(
config('anavel-crud.models'),
$this->app['ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'],
$this->app['Anavel\Crud\Contracts\Abstractor\RelationFactory'],
$this->app['Anavel\Crud\Contracts\Abstractor\FieldFactory'],
$this->app['Anavel\Crud\Contracts\Form\Generator'],
$this->app['Anavel\Foundation\Contracts\Anavel']
);
});

$this->app->bind('Anavel\Crud\Contracts\Form\Generator', function () {
return new FormGenerator(new FormFactory());
});

$this->app->register('Anavel\Crud\Providers\ViewComposersServiceProvider');

Expand Down Expand Up @@ -144,19 +127,17 @@ public function sidebarMenu()

public function isActive()
{
$uri = Request::route()->uri();

return self::isAnavel() && (strpos($uri, 'crud') !== false);
return self::isAnavel() && (strpos(Request::route()->uri(), 'crud') !== false);
}

/**
* Registers types that Doctrine doesn's support by default.
*/
protected function registerDoctrineTypeMappings()
{
$connection = Schema::getConnection();
$platform = $connection->getDoctrineConnection()->getDatabasePlatform();

$platform->registerDoctrineTypeMapping('enum', 'string');
Schema::getConnection()
->getDoctrineConnection()
->getDatabasePlatform()
->registerDoctrineTypeMapping('enum', 'string');
}
}
5 changes: 1 addition & 4 deletions src/Repository/Criteria/SearchCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(array $columns, $queryString)

public function apply($model, Repository $repository)
{
$query = $model->where(function ($query) use ($repository) {
return $model->where(function ($query) {
$firstColumn = array_shift($this->columns);

if (strpos($firstColumn, '.')) {
Expand All @@ -35,14 +35,11 @@ public function apply($model, Repository $repository)
}
}
});

return $query;
}

private function setRelationFieldCondition($query, $column, $or = true)
{
$columnRelation = explode('.', $column);

$firstRelation = array_shift($columnRelation);

if ($or) {
Expand Down
4 changes: 1 addition & 3 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ function uniqueSlugify($text)
*/
function transcrud($text)
{
$translation = trans('anavel-crud::models.'.$text);

return str_replace('anavel-crud::models.', '', $translation);
return str_replace('anavel-crud::models.', '', trans('anavel-crud::models.'.$text));
}
}

0 comments on commit 6889702

Please sign in to comment.