Skip to content

Commit c4f7bc6

Browse files
authored
Add empty package when storing namespaced object in vehicle (#201)
Objects stored in an xPDOVehicle from classes with a namespace should not add a package containing that namespace to the vehicle payload. Doing so causes unnecessary attempts to load classes with the namespace prefixed to the already fully-qualified classname.
1 parent 5a5a3c0 commit c4f7bc6

File tree

7 files changed

+38
-2
lines changed

7 files changed

+38
-2
lines changed

src/xPDO/Transport/xPDOObjectVehicle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public function put(& $transport, & $object, $attributes = array ()) {
387387
parent :: put($transport, $object, $attributes);
388388
if (is_object($object)) {
389389
if (!isset ($this->payload['package'])) {
390-
if ($object instanceof xPDOObject) {
390+
if ($object instanceof xPDOObject && strpos(get_class($object), '\\') === false) {
391391
$packageName = $object->_package;
392392
} else {
393393
$packageName = '';

src/xPDO/Transport/xPDOVehicle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public function put(& $transport, & $object, $attributes = array ()) {
287287
$this->payload['guid'] = md5(uniqid(rand(), true));
288288
}
289289
if (!isset ($this->payload['package'])) {
290-
if ($object instanceof xPDOObject) {
290+
if ($object instanceof xPDOObject && strpos(get_class($object), '\\') === false) {
291291
$packageName = $object->_package;
292292
} else {
293293
$packageName = '';

test/complete.phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<file>./xPDO/Test/Cache/xPDOCacheDbTest.php</file>
3030
<file>./xPDO/Test/Compression/xPDOZipTest.php</file>
3131
<file>./xPDO/Test/Transport/xPDOTransportTest.php</file>
32+
<file>./xPDO/Test/Transport/xPDOVehicleTest.php</file>
3233
<file>./xPDO/Test/PSR4/xPDOTest.php</file>
3334
<file>./xPDO/Test/TearDownTest.php</file>
3435
</testsuite>

test/mysql.phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<file>./xPDO/Test/Cache/xPDOCacheDbTest.php</file>
3030
<file>./xPDO/Test/Compression/xPDOZipTest.php</file>
3131
<file>./xPDO/Test/Transport/xPDOTransportTest.php</file>
32+
<file>./xPDO/Test/Transport/xPDOVehicleTest.php</file>
3233
<file>./xPDO/Test/PSR4/xPDOTest.php</file>
3334
<file>./xPDO/Test/TearDownTest.php</file>
3435
</testsuite>

test/pgsql.phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<file>./xPDO/Test/Cache/xPDOCacheDbTest.php</file>
3030
<file>./xPDO/Test/Compression/xPDOZipTest.php</file>
3131
<file>./xPDO/Test/Transport/xPDOTransportTest.php</file>
32+
<file>./xPDO/Test/Transport/xPDOVehicleTest.php</file>
3233
<file>./xPDO/Test/PSR4/xPDOTest.php</file>
3334
<file>./xPDO/Test/TearDownTest.php</file>
3435
</testsuite>

test/sqlite.phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<file>./xPDO/Test/Cache/xPDOCacheDbTest.php</file>
3030
<file>./xPDO/Test/Compression/xPDOZipTest.php</file>
3131
<file>./xPDO/Test/Transport/xPDOTransportTest.php</file>
32+
<file>./xPDO/Test/Transport/xPDOVehicleTest.php</file>
3233
<file>./xPDO/Test/PSR4/xPDOTest.php</file>
3334
<file>./xPDO/Test/TearDownTest.php</file>
3435
</testsuite>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/*
3+
* The file is part of the xPDO package.
4+
*
5+
* Copyright (c) Jason Coward <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace xPDO\Test\Transport;
12+
13+
14+
use xPDO\Test\Sample\xPDOSample;
15+
use xPDO\TestCase;
16+
use xPDO\Transport\xPDOObjectVehicle;
17+
use xPDO\Transport\xPDOTransport;
18+
19+
class xPDOVehicleTest extends TestCase
20+
{
21+
public function testPutDoesNotAddPackageForNamespacedClass()
22+
{
23+
$transport = new xPDOTransport($this->xpdo, uniqid('transport-'), self::$properties['xpdo_test_path'] . 'fs/transport/');
24+
25+
$object = $this->xpdo->newObject(xPDOSample::class);
26+
27+
$vehicle = new xPDOObjectVehicle();
28+
$vehicle->put($transport, $object);
29+
30+
$this->assertEmpty($vehicle->payload['package']);
31+
}
32+
}

0 commit comments

Comments
 (0)