-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from keboola/odin-php7
new version
- Loading branch information
Showing
10 changed files
with
186 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea | ||
composer.lock | ||
vendor | ||
/build/logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
language: php | ||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
- 7.2 | ||
env: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="Project"> | ||
<rule ref="vendor/keboola/coding-standard/src/ruleset.xml"/> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
parameters: | ||
ignoreErrors: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Keboola\Temp; | ||
|
||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
class Temp | ||
{ | ||
/** | ||
* @var String | ||
*/ | ||
private $prefix; | ||
|
||
/** | ||
* @var Filesystem | ||
*/ | ||
private $fileSystem; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $tmpFolder; | ||
|
||
public function __construct(string $prefix = '') | ||
{ | ||
$this->prefix = $prefix; | ||
$this->id = uniqid("run-", true); | ||
$this->fileSystem = new Filesystem(); | ||
} | ||
|
||
private function initRunFolder(): void | ||
{ | ||
clearstatcache(); | ||
$path = $this->getTmpPath(); | ||
if (!file_exists($path) && !is_dir($path)) { | ||
$this->fileSystem->mkdir($path, 0777); | ||
} | ||
$this->tmpFolder = $path; | ||
} | ||
|
||
/** | ||
* Get path to the temporary folder. | ||
* | ||
* @return string | ||
*/ | ||
private function getTmpPath(): string | ||
{ | ||
$tmpDir = sys_get_temp_dir(); | ||
if (!empty($this->prefix)) { | ||
$tmpDir .= "/" . $this->prefix; | ||
} | ||
$tmpDir .= "/" . $this->id; | ||
return $tmpDir; | ||
} | ||
|
||
/** | ||
* Returns path to the temporary folder. | ||
* | ||
* @return string | ||
*/ | ||
public function getTmpFolder(): string | ||
{ | ||
if (!$this->tmpFolder) { | ||
$this->initRunFolder(); | ||
} | ||
return $this->tmpFolder; | ||
} | ||
|
||
/** | ||
* Create a randomly named temporary file. | ||
* | ||
* @param string $suffix filename suffix | ||
* @throws \Exception | ||
* @return \SplFileInfo | ||
*/ | ||
public function createTmpFile(string $suffix = ''): \SplFileInfo | ||
{ | ||
$file = uniqid(); | ||
if ($suffix) { | ||
$file .= '-' . $suffix; | ||
} | ||
return $this->createFile($file); | ||
} | ||
|
||
/** | ||
* Creates a named temporary file. | ||
* | ||
* @param string $fileName | ||
* @return \SplFileInfo | ||
* @throws \Exception | ||
*/ | ||
public function createFile(string $fileName): \SplFileInfo | ||
{ | ||
$fileInfo = new \SplFileInfo($this->getTmpFolder() . '/' . $fileName); | ||
$pathName = $fileInfo->getPathname(); | ||
if (!file_exists(dirname($pathName))) { | ||
$this->fileSystem->mkdir(dirname($pathName), 0777); | ||
} | ||
$this->fileSystem->touch($pathName); | ||
$this->fileSystem->chmod($pathName, 0600); | ||
return $fileInfo; | ||
} | ||
|
||
/** | ||
* Delete the whole temporary folder including all files. | ||
*/ | ||
public function remove(): void | ||
{ | ||
$this->fileSystem->remove($this->getTmpFolder()); | ||
} | ||
} |
Oops, something went wrong.