mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 14:16:39 +02:00
removed Dibi\Strict
This commit is contained in:
@@ -20,8 +20,6 @@ use Tracy;
|
||||
*/
|
||||
class Panel implements Tracy\IBarPanel
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var int maximum SQL length */
|
||||
public static $maxLength = 1000;
|
||||
|
||||
|
@@ -20,8 +20,6 @@ use Traversable;
|
||||
*/
|
||||
class Connection implements IConnection
|
||||
{
|
||||
use Strict;
|
||||
|
||||
/** @var array of function (Event $event); Occurs after query is executed */
|
||||
public $onEvent = [];
|
||||
|
||||
|
@@ -15,8 +15,6 @@ namespace Dibi;
|
||||
*/
|
||||
class DataSource implements IDataSource
|
||||
{
|
||||
use Strict;
|
||||
|
||||
/** @var Connection */
|
||||
private $connection;
|
||||
|
||||
|
@@ -15,8 +15,6 @@ namespace Dibi;
|
||||
*/
|
||||
class DateTime extends \DateTimeImmutable
|
||||
{
|
||||
use Strict;
|
||||
|
||||
/**
|
||||
* @param string|int $time
|
||||
*/
|
||||
|
@@ -17,8 +17,6 @@ use Dibi;
|
||||
*/
|
||||
class DummyDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
public function disconnect(): void
|
||||
{
|
||||
}
|
||||
|
@@ -26,8 +26,6 @@ use Dibi\Helpers;
|
||||
*/
|
||||
class FirebirdDriver implements Dibi\Driver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
public const ERROR_EXCEPTION_THROWN = -836;
|
||||
|
||||
/** @var resource */
|
||||
|
@@ -17,8 +17,6 @@ use Dibi;
|
||||
*/
|
||||
class FirebirdReflector implements Dibi\Reflector
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var Dibi\Driver */
|
||||
private $driver;
|
||||
|
||||
|
@@ -18,8 +18,6 @@ use Dibi\Helpers;
|
||||
*/
|
||||
class FirebirdResult implements Dibi\ResultDriver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var resource */
|
||||
private $resultSet;
|
||||
|
||||
|
@@ -18,8 +18,6 @@ use Dibi;
|
||||
*/
|
||||
class MySqlReflector implements Dibi\Reflector
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var Dibi\Driver */
|
||||
private $driver;
|
||||
|
||||
|
@@ -32,8 +32,6 @@ use Dibi;
|
||||
*/
|
||||
class MySqliDriver implements Dibi\Driver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
public const ERROR_ACCESS_DENIED = 1045;
|
||||
|
||||
public const ERROR_DUPLICATE_ENTRY = 1062;
|
||||
|
@@ -17,8 +17,6 @@ use Dibi;
|
||||
*/
|
||||
class MySqliResult implements Dibi\ResultDriver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var \mysqli_result */
|
||||
private $resultSet;
|
||||
|
||||
|
@@ -17,8 +17,6 @@ use Dibi;
|
||||
*/
|
||||
class NoDataResult implements Dibi\ResultDriver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var int */
|
||||
private $rows;
|
||||
|
||||
|
@@ -25,8 +25,6 @@ use Dibi;
|
||||
*/
|
||||
class OdbcDriver implements Dibi\Driver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var resource */
|
||||
private $connection;
|
||||
|
||||
|
@@ -17,8 +17,6 @@ use Dibi;
|
||||
*/
|
||||
class OdbcReflector implements Dibi\Reflector
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var Dibi\Driver */
|
||||
private $driver;
|
||||
|
||||
|
@@ -17,8 +17,6 @@ use Dibi;
|
||||
*/
|
||||
class OdbcResult implements Dibi\ResultDriver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var resource */
|
||||
private $resultSet;
|
||||
|
||||
|
@@ -27,8 +27,6 @@ use Dibi;
|
||||
*/
|
||||
class OracleDriver implements Dibi\Driver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var resource */
|
||||
private $connection;
|
||||
|
||||
|
@@ -17,8 +17,6 @@ use Dibi;
|
||||
*/
|
||||
class OracleReflector implements Dibi\Reflector
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var Dibi\Driver */
|
||||
private $driver;
|
||||
|
||||
|
@@ -17,8 +17,6 @@ use Dibi;
|
||||
*/
|
||||
class OracleResult implements Dibi\ResultDriver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var resource */
|
||||
private $resultSet;
|
||||
|
||||
|
@@ -27,8 +27,6 @@ use PDO;
|
||||
*/
|
||||
class PdoDriver implements Dibi\Driver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var PDO|null Connection resource */
|
||||
private $connection;
|
||||
|
||||
|
@@ -19,8 +19,6 @@ use PDO;
|
||||
*/
|
||||
class PdoResult implements Dibi\ResultDriver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var \PDOStatement|null */
|
||||
private $resultSet;
|
||||
|
||||
|
@@ -28,8 +28,6 @@ use PgSql;
|
||||
*/
|
||||
class PostgreDriver implements Dibi\Driver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var resource|PgSql\Connection */
|
||||
private $connection;
|
||||
|
||||
|
@@ -17,8 +17,6 @@ use Dibi;
|
||||
*/
|
||||
class PostgreReflector implements Dibi\Reflector
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var Dibi\Driver */
|
||||
private $driver;
|
||||
|
||||
|
@@ -19,8 +19,6 @@ use PgSql;
|
||||
*/
|
||||
class PostgreResult implements Dibi\ResultDriver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var resource|PgSql\Result */
|
||||
private $resultSet;
|
||||
|
||||
|
@@ -25,8 +25,6 @@ use SQLite3;
|
||||
*/
|
||||
class SqliteDriver implements Dibi\Driver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var SQLite3 */
|
||||
private $connection;
|
||||
|
||||
|
@@ -17,8 +17,6 @@ use Dibi;
|
||||
*/
|
||||
class SqliteReflector implements Dibi\Reflector
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var Dibi\Driver */
|
||||
private $driver;
|
||||
|
||||
|
@@ -18,8 +18,6 @@ use Dibi\Helpers;
|
||||
*/
|
||||
class SqliteResult implements Dibi\ResultDriver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var \SQLite3Result */
|
||||
private $resultSet;
|
||||
|
||||
|
@@ -27,8 +27,6 @@ use Dibi\Helpers;
|
||||
*/
|
||||
class SqlsrvDriver implements Dibi\Driver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var resource */
|
||||
private $connection;
|
||||
|
||||
|
@@ -17,8 +17,6 @@ use Dibi;
|
||||
*/
|
||||
class SqlsrvReflector implements Dibi\Reflector
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var Dibi\Driver */
|
||||
private $driver;
|
||||
|
||||
|
@@ -17,8 +17,6 @@ use Dibi;
|
||||
*/
|
||||
class SqlsrvResult implements Dibi\ResultDriver
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var resource */
|
||||
private $resultSet;
|
||||
|
||||
|
@@ -15,8 +15,6 @@ namespace Dibi;
|
||||
*/
|
||||
class Event
|
||||
{
|
||||
use Strict;
|
||||
|
||||
/** event type */
|
||||
public const
|
||||
CONNECT = 1,
|
||||
|
@@ -15,8 +15,6 @@ namespace Dibi;
|
||||
*/
|
||||
class Expression
|
||||
{
|
||||
use Strict;
|
||||
|
||||
/** @var array */
|
||||
private $values;
|
||||
|
||||
|
@@ -45,8 +45,6 @@ namespace Dibi;
|
||||
*/
|
||||
class Fluent implements IDataSource
|
||||
{
|
||||
use Strict;
|
||||
|
||||
public const REMOVE = false;
|
||||
|
||||
/** @var array */
|
||||
|
@@ -12,8 +12,6 @@ namespace Dibi;
|
||||
|
||||
class Helpers
|
||||
{
|
||||
use Strict;
|
||||
|
||||
/** @var HashMap */
|
||||
private static $types;
|
||||
|
||||
|
@@ -15,8 +15,6 @@ namespace Dibi;
|
||||
*/
|
||||
class Literal
|
||||
{
|
||||
use Strict;
|
||||
|
||||
/** @var string */
|
||||
private $value;
|
||||
|
||||
|
@@ -17,8 +17,6 @@ use Dibi;
|
||||
*/
|
||||
class FileLogger
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var string Name of the file where SQL errors should be logged */
|
||||
public $file;
|
||||
|
||||
|
@@ -27,8 +27,6 @@ use Dibi;
|
||||
*/
|
||||
class Column
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var Dibi\Reflector|null when created by Result */
|
||||
private $reflector;
|
||||
|
||||
|
@@ -21,8 +21,6 @@ use Dibi;
|
||||
*/
|
||||
class Database
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var Dibi\Reflector */
|
||||
private $reflector;
|
||||
|
||||
|
@@ -9,7 +9,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Dibi\Reflection;
|
||||
|
||||
use Dibi;
|
||||
|
||||
|
||||
/**
|
||||
@@ -20,8 +19,6 @@ use Dibi;
|
||||
*/
|
||||
class ForeignKey
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
|
@@ -9,7 +9,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Dibi\Reflection;
|
||||
|
||||
use Dibi;
|
||||
|
||||
|
||||
/**
|
||||
@@ -22,8 +21,6 @@ use Dibi;
|
||||
*/
|
||||
class Index
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var array (name, columns, [unique], [primary]) */
|
||||
private $info;
|
||||
|
||||
|
@@ -20,8 +20,6 @@ use Dibi;
|
||||
*/
|
||||
class Result
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var Dibi\ResultDriver */
|
||||
private $driver;
|
||||
|
||||
|
@@ -25,8 +25,6 @@ use Dibi;
|
||||
*/
|
||||
class Table
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
/** @var Dibi\Reflector */
|
||||
private $reflector;
|
||||
|
||||
|
@@ -17,8 +17,6 @@ namespace Dibi;
|
||||
*/
|
||||
class Result implements IDataSource
|
||||
{
|
||||
use Strict;
|
||||
|
||||
/** @var ResultDriver|null */
|
||||
private $driver;
|
||||
|
||||
|
@@ -15,8 +15,6 @@ namespace Dibi;
|
||||
*/
|
||||
class ResultIterator implements \Iterator, \Countable
|
||||
{
|
||||
use Strict;
|
||||
|
||||
/** @var Result */
|
||||
private $result;
|
||||
|
||||
|
@@ -1,112 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Dibi, smart database abstraction layer (https://dibiphp.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dibi;
|
||||
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use ReflectionProperty;
|
||||
|
||||
|
||||
/**
|
||||
* Better OOP experience.
|
||||
*/
|
||||
trait Strict
|
||||
{
|
||||
/** @var array [method => [type => callback]] */
|
||||
private static $extMethods;
|
||||
|
||||
|
||||
/**
|
||||
* Call to undefined method.
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function __call(string $name, array $args)
|
||||
{
|
||||
$class = method_exists($this, $name) ? 'parent' : static::class;
|
||||
$items = (new ReflectionClass($this))->getMethods(ReflectionMethod::IS_PUBLIC);
|
||||
$items = array_map(fn($item) => $item->getName(), $items);
|
||||
$hint = ($t = Helpers::getSuggestion($items, $name))
|
||||
? ", did you mean $t()?"
|
||||
: '.';
|
||||
throw new \LogicException("Call to undefined method $class::$name()$hint");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call to undefined static method.
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public static function __callStatic(string $name, array $args)
|
||||
{
|
||||
$rc = new ReflectionClass(static::class);
|
||||
$items = array_filter($rc->getMethods(\ReflectionMethod::IS_STATIC), fn($m) => $m->isPublic());
|
||||
$items = array_map(fn($item) => $item->getName(), $items);
|
||||
$hint = ($t = Helpers::getSuggestion($items, $name))
|
||||
? ", did you mean $t()?"
|
||||
: '.';
|
||||
throw new \LogicException("Call to undefined static method {$rc->getName()}::$name()$hint");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Access to undeclared property.
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function &__get(string $name)
|
||||
{
|
||||
if ((method_exists($this, $m = 'get' . $name) || method_exists($this, $m = 'is' . $name))
|
||||
&& (new ReflectionMethod($this, $m))->isPublic()
|
||||
) { // back compatiblity
|
||||
$ret = $this->$m();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$rc = new ReflectionClass($this);
|
||||
$items = array_filter($rc->getProperties(ReflectionProperty::IS_PUBLIC), fn($p) => !$p->isStatic());
|
||||
$items = array_map(fn($item) => $item->getName(), $items);
|
||||
$hint = ($t = Helpers::getSuggestion($items, $name))
|
||||
? ", did you mean $$t?"
|
||||
: '.';
|
||||
throw new \LogicException("Attempt to read undeclared property {$rc->getName()}::$$name$hint");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Access to undeclared property.
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function __set(string $name, $value)
|
||||
{
|
||||
$rc = new ReflectionClass($this);
|
||||
$items = array_filter($rc->getProperties(ReflectionProperty::IS_PUBLIC), fn($p) => !$p->isStatic());
|
||||
$items = array_map(fn($item) => $item->getName(), $items);
|
||||
$hint = ($t = Helpers::getSuggestion($items, $name))
|
||||
? ", did you mean $$t?"
|
||||
: '.';
|
||||
throw new \LogicException("Attempt to write to undeclared property {$rc->getName()}::$$name$hint");
|
||||
}
|
||||
|
||||
|
||||
public function __isset(string $name): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Access to undeclared property.
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function __unset(string $name)
|
||||
{
|
||||
$class = static::class;
|
||||
throw new \LogicException("Attempt to unset undeclared property $class::$$name.");
|
||||
}
|
||||
}
|
@@ -15,8 +15,6 @@ namespace Dibi;
|
||||
*/
|
||||
final class Translator
|
||||
{
|
||||
use Strict;
|
||||
|
||||
/** @var Connection */
|
||||
private $connection;
|
||||
|
||||
|
@@ -37,8 +37,6 @@ declare(strict_types=1);
|
||||
*/
|
||||
class dibi
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
public const
|
||||
AFFECTED_ROWS = 'a',
|
||||
IDENTIFIER = 'n';
|
||||
|
@@ -1,151 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
|
||||
class TestClass
|
||||
{
|
||||
use Dibi\Strict;
|
||||
|
||||
public $public;
|
||||
|
||||
public static $publicStatic;
|
||||
|
||||
protected $protected;
|
||||
|
||||
|
||||
public function publicMethod()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public static function publicMethodStatic()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
protected function protectedMethod()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
protected static function protectedMethodS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function getBar()
|
||||
{
|
||||
return 123;
|
||||
}
|
||||
|
||||
|
||||
public function isFoo()
|
||||
{
|
||||
return 456;
|
||||
}
|
||||
}
|
||||
|
||||
class TestChild extends TestClass
|
||||
{
|
||||
public function callParent()
|
||||
{
|
||||
parent::callParent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// calling
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$obj->undeclared();
|
||||
}, LogicException::class, 'Call to undefined method TestClass::undeclared().');
|
||||
|
||||
Assert::exception(function () {
|
||||
TestClass::undeclared();
|
||||
}, LogicException::class, 'Call to undefined static method TestClass::undeclared().');
|
||||
|
||||
Assert::exception(function () {
|
||||
$obj = new TestChild;
|
||||
$obj->callParent();
|
||||
}, LogicException::class, 'Call to undefined method parent::callParent().');
|
||||
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$obj->publicMethodX();
|
||||
}, LogicException::class, 'Call to undefined method TestClass::publicMethodX(), did you mean publicMethod()?');
|
||||
|
||||
Assert::exception(function () { // suggest static method
|
||||
$obj = new TestClass;
|
||||
$obj->publicMethodStaticX();
|
||||
}, LogicException::class, 'Call to undefined method TestClass::publicMethodStaticX(), did you mean publicMethodStatic()?');
|
||||
|
||||
Assert::exception(function () { // suggest only public method
|
||||
$obj = new TestClass;
|
||||
$obj->protectedMethodX();
|
||||
}, LogicException::class, 'Call to undefined method TestClass::protectedMethodX().');
|
||||
|
||||
|
||||
// writing
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$obj->undeclared = 'value';
|
||||
}, LogicException::class, 'Attempt to write to undeclared property TestClass::$undeclared.');
|
||||
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$obj->publicX = 'value';
|
||||
}, LogicException::class, 'Attempt to write to undeclared property TestClass::$publicX, did you mean $public?');
|
||||
|
||||
Assert::exception(function () { // suggest only non-static property
|
||||
$obj = new TestClass;
|
||||
$obj->publicStaticX = 'value';
|
||||
}, LogicException::class, 'Attempt to write to undeclared property TestClass::$publicStaticX.');
|
||||
|
||||
Assert::exception(function () { // suggest only public property
|
||||
$obj = new TestClass;
|
||||
$obj->protectedX = 'value';
|
||||
}, LogicException::class, 'Attempt to write to undeclared property TestClass::$protectedX.');
|
||||
|
||||
|
||||
// property getter
|
||||
$obj = new TestClass;
|
||||
Assert::false(isset($obj->bar));
|
||||
Assert::same(123, $obj->bar);
|
||||
Assert::false(isset($obj->foo));
|
||||
Assert::same(456, $obj->foo);
|
||||
|
||||
|
||||
// reading
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$val = $obj->undeclared;
|
||||
}, LogicException::class, 'Attempt to read undeclared property TestClass::$undeclared.');
|
||||
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$val = $obj->publicX;
|
||||
}, LogicException::class, 'Attempt to read undeclared property TestClass::$publicX, did you mean $public?');
|
||||
|
||||
Assert::exception(function () { // suggest only non-static property
|
||||
$obj = new TestClass;
|
||||
$val = $obj->publicStaticX;
|
||||
}, LogicException::class, 'Attempt to read undeclared property TestClass::$publicStaticX.');
|
||||
|
||||
Assert::exception(function () { // suggest only public property
|
||||
$obj = new TestClass;
|
||||
$val = $obj->protectedX;
|
||||
}, LogicException::class, 'Attempt to read undeclared property TestClass::$protectedX.');
|
||||
|
||||
|
||||
// unset/isset
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
unset($obj->undeclared);
|
||||
}, LogicException::class, 'Attempt to unset undeclared property TestClass::$undeclared.');
|
||||
|
||||
Assert::false(isset($obj->undeclared));
|
Reference in New Issue
Block a user