Skip to content

Commit 492be88

Browse files
committed
removed deprecated class
clean up properties class
1 parent d145ff1 commit 492be88

File tree

2 files changed

+39
-229
lines changed

2 files changed

+39
-229
lines changed

src/System/PHPString.php

Lines changed: 0 additions & 185 deletions
This file was deleted.
Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
/**
34
* MIT License
45
*
@@ -28,65 +29,62 @@
2829
use doganoo\PHPUtil\Exception\FileNotFoundException;
2930
use doganoo\PHPUtil\Exception\InvalidPropertyStructureException;
3031
use doganoo\PHPUtil\Exception\NoPathException;
32+
use function array_keys;
33+
use function count;
34+
use function is_file;
35+
use function trim;
3136

3237
/**
33-
* Class SysProperties
34-
*
35-
* @package Core\Objects
38+
* Class Properties
39+
* @package doganoo\PHPUtil\System
40+
* @author Dogan Ucar <dogan@dogan-ucar.de>
3641
*/
37-
class SysProperties {
42+
class Properties {
3843

39-
/**
40-
* @var null
41-
*/
42-
private static $path = null;
44+
/** @var string */
45+
private $path;
4346

44-
/**
45-
* @var null|array $properties
46-
*/
47-
private $properties = null;
47+
/** @var array */
48+
private $properties;
4849

4950
/**
51+
* Properties constructor.
5052
* @param string $path
5153
*/
52-
public static function setPropertiesPath(string $path) {
53-
self::$path = $path;
54+
public function __construct(string $path) {
55+
$this->path = $path;
5456
}
5557

5658
/**
57-
* @param string $index
58-
* @return string
59-
* @throws FileNotFoundException
60-
* @throws NoPathException
61-
* @throws InvalidPropertyStructureException
59+
* reads the property value assigned to $key
60+
* @param string $key
61+
* @return string|null
6262
*/
63-
public function read(string $index): string {
64-
$index = \trim($index);
65-
$properties = $this->getProperties();
66-
if (isset($properties[$index])) {
67-
return $properties[$index];
68-
} else {
69-
throw new \InvalidArgumentException();
70-
}
63+
public function read(string $key): ?string {
64+
$key = trim($key);
65+
$properties = $this->loadProperties();
66+
return $this->properties[$key] ?? null;
7167
}
7268

7369
/**
70+
* loads the ini file located at a given path
71+
*
7472
* @return array
7573
* @throws FileNotFoundException
76-
* @throws NoPathException
7774
* @throws InvalidPropertyStructureException
75+
* @throws NoPathException
7876
*/
79-
private function getProperties(): array {
77+
private function loadProperties(): array {
8078
if (null !== $this->properties) {
8179
return $this->properties;
8280
}
83-
if (self::$path === null) {
81+
if (null === $this->path) {
8482
throw new NoPathException();
8583
}
86-
if (!\is_file(self::$path)) {
84+
if (!is_file($this->path)) {
8785
throw new FileNotFoundException();
8886
}
89-
$ini = parse_ini_file(self::$path);
87+
$ini = parse_ini_file($this->path);
9088
if (false === $ini) {
9189
throw new InvalidPropertyStructureException();
9290
}
@@ -95,26 +93,23 @@ private function getProperties(): array {
9593
}
9694

9795
/**
96+
* returns the number of properties
97+
*
9898
* @return int
99-
* @throws FileNotFoundException
100-
* @throws InvalidPropertyStructureException
101-
* @throws NoPathException
10299
*/
103100
public function size(): int {
104-
$properties = $this->getProperties();
105-
return \count($properties);
101+
$properties = $this->loadProperties();
102+
return count($properties);
106103
}
107104

108105
/**
106+
* returns the key set of the properties
107+
*
109108
* @return array
110-
* @throws FileNotFoundException
111-
* @throws InvalidPropertyStructureException
112-
* @throws NoPathException
113109
*/
114110
public function keySet(): array {
115-
$array = $this->getProperties();
116-
$array = \array_keys($array);
117-
return $array;
111+
$array = $this->loadProperties();
112+
return array_keys($array);
118113
}
119114

120-
}
115+
}

0 commit comments

Comments
 (0)