public function __construct($source) { if (!Support\is_path_exists(app_path('../' . $source))) { throw new TableException(_('Invalid path config file')); } $source = (require app_path('../' . $source)); $this->setSource($source); }
/** * Set settings . * * @return mixed */ public function init() { $attributes = $this->getAttributes(); $fullPath = storage_path($attributes['path']); if (Support\is_path_exists($fullPath)) { $this->settings = Support\get_file_contents($fullPath); } else { Support\dump_file($fullPath, json_encode([])); } register_shutdown_function(function () use($fullPath) { Support\dump_file($fullPath, $this->packData($this->settings)); }); }
/** * Delete image by id * * @param $imageIds * @throws PermissionException */ public function deleteImage($imageIds) { if (Support\isAllowed(isset($behaviors['roles']) ? $behaviors['roles'] : [], isset($behaviors['permissions']) ? $behaviors['permissions'] : [])) { if (!is_array($imageIds)) { $imageIds = (array) $imageIds; } $images = $this->images()->whereIn('id', $imageIds); array_walk($images, function ($image) { if (Support\is_path_exists($image->fullpath)) { Support\remove_paths($image->fullpath); } $image->delete(); }); } throw new PermissionException('Have no access for delete.'); }
/** * Filter images . * * @param $urls * @param array $filters * @param callable $callback * @return array */ public function filter($urls, $filters = [], \Closure $callback = null) { if (!is_array($urls)) { $urls = (array) $urls; } return array_map(function ($url) use($callback, $filters) { if (!Support\is_path_exists($url)) { return false; } $image = app('image')->make($url); $image = $this->applyFilters($image, $filters); if (!is_null($callback)) { $image = $callback($image); } return $image->save($url); }, array_filter($urls)); }
/** * Get default path . * * @param null $filename * @return string */ protected function fullPath($filename = null) { if (!($path = config('laravel-exporter')['default_path'])) { $path = ''; } #@todo check for storage path, we need use without laravel . $path = storage_path($path); if (is_null($filename)) { $filename = $this->getFilename(); } if (!Support\is_path_exists($path)) { Support\mk_path($path); } return $path . DIRECTORY_SEPARATOR . $filename; }
/** * Add module namespace . * * @param $namespaces * @param bool $fullPath * @return $this */ public function addNamespace($namespaces, $fullPath = false) { if (!is_array($namespaces)) { $namespaces = (array) $namespaces; } foreach ($namespaces as $namespace) { $path = !$fullPath ? app_path('../' . $namespace) : $namespace; if (!Support\is_path_exists($path)) { return false; } $this->namespaces[] = $path; } return $this; }