Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
Made a few adjustments to support php 5.6 (the scope resolution opera…
Browse files Browse the repository at this point in the history
…tor issue)
  • Loading branch information
timothymarois committed May 28, 2018
1 parent d6fd650 commit dbbe554
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 additions & 7 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Database
* __construct
*
*/
public function __construct(array $config)
public function __construct(array $config = [])
{
$this->config = new Config($config);

Expand Down Expand Up @@ -85,7 +85,9 @@ public function version()
*/
public function findAll($include_documents = true, $data_only = false)
{
$file_extension = $this->config->format::getFileExtension();
$format = $this->config->format;

$file_extension = $format::getFileExtension();
$file_location = $this->config->dir.'/';

$all_items = Filesystem::getAllFiles($file_location, $file_extension);
Expand Down Expand Up @@ -223,8 +225,9 @@ public function save(Document $document, $wdata = '')
throw new \Exception("This database is set to be read-only. No modifications can be made.");
}

$format = $this->config->format;
$id = $document->getId();
$file_extension = $this->config->format::getFileExtension();
$file_extension = $format::getFileExtension();
$file_location = $this->config->dir.'/'.Filesystem::validateName($id, $this->config->safe_filename).'.'.$file_extension;
$created = $document->createdAt(false);

Expand All @@ -243,7 +246,7 @@ public function save(Document $document, $wdata = '')

$document->setUpdatedAt(time());

$data = $this->config->format::encode( $document->saveAs(), $this->config->pretty );
$data = $format::encode( $document->saveAs(), $this->config->pretty );

if (Filesystem::write($file_location, $data))
{
Expand Down Expand Up @@ -282,7 +285,8 @@ public function query()
*/
protected function read($name)
{
return $this->config->format::decode( Filesystem::read( $this->config->dir.'/'.Filesystem::validateName($name, $this->config->safe_filename).'.'.$this->config->format::getFileExtension() ) );
$format = $this->config->format;
return $format::decode( Filesystem::read( $this->config->dir.'/'.Filesystem::validateName($name, $this->config->safe_filename).'.'.$format::getFileExtension() ) );
}


Expand All @@ -302,7 +306,9 @@ public function delete(Document $document)
throw new \Exception("This database is set to be read-only. No modifications can be made.");
}

return Filesystem::delete($this->config->dir.'/'.Filesystem::validateName($document->getId(), $this->config->safe_filename).'.'.$this->config->format::getFileExtension());
$format = $this->config->format;

return Filesystem::delete($this->config->dir.'/'.Filesystem::validateName($document->getId(), $this->config->safe_filename).'.'.$format::getFileExtension());
}


Expand Down Expand Up @@ -341,10 +347,11 @@ public function flush($confirm = false)

if ($confirm===true)
{
$format = $this->config->format;
$documents = $this->findAll(false);
foreach($documents as $document)
{
Filesystem::delete($this->config->dir.'/'.$document.'.'.$this->config->format::getFileExtension());
Filesystem::delete($this->config->dir.'/'.$document.'.'.$format::getFileExtension());
}

if ($this->count() === 0)
Expand Down
2 changes: 1 addition & 1 deletion src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public function setId($id)
*
* @param boolean $cache
*/
public function setFromCache(bool $cache = true)
public function setFromCache($cache = true)
{
$this->__cache = $cache;

Expand Down

0 comments on commit dbbe554

Please sign in to comment.