diff --git a/src/ncc/Abstracts/ExceptionCodes.php b/src/ncc/Abstracts/ExceptionCodes.php index cbd94bc..b6ffcf6 100644 --- a/src/ncc/Abstracts/ExceptionCodes.php +++ b/src/ncc/Abstracts/ExceptionCodes.php @@ -14,6 +14,7 @@ use ncc\Exceptions\InvalidScopeException; use ncc\Exceptions\InvalidVersionNumberException; use ncc\Exceptions\MalformedJsonException; + use ncc\Exceptions\MethodNotAvailableException; use ncc\Exceptions\ProjectAlreadyExistsException; use ncc\Exceptions\RuntimeException; diff --git a/src/ncc/Classes/EnvironmentConfiguration/EnvironmentConfiguration.php b/src/ncc/Classes/EnvironmentConfiguration/EnvironmentConfiguration.php new file mode 100644 index 0000000..53eb268 --- /dev/null +++ b/src/ncc/Classes/EnvironmentConfiguration/EnvironmentConfiguration.php @@ -0,0 +1,71 @@ + $config) + { + $results[$name] = PhpConfiguration::fromArray($config); + } + + return $results; + } + + /** + * Returns an array of only the changed configuration values + * + * @return PhpConfiguration[] + */ + public static function getChangedValues(): array + { + $results = []; + + foreach(ini_get_all() as $name => $config) + { + $config = PhpConfiguration::fromArray($config); + if($config->LocalValue !== $config->GlobalValue) + { + $results[$name] = $config; + } + } + + return $results; + } + + /** + * @param string $file_path + * @return void + */ + public static function export(string $file_path) + { + $configuration = []; + foreach(self::getChangedValues() as $changedValue) + { + $configuration[$changedValue->getName()] = $changedValue->getValue(); + } + + // TODO: Implement ini writing process here + } + + public static function import(string $file_path) + { + // TODO: Implement ini reading process here + $configuration = []; + foreach($configuration as $item => $value) + { + ini_set($item, $value); + } + } + } \ No newline at end of file diff --git a/src/ncc/Objects/PhpConfiguration.php b/src/ncc/Objects/PhpConfiguration.php new file mode 100644 index 0000000..e6d4e50 --- /dev/null +++ b/src/ncc/Objects/PhpConfiguration.php @@ -0,0 +1,139 @@ +Name == null) + { + return false; + } + + ini_set($this->Name, $value); + return true; + } + + /** + * Returns the current value set for this configuration + * + * @return string + * @noinspection PhpUnused + */ + public function getValue(): string + { + return $this->LocalValue; + } + + /** + * Resets the configuration value to its default state + * + * @return bool + * @noinspection PhpUnused + */ + public function resetValue(): bool + { + if($this->Name == null) + { + return false; + } + + ini_restore($this->Name); + return true; + } + + /** + * Returns an array representation of the object + * + * @return array + * @noinspection PhpArrayShapeAttributeCanBeAddedInspection + */ + public function toArray(): array + { + return [ + 'global_value' => $this->GlobalValue, + 'local_value' => $this->LocalValue, + 'access' => $this->Access + ]; + } + + /** + * Constructs the object from an array representation + * + * @param array $data + * @param string|null $name + * @return PhpConfiguration + */ + public static function fromArray(array $data, ?string $name=null): PhpConfiguration + { + $PhpConfiguratoinObject = new PhpConfiguration(); + + if($name !== null) + { + $PhpConfiguratoinObject->Name = $name; + } + + if(isset($data['global_value'])) + { + $PhpConfiguratoinObject->GlobalValue = $data['global_value']; + } + + if(isset($data['local_value'])) + { + $PhpConfiguratoinObject->LocalValue = $data['local_value']; + } + + if(isset($data['access'])) + { + $PhpConfiguratoinObject->Access = $data['access']; + } + + return $PhpConfiguratoinObject; + } + + /** + * @return string|null + */ + public function getName(): ?string + { + return $this->Name; + } + } \ No newline at end of file