Skip to content

Commit d9d97b2

Browse files
committed
Add Crate\CratePDO as a better export symbol
Reason: Importing `Crate\PDO\PDO` without alias into the main namespace collides with PHP's native `PDO` class.
1 parent e0a982d commit d9d97b2

File tree

5 files changed

+89
-2
lines changed

5 files changed

+89
-2
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Unreleased
1010

1111
- Documentation: Added two standalone example programs about inserts
1212

13+
- Added ``Crate\CratePDO`` as a better export symbol, because importing
14+
``Crate\PDO\PDO`` without alias into the main namespace collides with
15+
PHP's native ``PDO`` class.
16+
1317
.. _CrateDB bulk operations: https://crate.io/docs/crate/reference/en/latest/interfaces/http.html#bulk-operations
1418

1519
2022/11/29 2.1.4

examples/insert_basic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
error_reporting(E_ALL ^ E_DEPRECATED);
1616

1717
// Connect to CrateDB.
18-
use Crate\PDO\PDO as CratePDO;
18+
use Crate\CratePDO;
1919
$connection = new CratePDO("crate:localhost:4200", "crate");
2020

2121
// Create database table.

examples/insert_bulk.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
error_reporting(E_ALL ^ E_DEPRECATED);
1717

1818
// Connect to CrateDB.
19-
use Crate\PDO\PDO as CratePDO;
19+
use Crate\CratePDO;
2020
$connection = new CratePDO("crate:localhost:4200", "crate");
2121

2222
// Create database table.

src/Crate/CratePDO.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Licensed to CRATE Technology GmbH("Crate") under one or more contributor
4+
* license agreements. See the NOTICE file distributed with this work for
5+
* additional information regarding copyright ownership. Crate licenses
6+
* this file to you under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License. You may
8+
* obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
* License for the specific language governing permissions and limitations
16+
* under the License.
17+
*
18+
* However, if you have executed another commercial license agreement
19+
* with Crate these terms will supersede the license and you may use the
20+
* software solely pursuant to the terms of the relevant commercial agreement.
21+
*/
22+
23+
declare(strict_types=1);
24+
25+
namespace Crate;
26+
27+
use Crate\PDO\PDO;
28+
use Crate\PDO\PDOImplementation;
29+
use Crate\PDO\PDOInterface;
30+
31+
class CratePDO extends PDO implements PDOInterface
32+
{
33+
use PDOImplementation;
34+
}

test/CrateTest/CratePDOTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Licensed to CRATE Technology GmbH("Crate") under one or more contributor
4+
* license agreements. See the NOTICE file distributed with this work for
5+
* additional information regarding copyright ownership. Crate licenses
6+
* this file to you under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License. You may
8+
* obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
* License for the specific language governing permissions and limitations
16+
* under the License.
17+
*
18+
* However, if you have executed another commercial license agreement
19+
* with Crate these terms will supersede the license and you may use the
20+
* software solely pursuant to the terms of the relevant commercial agreement.
21+
*/
22+
23+
namespace CrateTest;
24+
25+
use Crate\CratePDO;
26+
use PHPUnit\Framework\TestCase;
27+
28+
/**
29+
* Tests for {@see \Crate\CratePDO}
30+
*
31+
* @coversDefaultClass \Crate\CratePDO
32+
* @covers ::<!public>
33+
*
34+
* @group unit
35+
*/
36+
class CratePDOTest extends TestCase
37+
{
38+
/**
39+
* @covers ::__construct
40+
*/
41+
public function testInstantiation()
42+
{
43+
$pdo = new CratePDO('crate:localhost:1234', null, null, []);
44+
45+
$this->assertInstanceOf(CratePDO::class, $pdo);
46+
$this->assertInstanceOf('PDO', $pdo);
47+
}
48+
49+
}

0 commit comments

Comments
 (0)