Skip to content

Commit

Permalink
Merge pull request #9 from ricklambrechts/patch-1
Browse files Browse the repository at this point in the history
Only initialize connection when needed
  • Loading branch information
websmurf authored Nov 18, 2021
2 parents 96f9682 + 7abc6fd commit 7b49a2c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/LaravelExactOnline.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ class LaravelExactOnline
*/
public function __construct()
{
$this->connection = app()->make('Exact\Connection');
}

/**
Expand All @@ -351,7 +350,7 @@ public function __call($method, $arguments)
if (strpos($method, "connection") === 0) {
$method = lcfirst(substr($method, 10));

call_user_func([$this->connection, $method], implode(",", $arguments));
call_user_func([$this->connection(), $method], implode(",", $arguments));

return $this;

Expand All @@ -363,7 +362,7 @@ public function __call($method, $arguments)
throw new RuntimeException("Invalid type called");
}

return new $classname($this->connection);
return new $classname($this->connection());
}

/**
Expand All @@ -373,6 +372,9 @@ public function __call($method, $arguments)
*/
public function connection(): Connection
{
if (!$this->connection) {
$this->connection = app()->make('Exact\Connection');
}
return $this->connection;
}

Expand Down

0 comments on commit 7b49a2c

Please sign in to comment.