Download Folder

@param array $params

@return void
@throws \Exception
779738
public function downloadFolder(array $params)
    {
        try {
            if (extension_loaded('Phar')) {
                /**
                 * Decode Path
                 */
                $base64 = base64_decode($params['dir']);

                /**
                 * Path to File on Disk
                 */
                $path = $this->getSearchPath() . '/' . $base64;

                clearstatcache();

                if (is_dir($path)) {
                    $array = $this->directoryListing($base64);

                    if (is_array($array) && count($array) > '0') {
                        unset($array['totalLength']);
                        unset($array['totalFileSize']);

                        $filename = $path . '.' . $params['format'];

                        $phar = new \PharData($filename);

                        foreach ($array as $value) {
                            $phar->addFile(
                                $value['fullPath'],
                                $value['name']
                            );
                        }

                        switch ($params['format']) {
                            case 'tar':
                                header('Content-Type: application/x-tar');
                                break;

                            case 'zip':
                                header('Content-Type: application/zip');
                                break;

                            case 'bz2':
                                header('Content-Type: application/x-bzip2');
                                break;

                            case 'rar':
                                header('Content-Type: x-rar-compressed');
                                break;
                        }

                        header('Content-disposition: attachment; filename=' . basename($filename));
                        header('Content-Length: ' . filesize($filename));

                        readfile($filename);

                        unlink($filename);

                        exit;
                    } else {
                        throw new \Exception(
                            $this->translate->translate(
                                'Something went wrong and we cannot download this folder',
                                'mp3'
                            )
                        );
                    }
                } else {
                    throw new \Exception(
                        $path . ' ' . $this->translate->translate(
                            'was not found',
                            'mp3'
                        )
                    );
                }
            } else {
                throw new \Exception(
                    $this->translate->translate('Phar Extension is not loaded')
                );
            }
        } catch (\Exception $e) {
            throw $e;
        }
    }
1323069
public function all(array $params = array())
    {
        $endpoint = '/admin/locations.json';
        $response = $this->request($endpoint, 'GET', $params);
        return $this->createCollection(Location::class, $response['locations']);
    }
1320992
public function create(array $params = [])
    {
        return $this->executeRequest(
            RequestMethodEnum::POST,
            ResourceMethodEnum::CREATE,
            $params,
            null
        );
    }
78969
public function makeImage($path, array $params)
    {
        $sourcePath = $this->getSourcePath($path);
        $cachedPath = $this->getCachePath($path, $params);

        if ($this->cacheFileExists($path, $params) === true) {
            return $cachedPath;
        }

        if ($this->sourceFileExists($path) === false) {
            throw new FileNotFoundException(
                'Could not find the image `'.$sourcePath.'`.'
            );
        }

        $source = $this->source->read(
            $sourcePath
        );

        if ($source === false) {
            throw new FilesystemException(
                'Could not read the image `'.$sourcePath.'`.'
            );
        }

        // We need to write the image to the local disk before
        // doing any manipulations. This is because EXIF data
        // can only be read from an actual file.
        $tmp = tempnam(sys_get_temp_dir(), 'Glide');

        if (file_put_contents($tmp, $source) === false) {
            throw new FilesystemException(
                'Unable to write temp file for `'.$sourcePath.'`.'
            );
        }

        try {
            $write = $this->cache->write(
                $cachedPath,
                $this->api->run($tmp, $this->getAllParams($params))
            );

            if ($write === false) {
                throw new FilesystemException(
                    'Could not write the image `'.$cachedPath.'`.'
                );
            }
        } catch (FileExistsException $exception) {
            // This edge case occurs when the target already exists
            // because it's currently be written to disk in another
            // request. It's best to just fail silently.
        } finally {
            unlink($tmp);
        }

        return $cachedPath;
    }
1293946
private function splitParams(array $params)
    {
        $parameters = [];
        $files      = [];

        foreach ($params as $name => $value) {
            if (is_readable($value)) { //file
                $files[$name] = $value;
            } else {
                $parameters[$name] = $value;
            }
        }

        return [$parameters, $files];
    }
675911
public function download(array $params): string
    {
        unset($this->payload['spbill_create_ip']);

        $this->payload = Support::filterPayload($this->payload, $params, true);

        Events::dispatch(Events::METHOD_CALLED, new Events\MethodCalled('Wechat', 'Download', $this->gateway, $this->payload));

        $result = Support::getInstance()->post(
            'pay/downloadbill',
            Support::getInstance()->toXml($this->payload)
        );

        if (is_array($result)) {
            throw new GatewayException('Get Wechat API Error: '.$result['return_msg'], $result);
        }

        return $result;
    }
952215
public function action_create( $params )
	{
		$name = array_shift( $params );
		
		$file = \DB\Migrator::path( $name );
		
		\CCFile::write( $file, "# ---> up\n\n\n\n# ---> down\n\n" );
	}
