From 1a9abfb32640e63c696f63d09d1ebd24761e2dd6 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 26 Nov 2007 01:44:07 +0000 Subject: [PATCH] NClass moved to separate file --- dibi/dibi.php | 1 + dibi/libs/DibiConnection.php | 2 -- dibi/libs/DibiException.php | 2 ++ dibi/libs/NClass.php | 39 ++++++++++++++++++++++++++++++++++ dibi/libs/NObject.php | 41 ++++++++++-------------------------- 5 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 dibi/libs/NClass.php diff --git a/dibi/dibi.php b/dibi/dibi.php index f1c4eb60..90548744 100644 --- a/dibi/dibi.php +++ b/dibi/dibi.php @@ -32,6 +32,7 @@ if (version_compare(PHP_VERSION , '5.1.0', '<')) { // nette libraries 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'; } // dibi libraries diff --git a/dibi/libs/DibiConnection.php b/dibi/libs/DibiConnection.php index 3dfdbb36..2859b512 100644 --- a/dibi/libs/DibiConnection.php +++ b/dibi/libs/DibiConnection.php @@ -309,8 +309,6 @@ class DibiConnection extends NObject $this->driver->begin(); $this->inTxn = TRUE; dibi::notify($this, 'begin'); - - return $this; } diff --git a/dibi/libs/DibiException.php b/dibi/libs/DibiException.php index 9aaa2c27..dfe2e2c9 100644 --- a/dibi/libs/DibiException.php +++ b/dibi/libs/DibiException.php @@ -32,6 +32,8 @@ class DibiException extends NException } + + /** * database server exception * diff --git a/dibi/libs/NClass.php b/dibi/libs/NClass.php new file mode 100644 index 00000000..46622cb0 --- /dev/null +++ b/dibi/libs/NClass.php @@ -0,0 +1,39 @@ +Label; // equivalent to $val = $obj->getLabel(); * $obj->Label = 'Nette'; // equivalent to $obj->setLabel('Nette'); * - * Property names are case-sensitive, and they are written in the PascalCaps, - * in contrast to camelCaps used by normal members. + * Property names are case-sensitive, and they are written in the camelCaps + * or PascalCaps. * * Adding method to class (i.e. to all instances) works similar to JavaScript * prototype property. The syntax for adding a new method is: @@ -123,7 +123,7 @@ abstract class NObject // property getter support $class = get_class($this); $m = 'get' . $name; - if (self::isCallable($class, $m)) { + if (self::hasAccessor($class, $m)) { // ampersands: // - 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'; @@ -153,9 +153,9 @@ abstract class NObject // property setter support $class = get_class($this); - if (self::isCallable($class, 'get' . $name)) { + if (self::hasAccessor($class, 'get' . $name)) { $m = 'set' . $name; - if (self::isCallable($class, $m)) { + if (self::hasAccessor($class, $m)) { $this->$m($value); } else { @@ -177,7 +177,7 @@ abstract class NObject */ 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 method name * @return bool */ - private static function isCallable($c, $m) + private static function hasAccessor($c, $m) { static $cache; if (!isset($cache[$c])) { // 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...) // and is much faster than reflection // (works good since 5.0.4) $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]); } } - - - -/** - * 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)); - } - -}