Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 50 additions & 50 deletions config/filterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@
|
*/
'direction_map' => [
'asc' => 'asc',
'desc' => 'desc',
'asc' => 'asc',
'desc' => 'desc',
'prefix' => '-', // "-field" = desc
],

Expand Down Expand Up @@ -247,17 +247,17 @@
|
*/
'allowed_operators' => [
'eq' => '=',
'neq' => '!=',
'gt' => '>',
'lt' => '<',
'gte' => '>=',
'lte' => '<=',
'like' => 'like',
'nlike' => 'not like',
'in' => 'in',
'nin' => 'not in',
'null' => 'is null',
'eq' => '=',
'neq' => '!=',
'gt' => '>',
'lt' => '<',
'gte' => '>=',
'lte' => '<=',
'like' => 'like',
'nlike' => 'not like',
'in' => 'in',
'nin' => 'not in',
'null' => 'is null',
'notnull' => 'is not null',
'between' => 'between',
],
Expand Down Expand Up @@ -295,17 +295,17 @@
|
*/
'allowed_operators' => [
'eq' => '=',
'neq' => '!=',
'gt' => '>',
'lt' => '<',
'gte' => '>=',
'lte' => '<=',
'like' => 'like',
'nlike' => 'not like',
'in' => 'in',
'nin' => 'not in',
'null' => 'is null',
'eq' => '=',
'neq' => '!=',
'gt' => '>',
'lt' => '<',
'gte' => '>=',
'lte' => '<=',
'like' => 'like',
'nlike' => 'not like',
'in' => 'in',
'nin' => 'not in',
'null' => 'is null',
'notnull' => 'is not null',
'between' => 'between',
],
Expand Down Expand Up @@ -394,17 +394,17 @@
|
*/
'allowed_operators' => [
'eq' => '=',
'neq' => '!=',
'gt' => '>',
'lt' => '<',
'gte' => '>=',
'lte' => '<=',
'like' => 'like',
'nlike' => 'not like',
'in' => 'in',
'nin' => 'not in',
'null' => 'is null',
'eq' => '=',
'neq' => '!=',
'gt' => '>',
'lt' => '<',
'gte' => '>=',
'lte' => '<=',
'like' => 'like',
'nlike' => 'not like',
'in' => 'in',
'nin' => 'not in',
'null' => 'is null',
'notnull' => 'is not null',
'between' => 'between',
],
Expand Down Expand Up @@ -461,17 +461,17 @@
|
*/
'allowed_operators' => [
'eq' => '=',
'neq' => '!=',
'gt' => '>',
'lt' => '<',
'gte' => '>=',
'lte' => '<=',
'like' => 'like',
'nlike' => 'not like',
'in' => 'in',
'nin' => 'not in',
'null' => 'is null',
'eq' => '=',
'neq' => '!=',
'gt' => '>',
'lt' => '<',
'gte' => '>=',
'lte' => '<=',
'like' => 'like',
'nlike' => 'not like',
'in' => 'in',
'nin' => 'not in',
'null' => 'is null',
'notnull' => 'is not null',
'between' => 'between',
],
Expand Down Expand Up @@ -527,7 +527,7 @@
|
*/
'normalize_keys' => false,
]
],
],

/*
Expand Down Expand Up @@ -842,7 +842,7 @@
*/
'auto_invalidate' => [
'enabled' => env('FILTERABLE_AUTO_INVALIDATE', false),
'models' => [
'models' => [
// Define model-to-tags mappings here
],
],
Expand All @@ -857,7 +857,7 @@
|
*/
'tracking' => [
'enabled' => env('FILTERABLE_CACHE_TRACKING', false),
'enabled' => env('FILTERABLE_CACHE_TRACKING', false),
'log_channel' => env('FILTERABLE_CACHE_LOG_CHANNEL', 'daily'),
],
],
Expand Down Expand Up @@ -900,5 +900,5 @@
|
*/
'strict' => env('FILTERABLE_EXCEPTION_STRICT', false),
]
],
];
80 changes: 40 additions & 40 deletions database/migrations/CreateProfilerTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@

