Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Encore\Admin\Grid; use Encore\Admin\Grid; use Encore\Admin\Middleware\Pja..

Decoded Output download

<?php
 namespace Encore\Admin\Grid; use Encore\Admin\Grid; use Encore\Admin\Middleware\Pjax; use Illuminate\Database\Eloquent\Model as EloquentModel; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Query\Expression; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Request; use Illuminate\Support\Str; class Model { protected $model; protected $originalModel; protected $queries; protected $sort; protected $data = array(); protected $perPage = 20; protected $usePaginate = true; protected $perPageName = "per_page"; protected $sortName = "_sort"; protected $collectionCallback; protected $grid; protected $relation; public function __construct(EloquentModel $model, Grid $grid = null) { $this->model = $model; $this->originalModel = $model; $this->grid = $grid; $this->queries = collect(); } public function getOriginalModel() { return $this->originalModel; } public function eloquent() { return $this->model; } public function usePaginate($use = true) { $this->usePaginate = $use; } public function getPerPageName() { return $this->perPageName; } public function setPerPageName($name) { $this->perPageName = $name; return $this; } public function getPerPage() { return $this->perPage; } public function setPerPage($perPage) { $this->perPage = $perPage; $this->__call("paginate", array($perPage)); return $this; } public function getSortName() { return $this->sortName; } public function setSortName($name) { $this->sortName = $name; return $this; } public function setGrid(Grid $grid) { $this->grid = $grid; return $this; } public function getGrid() { return $this->grid; } public function setRelation(Relation $relation) { $this->relation = $relation; return $this; } public function getRelation() { return $this->relation; } public function getConstraints() { if ($this->relation instanceof HasMany) { return array($this->relation->getForeignKeyName() => $this->relation->getParentKey()); } return false; } public function collection(\Closure $callback = null) { $this->collectionCallback = $callback; return $this; } public function buildData($toArray = true) { if (empty($this->data)) { $collection = $this->get(); if ($this->collectionCallback) { $collection = call_user_func($this->collectionCallback, $collection); } if ($toArray) { $this->data = $collection->toArray(); } else { $this->data = $collection; } } return $this->data; } public function chunk($callback, $count = 100) { if ($this->usePaginate) { return $this->buildData(false)->chunk($count)->each($callback); } $this->setSort(); $this->queries->reject(function ($query) { return $query["method"] == "paginate"; })->each(function ($query) { $this->model = $this->model->{$query["method"]}(...$query["arguments"]); }); return $this->model->chunk($count, $callback); } public function addConditions(array $conditions) { foreach ($conditions as $condition) { call_user_func_array(array($this, key($condition)), current($condition)); } return $this; } public function getTable() { return $this->model->getTable(); } protected function get() { if ($this->model instanceof LengthAwarePaginator) { return $this->model; } if ($this->relation) { $this->model = $this->relation; } $this->setSort(); $this->setPaginate(); $this->queries->unique()->each(function ($query) { $this->model = call_user_func_array(array($this->model, $query["method"]), $query["arguments"]); }); if ($this->model instanceof Collection) { return $this->model; } if ($this->model instanceof LengthAwarePaginator) { $this->handleInvalidPage($this->model); return $this->model->getCollection(); } throw new \Exception("Grid query error"); } public function getQueryBuilder() { if ($this->relation) { return $this->relation->getQuery(); } $this->setSort(); $queryBuilder = $this->originalModel; $this->queries->reject(function ($query) { return in_array($query["method"], array("get", "paginate")); })->each(function ($query) use(&$queryBuilder) { $queryBuilder = $queryBuilder->{$query["method"]}(...$query["arguments"]); }); return $queryBuilder; } protected function handleInvalidPage(LengthAwarePaginator $paginator) { if ($paginator->lastPage() && $paginator->currentPage() > $paginator->lastPage()) { $lastPageUrl = Request::fullUrlWithQuery(array($paginator->getPageName() => $paginator->lastPage())); Pjax::respond(redirect($lastPageUrl)); } } protected function setPaginate() { $paginate = $this->findQueryByMethod("paginate"); $this->queries = $this->queries->reject(function ($query) { return $query["method"] == "paginate"; }); if (!$this->usePaginate) { $query = array("method" => "get", "arguments" => array()); } else { $query = array("method" => "paginate", "arguments" => $this->resolvePerPage($paginate)); } $this->queries->push($query); } protected function resolvePerPage($paginate) { if ($perPage = request($this->perPageName)) { if (is_array($paginate)) { $paginate["arguments"][0] = (int) $perPage; return $paginate["arguments"]; } $this->perPage = (int) $perPage; } if (isset($paginate["arguments"][0])) { return $paginate["arguments"]; } if ($name = $this->grid->getName()) { return array($this->perPage, array("*"), "{$name}_page"); } return array($this->perPage); } protected function findQueryByMethod($method) { return $this->queries->first(function ($query) use($method) { return $query["method"] == $method; }); } protected function setSort() { $this->sort = 
equest($this->sortName, array()); if (!is_array($this->sort)) { return; } $columnName = $this->sort["column"] ?? null; if ($columnName === null || empty($this->sort["type"])) { return; } $columnNameContainsDots = Str::contains($columnName, "."); $isRelation = $this->queries->contains(function ($query) use($columnName) { $columnName = Str::camel(Str::before($columnName, ".")); return $query["method"] === "with" && in_array($columnName, $query["arguments"], true); }); if ($columnNameContainsDots === true && $isRelation) { $this->setRelationSort($columnName); } else { $this->resetOrderBy(); if ($columnNameContainsDots === true) { $this->resetOrderBy(); $explodedCols = explode(".", $this->sort["column"]); $col = array_shift($explodedCols); $parts = implode(".", $explodedCols); $columnName = "JSON_EXTRACT({$col}, '$.{$parts}')"; } if (!empty($this->sort["cast"])) { $column = "CAST({$columnName} AS {$this->sort["cast"]}) {$this->sort["type"]}"; $method = "orderByRaw"; $arguments = array($column); } else { $column = $columnNameContainsDots ? new Expression($columnName) : $columnName; $method = "orderBy"; $arguments = array($column, $this->sort["type"]); } $this->queries->push(array("method" => $method, "arguments" => $arguments)); } } protected function setRelationSort($column) { list($relationName, $relationColumn) = explode(".", $column); $relationName = Str::camel($relationName); if ($this->queries->contains(function ($query) use($relationName) { return $query["method"] == "with" && in_array($relationName, $query["arguments"]); })) { $relation = $this->model->{$relationName}(); $this->queries->push(array("method" => "select", "arguments" => array($this->model->getTable() . ".*"))); $this->queries->push(array("method" => "join", "arguments" => $this->joinParameters($relation))); $this->resetOrderBy(); $this->queries->push(array("method" => "orderBy", "arguments" => array($relation->getRelated()->getTable() . "." . $relationColumn, $this->sort["type"]))); } } public function resetOrderBy() { $this->queries = $this->queries->reject(function ($query) { return $query["method"] == "orderBy" || $query["method"] == "orderByDesc"; }); } protected function joinParameters(Relation $relation) { $relatedTable = $relation->getRelated()->getTable(); if ($relation instanceof BelongsTo) { $foreignKeyMethod = version_compare(app()->version(), "5.8.0", "<") ? "getForeignKey" : "getForeignKeyName"; return array($relatedTable, $relation->{$foreignKeyMethod}(), "=", $relatedTable . "." . $relation->getRelated()->getKeyName()); } if ($relation instanceof HasOne) { return array($relatedTable, $relation->getQualifiedParentKeyName(), "=", $relation->getQualifiedForeignKeyName()); } throw new \Exception("Related sortable only support `HasOne` and `BelongsTo` relation."); } public function __call($method, $arguments) { $this->queries->push(array("method" => $method, "arguments" => $arguments)); return $this; } public function __get($key) { $data = $this->buildData(); if (array_key_exists($key, $data)) { return $data[$key]; } } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace Encore\Admin\Grid; use Encore\Admin\Grid; use Encore\Admin\Middleware\Pjax; use Illuminate\Database\Eloquent\Model as EloquentModel; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Query\Expression; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Request; use Illuminate\Support\Str; class Model { protected $model; protected $originalModel; protected $queries; protected $sort; protected $data = array(); protected $perPage = 20; protected $usePaginate = true; protected $perPageName = "\x70\145\162\137\x70\141\147\145"; protected $sortName = "\137\x73\157\162\x74"; protected $collectionCallback; protected $grid; protected $relation; public function __construct(EloquentModel $model, Grid $grid = null) { $this->model = $model; $this->originalModel = $model; $this->grid = $grid; $this->queries = collect(); } public function getOriginalModel() { return $this->originalModel; } public function eloquent() { return $this->model; } public function usePaginate($use = true) { $this->usePaginate = $use; } public function getPerPageName() { return $this->perPageName; } public function setPerPageName($name) { $this->perPageName = $name; return $this; } public function getPerPage() { return $this->perPage; } public function setPerPage($perPage) { $this->perPage = $perPage; $this->__call("\x70\141\x67\x69\x6e\141\164\x65", array($perPage)); return $this; } public function getSortName() { return $this->sortName; } public function setSortName($name) { $this->sortName = $name; return $this; } public function setGrid(Grid $grid) { $this->grid = $grid; return $this; } public function getGrid() { return $this->grid; } public function setRelation(Relation $relation) { $this->relation = $relation; return $this; } public function getRelation() { return $this->relation; } public function getConstraints() { if ($this->relation instanceof HasMany) { return array($this->relation->getForeignKeyName() => $this->relation->getParentKey()); } return false; } public function collection(\Closure $callback = null) { $this->collectionCallback = $callback; return $this; } public function buildData($toArray = true) { if (empty($this->data)) { $collection = $this->get(); if ($this->collectionCallback) { $collection = call_user_func($this->collectionCallback, $collection); } if ($toArray) { $this->data = $collection->toArray(); } else { $this->data = $collection; } } return $this->data; } public function chunk($callback, $count = 100) { if ($this->usePaginate) { return $this->buildData(false)->chunk($count)->each($callback); } $this->setSort(); $this->queries->reject(function ($query) { return $query["\x6d\145\164\150\x6f\144"] == "\160\x61\x67\151\156\x61\x74\x65"; })->each(function ($query) { $this->model = $this->model->{$query["\155\x65\x74\x68\x6f\144"]}(...$query["\141\162\147\x75\155\x65\x6e\x74\163"]); }); return $this->model->chunk($count, $callback); } public function addConditions(array $conditions) { foreach ($conditions as $condition) { call_user_func_array(array($this, key($condition)), current($condition)); } return $this; } public function getTable() { return $this->model->getTable(); } protected function get() { if ($this->model instanceof LengthAwarePaginator) { return $this->model; } if ($this->relation) { $this->model = $this->relation; } $this->setSort(); $this->setPaginate(); $this->queries->unique()->each(function ($query) { $this->model = call_user_func_array(array($this->model, $query["\155\145\x74\150\157\144"]), $query["\141\x72\147\x75\155\x65\x6e\164\163"]); }); if ($this->model instanceof Collection) { return $this->model; } if ($this->model instanceof LengthAwarePaginator) { $this->handleInvalidPage($this->model); return $this->model->getCollection(); } throw new \Exception("\107\162\x69\144\40\x71\165\145\x72\171\40\x65\162\162\x6f\162"); } public function getQueryBuilder() { if ($this->relation) { return $this->relation->getQuery(); } $this->setSort(); $queryBuilder = $this->originalModel; $this->queries->reject(function ($query) { return in_array($query["\x6d\145\164\150\157\x64"], array("\147\x65\164", "\x70\141\147\151\x6e\141\x74\145")); })->each(function ($query) use(&$queryBuilder) { $queryBuilder = $queryBuilder->{$query["\155\x65\x74\150\157\144"]}(...$query["\x61\162\147\x75\155\145\x6e\164\163"]); }); return $queryBuilder; } protected function handleInvalidPage(LengthAwarePaginator $paginator) { if ($paginator->lastPage() && $paginator->currentPage() > $paginator->lastPage()) { $lastPageUrl = Request::fullUrlWithQuery(array($paginator->getPageName() => $paginator->lastPage())); Pjax::respond(redirect($lastPageUrl)); } } protected function setPaginate() { $paginate = $this->findQueryByMethod("\x70\x61\x67\x69\x6e\x61\164\x65"); $this->queries = $this->queries->reject(function ($query) { return $query["\155\x65\164\x68\x6f\x64"] == "\x70\x61\147\x69\156\x61\164\x65"; }); if (!$this->usePaginate) { $query = array("\x6d\145\x74\x68\157\144" => "\147\x65\x74", "\141\162\x67\165\155\145\156\164\163" => array()); } else { $query = array("\x6d\145\164\x68\157\x64" => "\x70\x61\x67\151\x6e\x61\x74\145", "\x61\162\x67\165\x6d\x65\156\x74\x73" => $this->resolvePerPage($paginate)); } $this->queries->push($query); } protected function resolvePerPage($paginate) { if ($perPage = request($this->perPageName)) { if (is_array($paginate)) { $paginate["\x61\162\x67\x75\155\x65\x6e\x74\163"][0] = (int) $perPage; return $paginate["\x61\162\147\165\155\x65\156\164\x73"]; } $this->perPage = (int) $perPage; } if (isset($paginate["\x61\x72\x67\x75\x6d\x65\156\x74\x73"][0])) { return $paginate["\141\x72\x67\x75\x6d\145\156\x74\163"]; } if ($name = $this->grid->getName()) { return array($this->perPage, array("\x2a"), "{$name}\137\x70\x61\147\145"); } return array($this->perPage); } protected function findQueryByMethod($method) { return $this->queries->first(function ($query) use($method) { return $query["\155\x65\164\x68\157\x64"] == $method; }); } protected function setSort() { $this->sort = \request($this->sortName, array()); if (!is_array($this->sort)) { return; } $columnName = $this->sort["\143\157\x6c\165\x6d\x6e"] ?? null; if ($columnName === null || empty($this->sort["\164\171\x70\x65"])) { return; } $columnNameContainsDots = Str::contains($columnName, "\x2e"); $isRelation = $this->queries->contains(function ($query) use($columnName) { $columnName = Str::camel(Str::before($columnName, "\x2e")); return $query["\155\x65\x74\150\157\144"] === "\167\x69\x74\150" && in_array($columnName, $query["\x61\x72\x67\x75\x6d\145\156\x74\x73"], true); }); if ($columnNameContainsDots === true && $isRelation) { $this->setRelationSort($columnName); } else { $this->resetOrderBy(); if ($columnNameContainsDots === true) { $this->resetOrderBy(); $explodedCols = explode("\x2e", $this->sort["\143\x6f\x6c\x75\x6d\x6e"]); $col = array_shift($explodedCols); $parts = implode("\x2e", $explodedCols); $columnName = "\112\123\x4f\116\137\105\130\124\x52\101\x43\x54\50{$col}\x2c\x20\47\x24\56{$parts}\47\51"; } if (!empty($this->sort["\x63\x61\163\164"])) { $column = "\x43\101\123\124\x28{$columnName}\x20\x41\123\x20{$this->sort["\143\141\163\x74"]}\51\40{$this->sort["\x74\171\160\x65"]}"; $method = "\x6f\162\x64\x65\162\x42\171\122\141\x77"; $arguments = array($column); } else { $column = $columnNameContainsDots ? new Expression($columnName) : $columnName; $method = "\x6f\162\x64\145\162\102\x79"; $arguments = array($column, $this->sort["\164\171\x70\x65"]); } $this->queries->push(array("\x6d\145\164\x68\157\144" => $method, "\141\x72\147\165\x6d\145\156\164\163" => $arguments)); } } protected function setRelationSort($column) { list($relationName, $relationColumn) = explode("\x2e", $column); $relationName = Str::camel($relationName); if ($this->queries->contains(function ($query) use($relationName) { return $query["\x6d\x65\164\150\157\144"] == "\167\151\x74\150" && in_array($relationName, $query["\141\162\147\x75\155\145\156\x74\163"]); })) { $relation = $this->model->{$relationName}(); $this->queries->push(array("\155\x65\x74\150\x6f\x64" => "\163\x65\x6c\145\143\164", "\x61\162\147\x75\x6d\x65\x6e\x74\x73" => array($this->model->getTable() . "\x2e\x2a"))); $this->queries->push(array("\155\145\x74\150\x6f\x64" => "\152\x6f\x69\x6e", "\x61\162\x67\165\155\145\156\164\163" => $this->joinParameters($relation))); $this->resetOrderBy(); $this->queries->push(array("\x6d\x65\x74\x68\x6f\x64" => "\x6f\162\x64\145\x72\x42\x79", "\x61\x72\x67\165\155\x65\x6e\x74\x73" => array($relation->getRelated()->getTable() . "\x2e" . $relationColumn, $this->sort["\164\171\160\145"]))); } } public function resetOrderBy() { $this->queries = $this->queries->reject(function ($query) { return $query["\x6d\145\x74\x68\x6f\144"] == "\x6f\162\144\x65\x72\x42\x79" || $query["\155\x65\164\x68\x6f\x64"] == "\157\x72\144\x65\x72\x42\x79\104\x65\x73\143"; }); } protected function joinParameters(Relation $relation) { $relatedTable = $relation->getRelated()->getTable(); if ($relation instanceof BelongsTo) { $foreignKeyMethod = version_compare(app()->version(), "\65\x2e\70\x2e\x30", "\74") ? "\x67\145\x74\106\157\162\x65\151\147\156\113\x65\x79" : "\147\145\x74\106\x6f\x72\145\x69\147\156\113\145\171\x4e\141\155\x65"; return array($relatedTable, $relation->{$foreignKeyMethod}(), "\75", $relatedTable . "\56" . $relation->getRelated()->getKeyName()); } if ($relation instanceof HasOne) { return array($relatedTable, $relation->getQualifiedParentKeyName(), "\75", $relation->getQualifiedForeignKeyName()); } throw new \Exception("\x52\x65\154\x61\x74\145\144\x20\163\x6f\162\164\x61\142\x6c\x65\x20\157\156\154\171\x20\x73\165\x70\160\157\162\164\40\x60\x48\x61\163\x4f\x6e\145\140\x20\141\156\x64\x20\x60\102\x65\x6c\157\x6e\x67\163\x54\157\x60\40\162\145\x6c\141\164\151\157\156\56"); } public function __call($method, $arguments) { $this->queries->push(array("\155\x65\164\x68\x6f\144" => $method, "\x61\x72\147\x75\x6d\x65\x6e\164\163" => $arguments)); return $this; } public function __get($key) { $data = $this->buildData(); if (array_key_exists($key, $data)) { return $data[$key]; } } }

Function Calls

None

Variables

None

Stats

MD5 156a6de267d5c581d556b008638cc8ac
Eval Count 0
Decode Time 111 ms