193062
private function thumbnail(array $params)
    {
        $mode = isset($params['mode']) ? $params['mode'] : self::THUMBNAIL_OUTBOUND;

        $width = (isset($params['width']) && is_numeric($params['width'])) ? $params['width'] : null;
        $height = (isset($params['height']) && is_numeric($params['height'])) ? $params['height'] : null;

        if (is_null($width) || is_null($height)) {
            throw new Exception('Wrong thumbnail width or height');
        }

        $this->image = $this->image->thumbnail(new Box($width, $height), $mode);
    }
1216318
protected function checkMultipartParams( $params ) {
		foreach ( $params as $key => $val ) {
			if ( !is_array( $val ) ) {
				throw new Exception( "Parameter '$key' must be an array." );
			}
			if ( !in_array( $key, array_keys( $this->getParams() ) ) ) {
				throw new Exception( "Parameter '$key' is not already set on this request." );
			}
		}
	}
934806
public function download(string $commit, string $path, array $params = [])
    {
        $path = $this->buildFilesPath($commit, 'files', ...explode('/', $path));

        return $this->pureGet($path, $params, ['Accept' => '*/*'])->getBody();
    }
919669
public function execute(array $params = []): Promise
    {
        $this->lastUsedAt = \time();

        return call(function () use ($params) {
            $statement = yield from $this->pop();
            \assert($statement instanceof Statement);

            try {
                $statement = yield $this->prepare($statement);
                \assert($statement instanceof Statement);
                $result = yield $statement->execute($params);
            } catch (\Throwable $exception) {
                $this->push($statement);
                throw $exception;
            }

            if ($result instanceof ResultSet) {
                $result = $this->createResultSet($result, function () use ($statement) {
                    $this->push($statement);
                });
            } else {
                $this->push($statement);
            }

            return $result;
        });
    }
628556
public function deleteByParams($params = [])
    {
        extract($params);

        $query = $this->newDeleteQuery();

        if (isset($where)) {
            if (is_array($where)) {
                foreach ($where as $condition) {
                    $condition = (array)$condition;
                    $query->where($condition[0], $condition[1]);
                }
            } else {
                call_user_func_array([$query, 'where'], $where);
            }
        }

        if (isset($order)) {
            call_user_func_array([$query, 'order'], $order);
        }

        if (isset($limit)) {
            call_user_func_array([$query, 'limit'], $limit);
        }

        $this->getDB()->execute($query);

        return $this;
    }
865212
public function setParams(array $params = [])
    {
        if (isset($params['access_token'])) {
            $this->setAccessTokenFromParams($params['access_token']);
        }

        unset($params['access_token']);

        $params = $this->sanitizeFileParams($params);
        $this->dangerouslySetParams($params);

        return $this;
    }
665364
public function setUrlParams(array $params) {
		foreach ($params as $param => $value) {
			$this->setUrlParam($param, $value);
		}
		
		return $this;
	}
1036466
public function downloadFile(string $url, Filesystem $filesystem, string $path): int
    {
        // Overwrite any previous/partial/failed download.
        if ($filesystem->has($path)) {
            $filesystem->delete($path);
        }

        // We store the data in PHP temporary storage.
        $tmp = fopen('php://temp', 'wb+');

        // Read from the URL
        $client   = new Client();
        $response = $client->get($url, self::GUZZLE_OPTIONS);
        $stream   = $response->getBody();

        // Download the file to temporary storage.
        while (!$stream->eof()) {
            fwrite($tmp, $stream->read(self::READ_BLOCK_SIZE));

            if ($this->timeout_service->isTimeNearlyUp()) {
                throw new InternalServerErrorException(I18N::translate('The server’s time limit has been reached.'));
            }
        }

        if (is_resource($stream)) {
            fclose($stream);
        }

        // Copy from temporary storage to the file.
        $bytes = ftell($tmp);
        rewind($tmp);
        $filesystem->writeStream($path, $tmp);
        fclose($tmp);

        return $bytes;
    }
693009
private function get($path, array $params = [])
    {
        $request = $this->createHttpGetRequest($this->buildUrl($path), $params);

        $response = $this->httpClient->sendRequest($request);

        return $this->parseResponse($response, $request);
    }
1309622
public function execute (Array $params)
    {
        try {
            $this->_validateParameters($params);
            
            // スケルトンファイルを取得する
            $skeleton = $this->_getSkeletonFile();

            // スケルトンファイルのコンテンツを置換
            $skeleton = str_replace('${command}', $this->command_name, $skeleton);
            file_put_contents(LIB.'/'.APP.'/Commands/'.$this->command_name.'.php', $skeleton);

            $this->log($this->command_name.' command is created!', 'success');
        
        } catch (\Exception $e) {
            $this->errorLog($e->getMessage());
        }
    }