Skip to content

Commit 27c0e3b

Browse files
committed
Merge branch 'release/0.7.10'
2 parents 0e5a3d6 + ec14858 commit 27c0e3b

4 files changed

Lines changed: 65 additions & 4 deletions

File tree

.version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"strategy": "semver",
33
"major": 0,
44
"minor": 7,
5-
"patch": 9,
5+
"patch": 10,
66
"build": 0
77
}

VERSIONLOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
## 0.7.9 2026-01-13
1+
## 0.7.10 2026-01-14
2+
* Added the has method to the Registry.
23

4+
## 0.7.9 2026-01-13
35
## 0.7.8 2026-01-13
4-
56
## 0.7.7 2026-01-13
67

78
## 0.7.6 2025-12-27

src/Patterns/Registry.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
* // Retrieve objects (property syntax using magic methods)
3232
* $dbConfig = $registry->databaseConfig;
3333
*
34-
* // Check existence
34+
* // Check existence (method syntax)
35+
* $exists = $registry->has('database.config');
36+
*
37+
* // Check existence (property syntax using magic methods)
3538
* $exists = isset($registry->databaseConfig);
3639
*
3740
* // Cleanup
@@ -70,6 +73,17 @@ public function get( string $name ) : mixed
7073
return $this->_objects[ $name ];
7174
}
7275

76+
/**
77+
* Check if a named object exists in the registry.
78+
*
79+
* @param string $name The name of the object to check
80+
* @return bool True if the object exists, false otherwise
81+
*/
82+
public function has( string $name ): bool
83+
{
84+
return array_key_exists( $name, $this->_objects );
85+
}
86+
7387
/**
7488
* @return void
7589
*/

tests/Patterns/RegistryTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,52 @@ public function testMagicIsset()
9393
$this->assertFalse( isset( $Reg1->testKey ) );
9494
}
9595

96+
public function testHasMethod()
97+
{
98+
$Reg1 = Registry::getInstance();
99+
$Reg1->reset();
100+
101+
// Test has() returns false for non-existent key
102+
$this->assertFalse( $Reg1->has( 'testKey' ) );
103+
104+
// Set a value using regular method
105+
$Reg1->set( 'testKey', 'test value' );
106+
107+
// Test has() returns true for existing key
108+
$this->assertTrue( $Reg1->has( 'testKey' ) );
109+
110+
// Set another value using magic method
111+
$Reg1->magicKey = 'magic value';
112+
113+
// Test has() works with magic-set values
114+
$this->assertTrue( $Reg1->has( 'magicKey' ) );
115+
116+
// Reset and verify has() returns false
117+
$Reg1->reset();
118+
$this->assertFalse( $Reg1->has( 'testKey' ) );
119+
$this->assertFalse( $Reg1->has( 'magicKey' ) );
120+
}
121+
122+
public function testHasMethodConsistency()
123+
{
124+
$Reg1 = Registry::getInstance();
125+
$Reg1->reset();
126+
127+
// has() and isset() should be consistent
128+
$this->assertFalse( $Reg1->has( 'testKey' ) );
129+
$this->assertFalse( isset( $Reg1->testKey ) );
130+
131+
$Reg1->set( 'testKey', 'value' );
132+
133+
$this->assertTrue( $Reg1->has( 'testKey' ) );
134+
$this->assertTrue( isset( $Reg1->testKey ) );
135+
136+
// Test with null value - both should return true (key exists)
137+
$Reg1->set( 'nullKey', null );
138+
$this->assertTrue( $Reg1->has( 'nullKey' ) );
139+
$this->assertTrue( isset( $Reg1->nullKey ) );
140+
}
141+
96142
public function testMagicMethodsIntegration()
97143
{
98144
$Reg1 = Registry::getInstance();

0 commit comments

Comments
 (0)