Skip to content

Commit 0cc586e

Browse files
committed
Improve the bundled autoloader
1 parent 5003161 commit 0cc586e

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

CHANGES.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
## v1.1.0 (2017-06-28) ##
44

5-
* Empty objects and objects that don't implement `Traversable` are now always
6-
encoded as JSON objects (for `json_encode()` compatibility).
7-
* Associative array testing now returns faster and more memory efficiently
8-
* JSON encoding errors now contain the error constant
9-
* The visibility for `write()` method in `StreamJsonEncoder` and
10-
`BufferJsonEncoder` has been changed to protected (as originally intended)
11-
* A protected method `getValueStack()` has been added to `AbstractJsonEncoder`
12-
that returns current unresolved value stack (for special write method
5+
* For `json_encode()` compatibility, all objects are encoded as JSON objects
6+
unless they implement `Traversable` and either return `0` as the first key or
7+
return no values at all.
8+
* Testing for associative arrays is now more memory efficient and fails faster.
9+
* JSON encoding errors now contain the error constant.
10+
* The visibility for `StreamJsonEncoder::write()` and `BufferJsonEncoder::write()`
11+
has been changed to protected (as was originally intended).
12+
* A new protected method `AbstractJsonEncoder::getValueStack()` has been added
13+
that returns the current unresolved value stack (for special write method
1314
implementations).
14-
* An overridable protected method `resolveValue()` has been added to
15-
`AbstractJsonEncoder` which is used to resolve closures and objects
16-
implementing `JsonSerializable`.
15+
* An overridable protected method `AbstractJsonEncoder::resolveValue()` has
16+
been added which is used to resolve objects (i.e. resolving the value of
17+
closures and objects implementing `JsonSerializable`).
1718

1819
## v1.0.0 (2017-02-26) ##
1920

src/autoload.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
22

3-
// Autoloader for loading the library when composer is not available
3+
namespace Violet\StreamingJsonEncoder;
4+
45
spl_autoload_register(function ($class) {
5-
if (strncmp($class, $ns = 'Violet\\StreamingJsonEncoder', strlen($ns)) === 0) {
6-
$file = substr_replace($class, '\\', 0, strlen($ns)) . '.php';
7-
$path = __DIR__ . str_replace('\\', DIRECTORY_SEPARATOR, $file);
6+
if (strncmp($class, __NAMESPACE__, strlen(__NAMESPACE__)) === 0) {
7+
$path = __DIR__ . strtr(substr($class, strlen(__NAMESPACE__)), ['\\' => DIRECTORY_SEPARATOR]) . '.php';
8+
89
if (file_exists($path)) {
910
require $path;
1011
}

0 commit comments

Comments
 (0)