1- # PHP Weak extension
1+ # PHP Ref extension
22
3- [ ![ Build Status] ( https://travis-ci.org/pinepain/php-weak .svg )] ( https://travis-ci.org/pinepain/php-weak )
4- [ ![ Windows Build status] ( https://ci.appveyor.com/api/projects/status/7r07eydi6c3lj36a/branch/master?svg=true )] ( https://ci.appveyor.com/project/pinepain/php-weak )
5- [ ![ GitHub license] ( https://img.shields.io/badge/license-MIT-blue.svg )] ( https://raw.githubusercontent.com/pinepain/php-weak /master/LICENSE )
3+ [ ![ Build Status] ( https://travis-ci.org/pinepain/php-ref .svg )] ( https://travis-ci.org/pinepain/php-ref )
4+ [ ![ Windows Build status] ( https://ci.appveyor.com/api/projects/status/7r07eydi6c3lj36a/branch/master?svg=true )] ( https://ci.appveyor.com/project/pinepain/php-ref )
5+ [ ![ GitHub license] ( https://img.shields.io/badge/license-MIT-blue.svg )] ( https://raw.githubusercontent.com/pinepain/php-ref /master/LICENSE )
66
77This extension adds [ Soft Reference] ( https://en.wikipedia.org/wiki/Weak_reference ) and
88[ Weak References] ( https://en.wikipedia.org/wiki/Weak_reference ) to PHP 7 and may serve as a ground for other
@@ -14,8 +14,8 @@ data structures that require advanced referencing model.
1414``` php
1515<?php
1616
17- use Weak\Reference ;
18- use Weak \SoftReference;
17+ use Ref\WeakReference ;
18+ use Ref \SoftReference;
1919
2020$obj = new class {
2121 public function __destruct() {
@@ -32,29 +32,32 @@ $obj = null; // outputs "Object will be destroyed", "Destructor called", "Object
3232
3333## Docs
3434
35- This extension adds ` Weak ` namespace and all entities are created inside it.
35+ This extension adds ` Ref ` namespace and all entities are created inside it.
3636
3737There are no INI setting or constants provided by this extension.
3838
39- Brief docs about classes and [ functions] ( ./stubs/weak /functions.php )
40- may be seen in [ stub files] ( ./stubs/weak ) .
39+ Brief docs about classes and [ functions] ( ./stubs/src /functions.php )
40+ may be seen in [ stub files] ( ./stubs/src ) .
4141
4242Short list if what provided by this extension is:
4343
44- - ` abstract class Weak\AbstractReference ` * may not be subclassed directly* [ doc] ( ./stubs/weak/AbstractReference.php )
45- - ` class Weak\SoftReference extends AbstractReference ` [ doc] ( ./stubs/weak/SoftReference.php )
46- - ` class Weak\Reference extends AbstractReference ` [ doc] ( ./stubs/weak/Reference.php )
47- - ` class Weak\NotifierException extend Exception ` [ doc] ( ./stubs/weak/NotifierException.php )
48- - ` function Weak\refcounted() `
49- - ` function Weak\refcount() `
50- - ` function Weak\softrefcounted() `
51- - ` function Weak\softrefcount() `
52- - ` function Weak\softrefs() `
53- - ` function Weak\weakrefcounted() `
54- - ` function Weak\weakrefcount() `
55- - ` function Weak\weakrefs() `
56- - ` function Weak\object_handle() `
57- - ` function Weak\is_obj_destructor_called() `
44+ Classes:
45+ - ` abstract class Ref\AbstractReference ` * may not be subclassed directly* ([ doc] ( ./stubs/src/AbstractReference.php ) )
46+ - ` class Ref\SoftReference extends AbstractReference ` ([ doc] ( ./stubs/srd/SoftReference.php ) )
47+ - ` class Ref\WeakReference extends AbstractReference ` ([ doc] ( ./stubs/src/Reference.php ) )
48+ - ` class Ref\NotifierException extend Exception ` ([ doc] ( ./stubs/src/NotifierException.php ) )
49+
50+ Functions ([ doc] ( ./stubs/src/functions.php ) ):
51+ - ` function Ref\refcounted() `
52+ - ` function Ref\refcount() `
53+ - ` function Ref\softrefcounted() `
54+ - ` function Ref\softrefcount() `
55+ - ` function Ref\softrefs() `
56+ - ` function Ref\weakrefcounted() `
57+ - ` function Ref\weakrefcount() `
58+ - ` function Ref\weakrefs() `
59+ - ` function Ref\object_handle() `
60+ - ` function Ref\is_obj_destructor_called() `
5861
5962### References
6063
@@ -68,13 +71,13 @@ Note: What this extension provides aren't quite actual soft and weak references,
6871
6972Notifier can be one of ` callable ` , ` array ` or ` null ` types. ` null ` notifier denotes no notifier set.
7073
71- Note that notification happens * after* referent object destruction, so at the time of notification ` Weak \Referent::get()`
74+ Note that notification happens * after* referent object destruction, so at the time of notification ` Ref \Referent::get()`
7275will return ` null ` (unless rare case when object refcount get incremented in destructor, e.g. by storing destructing value
7376somewhere else).
7477
7578If object destructor or one or more notifiers throw exception, all further notifier callbacks will be called as if
76- that exception was thrown inside ` try-catch ` block. In case one or more exceptions were thrown, ` Weak \NotifierException`
77- will be thrown and all thrown exceptions will be available via ` Weak \NotifierException::getExceptions()` method.
79+ that exception was thrown inside ` try-catch ` block. In case one or more exceptions were thrown, ` Ref \NotifierException`
80+ will be thrown and all thrown exceptions will be available via ` Ref \NotifierException::getExceptions()` method.
7881
7982
8083### Cloning
@@ -85,7 +88,7 @@ but they will be invoked with different reference objects.
8588``` php
8689<?php
8790
88- use Weak\Reference ;
91+ use Ref\WeakReference ;
8992
9093$obj = new stdClass();
9194
@@ -100,7 +103,7 @@ To avoid this you may want to change notifier in `__clone()` method:
100103``` php
101104<?php
102105
103- class OwnNotifierReference extends Weak\Reference
106+ class OwnNotifierReference extends Ref\WeakReference
104107{
105108 public function __clone()
106109 {
@@ -127,11 +130,11 @@ fatal error.
127130
128131## Stub files
129132
130- If you are also using Composer, it is recommended to add the [ php-weak -stub] ( https://github.com/pinepain/php-weak -stubs )
133+ If you are also using Composer, it is recommended to add the [ php-ref -stub] ( https://github.com/pinepain/php-ref -stubs )
131134package as a dev-mode requirement. It provides skeleton definitions and annotations to enable support for auto-completion
132135in your IDE and other code-analysis tools.
133136
134- composer require --dev pinepain/php-weak -stubs
137+ composer require --dev pinepain/php-ref -stubs
135138
136139
137140## Extra weak data structures support
@@ -148,8 +151,8 @@ to add it to your project.
148151
149152### Building from sources
150153
151- git clone https://github.com/pinepain/php-weak .git
152- cd php-weak
154+ git clone https://github.com/pinepain/php-ref .git
155+ cd php-ref
153156 phpize && ./configure && make
154157 make test
155158
@@ -160,22 +163,22 @@ To install extension globally run
160163You will need to copy the extension config to your php dir, here is example for Ubuntu with PHP 7.0 from
161164[ Ondřej Surý's PPA for PHP] ( https://launchpad.net/~ondrej/+archive/ubuntu/php ) :
162165
163- # sudo cp provision/php/weak .ini /etc/php/mods-available/
164- # sudo phpenmod -v ALL weak
166+ # sudo cp provision/php/ref .ini /etc/php/mods-available/
167+ # sudo phpenmod -v ALL ref
165168 # sudo service php7.0-fpm restart
166169
167- You may also want to add php-weak extension as a [ composer.json dependency] ( https://getcomposer.org/doc/02-libraries.md#platform-packages ) :
170+ You may also want to add php-ref extension as a [ composer.json dependency] ( https://getcomposer.org/doc/02-libraries.md#platform-packages ) :
168171
169172 "require": {
170173 ...
171- "ext-weak ": "~0.1.0"
174+ "ext-ref ": "~0.1.0"
172175 ...
173176 }
174177
175178
176179## Internals
177180
178- ` Weak\Reference ` class is implemented by storing tracked object handlers and then wrapping it original ` dtor_obj ` handler
181+ ` Ref\WeakReference ` class is implemented by storing tracked object handlers and then wrapping it original ` dtor_obj ` handler
179182with a custom one, which meta-code is:
180183
181184``` php
@@ -194,7 +197,7 @@ foreach($soft_references as $soft_ref_object_handle => $soft_reference) {
194197}
195198
196199if ($exceptions) {
197- throw new Weak \NotifierException('One or more exceptions thrown during notifiers calling', $exceptions);
200+ throw new Ref \NotifierException('One or more exceptions thrown during notifiers calling', $exceptions);
198201}
199202
200203if (refcount($object) == 1) {
@@ -217,7 +220,7 @@ if (refcount($object) == 1) {
217220 }
218221
219222 if ($exceptions) {
220- throw new Weak \NotifierException('One or more exceptions thrown during notifiers calling', $exceptions);
223+ throw new Ref \NotifierException('One or more exceptions thrown during notifiers calling', $exceptions);
221224 }
222225} else {
223226 // required while internally PHP GC mark object as it dtor was called before calling dtor
@@ -228,7 +231,7 @@ if (refcount($object) == 1) {
228231## Development and testing
229232
230233This extension shipped with Vagrant file which provides basic environment for development and testing purposes.
231- To start it, just type ` vagrant up ` and then ` vagrant ssh ` in php-weak directory.
234+ To start it, just type ` vagrant up ` and then ` vagrant ssh ` in php-ref directory.
232235
233236Services available out of the box are:
234237
@@ -270,4 +273,4 @@ between large variety of PHP versions.
270273
271274## License
272275
273- [ php-weak ] ( https://github.com/pinepain/php-weak ) PHP extension is licensed under the [ MIT license] ( http://opensource.org/licenses/MIT ) .
276+ [ php-ref ] ( https://github.com/pinepain/php-ref ) PHP extension is licensed under the [ MIT license] ( http://opensource.org/licenses/MIT ) .
0 commit comments