1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-05 13:47:33 +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. * Custom output for Nette::Debug.
*
* @author David Grudl
* @copyright Copyright (c) 2004, 2008 David Grudl
* @package Nette
* @version $Revision$ $Date$
*/ */
interface IDebuggable interface IDebuggable
{ {

View File

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

View File

@@ -1,57 +1,57 @@
---------------------------------------------------------------------------------- ----------------------------------------------------------------------------------
Tento text je NEOFICI<43>LN<4C>M p<>ekladem "dibi license". Nevyjad<61>uje pr<70>vn<76> podstatu Tento text je NEOFICI<43>LN<4C>M p<>ekladem "Dibi license". Nevyjad<61>uje pr<70>vn<76> podstatu
podm<EFBFBD>nek pro <20><><EFBFBD>en<65> tohoto softwaru - k tomuto <20><>elu slou<6F><75> v<>hradn<64> p<>vodn<64> podm<EFBFBD>nek pro <20><><EFBFBD>en<65> tohoto softwaru - k tomuto <20><>elu slou<6F><75> v<>hradn<64> p<>vodn<64>
anglick<EFBFBD> verze licence. anglick<EFBFBD> verze licence.
---------------------------------------------------------------------------------- ----------------------------------------------------------------------------------
Dibi Licence, Verze 1 Dibi Licence, verze 1
===================== ======================
Copyright (c) 2005, 2008 David Grudl (http://davidgrudl.com) Copyright (c) 2005, 2008 David Grudl (http://davidgrudl.com)
V<EFBFBD>echna pr<70>va vyhrazena. V<EFBFBD>echna pr<70>va vyhrazena.
Tato licence je pr<70>vn<76> ujedn<64>n<EFBFBD> mezi v<>mi a Davidem Grudlem pro pot<6F>eby Tato licence je pr<70>vn<76> ujedn<64>n<EFBFBD> mezi v<>mi a Davidem Grudlem (d<>le Author)
pou<EFBFBD>it<EFBFBD> "dibi" (d<>le "Software"). By obtaining the Software you agree to comply pro pot<6F>eby pou<EFBFBD>it<EFBFBD> "dibi" (d<>le "Software"). Z<EFBFBD>sk<EFBFBD>n<EFBFBD>m, pou<6F>it<69>m
with the terms and conditions of this license. a/nebo zkop<6F>rov<6F>n<EFBFBD>m Software projevujete souhlas s t<>m, <20>e jste p<>e<EFBFBD>etli,
porozum<EFBFBD>li a budete jednat v souladu s podm<64>nkami t<>to licence.
POVOLEN<EFBFBD> POU<4F>IT<49> POVOLEN<EFBFBD> POU<4F>IT<49>
---------------- ----------------
M<EFBFBD><EFBFBD>ete pou<6F><75>vat, kop<6F>rovat, modifikovat a distribuovat Software a jeho Je povoleno pou<6F><75>vat, kop<6F>rovat, modifikovat a distribuovat Software
dokumentaci, v p<>vodn<64>m i upravovan<61>m tvaru, k jak<61>mukoliv <20><>elu, a to a jeho dokumentaci, v p<>vodn<64>m i upravovan<61>m tvaru, pro jak<61>koliv <20><>el,
za n<EFBFBD>sleduj<EFBFBD>c<EFBFBD>ch podm<64>nek: za p<EFBFBD>edpokladu, <20>e jsou spln<6C>ny tyto podm<64>nky:
1. Kopie tohoto licen<65>n<EFBFBD>ho ujedn<64>n<EFBFBD> mus<75> b<>t p<>ilo<6C>ena v distribuci. 1. Kopie t<EFBFBD>to licen<65>n<EFBFBD> smlouvy mus<75> b<>t sou<6F><75>st<73> distribuce.
2. <20><><EFBFBD>en<65> zdrojov<6F> k<>d mus<75> obsahovat v<><76>e uvedenou informaci o copyrightu 2. <20><><EFBFBD>en<65> zdrojov<6F> k<>d mus<75> zachovat v<><76>e uvedenou informaci o autorsk<EFBFBD>ch
ve v<>ech souborech zdrojov<6F>ho k<>du. pr<EFBFBD>vech ve v<>ech souborech zdrojov<6F>ho k<>du.
3. <20><><EFBFBD>en<65> bin<69>rn<72> tvar mus<75> n<EFBFBD>st v<><76>e uvedenou informaci o copyrightu ve sv<73> 3. <20><><EFBFBD>en<65> bin<69>rn<72> tvar mus<75> reprodukovat v<><76>e uvedenou informaci o autorsk<EFBFBD>ch
dokumentaci a/nebo dal<EFBFBD><EFBFBD>ch materi<72>lech poskytovan<61>ch s distribuc<75>. pr<EFBFBD>vech v dokumentaci a/nebo jin<EFBFBD>ch materi<72>lech poskytovan<61>ch s distribuc<75>.
4. Produkty odvozen<65> od tohoto Software mus<75> ve sv<73> dokumentaci a/nebo 4. Produkty odvozen<65> od Software mus<75> obsahovat potvrzen<65>, <20>e jsou odvozen<65>
dal<EFBFBD><EFBFBD>ch materi<72>lech poskytovan<61>ch s distribuc<75> obsahovat zm<7A>nku, <20>e jsou od "dibi", ve sv<73> dokumentaci a/nebo jin<69>ch materi<72>lech
odvozen<EFBFBD> od "dibi". poskytovan<EFBFBD>ch s distribuc<75>.
5. N<>zev "dibi" nesm<73> b<>t pou<6F>it p<>i podpo<70>e nebo pr<EFBFBD>vn<EFBFBD>ch aktech 5. N<>zev "dibi" nesm<73> b<>t pou<6F>it p<>i podpo<70>e nebo propagaci produkt<6B>
souvisej<EFBFBD>c<EFBFBD>ch s produkty odvozen<EFBFBD>mi z tohoto Software bez p<>edchoz<6F>ho odvozen<65>mi ze Software bez p<>edchoz<6F>ho p<>semn<6D>ho souhlasu Autora.
p<>semn<6D>ho souhlasu Davida Grudla.
6. Produkty odvozen<65> od tohoto Software nesm<73> b<>t nazv<7A>ny "dibi", 6. Produkty odvozen<65> od Software nesm<73> b<>t nazv<7A>ny "dibi",
ani se nesm<73> "dibi" objevovat v jejich n<>zvu bez p<>edchoz<6F>ho ani se nesm<73> "dibi" objevit v jejich n<>zvu bez p<>edchoz<6F>ho
p<>semn<6D>ho souhlasu Davida Grudla. p<>semn<6D>ho souhlasu Autora.
INDEMNITY ZBAVEN<EFBFBD> ZODPOV<4F>DNOSTI
--------- ---------------------
You agree to indemnify and hold harmless the authors of the Software and Souhlas<EFBFBD>te se zbaven<65>m zodpov<6F>dnosti a kryt<79>m Autora a p<>isp<73>vatel<65> v<><76>i
any contributors for any direct, indirect, incidental, or consequential jak<EFBFBD>mkoliv p<><70>m<EFBFBD>m, nep<65><70>m<EFBFBD>m, n<>hodn<64>m nebo n<>sledn<64>m odjinud poch<63>zej<65>c<EFBFBD>m <20>kod<6F>m,
third-party claims, actions or suits, as well as any related expenses, <EFBFBD>alob<EFBFBD>m nebo spor<6F>m, jako<6B> i p<>ed v<>emi souvisej<65>c<EFBFBD>mi n<>klady, z<>vazky,
liabilities, damages, settlements or fees arising from your use or misuse od<EFBFBD>kodn<EFBFBD>n<EFBFBD>mi, <20>hradami nebo poplatky vypl<70>vaj<61>c<EFBFBD>ch z pou<6F><75>v<EFBFBD>n<EFBFBD> nebo
of the Software, or a violation of any terms of this license. nespr<EFBFBD>vn<EFBFBD>ho u<>it<69> Software, nebo z poru<72>en<65> podm<64>nek t<>to licence.
Z<EFBFBD>RUKA SE NEPOSKYTUJE Z<EFBFBD>RUKA SE NEPOSKYTUJE

View File

@@ -1,12 +1,13 @@
The Dibi License, Version 1 The Dibi License, Version 1
=========================== ============================
Copyright (c) 2005, 2008 David Grudl (http://davidgrudl.com) Copyright (c) 2005, 2008 David Grudl (http://davidgrudl.com)
All rights reserved. All rights reserved.
This license is a legal agreement between you and David Grudl for the use This license is a legal agreement between you and David Grudl (the "Author")
of "dibi" (the "Software"). By obtaining the Software you agree to comply for the use of "dibi" (the "Software"). By obtaining, using and/or
with the terms and conditions of this license. copying the Software, you agree that you have read, understood, and will
comply with the terms and conditions of this license.
PERMITTED USE PERMITTED USE
@@ -28,22 +29,22 @@ the following conditions are met:
they are derived from "dibi" in their documentation and/or other they are derived from "dibi" in their documentation and/or other
materials provided with the distribution. materials provided with the distribution.
5. The name "dibi" must not be used to endorse or promote products derived 5. The name "dibi" must not be used to endorse or promote products
from the Software without prior written permission from David Grudl. derived from the Software without prior written permission from Author.
6. Products derived from the Software may not be called "dibi", 6. Products derived from the Software may not be called "dibi",
nor may "dibi" appear in their name, without prior written nor may "dibi" appear in their name, without prior written
permission from David Grudl. permission from Author.
INDEMNITY INDEMNITY
--------- ---------
You agree to indemnify and hold harmless the authors of the Software and You agree to indemnify and hold harmless the Author and any contributors
any contributors for any direct, indirect, incidental, or consequential for any direct, indirect, incidental, or consequential third-party claims,
third-party claims, actions or suits, as well as any related expenses, actions or suits, as well as any related expenses, liabilities, damages,
liabilities, damages, settlements or fees arising from your use or misuse settlements or fees arising from your use or misuse of the Software,
of the Software, or a violation of any terms of this license. or a violation of any terms of this license.
DISCLAIMER OF WARRANTY DISCLAIMER OF WARRANTY