Skip to content

Commit

Permalink
updating namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
raghuveer committed Feb 25, 2024
1 parent b6cb9fc commit f2fbeab
Show file tree
Hide file tree
Showing 20 changed files with 1,320 additions and 12 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"monolog/monolog": "^3.5",
"amphp/log": "^2.0",
"illuminate/container": "^10.45",
"phpunit/php-timer": "^7.0"
"phpunit/php-timer": "^7.0",
"filp/whoops": "^2.15"
},
"require-dev": {
"ext-json": "*",
Expand Down Expand Up @@ -43,4 +44,4 @@
"EaseAppPHP\\EARapid\\": "src/"
}
}
}
}
20 changes: 10 additions & 10 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,23 @@
*/
public function __construct(Container $container)
{
/* $this->container = $container;
$this->container = $container;

$this->config = $this->container->get('config'); */
$this->config = $this->container->get('config');

/*
*--------------------------------------------------------------------------
* Define Default timezone
*--------------------------------------------------------------------------
*
*/
/* if (function_exists("date_default_timezone_set")) {
if (function_exists("date_default_timezone_set")) {

date_default_timezone_set($_ENV['TIMEZONE']);

}
*/
/* //Check if the request is based upon Console or Web

//Check if the request is based upon Console or Web
$eaIsConsole = new EAIsConsole();
$this->container->instance('EAIsConsole', $eaIsConsole);
$this->eaIsConsoleInstance = $this->container->get('EAIsConsole')->checkSTDIN();
Expand Down Expand Up @@ -160,7 +160,7 @@ public function __construct(Container $container)

$this->container->instance('argv', $this->argv);

} */
}

}

Expand All @@ -171,7 +171,7 @@ public function __construct(Container $container)
*/
public function init()
{
/* if ($this->container->get('EARequestConsoleStatusResult') == "Console") {
if ($this->container->get('EARequestConsoleStatusResult') == "Console") {

//Console
if ($_ENV['APP_DEBUG'] == "true") {
Expand Down Expand Up @@ -204,7 +204,7 @@ public function init()
//Save available Serviceproviders to Container
$this->container->instance('EALoadedServiceProviders', $this->loadedProviders);
$this->eaLoadedServiceProvidersList = $this->container->get('EALoadedServiceProviders');
} */
}
}

/**
Expand All @@ -214,7 +214,7 @@ public function init()
*/
public function run()
{
/* if ($this->container->get('EARequestConsoleStatusResult') == "Console") {
if ($this->container->get('EARequestConsoleStatusResult') == "Console") {

//Console

Expand Down Expand Up @@ -378,7 +378,7 @@ static function (\Throwable $e) {
$this->requestHandlerRunnerServerInstance = $this->container->get('\Laminas\HttpHandlerRunner\RequestHandlerRunner');
$this->requestHandlerRunnerServerInstance->run();

} */
}
}

/**
Expand Down
179 changes: 179 additions & 0 deletions src/Core/EAConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php
declare(strict_types=1);

namespace EaseAppPHP\EARapid\Core;

use \Illuminate\Container\Container;

/**
* EAConfig Class
*
*/

