Skip to content

Commit

Permalink
start of cookiejar; cookie encryption middleware; new please action d…
Browse files Browse the repository at this point in the history
…emo; convert double quotes to singular quotes
  • Loading branch information
donwilson committed Nov 15, 2023
1 parent ff8520a commit 791b441
Show file tree
Hide file tree
Showing 49 changed files with 778 additions and 559 deletions.
4 changes: 2 additions & 2 deletions src/Magnetar/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ public function terminate(): void {
}

/**
* Set the environment ("dev", "prod", etc)
* Set the environment ('dev', 'prod', etc)
* @param string $env The environment to set
* @return void
*/
Expand All @@ -658,7 +658,7 @@ public function setEnvironment(string $env): void {
}

/**
* Get the environment ("dev", "prod", etc)
* Get the environment ('dev', 'prod', etc)
* @return string The environment
*/
public function environment(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/Magnetar/Cache/StoreManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function connection(string|null $driver_name=null): AbstractCacheStore {
$driver_name = $this->app->make('config')->get('cache.default', null);

if(is_null($driver_name)) {
throw new Exception("No default cache driver specified");
throw new Exception('No default cache driver specified');
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/Magnetar/Container/BoundMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected static function callClass(

// We will assume an @ sign is used to delimit the class name from the method
// name. We will split on this @ sign and then build a callable array that
// we can pass right back into the "call" method for dependency binding.
// we can pass right back into the 'call' method for dependency binding.
$method = ((count($segments) === 2)?$segments[1]:$defaultMethod);

if(is_null($method)) {
Expand Down Expand Up @@ -116,7 +116,7 @@ protected static function callBoundMethod(
protected static function normalizeMethod(callable $callback): string {
$class = is_string($callback[0]) ? $callback[0] : get_class($callback[0]);

return "{$class}@{$callback[1]}";
return $class .'@'. $callback[1];
}

/**
Expand Down Expand Up @@ -205,9 +205,7 @@ protected static function addDependencyForCallParameter(
} elseif($parameter->isDefaultValueAvailable()) {
$dependencies[] = $parameter->getDefaultValue();
} elseif(!$parameter->isOptional() && !array_key_exists($paramName, $parameters)) {
$message = "Unable to resolve dependency [{$parameter}] in class {$parameter->getDeclaringClass()->getName()}";

throw new BuildResolutionException($message);
throw new BuildResolutionException('Unable to resolve dependency ['. $parameter .'] in class '. $parameter->getDeclaringClass()->getName());
}
}

Expand Down
18 changes: 7 additions & 11 deletions src/Magnetar/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public function scopedIf(
}

/**
* "Extend" an abstract type in the container
* 'Extend' an abstract type in the container
* @param string $abstract The abstract type to extend
* @param Closure $closure The closure to use to extend the type
* @return void
Expand Down Expand Up @@ -528,7 +528,7 @@ public function tagged(string $tag): iterable {
*/
public function alias(string $abstract, string $alias): void {
if($alias === $abstract) {
throw new SelfAliasException("[". $abstract ."] is aliased to itself.");
throw new SelfAliasException('['. $abstract .'] is aliased to itself.');
}

$this->aliases[ $alias ] = $abstract;
Expand Down Expand Up @@ -726,7 +726,7 @@ protected function resolve(
): mixed {
$abstract = $this->getAlias($abstract);

// First we'll fire any event handlers which handle the "before" resolving of
// First we'll fire any event handlers which handle the 'before' resolving of
// specific types. This gives some hooks the chance to add various extends
// calls to change the resolution of objects that they're interested in.
if($raiseEvents) {
Expand Down Expand Up @@ -849,7 +849,7 @@ public function build(Closure|string $concrete): mixed {
try {
$reflector = new ReflectionClass($concrete);
} catch(ReflectionException $e) {
throw new BuildResolutionException("Target class [$concrete] does not exist.", 0, $e);
throw new BuildResolutionException('Target class ['. $concrete .'] does not exist.', 0, $e);
}

// If the type is not instantiable, the developer is attempting to resolve
Expand Down Expand Up @@ -1025,12 +1025,10 @@ protected function notInstantiable(string $concrete): void {
if(!empty($this->buildStack)) {
$previous = implode(', ', $this->buildStack);

$message = "Target [$concrete] is not instantiable while building [$previous].";
} else {
$message = "Target [$concrete] is not instantiable.";
throw new UninstantiableException('Target ['. $concrete .'] is not instantiable while building ['. $previous .'].');
}

throw new UninstantiableException($message);
throw new UninstantiableException('Target ['. $concrete .'] is not instantiable.');
}

/**
Expand All @@ -1041,9 +1039,7 @@ protected function notInstantiable(string $concrete): void {
* @throws BuildResolutionException
*/
protected function unresolvablePrimitive(ReflectionParameter $parameter): void {
$message = "Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}";

throw new BuildResolutionException($message);
throw new BuildResolutionException('Unresolvable dependency resolving ['. $parameter .'] in class '. $parameter->getDeclaringClass()->getName());
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Magnetar/Database/HasPDOTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function createConnection(): void {
*/
protected function generateDSN(): string {
// individual adapters must override this method
throw new DatabaseAdapterException("Database adapter needs to override the generateDSN method.");
throw new DatabaseAdapterException('Database adapter needs to override the generateDSN method.');
}

/**
Expand All @@ -76,7 +76,7 @@ protected function bindStatementParams(
} else {
if($prepend_param_key_with_colon) {
// prepend the param key with a colon
$param_key = ":". $param_key;
$param_key = ':'. $param_key;
}
}

Expand Down Expand Up @@ -110,9 +110,9 @@ protected function bindStatementParams(
* @see https://www.php.net/manual/en/pdo.exec.php
* @see https://www.php.net/manual/en/pdo.prepare.php
*
* @example $db->query("INSERT INTO `table` (`column`, `column2`) VALUES (:value, :value2)", ['value' => 'test', 'value2' => 'test2']);
* @example $db->query("INSERT INTO `table` (`column`, `column2`) VALUES (?, ?)", ['test', 'test2']);
* @example $db->query("INSERT INTO `table` (`column`, `column2`) VALUES ('test', 'test2')");
* @example $db->query('INSERT INTO `table` (`column`, `column2`) VALUES (:value, :value2)', ['value' => 'test', 'value2' => 'test2']);
* @example $db->query('INSERT INTO `table` (`column`, `column2`) VALUES (?, ?)', ['test', 'test2']);
* @example $db->query('INSERT INTO `table` (`column`, `column2`) VALUES ('test', 'test2')');
*/
public function query(string $sql_query, array $params=[]): int|false {
if(!empty($params)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Magnetar/Database/HasQuickQueryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ public function get_col(
if(is_string($column_key)) {
// column key is set to a specific named column, throw error if it doesn't exist
foreach($results as $result) {
$rows[] = $result[ $column_key ] ?? throw new DatabaseAdapterException("Column key ". $column_key ." does not exist in result set");
$rows[] = $result[ $column_key ] ?? throw new DatabaseAdapterException('Column key ['. $column_key .'] does not exist in result set');
}
} elseif(0 !== $column_key) {
// column key is set to a specific numbered column, throw error if it doesn't exist
foreach($results as $result) {
$rows[] = $result[0] ?? throw new DatabaseAdapterException("Column key ". $column_key ." does not exist in result set");
$rows[] = $result[0] ?? throw new DatabaseAdapterException('Column key ['. $column_key .'] does not exist in result set');
}
} else {
// use the first column
Expand Down
27 changes: 12 additions & 15 deletions src/Magnetar/Database/MariaDB/DatabaseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@ class DatabaseAdapter extends BaseDatabaseAdapter {
protected function validateRuntime(): void {
parent::validateRuntime();

// check if the PDO MySQL extension is loaded
if(!extension_loaded('pdo_mysql')) {
throw new RuntimeException('The PDO MySQL extension (pdo_mysql) is not loaded');
}

if(!isset($this->connection_config['host'])) {
throw new DatabaseAdapterException("Database configuration is missing host");
throw new DatabaseAdapterException('Database configuration is missing host');
}

if(!isset($this->connection_config['port'])) {
throw new DatabaseAdapterException("Database configuration is missing port");
throw new DatabaseAdapterException('Database configuration is missing port');
}

//if(!isset($this->connection_config['user'])) {
// throw new DatabaseAdapterException("Database configuration is missing user");
// throw new DatabaseAdapterException('Database configuration is missing user');
//}
//
//if(!isset($this->connection_config['password'])) {
// throw new DatabaseAdapterException("Database configuration is missing password");
// throw new DatabaseAdapterException('Database configuration is missing password');
//}

if(!isset($this->connection_config['database'])) {
throw new DatabaseAdapterException("Database configuration is missing database");
}

// check if the PDO MySQL extension is loaded
if(!extension_loaded('pdo_mysql')) {
throw new RuntimeException("The PDO MySQL extension (pdo_mysql) is not loaded");
throw new DatabaseAdapterException('Database configuration is missing database');
}
}

Expand All @@ -64,11 +64,8 @@ protected function postConnection(): void {

// optional charset settings
if(isset($this->connection_config['charset'])) {
//$this->dbh->exec("SET NAMES ". $this->connection_config['charset']);
//$this->dbh->exec("SET CHARACTER SET ". $this->connection_config['charset']);

$this->dbh->prepare("SET NAMES ?")->execute([$this->connection_config['charset']]);
$this->dbh->prepare("SET CHARACTER SET ?")->execute([$this->connection_config['charset']]);
$this->dbh->prepare('SET NAMES ?')->execute([$this->connection_config['charset']]);
$this->dbh->prepare('SET CHARACTER SET ?')->execute([$this->connection_config['charset']]);
}
}
}
27 changes: 12 additions & 15 deletions src/Magnetar/Database/MySQL/DatabaseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@ class DatabaseAdapter extends BaseDatabaseAdapter {
protected function validateRuntime(): void {
parent::validateRuntime();

// check if the PDO MySQL extension is loaded
if(!extension_loaded('pdo_mysql')) {
throw new RuntimeException('The PDO MySQL extension (pdo_mysql) is not loaded');
}

if(!isset($this->connection_config['host'])) {
throw new DatabaseAdapterException("Database configuration is missing host");
throw new DatabaseAdapterException('Database configuration is missing host');
}

if(!isset($this->connection_config['port'])) {
throw new DatabaseAdapterException("Database configuration is missing port");
throw new DatabaseAdapterException('Database configuration is missing port');
}

//if(!isset($this->connection_config['user'])) {
// throw new DatabaseAdapterException("Database configuration is missing user");
// throw new DatabaseAdapterException('Database configuration is missing user');
//}
//
//if(!isset($this->connection_config['password'])) {
// throw new DatabaseAdapterException("Database configuration is missing password");
// throw new DatabaseAdapterException('Database configuration is missing password');
//}

if(!isset($this->connection_config['database'])) {
throw new DatabaseAdapterException("Database configuration is missing database");
}

// check if the PDO MySQL extension is loaded
if(!extension_loaded('pdo_mysql')) {
throw new RuntimeException("The PDO MySQL extension (pdo_mysql) is not loaded");
throw new DatabaseAdapterException('Database configuration is missing database');
}
}

Expand All @@ -64,11 +64,8 @@ protected function postConnection(): void {

// optional charset settings
if(isset($this->connection_config['charset'])) {
//$this->dbh->exec("SET NAMES ". $this->connection_config['charset']);
//$this->dbh->exec("SET CHARACTER SET ". $this->connection_config['charset']);

$this->dbh->prepare("SET NAMES ?")->execute([$this->connection_config['charset']]);
$this->dbh->prepare("SET CHARACTER SET ?")->execute([$this->connection_config['charset']]);
$this->dbh->prepare('SET NAMES ?')->execute([$this->connection_config['charset']]);
$this->dbh->prepare('SET CHARACTER SET ?')->execute([$this->connection_config['charset']]);
}
}
}
23 changes: 11 additions & 12 deletions src/Magnetar/Database/PostgreSQL/DatabaseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@ class DatabaseAdapter extends BaseDatabaseAdapter {
protected function validateRuntime(): void {
parent::validateRuntime();

// check if the PDO PostgreSQL extension is loaded
if(!extension_loaded('pdo_pgsql')) {
throw new RuntimeException('The PDO PostgreSQL extension (pdo_pgsql) is not loaded');
}

if(!isset($this->connection_config['host'])) {
throw new DatabaseAdapterException("Database configuration is missing host");
throw new DatabaseAdapterException('Database configuration is missing host');
}

if(!isset($this->connection_config['port'])) {
throw new DatabaseAdapterException("Database configuration is missing port");
throw new DatabaseAdapterException('Database configuration is missing port');
}

//if(!isset($this->connection_config['user'])) {
// throw new DatabaseAdapterException("Database configuration is missing user");
// throw new DatabaseAdapterException('Database configuration is missing user');
//}
//
//if(!isset($this->connection_config['password'])) {
// throw new DatabaseAdapterException("Database configuration is missing password");
// throw new DatabaseAdapterException('Database configuration is missing password');
//}

if(!isset($this->connection_config['database'])) {
throw new DatabaseAdapterException("Database configuration is missing database");
}

// check if the PDO PostgreSQL extension is loaded
if(!extension_loaded('pdo_pgsql')) {
throw new RuntimeException("The PDO PostgreSQL extension (pdo_pgsql) is not loaded");
throw new DatabaseAdapterException('Database configuration is missing database');
}
}

Expand All @@ -64,8 +64,7 @@ protected function postConnection(): void {

// optional charset settings
if(isset($this->connection_config['charset'])) {
//$this->pdo->prepare("SET CLIENT_ENCODING TO ?")->execute([$this->connection_config['charset']]);
$this->dbh->prepare("SET NAMES ?")->execute([$this->connection_config['charset']]);
$this->dbh->prepare('SET NAMES ?')->execute([$this->connection_config['charset']]);
}
}
}
21 changes: 10 additions & 11 deletions src/Magnetar/Database/SQLServer/DatabaseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ class DatabaseAdapter extends BaseDatabaseAdapter {
protected function validateRuntime(): void {
parent::validateRuntime();

// check if the PDO SQLSRV extension is loaded
if(!extension_loaded('pdo_sqlsrv')) {
throw new RuntimeException('The PDO SQLServer extension (pdo_sqlsrv) is not loaded');
}

if(!isset($this->connection_config['host'])) {
throw new DatabaseAdapterException("Database configuration is missing host");
throw new DatabaseAdapterException('Database configuration is missing host');
}

//if(!isset($this->connection_config['user'])) {
// throw new DatabaseAdapterException("Database configuration is missing user");
// throw new DatabaseAdapterException('Database configuration is missing user');
//}
//
//if(!isset($this->connection_config['password'])) {
// throw new DatabaseAdapterException("Database configuration is missing password");
// throw new DatabaseAdapterException('Database configuration is missing password');
//}

if(!isset($this->connection_config['database'])) {
throw new DatabaseAdapterException("Database configuration is missing database");
}

// check if the PDO SQLSRV extension is loaded
if(!extension_loaded('pdo_sqlsrv')) {
throw new RuntimeException("The PDO SQLServer extension (pdo_sqlsrv) is not loaded");
throw new DatabaseAdapterException('Database configuration is missing database');
}
}

Expand All @@ -57,8 +57,7 @@ protected function postConnection(): void {

// optional charset settings
if(isset($config['charset'])) {
//$this->dbh->exec("SET NAMES ". $config['charset']);
$this->dbh->prepare("SET NAMES ?")->execute([$config['charset']]);
$this->dbh->prepare('SET NAMES ?')->execute([$config['charset']]);
}
}
}
Loading

0 comments on commit 791b441

Please sign in to comment.