Yeelight /
cloud2
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Created by PhpStorm. |
||
| 4 | * User: sheldon |
||
| 5 | * Date: 18-4-10 |
||
| 6 | * Time: 下午2:12. |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace Yeelight\Traits; |
||
| 10 | |||
| 11 | use Illuminate\Support\Facades\Input; |
||
| 12 | use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; |
||
| 13 | use Yeelight\Services\Exporters\Exporter; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Trait BackendExporter |
||
| 17 | * |
||
| 18 | * @category Yeelight |
||
| 19 | * |
||
| 20 | * @package Yeelight\Traits |
||
| 21 | * |
||
| 22 | * @author Sheldon Lee <[email protected]> |
||
| 23 | * |
||
| 24 | * @license https://opensource.org/licenses/MIT MIT |
||
| 25 | * |
||
| 26 | * @link https://www.yeelight.com |
||
| 27 | */ |
||
| 28 | trait BackendExporter |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * @var bool |
||
| 32 | */ |
||
| 33 | protected $useExporter = true; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Export driver. |
||
| 37 | * |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $exporter; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Setup grid exporter. |
||
| 44 | * |
||
| 45 | * @return void |
||
| 46 | */ |
||
| 47 | public function setupExporter() |
||
| 48 | { |
||
| 49 | if ($scope = Input::get(Exporter::$queryName)) { |
||
| 50 | if (!$this->useExporter) { |
||
| 51 | // Failed, throw exception |
||
| 52 | throw new NotAcceptableHttpException(trans('backend.export_forbidden')); |
||
| 53 | } |
||
| 54 | |||
| 55 | (new Exporter($this->repository))->resolve($this->exporter)->withScope($scope)->export(); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Set exporter driver to export. |
||
| 61 | * |
||
| 62 | * @param $exporter |
||
| 63 | * |
||
| 64 | * @return $this |
||
| 65 | */ |
||
| 66 | public function exporter($exporter) |
||
| 67 | { |
||
| 68 | $this->exporter = $exporter; |
||
| 69 | |||
| 70 | return $this; |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Get the export url. |
||
| 75 | * |
||
| 76 | * @param int $scope |
||
| 77 | * @param null $args |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 78 | * |
||
| 79 | * @return string |
||
| 80 | */ |
||
| 81 | public function exportUrl($scope = 1, $args = null) |
||
| 82 | { |
||
| 83 | $input = array_merge(Input::all(), Exporter::formatExportQuery($scope, $args)); |
||
| 84 | |||
| 85 | return get_resource().'?'.http_build_query($input); |
||
| 86 | } |
||
| 87 | } |
||
| 88 |