@@ -4,10 +4,6 @@ |
||
| 4 | 4 | |
| 5 | 5 | use Illuminate\Database\Eloquent\ModelNotFoundException; |
| 6 | 6 | use Illuminate\Contracts\Validation\ValidationException; |
| 7 | -use Illuminate\Foundation\Bus\DispatchesCommands; |
|
| 8 | -use Illuminate\Foundation\Validation\ValidatesRequests; |
|
| 9 | -use Illuminate\Routing\Controller as BaseController; |
|
| 10 | - |
|
| 11 | 7 | use Chrisbjr\ApiGuard\Http\Controllers\ApiGuardController; |
| 12 | 8 | |
| 13 | 9 | abstract class ApiController extends ApiGuardController |
@@ -60,7 +60,7 @@ |
||
| 60 | 60 | */ |
| 61 | 61 | public function __construct() |
| 62 | 62 | { |
| 63 | - $this->response = \Response::api(); |
|
| 63 | + $this->response = \Response::api(); |
|
| 64 | 64 | |
| 65 | 65 | if (!empty($this->modelName)) { |
| 66 | 66 | $this->model = new $this->modelName; |
@@ -12,160 +12,160 @@ |
||
| 12 | 12 | |
| 13 | 13 | abstract class ApiController extends ApiGuardController |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Laraponse object, which abstracts Fractal |
|
| 17 | - * |
|
| 18 | - * @var EllipseSynergie\ApiResponse\Laravel\Response |
|
| 19 | - */ |
|
| 20 | - public $response; |
|
| 15 | + /** |
|
| 16 | + * Laraponse object, which abstracts Fractal |
|
| 17 | + * |
|
| 18 | + * @var EllipseSynergie\ApiResponse\Laravel\Response |
|
| 19 | + */ |
|
| 20 | + public $response; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * The string name of the Eloquen Model |
|
| 24 | - * |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected $modelName; |
|
| 22 | + /** |
|
| 23 | + * The string name of the Eloquen Model |
|
| 24 | + * |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected $modelName; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The Eloquent Model |
|
| 31 | - * |
|
| 32 | - * @var Illuminate\Database\Eloquent\Model |
|
| 33 | - */ |
|
| 34 | - protected $model; |
|
| 29 | + /** |
|
| 30 | + * The Eloquent Model |
|
| 31 | + * |
|
| 32 | + * @var Illuminate\Database\Eloquent\Model |
|
| 33 | + */ |
|
| 34 | + protected $model; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * The string name of the Transformer class |
|
| 38 | - * |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - protected $transformerName; |
|
| 36 | + /** |
|
| 37 | + * The string name of the Transformer class |
|
| 38 | + * |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + protected $transformerName; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * The name of the collection that is returned in the JSON response |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - protected $collectionName; |
|
| 43 | + /** |
|
| 44 | + * The name of the collection that is returned in the JSON response |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + protected $collectionName; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * The Fractal Manager |
|
| 52 | - * |
|
| 53 | - * @var \League\Fractal\Manager |
|
| 54 | - */ |
|
| 55 | - public $manager; |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Constructor |
|
| 60 | - */ |
|
| 61 | - public function __construct() |
|
| 62 | - { |
|
| 63 | - $this->response = \Response::api(); |
|
| 50 | + /** |
|
| 51 | + * The Fractal Manager |
|
| 52 | + * |
|
| 53 | + * @var \League\Fractal\Manager |
|
| 54 | + */ |
|
| 55 | + public $manager; |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Constructor |
|
| 60 | + */ |
|
| 61 | + public function __construct() |
|
| 62 | + { |
|
| 63 | + $this->response = \Response::api(); |
|
| 64 | 64 | |
| 65 | - if (!empty($this->modelName)) { |
|
| 66 | - $this->model = new $this->modelName; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - // if no collection name provided, use the model's table name |
|
| 70 | - if (empty($this->collectionName)) { |
|
| 71 | - $this->collectionName = $this->model->getTable(); |
|
| 72 | - } |
|
| 65 | + if (!empty($this->modelName)) { |
|
| 66 | + $this->model = new $this->modelName; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + // if no collection name provided, use the model's table name |
|
| 70 | + if (empty($this->collectionName)) { |
|
| 71 | + $this->collectionName = $this->model->getTable(); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - // parse includes |
|
| 75 | - if (\Input::get('include') != '') { |
|
| 76 | - $this->manager = new \League\Fractal\Manager; |
|
| 77 | - $this->manager->parseIncludes(explode(',', \Input::get('include'))); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - parent::__construct(); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Create an item |
|
| 85 | - * |
|
| 86 | - * @return \Illuminate\Http\JsonResponse |
|
| 87 | - */ |
|
| 88 | - public function create($data = null) |
|
| 89 | - { |
|
| 90 | - $data = $data ?: \Input::json()->all(); |
|
| 91 | - |
|
| 92 | - try { |
|
| 93 | - $this->model->validate($data); |
|
| 94 | - $item = $this->model->create($data); |
|
| 74 | + // parse includes |
|
| 75 | + if (\Input::get('include') != '') { |
|
| 76 | + $this->manager = new \League\Fractal\Manager; |
|
| 77 | + $this->manager->parseIncludes(explode(',', \Input::get('include'))); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + parent::__construct(); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Create an item |
|
| 85 | + * |
|
| 86 | + * @return \Illuminate\Http\JsonResponse |
|
| 87 | + */ |
|
| 88 | + public function create($data = null) |
|
| 89 | + { |
|
| 90 | + $data = $data ?: \Input::json()->all(); |
|
| 91 | + |
|
| 92 | + try { |
|
| 93 | + $this->model->validate($data); |
|
| 94 | + $item = $this->model->create($data); |
|
| 95 | 95 | |
| 96 | - return $this->showByObject($item); |
|
| 96 | + return $this->showByObject($item); |
|
| 97 | 97 | |
| 98 | - } catch (ValidationException $e) { |
|
| 99 | - return $this->response->setStatusCode(422)->withError($e->errors()->toArray(), 'GEN-UNPROCESSABLE-ENTITY'); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Returns a single item |
|
| 105 | - * |
|
| 106 | - * @param int $id |
|
| 107 | - * @return \Illuminate\Http\JsonResponse |
|
| 108 | - */ |
|
| 109 | - public function show($id) |
|
| 110 | - { |
|
| 111 | - try { |
|
| 98 | + } catch (ValidationException $e) { |
|
| 99 | + return $this->response->setStatusCode(422)->withError($e->errors()->toArray(), 'GEN-UNPROCESSABLE-ENTITY'); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Returns a single item |
|
| 105 | + * |
|
| 106 | + * @param int $id |
|
| 107 | + * @return \Illuminate\Http\JsonResponse |
|
| 108 | + */ |
|
| 109 | + public function show($id) |
|
| 110 | + { |
|
| 111 | + try { |
|
| 112 | 112 | |
| 113 | - return $this->response->withItem($this->model->findOrFail($id), new $this->transformerName); |
|
| 113 | + return $this->response->withItem($this->model->findOrFail($id), new $this->transformerName); |
|
| 114 | 114 | |
| 115 | - } catch (ModelNotFoundException $e) { |
|
| 116 | - |
|
| 117 | - return $this->respondNotFound(); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Returns a single item |
|
| 123 | - * |
|
| 124 | - * @param object $object |
|
| 125 | - * @return \Illuminate\Http\JsonResponse |
|
| 126 | - */ |
|
| 127 | - public function showByObject($object) |
|
| 128 | - { |
|
| 129 | - try { |
|
| 130 | - return $this->response->withItem($object, new $this->transformerName); |
|
| 115 | + } catch (ModelNotFoundException $e) { |
|
| 116 | + |
|
| 117 | + return $this->respondNotFound(); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Returns a single item |
|
| 123 | + * |
|
| 124 | + * @param object $object |
|
| 125 | + * @return \Illuminate\Http\JsonResponse |
|
| 126 | + */ |
|
| 127 | + public function showByObject($object) |
|
| 128 | + { |
|
| 129 | + try { |
|
| 130 | + return $this->response->withItem($object, new $this->transformerName); |
|
| 131 | 131 | |
| 132 | - } catch (ModelNotFoundException $e) { |
|
| 133 | - |
|
| 134 | - return $this->respondNotFound(); |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Returns a paginated collection |
|
| 140 | - * |
|
| 141 | - * @return \Illuminate\Http\JsonResponse |
|
| 142 | - */ |
|
| 143 | - public function collection() |
|
| 144 | - { |
|
| 145 | - $limit = \Input::get('limit') ?: 10; |
|
| 146 | - $model = $this->model; |
|
| 132 | + } catch (ModelNotFoundException $e) { |
|
| 133 | + |
|
| 134 | + return $this->respondNotFound(); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Returns a paginated collection |
|
| 140 | + * |
|
| 141 | + * @return \Illuminate\Http\JsonResponse |
|
| 142 | + */ |
|
| 143 | + public function collection() |
|
| 144 | + { |
|
| 145 | + $limit = \Input::get('limit') ?: 10; |
|
| 146 | + $model = $this->model; |
|
| 147 | 147 | |
| 148 | - if (\Request::has('order')) { |
|
| 149 | - list($orderCol, $orderBy) = explode('|', \Input::get('order')); |
|
| 150 | - $model = $model->orderBy($orderCol, $orderBy); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $this->response->withPaginator($model->paginate($limit), new $this->transformerName, $this->collectionName); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Handles 404 errors |
|
| 158 | - * |
|
| 159 | - * @param string $msg |
|
| 160 | - * @return \Illuminate\Http\JsonResponse |
|
| 161 | - */ |
|
| 162 | - public function respondNotFound($msg = 'Not found!') |
|
| 163 | - { |
|
| 164 | - return \Response::json([ |
|
| 165 | - 'error' => [ |
|
| 166 | - 'message' => $msg, |
|
| 167 | - 'status_code' => 404 |
|
| 168 | - ] |
|
| 169 | - ], 404); |
|
| 170 | - } |
|
| 148 | + if (\Request::has('order')) { |
|
| 149 | + list($orderCol, $orderBy) = explode('|', \Input::get('order')); |
|
| 150 | + $model = $model->orderBy($orderCol, $orderBy); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $this->response->withPaginator($model->paginate($limit), new $this->transformerName, $this->collectionName); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Handles 404 errors |
|
| 158 | + * |
|
| 159 | + * @param string $msg |
|
| 160 | + * @return \Illuminate\Http\JsonResponse |
|
| 161 | + */ |
|
| 162 | + public function respondNotFound($msg = 'Not found!') |
|
| 163 | + { |
|
| 164 | + return \Response::json([ |
|
| 165 | + 'error' => [ |
|
| 166 | + 'message' => $msg, |
|
| 167 | + 'status_code' => 404 |
|
| 168 | + ] |
|
| 169 | + ], 404); |
|
| 170 | + } |
|
| 171 | 171 | } |
| 172 | 172 | \ No newline at end of file |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | * Relationship to the api_key table |
| 44 | 44 | * |
| 45 | 45 | * @codeCoverageIgnore |
| 46 | - * @return Illuminate\Database\Eloquent\Relations\HasOne |
|
| 46 | + * @return \Illuminate\Database\Eloquent\Relations\HasOne |
|
| 47 | 47 | */ |
| 48 | 48 | public function apiKey() |
| 49 | 49 | { |
@@ -15,6 +15,6 @@ |
||
| 15 | 15 | Route::group(['prefix' => 'api/v1', 'namespace' => 'Api\V1'], function() |
| 16 | 16 | { |
| 17 | 17 | // users/auth |
| 18 | - Route::post('user/login', 'UserController@authenticate'); |
|
| 19 | - Route::get('user/logout/{api_key}', 'UserController@deauthenticate'); |
|
| 18 | + Route::post('user/login', 'UserController@authenticate'); |
|
| 19 | + Route::get('user/logout/{api_key}', 'UserController@deauthenticate'); |
|
| 20 | 20 | }); |
| 21 | 21 | \ No newline at end of file |
@@ -37,8 +37,7 @@ |
||
| 37 | 37 | if ($request->ajax()) |
| 38 | 38 | { |
| 39 | 39 | return response('Unauthorized.', 401); |
| 40 | - } |
|
| 41 | - else |
|
| 40 | + } else |
|
| 42 | 41 | { |
| 43 | 42 | return redirect()->guest('auth/login'); |
| 44 | 43 | } |
@@ -67,7 +67,7 @@ |
||
| 67 | 67 | $searchCols = $this->getSearchCols(null, static::$labelCol); |
| 68 | 68 | $select = array_merge([static::$labelCol], ['url']); |
| 69 | 69 | //$query->select('*', implode(' ', static::$labelCol) . ' as label', \DB::raw('concat("' . static::$urlPrepend . '",url) as url')); |
| 70 | - $query->select('*', implode(' ', static::$labelCol) . ' as label', 'url'); |
|
| 70 | + $query->select('*', implode(' ', static::$labelCol) . ' as label', 'url'); |
|
| 71 | 71 | $match = ''; |
| 72 | 72 | |
| 73 | 73 | // make search results use the "and" clause |
@@ -2,81 +2,81 @@ |
||
| 2 | 2 | |
| 3 | 3 | trait SearchTrait { |
| 4 | 4 | |
| 5 | - public static $labelCol = []; |
|
| 6 | - public static $searchCols = []; |
|
| 5 | + public static $labelCol = []; |
|
| 6 | + public static $searchCols = []; |
|
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * Adds search methods to the model |
|
| 10 | - * |
|
| 11 | - * @param string $keyword |
|
| 12 | - * @param string $labelCol |
|
| 13 | - * @return \BaseModel |
|
| 14 | - */ |
|
| 15 | - public function addSearch($keyword = null, $labelCol = null) |
|
| 16 | - { |
|
| 17 | - $searchCols = self::getSearchCols(null, $labelCol); |
|
| 18 | - $keyword = strtolower($keyword); |
|
| 8 | + /** |
|
| 9 | + * Adds search methods to the model |
|
| 10 | + * |
|
| 11 | + * @param string $keyword |
|
| 12 | + * @param string $labelCol |
|
| 13 | + * @return \BaseModel |
|
| 14 | + */ |
|
| 15 | + public function addSearch($keyword = null, $labelCol = null) |
|
| 16 | + { |
|
| 17 | + $searchCols = self::getSearchCols(null, $labelCol); |
|
| 18 | + $keyword = strtolower($keyword); |
|
| 19 | 19 | |
| 20 | - if ($searchCols && !is_null($keyword) && trim($keyword) != '') { |
|
| 20 | + if ($searchCols && !is_null($keyword) && trim($keyword) != '') { |
|
| 21 | 21 | |
| 22 | - return self::orWhere(function($query) use ($searchCols, $keyword) |
|
| 23 | - { |
|
| 24 | - foreach ($searchCols as $key=>$val) { |
|
| 25 | - $query->orWhere($val, 'like', "%{$keyword}%"); |
|
| 26 | - } |
|
| 27 | - }); |
|
| 28 | - } else { |
|
| 29 | - return $this; |
|
| 30 | - } |
|
| 31 | - } |
|
| 22 | + return self::orWhere(function($query) use ($searchCols, $keyword) |
|
| 23 | + { |
|
| 24 | + foreach ($searchCols as $key=>$val) { |
|
| 25 | + $query->orWhere($val, 'like', "%{$keyword}%"); |
|
| 26 | + } |
|
| 27 | + }); |
|
| 28 | + } else { |
|
| 29 | + return $this; |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Retrieves the columns to search |
|
| 35 | - * |
|
| 36 | - * @param string $override |
|
| 37 | - * @param string $default |
|
| 38 | - * @return array |
|
| 39 | - */ |
|
| 40 | - public function getSearchCols($override = null, $default = null) |
|
| 41 | - { |
|
| 42 | - if (!is_null($override)) { |
|
| 43 | - $searchCols = $override; |
|
| 44 | - } else if (!is_null(static::$searchCols)) { |
|
| 45 | - $searchCols = static::$searchCols; |
|
| 46 | - } else if (!is_null(static::$labelCol)) { |
|
| 47 | - $searchCols = static::$labelCol; |
|
| 48 | - } else if (!is_null($default)) { |
|
| 49 | - $searchCols = $default; |
|
| 50 | - } else { |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 33 | + /** |
|
| 34 | + * Retrieves the columns to search |
|
| 35 | + * |
|
| 36 | + * @param string $override |
|
| 37 | + * @param string $default |
|
| 38 | + * @return array |
|
| 39 | + */ |
|
| 40 | + public function getSearchCols($override = null, $default = null) |
|
| 41 | + { |
|
| 42 | + if (!is_null($override)) { |
|
| 43 | + $searchCols = $override; |
|
| 44 | + } else if (!is_null(static::$searchCols)) { |
|
| 45 | + $searchCols = static::$searchCols; |
|
| 46 | + } else if (!is_null(static::$labelCol)) { |
|
| 47 | + $searchCols = static::$labelCol; |
|
| 48 | + } else if (!is_null($default)) { |
|
| 49 | + $searchCols = $default; |
|
| 50 | + } else { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - return (array) $searchCols; |
|
| 55 | - } |
|
| 54 | + return (array) $searchCols; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Eloquent scope of the search |
|
| 59 | - * |
|
| 60 | - * @param Illuminate\Database\Eloquent\Builder $query |
|
| 61 | - * @param string $keyword |
|
| 62 | - * @return Illuminate\Database\Eloquent\Builder |
|
| 63 | - */ |
|
| 64 | - public function scopeSearch($query, $keyword = null) |
|
| 65 | - { |
|
| 66 | - $searchCols = $this->getSearchCols(null, static::$labelCol); |
|
| 67 | - $query->select('*', implode(' ', static::$labelCol) . ' as label', 'url'); |
|
| 68 | - $match = ''; |
|
| 57 | + /** |
|
| 58 | + * Eloquent scope of the search |
|
| 59 | + * |
|
| 60 | + * @param Illuminate\Database\Eloquent\Builder $query |
|
| 61 | + * @param string $keyword |
|
| 62 | + * @return Illuminate\Database\Eloquent\Builder |
|
| 63 | + */ |
|
| 64 | + public function scopeSearch($query, $keyword = null) |
|
| 65 | + { |
|
| 66 | + $searchCols = $this->getSearchCols(null, static::$labelCol); |
|
| 67 | + $query->select('*', implode(' ', static::$labelCol) . ' as label', 'url'); |
|
| 68 | + $match = ''; |
|
| 69 | 69 | |
| 70 | - // make search results use the "and" clause |
|
| 71 | - $keyword[0] = '"' . $keyword[0] . '"'; |
|
| 70 | + // make search results use the "and" clause |
|
| 71 | + $keyword[0] = '"' . $keyword[0] . '"'; |
|
| 72 | 72 | |
| 73 | - if (is_array($searchCols)) { |
|
| 74 | - foreach ($searchCols as $searchCol) { |
|
| 75 | - $match = "MATCH(" . $searchCol . ") AGAINST (? IN BOOLEAN MODE)"; |
|
| 76 | - $query = $query->whereRaw($match, $keyword); |
|
| 77 | - } |
|
| 78 | - } |
|
| 73 | + if (is_array($searchCols)) { |
|
| 74 | + foreach ($searchCols as $searchCol) { |
|
| 75 | + $match = "MATCH(" . $searchCol . ") AGAINST (? IN BOOLEAN MODE)"; |
|
| 76 | + $query = $query->whereRaw($match, $keyword); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - return $query->orderByRaw($match . ' desc', $keyword); |
|
| 81 | - } |
|
| 80 | + return $query->orderByRaw($match . ' desc', $keyword); |
|
| 81 | + } |
|
| 82 | 82 | } |
| 83 | 83 | \ No newline at end of file |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | public function handle() |
| 28 | 28 | { |
| 29 | - $this->comment(PHP_EOL.Inspiring::quote().PHP_EOL); |
|
| 29 | + $this->comment(PHP_EOL . Inspiring::quote() . PHP_EOL); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | if ($this->isValidExtension($val['filename'])) { |
| 55 | 55 | $files[] = [ |
| 56 | 56 | 'fileName' => $val['filename'], |
| 57 | - 'fullFileName' => $dir . '/' .$val['filename'], |
|
| 57 | + 'fullFileName' => $dir . '/' . $val['filename'], |
|
| 58 | 58 | 'size' => $val['size'], |
| 59 | 59 | 'modified' => gmdate("m/d/Y H:i:s", $val['mtime']), |
| 60 | 60 | ]; |
@@ -154,6 +154,6 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | protected function isValidExtension($fileName) |
| 156 | 156 | { |
| 157 | - return substr(strrchr($fileName,'.'),1) === 'xml' || substr(strrchr($fileName,'.'),1) === 'err'; |
|
| 157 | + return substr(strrchr($fileName, '.'), 1) === 'xml' || substr(strrchr($fileName, '.'), 1) === 'err'; |
|
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | \ No newline at end of file |
@@ -7,154 +7,154 @@ |
||
| 7 | 7 | class Sftp |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - protected $connectionName; |
|
| 11 | - |
|
| 12 | - /** |
|
| 13 | - * Constructor |
|
| 14 | - * |
|
| 15 | - * @param string $connectionName |
|
| 16 | - */ |
|
| 17 | - public function __construct($connectionName) |
|
| 18 | - { |
|
| 19 | - $this->connectionName = $connectionName; |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Gets all XML files from a remote folder |
|
| 24 | - * |
|
| 25 | - * @param string $remoteDir |
|
| 26 | - * @param string $localDir |
|
| 27 | - * @return array |
|
| 28 | - */ |
|
| 10 | + protected $connectionName; |
|
| 11 | + |
|
| 12 | + /** |
|
| 13 | + * Constructor |
|
| 14 | + * |
|
| 15 | + * @param string $connectionName |
|
| 16 | + */ |
|
| 17 | + public function __construct($connectionName) |
|
| 18 | + { |
|
| 19 | + $this->connectionName = $connectionName; |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Gets all XML files from a remote folder |
|
| 24 | + * |
|
| 25 | + * @param string $remoteDir |
|
| 26 | + * @param string $localDir |
|
| 27 | + * @return array |
|
| 28 | + */ |
|
| 29 | 29 | public function getFiles($remoteDir, $localDir) |
| 30 | 30 | { |
| 31 | - $files = $this->remoteListPackaged($remoteDir); |
|
| 31 | + $files = $this->remoteListPackaged($remoteDir); |
|
| 32 | 32 | |
| 33 | - foreach ($files as $file) { |
|
| 33 | + foreach ($files as $file) { |
|
| 34 | 34 | $this->getFile($file['fullFileName'], $localDir . '/' . $file['fileName']); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - return $files; |
|
| 37 | + return $files; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Gets all XML files from a remote folder |
|
| 42 | - * |
|
| 43 | - * @param string $dir |
|
| 44 | - * @param bool $sorted |
|
| 45 | - * @param string $sortOrder |
|
| 46 | - * @return array |
|
| 47 | - */ |
|
| 40 | + /** |
|
| 41 | + * Gets all XML files from a remote folder |
|
| 42 | + * |
|
| 43 | + * @param string $dir |
|
| 44 | + * @param bool $sorted |
|
| 45 | + * @param string $sortOrder |
|
| 46 | + * @return array |
|
| 47 | + */ |
|
| 48 | 48 | public function remoteListPackaged($dir, $sorted = true, $sortOrder = 'desc') |
| 49 | 49 | { |
| 50 | - $files = []; |
|
| 50 | + $files = []; |
|
| 51 | 51 | $all = $this->remoteList($dir, $sorted, $sortOrder); |
| 52 | 52 | |
| 53 | - foreach ($all as $file=>$val) { |
|
| 53 | + foreach ($all as $file=>$val) { |
|
| 54 | 54 | if ($this->isValidExtension($val['filename'])) { |
| 55 | 55 | $files[] = [ |
| 56 | - 'fileName' => $val['filename'], |
|
| 57 | - 'fullFileName' => $dir . '/' .$val['filename'], |
|
| 58 | - 'size' => $val['size'], |
|
| 59 | - 'modified' => gmdate("m/d/Y H:i:s", $val['mtime']), |
|
| 60 | - ]; |
|
| 56 | + 'fileName' => $val['filename'], |
|
| 57 | + 'fullFileName' => $dir . '/' .$val['filename'], |
|
| 58 | + 'size' => $val['size'], |
|
| 59 | + 'modified' => gmdate("m/d/Y H:i:s", $val['mtime']), |
|
| 60 | + ]; |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | return $files; |
| 65 | - } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Retrieves a file from a SSH/SFTP server |
|
| 69 | - * |
|
| 70 | - * @param string $remoteFile |
|
| 71 | - * @param string $localFile |
|
| 67 | + /** |
|
| 68 | + * Retrieves a file from a SSH/SFTP server |
|
| 69 | + * |
|
| 70 | + * @param string $remoteFile |
|
| 71 | + * @param string $localFile |
|
| 72 | 72 | * @return \Symfony\Component\Console\Output\OutputInterface |
| 73 | - */ |
|
| 74 | - public function getFile($remoteFile, $localFile) |
|
| 75 | - { |
|
| 76 | - return \SSH::into($this->connectionName)->get($remoteFile, $localFile); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Places a file on a remote SSH/SFTP server |
|
| 81 | - * |
|
| 82 | - * @param string $remoteFile |
|
| 83 | - * @param string $localFile |
|
| 73 | + */ |
|
| 74 | + public function getFile($remoteFile, $localFile) |
|
| 75 | + { |
|
| 76 | + return \SSH::into($this->connectionName)->get($remoteFile, $localFile); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Places a file on a remote SSH/SFTP server |
|
| 81 | + * |
|
| 82 | + * @param string $remoteFile |
|
| 83 | + * @param string $localFile |
|
| 84 | 84 | * @return \Symfony\Component\Console\Output\OutputInterface |
| 85 | - */ |
|
| 86 | - public function putFile($remoteFile, $localFile) |
|
| 87 | - { |
|
| 88 | - return \SSH::into($this->connectionName)->put($localFile, $remoteFile); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Retrieves a listing from directory |
|
| 93 | - * |
|
| 94 | - * @param string $dir |
|
| 95 | - * @param bool $sorted |
|
| 96 | - * @param string $sortOrder |
|
| 85 | + */ |
|
| 86 | + public function putFile($remoteFile, $localFile) |
|
| 87 | + { |
|
| 88 | + return \SSH::into($this->connectionName)->put($localFile, $remoteFile); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Retrieves a listing from directory |
|
| 93 | + * |
|
| 94 | + * @param string $dir |
|
| 95 | + * @param bool $sorted |
|
| 96 | + * @param string $sortOrder |
|
| 97 | 97 | * @return array array of files and folders |
| 98 | - */ |
|
| 99 | - public function remoteList($dir, $sorted = true, $sortOrder = 'desc') |
|
| 100 | - { |
|
| 101 | - $conn = $this->getConnection(); |
|
| 102 | - $conn->chdir($dir); |
|
| 103 | - $list = $conn->rawlist(); |
|
| 104 | - |
|
| 105 | - if ($sorted) { |
|
| 106 | - $list = $this->sortList($list, $sortOrder); |
|
| 107 | - } |
|
| 98 | + */ |
|
| 99 | + public function remoteList($dir, $sorted = true, $sortOrder = 'desc') |
|
| 100 | + { |
|
| 101 | + $conn = $this->getConnection(); |
|
| 102 | + $conn->chdir($dir); |
|
| 103 | + $list = $conn->rawlist(); |
|
| 104 | + |
|
| 105 | + if ($sorted) { |
|
| 106 | + $list = $this->sortList($list, $sortOrder); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - return $list; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Retrieves a listing from directory |
|
| 114 | - * |
|
| 115 | - * @param array $list |
|
| 116 | - * @param string $sortOrder |
|
| 117 | - * @return array sorted array of a folder |
|
| 118 | - */ |
|
| 119 | - public function sortList($list, $sortOrder = 'desc') |
|
| 120 | - { |
|
| 121 | - usort($list, function($a, $b) { return $a['mtime'] - $b['mtime']; }); |
|
| 122 | - |
|
| 123 | - return $sortOrder == 'asc' ? $list : array_reverse($list); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Retrieves a listing from directory |
|
| 128 | - * |
|
| 129 | - * @param string $remoteFileFrom |
|
| 130 | - * @param string $remoteFileTo |
|
| 131 | - * @return boolean success |
|
| 132 | - */ |
|
| 133 | - public function rename($remoteFileFrom, $remoteFileTo) |
|
| 134 | - { |
|
| 135 | - $conn = $this->getConnection(); |
|
| 136 | - //print $conn->getSFTPLog(); |
|
| 137 | - return $conn->rename($remoteFileFrom, $remoteFileTo); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Gets a Net_SFTP connection as Laravels SSH doesn't have all the functionality |
|
| 142 | - * |
|
| 143 | - * @return Net_SFTP connection |
|
| 144 | - */ |
|
| 145 | - protected function getConnection() |
|
| 146 | - { |
|
| 147 | - return \SSH::into($this->connectionName)->getGateway()->getConnection(); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Gets a Net_SFTP connection as Laravels SSH doesn't have all the functionality |
|
| 152 | - * |
|
| 153 | - * @param string $fileName |
|
| 154 | - * @return bool |
|
| 155 | - */ |
|
| 156 | - protected function isValidExtension($fileName) |
|
| 157 | - { |
|
| 158 | - return substr(strrchr($fileName,'.'),1) === 'xml' || substr(strrchr($fileName,'.'),1) === 'err'; |
|
| 159 | - } |
|
| 109 | + return $list; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Retrieves a listing from directory |
|
| 114 | + * |
|
| 115 | + * @param array $list |
|
| 116 | + * @param string $sortOrder |
|
| 117 | + * @return array sorted array of a folder |
|
| 118 | + */ |
|
| 119 | + public function sortList($list, $sortOrder = 'desc') |
|
| 120 | + { |
|
| 121 | + usort($list, function($a, $b) { return $a['mtime'] - $b['mtime']; }); |
|
| 122 | + |
|
| 123 | + return $sortOrder == 'asc' ? $list : array_reverse($list); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Retrieves a listing from directory |
|
| 128 | + * |
|
| 129 | + * @param string $remoteFileFrom |
|
| 130 | + * @param string $remoteFileTo |
|
| 131 | + * @return boolean success |
|
| 132 | + */ |
|
| 133 | + public function rename($remoteFileFrom, $remoteFileTo) |
|
| 134 | + { |
|
| 135 | + $conn = $this->getConnection(); |
|
| 136 | + //print $conn->getSFTPLog(); |
|
| 137 | + return $conn->rename($remoteFileFrom, $remoteFileTo); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Gets a Net_SFTP connection as Laravels SSH doesn't have all the functionality |
|
| 142 | + * |
|
| 143 | + * @return Net_SFTP connection |
|
| 144 | + */ |
|
| 145 | + protected function getConnection() |
|
| 146 | + { |
|
| 147 | + return \SSH::into($this->connectionName)->getGateway()->getConnection(); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Gets a Net_SFTP connection as Laravels SSH doesn't have all the functionality |
|
| 152 | + * |
|
| 153 | + * @param string $fileName |
|
| 154 | + * @return bool |
|
| 155 | + */ |
|
| 156 | + protected function isValidExtension($fileName) |
|
| 157 | + { |
|
| 158 | + return substr(strrchr($fileName,'.'),1) === 'xml' || substr(strrchr($fileName,'.'),1) === 'err'; |
|
| 159 | + } |
|
| 160 | 160 | } |
| 161 | 161 | \ No newline at end of file |
@@ -4,150 +4,150 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Xml |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * xml |
|
| 9 | - * @var string |
|
| 10 | - */ |
|
| 11 | - protected $xml; |
|
| 12 | - |
|
| 13 | - /** |
|
| 14 | - * XSD validation errors |
|
| 15 | - * @var array |
|
| 16 | - */ |
|
| 17 | - protected $errors; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Constructor |
|
| 21 | - * |
|
| 22 | - * @param string $xml |
|
| 23 | - */ |
|
| 24 | - public function __construct($xml = '') |
|
| 25 | - { |
|
| 26 | - $this->xml = $xml; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Gets all XML files from a remote folder |
|
| 31 | - * |
|
| 32 | - * @param string $xml |
|
| 33 | - * @return array |
|
| 34 | - */ |
|
| 7 | + /** |
|
| 8 | + * xml |
|
| 9 | + * @var string |
|
| 10 | + */ |
|
| 11 | + protected $xml; |
|
| 12 | + |
|
| 13 | + /** |
|
| 14 | + * XSD validation errors |
|
| 15 | + * @var array |
|
| 16 | + */ |
|
| 17 | + protected $errors; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Constructor |
|
| 21 | + * |
|
| 22 | + * @param string $xml |
|
| 23 | + */ |
|
| 24 | + public function __construct($xml = '') |
|
| 25 | + { |
|
| 26 | + $this->xml = $xml; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Gets all XML files from a remote folder |
|
| 31 | + * |
|
| 32 | + * @param string $xml |
|
| 33 | + * @return array |
|
| 34 | + */ |
|
| 35 | 35 | public function toArray($xml) |
| 36 | 36 | { |
| 37 | - $xml = $xml ?: $this->xml; |
|
| 38 | - //$array = json_decode(str_replace('{"0":" "}','null', json_encode(simplexml_load_string($xml),JSON_NUMERIC_CHECK)), true); |
|
| 39 | - $array = json_decode(str_replace('{"0":" "}','null', json_encode(simplexml_load_string($xml))), true); |
|
| 40 | - $this->filterEmptyArray($array); |
|
| 37 | + $xml = $xml ?: $this->xml; |
|
| 38 | + //$array = json_decode(str_replace('{"0":" "}','null', json_encode(simplexml_load_string($xml),JSON_NUMERIC_CHECK)), true); |
|
| 39 | + $array = json_decode(str_replace('{"0":" "}','null', json_encode(simplexml_load_string($xml))), true); |
|
| 40 | + $this->filterEmptyArray($array); |
|
| 41 | 41 | |
| 42 | - return $array; |
|
| 42 | + return $array; |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Replace data in a node |
|
| 47 | - * |
|
| 48 | - * @param string $xml |
|
| 49 | - * @param string $node |
|
| 50 | - * @param string $find |
|
| 51 | - * @param string $replace |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public function replaceInNode($xml, $node, $find, $replace) |
|
| 55 | - { |
|
| 56 | - return preg_replace_callback('@(<' . $node . '>)' . $find . '(</' . $node . '>)@s', function ($matches) use ($replace) { |
|
| 57 | - return str_replace(' ', $replace, $matches[0]); |
|
| 58 | - }, $xml); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Converts an xml string into a SimpleXml object |
|
| 63 | - * |
|
| 64 | - * @param string $xml |
|
| 65 | - * @return SimpleXml |
|
| 66 | - */ |
|
| 67 | - public function toXml($xml, $namespace = null) |
|
| 68 | - { |
|
| 69 | - $xml = $xml ?: $this->xml; |
|
| 70 | - |
|
| 71 | - libxml_use_internal_errors(true); |
|
| 72 | - $xmlDoc = simplexml_load_string($xml, null, 0, $namespace, !is_null($namespace)); |
|
| 45 | + /** |
|
| 46 | + * Replace data in a node |
|
| 47 | + * |
|
| 48 | + * @param string $xml |
|
| 49 | + * @param string $node |
|
| 50 | + * @param string $find |
|
| 51 | + * @param string $replace |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public function replaceInNode($xml, $node, $find, $replace) |
|
| 55 | + { |
|
| 56 | + return preg_replace_callback('@(<' . $node . '>)' . $find . '(</' . $node . '>)@s', function ($matches) use ($replace) { |
|
| 57 | + return str_replace(' ', $replace, $matches[0]); |
|
| 58 | + }, $xml); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Converts an xml string into a SimpleXml object |
|
| 63 | + * |
|
| 64 | + * @param string $xml |
|
| 65 | + * @return SimpleXml |
|
| 66 | + */ |
|
| 67 | + public function toXml($xml, $namespace = null) |
|
| 68 | + { |
|
| 69 | + $xml = $xml ?: $this->xml; |
|
| 70 | + |
|
| 71 | + libxml_use_internal_errors(true); |
|
| 72 | + $xmlDoc = simplexml_load_string($xml, null, 0, $namespace, !is_null($namespace)); |
|
| 73 | 73 | |
| 74 | - if ($xmlDoc === false) { |
|
| 75 | - $this->errors = libxml_get_errors(); |
|
| 74 | + if ($xmlDoc === false) { |
|
| 75 | + $this->errors = libxml_get_errors(); |
|
| 76 | 76 | |
| 77 | - return false; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - return $xmlDoc; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Get an array of attributes from an XML node |
|
| 85 | - * @param SimpleXMLElement $node |
|
| 86 | - * @return array |
|
| 87 | - */ |
|
| 88 | - public static function attributes($node) |
|
| 89 | - { |
|
| 90 | - return current($node->attributes()); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Validates an xml string against |
|
| 95 | - * @param string $xml |
|
| 96 | - * @param string $xsdPath |
|
| 97 | - * @return bool |
|
| 98 | - */ |
|
| 99 | - public function validate($xsdPath, $xml = null) |
|
| 100 | - { |
|
| 101 | - $xml = $xml ?: $this->xml; |
|
| 102 | - |
|
| 103 | - libxml_use_internal_errors(true); |
|
| 104 | - $xmlDoc = new \DOMDocument(); |
|
| 105 | - $xmlDoc->loadXML($xml); |
|
| 77 | + return false; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + return $xmlDoc; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Get an array of attributes from an XML node |
|
| 85 | + * @param SimpleXMLElement $node |
|
| 86 | + * @return array |
|
| 87 | + */ |
|
| 88 | + public static function attributes($node) |
|
| 89 | + { |
|
| 90 | + return current($node->attributes()); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Validates an xml string against |
|
| 95 | + * @param string $xml |
|
| 96 | + * @param string $xsdPath |
|
| 97 | + * @return bool |
|
| 98 | + */ |
|
| 99 | + public function validate($xsdPath, $xml = null) |
|
| 100 | + { |
|
| 101 | + $xml = $xml ?: $this->xml; |
|
| 102 | + |
|
| 103 | + libxml_use_internal_errors(true); |
|
| 104 | + $xmlDoc = new \DOMDocument(); |
|
| 105 | + $xmlDoc->loadXML($xml); |
|
| 106 | 106 | |
| 107 | - if (!$xmlDoc->schemaValidate($xsdPath)) { |
|
| 107 | + if (!$xmlDoc->schemaValidate($xsdPath)) { |
|
| 108 | 108 | |
| 109 | - $this->errors = libxml_get_errors(); |
|
| 109 | + $this->errors = libxml_get_errors(); |
|
| 110 | 110 | |
| 111 | - return false; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return true; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Validates an xml string against |
|
| 119 | - * @param bool $compact |
|
| 120 | - * @return array |
|
| 121 | - */ |
|
| 122 | - public function getErrors($compact = true) |
|
| 123 | - { |
|
| 124 | - $errors = []; |
|
| 125 | - |
|
| 126 | - if (!$compact) { |
|
| 127 | - $errors = $this->errors; |
|
| 128 | - } else { |
|
| 129 | - |
|
| 130 | - foreach ($this->errors as $error) { |
|
| 131 | - $errors[] = $error->message; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return $errors; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Converts empty array nodes into empty strings to corredt the toArray() side effect |
|
| 140 | - * |
|
| 141 | - * @param array &$array |
|
| 142 | - */ |
|
| 143 | - public function filterEmptyArray(array &$array) |
|
| 144 | - { |
|
| 145 | - foreach ($array as $key=>&$val) { |
|
| 146 | - if (empty($val)) { |
|
| 147 | - $array[$key] = ""; |
|
| 148 | - } else { |
|
| 149 | - is_array($val) && $this->filterEmptyArray($val); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } |
|
| 111 | + return false; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return true; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Validates an xml string against |
|
| 119 | + * @param bool $compact |
|
| 120 | + * @return array |
|
| 121 | + */ |
|
| 122 | + public function getErrors($compact = true) |
|
| 123 | + { |
|
| 124 | + $errors = []; |
|
| 125 | + |
|
| 126 | + if (!$compact) { |
|
| 127 | + $errors = $this->errors; |
|
| 128 | + } else { |
|
| 129 | + |
|
| 130 | + foreach ($this->errors as $error) { |
|
| 131 | + $errors[] = $error->message; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return $errors; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Converts empty array nodes into empty strings to corredt the toArray() side effect |
|
| 140 | + * |
|
| 141 | + * @param array &$array |
|
| 142 | + */ |
|
| 143 | + public function filterEmptyArray(array &$array) |
|
| 144 | + { |
|
| 145 | + foreach ($array as $key=>&$val) { |
|
| 146 | + if (empty($val)) { |
|
| 147 | + $array[$key] = ""; |
|
| 148 | + } else { |
|
| 149 | + is_array($val) && $this->filterEmptyArray($val); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | 153 | } |
| 154 | 154 | \ No newline at end of file |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | { |
| 37 | 37 | $xml = $xml ?: $this->xml; |
| 38 | 38 | //$array = json_decode(str_replace('{"0":" "}','null', json_encode(simplexml_load_string($xml),JSON_NUMERIC_CHECK)), true); |
| 39 | - $array = json_decode(str_replace('{"0":" "}','null', json_encode(simplexml_load_string($xml))), true); |
|
| 39 | + $array = json_decode(str_replace('{"0":" "}', 'null', json_encode(simplexml_load_string($xml))), true); |
|
| 40 | 40 | $this->filterEmptyArray($array); |
| 41 | 41 | |
| 42 | 42 | return $array; |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function replaceInNode($xml, $node, $find, $replace) |
| 55 | 55 | { |
| 56 | - return preg_replace_callback('@(<' . $node . '>)' . $find . '(</' . $node . '>)@s', function ($matches) use ($replace) { |
|
| 56 | + return preg_replace_callback('@(<' . $node . '>)' . $find . '(</' . $node . '>)@s', function($matches) use ($replace) { |
|
| 57 | 57 | return str_replace(' ', $replace, $matches[0]); |
| 58 | 58 | }, $xml); |
| 59 | 59 | } |
@@ -10,29 +10,29 @@ |
||
| 10 | 10 | |
| 11 | 11 | class CallRoute extends Command { |
| 12 | 12 | |
| 13 | - protected $name = 'route:call'; |
|
| 14 | - protected $description = 'Call route from CLI'; |
|
| 15 | - |
|
| 16 | - public function __construct() |
|
| 17 | - { |
|
| 18 | - parent::__construct(); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function fire() |
|
| 22 | - { |
|
| 23 | - $request = Request::create((string)$this->option('uri'), 'GET'); |
|
| 24 | - $request->headers->set('X-Authorization', $this->option('token')); |
|
| 25 | - $this->info(strip_tags( |
|
| 26 | - app()['Illuminate\Contracts\Http\Kernel']->handle($request) |
|
| 27 | - )); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - protected function getOptions() |
|
| 31 | - { |
|
| 32 | - return [ |
|
| 33 | - ['token', null, InputOption::VALUE_REQUIRED, 'The auth token', null], |
|
| 34 | - ['uri', null, InputOption::VALUE_REQUIRED, 'The path of the route to be called', null], |
|
| 35 | - ]; |
|
| 36 | - } |
|
| 13 | + protected $name = 'route:call'; |
|
| 14 | + protected $description = 'Call route from CLI'; |
|
| 15 | + |
|
| 16 | + public function __construct() |
|
| 17 | + { |
|
| 18 | + parent::__construct(); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function fire() |
|
| 22 | + { |
|
| 23 | + $request = Request::create((string)$this->option('uri'), 'GET'); |
|
| 24 | + $request->headers->set('X-Authorization', $this->option('token')); |
|
| 25 | + $this->info(strip_tags( |
|
| 26 | + app()['Illuminate\Contracts\Http\Kernel']->handle($request) |
|
| 27 | + )); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + protected function getOptions() |
|
| 31 | + { |
|
| 32 | + return [ |
|
| 33 | + ['token', null, InputOption::VALUE_REQUIRED, 'The auth token', null], |
|
| 34 | + ['uri', null, InputOption::VALUE_REQUIRED, 'The path of the route to be called', null], |
|
| 35 | + ]; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | } |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | |
| 21 | 21 | public function fire() |
| 22 | 22 | { |
| 23 | - $request = Request::create((string)$this->option('uri'), 'GET'); |
|
| 23 | + $request = Request::create((string) $this->option('uri'), 'GET'); |
|
| 24 | 24 | $request->headers->set('X-Authorization', $this->option('token')); |
| 25 | 25 | $this->info(strip_tags( |
| 26 | 26 | app()['Illuminate\Contracts\Http\Kernel']->handle($request) |