Permalink
Browse files

* 0.8.5

git-svn-id: https://svn.shadanakar.org/onPHP/tags/0.8.5@2602 db88c99c-74ec-0310-8720-8416fdbde762
  • Loading branch information...
0 parents commit ae6fe3b526d3ab439baa92d099ed6202af71c8e1 Konstantin V. Arkhipov committed Feb 13, 2007
Showing 396 changed files with 33,226 additions and 0 deletions.
@@ -0,0 +1,114 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005-2007 by Konstantin V. Arkhipov *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+/* $Id$ */
+
+ /**
+ * Widely used assertions.
+ *
+ * @ingroup Base
+ **/
+ final class Assert extends StaticFactory
+ {
+ public static function isTrue($boolean, $message = null)
+ {
+ if ($boolean !== true)
+ self::fail($message);
+ }
+
+ public static function isFalse($boolean, $message = null)
+ {
+ if ($boolean !== false)
+ self::fail($message);
+ }
+
+ public static function isArray(&$variable, $message = null)
+ {
+ if (!is_array($variable))
+ self::fail($message);
+ }
+
+ public static function isInteger($variable, $message = null)
+ {
+ if (
+ !(
+ $variable == (int) $variable
+ && is_numeric($variable)
+ )
+ )
+ self::fail($message);
+ }
+
+ public static function isFloat($variable, $message = null)
+ {
+ if (
+ !(
+ $variable == (float) $variable
+ && is_numeric($variable)
+ )
+ )
+ self::fail($message);
+ }
+
+ public static function isString(&$variable, $message = null)
+ {
+ if (!is_string($variable))
+ self::fail($message);
+ }
+
+ public static function isBoolean(&$variable, $message = null)
+ {
+ if (!($variable === true || $variable === false))
+ self::fail($message);
+ }
+
+ public static function isTernaryBase(&$variable, $message = null)
+ {
+ if (
+ !(
+ ($variable === true)
+ || ($variable === false)
+ || ($variable === null)
+ )
+ )
+ self::fail($message);
+ }
+
+ public static function brothers(&$first, &$second, $message = null)
+ {
+ if (get_class($first) !== get_class($second))
+ self::fail($message);
+ }
+
+ /// exceptionless methods
+ //@{
+ public static function checkInteger($value)
+ {
+ return (
+ is_numeric($value)
+ && ($value == (int) $value)
+ && (strlen($value) == strlen((int) $value))
+ );
+ }
+ //@}
+
+ private static function fail($message = null)
+ {
+ throw new WrongArgumentException(
+ $message
+ .(
+ defined('__LOCAL_DEBUG__')
+ ? "\n\n".print_r(debug_backtrace(), true)
+ : null
+ )
+ );
+ }
+ }
+?>
@@ -0,0 +1,73 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2004-2006 by Konstantin V. Arkhipov *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+/* $Id$ */
+
+ /**
+ * Parent of all enumeration classes.
+ *
+ * @see AccessMode for example
+ *
+ * @ingroup Base
+ * @ingroup Module
+ **/
+ abstract class Enumeration extends NamedObject
+ {
+ protected $names = array(/* override me */);
+
+ public function __construct($id)
+ {
+ $names = $this->getNameList();
+
+ if (isset($names[$id])) {
+ $this->id = $id;
+ $this->name = $names[$id];
+ } else
+ throw new MissingElementException(
+ "knows nothing about such id == {$id}"
+ );
+ }
+
+ public static function getList(Enumeration $enum)
+ {
+ return $enum->getObjectList();
+ }
+
+ /**
+ * must return any existent ID
+ * 1 should be ok for most enumerations
+ **/
+ public static function getAnyId()
+ {
+ return 1;
+ }
+
+ public function getObjectList()
+ {
+ $list = array();
+ $names = $this->getNameList();
+
+ foreach ($names as $id => &$val)
+ $list[] = new $this($id);
+
+ return $list;
+ }
+
+ public function toString()
+ {
+ return $this->name;
+ }
+
+ public function getNameList()
+ {
+ return $this->names;
+ }
+ }
+?>
@@ -0,0 +1,26 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2004-2006 by Konstantin V. Arkhipov *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+/* $Id$ */
+
+ /**
+ * Essential interface for DAO-related operations.
+ *
+ * @see IdentifiableObject
+ *
+ * @ingroup Base
+ * @ingroup Module
+ **/
+ interface Identifiable
+ {
+ public function getId();
+ public function setId($id);
+ }
+?>
@@ -0,0 +1,50 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005-2006 by Garmonbozia Research Group *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+/* $Id$ */
+
+ /**
+ * Ideal Identifiable interface implementation. ;-)
+ *
+ * @see Identifiable
+ *
+ * @ingroup Base
+ * @ingroup Module
+ **/
+ class /* spirit of */ IdentifiableObject implements Identifiable
+ {
+ protected $id = null;
+
+ public static function wrap($id)
+ {
+ $io = new self;
+
+ return $io->setId($id);
+ }
+
+ final public function getId()
+ {
+ if (
+ $this->id instanceof Identifier
+ && $this->id->isFinalized()
+ )
+ return $this->id->getId();
+ else
+ return $this->id;
+ }
+
+ final public function setId($id)
+ {
+ $this->id = $id;
+
+ return $this;
+ }
+ }
+?>
@@ -0,0 +1,58 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005-2006 by Garmonbozia Research Group *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+/* $Id$ */
+
+ /**
+ * @see Identifiable
+ *
+ * @ingroup Base
+ * @ingroup Module
+ **/
+ final class Identifier implements Identifiable
+ {
+ private $id = null;
+ private $final = false;
+
+ public static function create()
+ {
+ return new self;
+ }
+
+ public static function wrap($id)
+ {
+ return self::create()->setId($id);
+ }
+
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ public function setId($id)
+ {
+ $this->id = $id;
+
+ return $this;
+ }
+
+ public function finalize()
+ {
+ $this->final = true;
+
+ return $this;
+ }
+
+ public function isFinalized()
+ {
+ return $this->final;
+ }
+ }
+?>
@@ -0,0 +1,21 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2006 by Konstantin V. Arkhipov *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+/* $Id$ */
+
+ /**
+ * @ingroup Base
+ * @ingroup Module
+ **/
+ interface Instantiatable
+ {
+ public static function me();
+ }
+?>
@@ -0,0 +1,24 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005-2006 by Konstantin V. Arkhipov *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+/* $Id$ */
+
+ /**
+ * @see NamedObject.class.php
+ *
+ * @ingroup Base
+ * @ingroup Module
+ **/
+ interface Named extends Identifiable
+ {
+ public function getName();
+ public function setName($name);
+ }
+?>
Oops, something went wrong.

0 comments on commit ae6fe3b

Please sign in to comment.