1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-15 02:25:10 +02:00

improved dibi, Texy and Nette exceptions compatibility

This commit is contained in:
David Grudl
2008-07-12 23:11:57 +00:00
parent 41e5b32a22
commit 69ead6da56
6 changed files with 87 additions and 167 deletions

View File

@@ -23,6 +23,11 @@
/**
* Custom output for Nette::Debug.
*
* @author David Grudl
* @copyright Copyright (c) 2004, 2008 David Grudl
* @package Nette
* @version $Revision$ $Date$
*/
interface IDebuggable
{

View File

@@ -98,12 +98,12 @@ abstract class Object
*/
protected function __call($name, $args)
{
if ($name === '') {
throw new /*::*/MemberAccessException("Call to method without name.");
}
$class = get_class($this);
if ($name === '') {
throw new /*::*/MemberAccessException("Call to class '$class' method without name.");
}
// event functionality
if (self::hasEvent($class, $name)) {
$list = $this->$name;
@@ -155,17 +155,18 @@ abstract class Object
*/
protected function &__get($name)
{
$class = get_class($this);
if ($name === '') {
throw new /*::*/MemberAccessException("Cannot read an property without name.");
throw new /*::*/MemberAccessException("Cannot read an class '$class' property without name.");
}
// property getter support
$class = get_class($this);
$m = 'get' . $name;
if (self::hasAccessor($class, $m)) {
// ampersands:
// - using &__get() because declaration should be forward compatible (e.g. with Nette::Web::Html)
// - not using &$this->$m because user could bypass property setter by: $x = & $obj->property; $x = 'new value';
// - uses &__get() because declaration should be forward compatible (e.g. with Nette::Web::Html)
// - doesn't call &$this->$m because user could bypass property setter by: $x = & $obj->property; $x = 'new value';
$val = $this->$m();
return $val;
@@ -179,19 +180,20 @@ abstract class Object
/**
* Sets value of a property. Do not call directly.
*
* @param string property name
* @param mixed property value
* @param string property name
* @param mixed property value
* @return void
* @throws ::MemberAccessException if the property is not defined or is read-only
*/
protected function __set($name, $value)
{
$class = get_class($this);
if ($name === '') {
throw new /*::*/MemberAccessException('Cannot assign to an property without name.');
throw new /*::*/MemberAccessException("Cannot assign to an class '$class' property without name.");
}
// property setter support
$class = get_class($this);
if (self::hasAccessor($class, 'get' . $name)) {
$m = 'set' . $name;
if (self::hasAccessor($class, $m)) {
@@ -211,7 +213,7 @@ abstract class Object
/**
* Is property defined?
*
* @param string property name
* @param string property name
* @return bool
*/
protected function __isset($name)

View File

@@ -1,110 +0,0 @@
<?php
/**
* Nette Framework
*
* Copyright (c) 2004, 2008 David Grudl (http://davidgrudl.com)
*
* This source file is subject to the "Nette license" that is bundled
* with this package in the file license.txt.
*
* For more information please see http://nettephp.com/
*
* @copyright Copyright (c) 2004, 2008 David Grudl
* @license http://nettephp.com/license Nette license
* @link http://nettephp.com/
* @category Nette
* @package Nette
*/
/*no namespace*/
/*
some useful SPL exception:
- LogicException
- InvalidArgumentException
- LengthException
- RuntimeException
- OutOfBoundsException
- UnexpectedValueException
other SPL exceptions are ambiguous; do not use them
*/
/**
* The exception that is thrown when the value of an argument is
* outside the allowable range of values as defined by the invoked method.
*/
class ArgumentOutOfRangeException extends InvalidArgumentException
{
}
/**
* The exception that is thrown when a method call is invalid for the object's
* current state, method has been invoked at an illegal or inappropriate time.
*/
class InvalidStateException extends RuntimeException // or InvalidOperationException?
{
}
/**
* The exception that is thrown when a requested method or operation is not implemented.
*/
class NotImplementedException extends LogicException
{
}
/**
* The exception that is thrown when an invoked method is not supported. For scenarios where
* it is sometimes possible to perform the requested operation, see InvalidStateException.
*/
class NotSupportedException extends LogicException
{
}
/**
* The exception that is thrown when accessing a class member (property or method) fails.
*/
class MemberAccessException extends LogicException
{
}
/**
* The exception that is thrown when an I/O error occurs.
*/
class IOException extends RuntimeException
{
}
/**
* The exception that is thrown when accessing a file that does not exist on disk.
*/
class FileNotFoundException extends IOException
{
}
/**
* The exception that is thrown when part of a file or directory cannot be found.
*/
class DirectoryNotFoundException extends IOException
{
}

View File

@@ -30,9 +30,31 @@ if (version_compare(PHP_VERSION, '5.1.0', '<')) {
// nette libraries
/**
* Compatibility with Nette
*/
if (!class_exists('NotImplementedException', FALSE)) {
require_once dirname(__FILE__) . '/Nette/exceptions.php';
class NotImplementedException extends LogicException {}
}
if (!class_exists('NotSupportedException', FALSE)) {
class NotSupportedException extends LogicException {}
}
if (!class_exists('MemberAccessException', FALSE)) {
class MemberAccessException extends LogicException {}
}
if (!class_exists('InvalidStateException', FALSE)) {
class InvalidStateException extends RuntimeException {}
}
if (!class_exists('IOException', FALSE)) {
class IOException extends RuntimeException {}
}
if (!class_exists('FileNotFoundException', FALSE)) {
class FileNotFoundException extends IOException {}
}
if (!class_exists(/*Nette::*/'Object', FALSE)) {