mirror of
https://github.com/dg/dibi.git
synced 2025-07-15 11:36:22 +02:00
NClass moved to separate file
This commit is contained in:
@ -32,6 +32,7 @@ if (version_compare(PHP_VERSION , '5.1.0', '<')) {
|
|||||||
|
|
||||||
// nette libraries
|
// nette libraries
|
||||||
if (!class_exists('NObject', FALSE)) { require_once __FILE__ . '/../libs/NObject.php'; }
|
if (!class_exists('NObject', FALSE)) { require_once __FILE__ . '/../libs/NObject.php'; }
|
||||||
|
if (!class_exists('NClass', FALSE)) { require_once __FILE__ . '/../libs/NClass.php'; }
|
||||||
if (!class_exists('NException', FALSE)) { require_once __FILE__ . '/../libs/NException.php'; }
|
if (!class_exists('NException', FALSE)) { require_once __FILE__ . '/../libs/NException.php'; }
|
||||||
|
|
||||||
// dibi libraries
|
// dibi libraries
|
||||||
|
@ -309,8 +309,6 @@ class DibiConnection extends NObject
|
|||||||
$this->driver->begin();
|
$this->driver->begin();
|
||||||
$this->inTxn = TRUE;
|
$this->inTxn = TRUE;
|
||||||
dibi::notify($this, 'begin');
|
dibi::notify($this, 'begin');
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ class DibiException extends NException
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* database server exception
|
* database server exception
|
||||||
*
|
*
|
||||||
|
39
dibi/libs/NClass.php
Normal file
39
dibi/libs/NClass.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dibi - tiny'n'smart database abstraction layer
|
||||||
|
* ----------------------------------------------
|
||||||
|
*
|
||||||
|
* Copyright (c) 2005, 2007 David Grudl aka -dgx- (http://www.dgx.cz)
|
||||||
|
*
|
||||||
|
* This source file is subject to the "dibi license" that is bundled
|
||||||
|
* with this package in the file license.txt.
|
||||||
|
*
|
||||||
|
* For more information please see http://php7.org/dibi/
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2004, 2007 David Grudl
|
||||||
|
* @license http://php7.org/nette/license Nette license
|
||||||
|
* @link http://php7.org/nette/
|
||||||
|
* @package Nette
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NClass is the ultimate ancestor of all uninstantiable classes.
|
||||||
|
*
|
||||||
|
* @author David Grudl
|
||||||
|
* @copyright Copyright (c) 2004, 2007 David Grudl
|
||||||
|
* @license http://php7.org/nette/license Nette license
|
||||||
|
* @link http://php7.org/nette/
|
||||||
|
* @package Nette
|
||||||
|
*/
|
||||||
|
abstract class NClass
|
||||||
|
{
|
||||||
|
|
||||||
|
final public function __construct()
|
||||||
|
{
|
||||||
|
throw new LogicException("Cannot instantiate static class " . get_class($this));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -34,8 +34,8 @@
|
|||||||
* $val = $obj->Label; // equivalent to $val = $obj->getLabel();
|
* $val = $obj->Label; // equivalent to $val = $obj->getLabel();
|
||||||
* $obj->Label = 'Nette'; // equivalent to $obj->setLabel('Nette');
|
* $obj->Label = 'Nette'; // equivalent to $obj->setLabel('Nette');
|
||||||
* </code>
|
* </code>
|
||||||
* Property names are case-sensitive, and they are written in the PascalCaps,
|
* Property names are case-sensitive, and they are written in the camelCaps
|
||||||
* in contrast to camelCaps used by normal members.
|
* or PascalCaps.
|
||||||
*
|
*
|
||||||
* Adding method to class (i.e. to all instances) works similar to JavaScript
|
* Adding method to class (i.e. to all instances) works similar to JavaScript
|
||||||
* prototype property. The syntax for adding a new method is:
|
* prototype property. The syntax for adding a new method is:
|
||||||
@ -123,7 +123,7 @@ abstract class NObject
|
|||||||
// property getter support
|
// property getter support
|
||||||
$class = get_class($this);
|
$class = get_class($this);
|
||||||
$m = 'get' . $name;
|
$m = 'get' . $name;
|
||||||
if (self::isCallable($class, $m)) {
|
if (self::hasAccessor($class, $m)) {
|
||||||
// ampersands:
|
// ampersands:
|
||||||
// - using &__get() because declaration should be forward compatible (e.g. with NHtml)
|
// - using &__get() because declaration should be forward compatible (e.g. with NHtml)
|
||||||
// - not using &$this->$m because user could bypass property setter by: $x = & $obj->property; $x = 'new value';
|
// - not using &$this->$m because user could bypass property setter by: $x = & $obj->property; $x = 'new value';
|
||||||
@ -153,9 +153,9 @@ abstract class NObject
|
|||||||
|
|
||||||
// property setter support
|
// property setter support
|
||||||
$class = get_class($this);
|
$class = get_class($this);
|
||||||
if (self::isCallable($class, 'get' . $name)) {
|
if (self::hasAccessor($class, 'get' . $name)) {
|
||||||
$m = 'set' . $name;
|
$m = 'set' . $name;
|
||||||
if (self::isCallable($class, $m)) {
|
if (self::hasAccessor($class, $m)) {
|
||||||
$this->$m($value);
|
$this->$m($value);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -177,7 +177,7 @@ abstract class NObject
|
|||||||
*/
|
*/
|
||||||
protected function __isset($name)
|
protected function __isset($name)
|
||||||
{
|
{
|
||||||
return $name !== '' && self::isCallable(get_class($this), 'get' . $name);
|
return $name !== '' && self::hasAccessor(get_class($this), 'get' . $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -198,45 +198,26 @@ abstract class NObject
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does public method exist? (case sensitive)
|
* Has property accessor?
|
||||||
*
|
*
|
||||||
* @param string class name
|
* @param string class name
|
||||||
* @param string method name
|
* @param string method name
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private static function isCallable($c, $m)
|
private static function hasAccessor($c, $m)
|
||||||
{
|
{
|
||||||
static $cache;
|
static $cache;
|
||||||
if (!isset($cache[$c])) {
|
if (!isset($cache[$c])) {
|
||||||
// get_class_methods returns private, protected and public methods of NObject (doesn't matter)
|
// get_class_methods returns private, protected and public methods of NObject (doesn't matter)
|
||||||
// only only public methods of descendants (perfect!)
|
// and ONLY PUBLIC methods of descendants (perfect!)
|
||||||
// but returns static methods too (nothing doing...)
|
// but returns static methods too (nothing doing...)
|
||||||
// and is much faster than reflection
|
// and is much faster than reflection
|
||||||
// (works good since 5.0.4)
|
// (works good since 5.0.4)
|
||||||
$cache[$c] = array_flip(get_class_methods($c));
|
$cache[$c] = array_flip(get_class_methods($c));
|
||||||
}
|
}
|
||||||
|
// case-sensitive checking, capitalize the fourth character
|
||||||
|
$m[3] = $m[3] & "\xDF";
|
||||||
return isset($cache[$c][$m]);
|
return isset($cache[$c][$m]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NClass is the ultimate ancestor of all uninstantiable classes.
|
|
||||||
*
|
|
||||||
* @author David Grudl
|
|
||||||
* @copyright Copyright (c) 2004, 2007 David Grudl
|
|
||||||
* @license http://php7.org/nette/license Nette license
|
|
||||||
* @link http://php7.org/nette/
|
|
||||||
* @package Nette
|
|
||||||
*/
|
|
||||||
abstract class NClass
|
|
||||||
{
|
|
||||||
|
|
||||||
final public function __construct()
|
|
||||||
{
|
|
||||||
throw new LogicException("Cannot instantiate static class " . get_class($this));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user