class EAConfig
{
protected $container;
protected $serverRequest;
public $config = array();
public $singleFileNameExploded = array();
public $singleConfigItemArray = array();
public $singleConfigItemString = "";
public $singleConfigItemNull = null;
public $dotSeparatedKeyBasedConfigArray = array();

public function __construct(Container $container)
{
$this->container = $container;
$this->serverRequest = $this->container->get('\Laminas\Diactoros\ServerRequestFactory');
}

/**
* Accepts Extracted Config Array
*
* @param array $configArray
* @return array
*/
public function getAsArray($configArray = array())
{
$this->config = $configArray;

return $this->config;
}

/**
* Gets the Config Array from a Single Config File
*
* @param string $filePath
* @return array
*/
public function getFromSingleFile(string $filePath)
{
//$config = require __DIR__.'/main-config.php';
return require $filePath;
}

/**
* Gets the Config Array from Multiple Config Files, that resides in a Single Config Folder. This method will read only PHP Files with Config info in an array, and specifically does not read those Config files, that have spaces in the filename.
*
* @param string $folderPath
* @return array
*/
public function getFromSingleFolder(string $folderPath)
{
foreach (glob($folderPath . "/*.php") as $singleFilePath) {

$this->singleFileNameExploded = explode(".", basename($singleFilePath));

if (stripos($this->singleFileNameExploded[0], " ") === false) {

$this->config[$this->singleFileNameExploded[0]] = require $singleFilePath;

}

}

return $this->config;
}

/**
* Gets the Config Array from Multiple Config Files, which list is provided as a numeric index array. This method will read only PHP Files with Config info in an array, from given paths.
*
* @param array $filepathsArray
* @return array
*/
public function getFromFilepathsArray(array $filepathsArray)
{
foreach ($filepathsArray as $singleFilePath) {

$this->singleFileNameExploded = explode(".", basename($singleFilePath));

if (stripos($this->singleFileNameExploded[0], " ") === false) {

$this->config[$this->singleFileNameExploded[0]] = require $singleFilePath;

}

}

return $this->config;
}

/**
* Get the Config Array Data
*
* @param array $filepathsArray
* @return array
*/
public function get(string $configSource, string $configSourceValueDataType, string $configSourceValueData)
{

if (($configSource == 'As-Array') && ($configSourceValueDataType == 'array') && (is_array($configSourceValueData))) {

$collectedConfigData = $this->getAsArray($configSourceValueData);

} elseif (($configSource == 'From-Single-File') && ($configSourceValueDataType == 'string') && (is_string($configSourceValueData))) {

$collectedConfigData = $this->getFromSingleFile($configSourceValueData);

} elseif (($configSource == 'From-Single-Folder') && ($configSourceValueDataType == 'string') && (is_string($configSourceValueData))) {

$collectedConfigData = $this->getFromSingleFolder($configSourceValueData);

} elseif (($configSource == 'From-Filepaths-Array') && ($configSourceValueDataType == 'array') && (is_array($configSourceValueData))) {

$collectedConfigData = $this->getFromFilepathsArray($configSourceValueData);

}

return $collectedConfigData;
}

/**
* Generate dot seperated keys based config array, from the multi-dimensional config array.
*
* @param array $multiDimensionalConfigArray
* @param string $prefix - an optional input parameter as prefix to all generated keys
* @return array
*/
public function generateDotSeparatedKeyBasedConfigArray(array $multiDimensionalConfigArray, $prefix = '')
{

foreach ($multiDimensionalConfigArray as $key => $value) {

if (is_array($value) && ! empty($value)) {

$this->dotSeparatedKeyBasedConfigArray[$prefix.$key] = $value;

$this->dotSeparatedKeyBasedConfigArray = array_merge($this->dotSeparatedKeyBasedConfigArray, $this->generateDotSeparatedKeyBasedConfigArray($value, $prefix.$key.'.'));

} else {

$this->dotSeparatedKeyBasedConfigArray[$prefix.$key] = $value;

}

}

return $this->dotSeparatedKeyBasedConfigArray;
}

/**
* Gets the specific Config Array item from dot separated key based config array.
*
* @param string $dotSeperatedConfigItem
* @return mixed
*/
public function getDotSeparatedKeyValue(string $dotSeperatedConfigItem)
{

if (isset($this->dotSeparatedKeyBasedConfigArray[$dotSeperatedConfigItem])) {

return $this->dotSeparatedKeyBasedConfigArray[$dotSeperatedConfigItem];

} else {
return null;
}

}

}
38 changes: 38 additions & 0 deletions src/Core/EAIsConsole.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);

namespace EaseAppPHP\EARapid\Core;

/**
* EAIsConsole Class
*
*/

class EAIsConsole
{
private $consoleCheckResult;

/**
* Checks if STDIN is Defined
*
* @param array $configArray
* @return array
*/
public function checkSTDIN()
{
if(defined('STDIN') ){

//echo("Running from CLI Console");
$this->consoleCheckResult = "Console";

}else{

//echo("Not Running from CLI");
$this->consoleCheckResult = "Web";

}

return $this->consoleCheckResult;
}

}
1 change: 1 addition & 0 deletions src/Core/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><title></title>
Loading

0 comments on commit f2fbeab

Please sign in to comment.