namespace Kettasoft\Filterable\Database\Migrations;

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProfilerTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('profiler', function (Blueprint $table) {
$table->id();
$table->text('query');
$table->integer('execution_time');
$table->integer('memory_usage');
$table->string('status')->default('success'); // 'success' or 'error'
$table->text('error_message')->nullable(); // For storing error messages if any
$table->string('connection_name')->nullable(); // For multi-connection support
$table->string('model_class')->nullable(); // For storing the model class if applicable
$table->string('query_type')->nullable(); // For storing the type of query (e.g., 'select', 'insert', 'update', 'delete')
$table->string('user_id')->nullable(); // For storing the user ID if applicable
$table->string('ip_address')->nullable(); // For storing the IP address of the user executing the query
$table->string('session_id')->nullable(); // For storing the session ID if applicable
$table->timestamp('executed_at')->useCurrent(); // Timestamp for when the query was executed
$table->string('environment')->nullable(); // For storing the environment (e.g., 'production', 'development', 'testing')
$table->string('application_version')->nullable(); // For storing the application version if applicable
$table->string('query_hash')->nullable(); // For storing a hash of the query for quick lookups
$table->string('request_method')->nullable(); // For storing the HTTP request method (e.g., 'GET', 'POST')
$table->string('request_uri')->nullable(); // For storing the request URI
$table->timestamps();
});
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('profiler', function (Blueprint $table) {
$table->id();
$table->text('query');
$table->integer('execution_time');
$table->integer('memory_usage');
$table->string('status')->default('success'); // 'success' or 'error'
$table->text('error_message')->nullable(); // For storing error messages if any
$table->string('connection_name')->nullable(); // For multi-connection support
$table->string('model_class')->nullable(); // For storing the model class if applicable
$table->string('query_type')->nullable(); // For storing the type of query (e.g., 'select', 'insert', 'update', 'delete')
$table->string('user_id')->nullable(); // For storing the user ID if applicable
$table->string('ip_address')->nullable(); // For storing the IP address of the user executing the query
$table->string('session_id')->nullable(); // For storing the session ID if applicable
$table->timestamp('executed_at')->useCurrent(); // Timestamp for when the query was executed
$table->string('environment')->nullable(); // For storing the environment (e.g., 'production', 'development', 'testing')
$table->string('application_version')->nullable(); // For storing the application version if applicable
$table->string('query_hash')->nullable(); // For storing a hash of the query for quick lookups
$table->string('request_method')->nullable(); // For storing the HTTP request method (e.g., 'GET', 'POST')
$table->string('request_uri')->nullable(); // For storing the request URI
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('profiler');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('profiler');
}
}
31 changes: 24 additions & 7 deletions src/Commands/Concerns/CommandHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ trait CommandHelpers
*
* @param string $highlighter
* @param string $color
*
* @return string
*/
protected function highlight(string $highlighter, string $color): string
Expand All @@ -27,7 +28,9 @@ protected function highlight(string $highlighter, string $color): string
protected function getFilters(): array
{
$filtersPath = app_path('Http/Filters');
if (!File::isDirectory($filtersPath)) return [];
if (!File::isDirectory($filtersPath)) {
return [];
}

$classes = [];
foreach (File::allFiles($filtersPath) as $file) {
Expand All @@ -36,37 +39,43 @@ protected function getFilters(): array
$classes[] = $class;
}
}

return $classes;
}

/**
* Convert a file path to a fully qualified class name.
*
* @param string $path
*
* @return string
*/
protected function pathToClass($path): string
{
$relative = str_replace([app_path() . '/', '.php'], '', $path);
return 'App\\' . str_replace('/', '\\', $relative);
$relative = str_replace([app_path().'/', '.php'], '', $path);

return 'App\\'.str_replace('/', '\\', $relative);
}

/**
* Get the model associated with the filter.
*
* @param mixed $filter
*
* @return string
*/
protected function getModel($filter): string
{
$model = class_basename($filter->getModel()) ?: "N/A";
$model = class_basename($filter->getModel()) ?: 'N/A';

return method_exists($filter, 'getModel') ? $model : '-';
}

/**
* Get the engine associated with the filter.
*
* @param mixed $filter
*
* @return string
*/
protected function getEngine($filter): string
Expand All @@ -78,6 +87,7 @@ protected function getEngine($filter): string
* Get the provided data keys from the filter.
*
* @param mixed $filter
*
* @return array
*/
protected function getProvidedData($filter): array
Expand All @@ -91,21 +101,28 @@ protected function getProvidedData($filter): array
* Resolve the Filterable class from input.
*
* @param string $input
*
* @return string|null
*/
protected function resolveFilterClass(string $input): ?string
{
// If fully qualified, just return
if (class_exists($input)) return $input;
if (class_exists($input)) {
return $input;
}

// Try with App\Filters namespace
$guessed = "App\\Filters\\{$input}";
if (class_exists($guessed)) return $guessed;
if (class_exists($guessed)) {
return $guessed;
}

// Try with configured namespace
$namespace = config('filterable.namespace', 'App\\Filters');
$alt = sprintf('%s\\%s', rtrim($namespace, '\\'), $input);
if (class_exists($alt)) return $alt;
if (class_exists($alt)) {
return $alt;
}

return null;
}
Expand Down
Loading
Loading