1
0
mirror of https://github.com/dg/dibi.git synced 2025-07-15 03:26:23 +02:00

NClass moved to separate file

This commit is contained in:
David Grudl
2007-11-26 01:44:07 +00:00
parent a0febd3d50
commit 1a9abfb326
5 changed files with 53 additions and 32 deletions

View File

@ -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

View File

@ -309,8 +309,6 @@ class DibiConnection extends NObject
$this->driver->begin();
$this->inTxn = TRUE;
dibi::notify($this, 'begin');
return $this;
}

View File

@ -32,6 +32,8 @@ class DibiException extends NException
}
/**
* database server exception
*

39
dibi/libs/NClass.php Normal file
View 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));
}
}

View File

@ -34,8 +34,8 @@
* $val = $obj->Label; // equivalent to $val = $obj->getLabel();
* $obj->Label = 'Nette'; // equivalent to $obj->setLabel('Nette');
* </code>
* 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));
}
}