Author: voxus
Date: 2006-06-25 21:26:10 +0400 (Sun, 25 Jun 2006)
New Revision: 1782
Added:
trunk/core/Form/Filter/
trunk/core/Form/Filter/BaseFilter.class.php
trunk/core/Form/Filter/Filter.class.php
trunk/core/Form/Filter/FilterChain.class.php
trunk/core/Form/Filter/Filtrator.class.php
trunk/core/Form/Filter/HashFilter.class.php
trunk/core/Form/Filter/HtmlSpecialCharsFilter.class.php
trunk/core/Form/Filter/PCREFilter.class.php
trunk/core/Form/Filter/RemoveSymbolsFilter.class.php
trunk/core/Form/Filter/StringReplaceFilter.class.php
trunk/core/Form/Filter/StripTagsFilter.class.php
trunk/core/Form/Filter/TrimFilter.class.php
trunk/core/Form/Filter/UrlDecodeFilter.class.php
trunk/core/Form/Filter/UrlEncodeFilter.class.php
trunk/core/Form/Primitive/
trunk/core/Form/Primitive/BasePrimitive.class.php
trunk/core/Form/Primitive/ComplexPrimitive.class.php
trunk/core/Form/Primitive/DateRangeList.class.php
trunk/core/Form/Primitive/ExplodedPrimitive.class.php
trunk/core/Form/Primitive/FiltrablePrimitive.class.php
trunk/core/Form/Primitive/IdentifiablePrimitive.class.php
trunk/core/Form/Primitive/ListedPrimitive.class.php
trunk/core/Form/Primitive/Primitive.class.php
trunk/core/Form/Primitive/PrimitiveArray.class.php
trunk/core/Form/Primitive/PrimitiveBoolean.class.php
trunk/core/Form/Primitive/PrimitiveDate.class.php
trunk/core/Form/Primitive/PrimitiveDumper.class.php
trunk/core/Form/Primitive/PrimitiveEnumeration.class.php
trunk/core/Form/Primitive/PrimitiveFile.class.php
trunk/core/Form/Primitive/PrimitiveIdentifier.class.php
trunk/core/Form/Primitive/PrimitiveImage.class.php
trunk/core/Form/Primitive/PrimitiveInteger.class.php
trunk/core/Form/Primitive/PrimitiveList.class.php
trunk/core/Form/Primitive/PrimitiveMultiList.class.php
trunk/core/Form/Primitive/PrimitiveRange.class.php
trunk/core/Form/Primitive/PrimitiveString.class.php
trunk/core/Form/Primitive/RangedPrimitive.class.php
trunk/core/Form/Primitive/TimeList.class.php
Removed:
trunk/core/Form/BaseFilter.class.php
trunk/core/Form/BasePrimitive.class.php
trunk/core/Form/ComplexPrimitive.class.php
trunk/core/Form/DateRangeList.class.php
trunk/core/Form/ExplodedPrimitive.class.php
trunk/core/Form/Filter.class.php
trunk/core/Form/FilterChain.class.php
trunk/core/Form/FiltrablePrimitive.class.php
trunk/core/Form/Filtrator.class.php
trunk/core/Form/HashFilter.class.php
trunk/core/Form/HtmlSpecialCharsFilter.class.php
trunk/core/Form/IdentifiablePrimitive.class.php
trunk/core/Form/ListedPrimitive.class.php
trunk/core/Form/PCREFilter.class.php
trunk/core/Form/Primitive.class.php
trunk/core/Form/PrimitiveArray.class.php
trunk/core/Form/PrimitiveBoolean.class.php
trunk/core/Form/PrimitiveDate.class.php
trunk/core/Form/PrimitiveDumper.class.php
trunk/core/Form/PrimitiveEnumeration.class.php
trunk/core/Form/PrimitiveFile.class.php
trunk/core/Form/PrimitiveIdentifier.class.php
trunk/core/Form/PrimitiveImage.class.php
trunk/core/Form/PrimitiveInteger.class.php
trunk/core/Form/PrimitiveList.class.php
trunk/core/Form/PrimitiveMultiList.class.php
trunk/core/Form/PrimitiveRange.class.php
trunk/core/Form/PrimitiveString.class.php
trunk/core/Form/RangedPrimitive.class.php
trunk/core/Form/RemoveSymbolsFilter.class.php
trunk/core/Form/StringReplaceFilter.class.php
trunk/core/Form/StripTagsFilter.class.php
trunk/core/Form/TimeList.class.php
trunk/core/Form/TrimFilter.class.php
trunk/core/Form/UrlDecodeFilter.class.php
trunk/core/Form/UrlEncodeFilter.class.php
Log:
+ sub-sections in Form
Deleted: trunk/core/Form/BaseFilter.class.php
===================================================================
--- trunk/core/Form/BaseFilter.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/BaseFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,19 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2005 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$ */
-
- /**
- * Filter's template.
- *
- * @ingroup Filter
- **/
- abstract class BaseFilter extends Singleton implements Filtrator {/*_*/}
-?>
\ No newline at end of file
Deleted: trunk/core/Form/BasePrimitive.class.php
===================================================================
--- trunk/core/Form/BasePrimitive.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/BasePrimitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,131 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2004-2005 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 every Primitive.
- *
- * @ingroup Primitives
- **/
- abstract class BasePrimitive
- {
- protected $name = null;
- protected $default = null;
- protected $value = null;
-
- protected $required = false;
-
- protected $raw = null;
-
- public function __construct($name)
- {
- $this->name = $name;
- }
-
- public function getName()
- {
- return $this->name;
- }
-
- public function setName($name)
- {
- $this->name = $name;
-
- return $this;
- }
-
- public function getDefault()
- {
- return $this->default;
- }
-
- public function setDefault($default)
- {
- $this->default = $default;
-
- return $this;
- }
-
- public function getValue()
- {
- return $this->value;
- }
-
- public function getRawValue()
- {
- return $this->raw;
- }
-
- public function getActualValue()
- {
- if (null !== $this->value)
- return $this->value;
- elseif (null !== $this->raw)
- return $this->raw;
-
- return $this->default;
- }
-
- public function setValue($value)
- {
- $this->value = $value;
-
- return $this;
- }
-
- public function setRawValue($raw)
- {
- $this->raw = $raw;
-
- return $this;
- }
-
- public function isRequired()
- {
- return $this->required;
- }
-
- public function setRequired($really = false)
- {
- $this->required = (true === $really ? true : false);
-
- return $this;
- }
-
- public function required()
- {
- $this->required = true;
-
- return $this;
- }
-
- public function optional()
- {
- $this->required = false;
-
- return $this;
- }
-
- protected function import(&$scope)
- {
- if (
- isset($scope[$this->name]) &&
- $scope[$this->name] !== ''
- ) {
- $this->raw = $scope[$this->name];
-
- return true;
- }
-
- return null;
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/ComplexPrimitive.class.php
===================================================================
--- trunk/core/Form/ComplexPrimitive.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/ComplexPrimitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,83 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2004-2005 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$ */
-
- /**
- * Basis for primitives which can be scattered across import scope.
- *
- * @ingroup Primitives
- **/
- abstract class ComplexPrimitive extends RangedPrimitive
- {
- private $single = null; // single, not single or fsck it
-
- public function __construct($name)
- {
- $this->single = new Ternary(null);
- parent::__construct($name);
- }
-
- public function getState()
- {
- return $this->single;
- }
-
- public function setState(Ternary $ternary)
- {
- $this->single->setValue($ternary->getValue());
-
- return $this;
- }
-
- public function setSingle()
- {
- $this->single->setTrue();
-
- return $this;
- }
-
- public function setComplex()
- {
- $this->single->setFalse();
-
- return $this;
- }
-
- public function setAnyState()
- {
- $this->single->setNull();
-
- return $this;
- }
-
- // implement me, child :-)
- abstract protected function importSingle(&$scope);
- abstract protected function importMarried(&$scope);
-
- public function import(&$scope)
- {
- parent::import($scope);
-
- if ($this->single->isTrue())
- return $this->importSingle($scope);
- elseif ($this->single->isFalse())
- return $this->importMarried($scope);
- else {
- if (!$this->importMarried($scope))
- return $this->importSingle($scope);
-
- return true;
- }
-
- /* NOTREACHED */
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/DateRangeList.class.php
===================================================================
--- trunk/core/Form/DateRangeList.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/DateRangeList.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,191 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2005 by Konstantin V. Arkhipov, Igor V. Gulyaev *
- * *
- * 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 Primitives
- **/
- class DateRangeList extends BasePrimitive implements Stringable
- {
- public function import(&$scope)
- {
- if (
- !isset($scope[$this->name])
- || !is_array($scope[$this->name])
- || empty($scope[$this->name])
- ||
- (
- count($scope[$this->name]) == 1
- && !current($scope[$this->name])
- )
- )
- return null;
-
- $array = $scope[$this->name];
- $list = array();
-
- foreach ($array as $string)
- if (array() !== self::stringToDateRangeList($string))
- foreach (self::stringToDateRangeList($string) as $range)
- $list[] = $range;
-
- $this->value = $list;
-
- return ($this->value !== array());
- }
-
- public function toString()
- {
- if ($this->value) {
- $out = array();
-
- foreach ($this->value as $range)
- $out[] = $range->toDateString();
-
- return implode(', ', $out);
- }
-
- return null;
- }
-
- public static function stringToDateRangeList($string)
- {
- $list = array();
-
- if (!empty($string)) {
- if (strpos($string, ',') !== false)
- $dates = explode(',', $string);
- else
- $dates = array($string);
-
- foreach ($dates as $date) {
- try {
- $list[] = self::makeRange($date);
- } catch (WrongArgumentException $e) {
- // ignore?
- }
- }
- }
-
- return $list;
- }
-
- public static function printRange(DateRange $range, $delimiter = '-')
- {
- $rangeString = null;
-
- if ($range->getStart())
- $rangeString .= $range->getStart()->toDate($delimiter);
-
- $rangeString .= ' - ';
-
- if ($range->getEnd())
- $rangeString .= $range->getEnd()->toDate($delimiter);
-
- return $rangeString;
- }
-
- public static function makeRange($string)
- {
- if (
- (substr_count($string, ' - ') === 1)
- || (substr_count($string, '-'))
- ) {
- $delimiter = ' - ';
-
- if (substr_count($string, '-') === 1)
- $delimiter = '-';
-
- list($start, $finish) = explode($delimiter, $string, 2);
-
- $start = self::toDate(trim($start));
- $finish = self::toDate(trim($finish));
-
- if ($start || $finish) {
-
- $range = new DateRange();
-
- $range =
- DateRange::create()->
- lazySet($start, $finish);
-
- return $range;
-
- } elseif ($string == ' - ')
- return DateRange::create();
-
- } elseif ($single = self::toDate(trim($string)))
- return
- DateRange::create()->
- setStart($single)->
- setEnd($single);
-
- throw new WrongArgumentException(
- "unknown string format '{$string}'"
- );
- }
-
- private static function toDate($date)
- {
- if (strpos($date, '.') !== false) {
-
- $dots = substr_count($date, '.');
-
- $year = null;
-
- if ($dots == 2) {
- list($day, $month, $year) = explode('.', $date, ($dots + 1));
-
- if (strlen($day) > 2) {
- $tmp = $year;
- $year = $day;
- $day = $tmp;
- }
- } else
- list($day, $month) = explode('.', $date, ($dots + 1));
-
- if (strlen($day) == 1)
- $day = "0{$day}";
-
- if ($month === null)
- $month = date('m');
- elseif (strlen($month) == 1)
- $month = "0{$month}";
-
- if ($year === null)
- $year = date('Y');
- // we're all die in 2100+ anyway
- elseif (strlen($year) === 2)
- $year = "20{$year}";
-
- $date = $year.$month.$day;
- }
-
- $lenght = strlen($date);
-
- try {
- if ($lenght > 4)
- return new Timestamp(strtotime($date));
- elseif ($lenght === 4) {
- $date = substr($date, 2).'-'.substr($date, 0, 2);
-
- return new Timestamp(strtotime(date('Y-').$date));
- } elseif (($lenght == 2) || ($lenght == 1)) {
- return new Timestamp(strtotime(date('Y-m-').$date));
- }
- } catch (WrongArgumentException $e) {
- // seems to be unparseable
- }
-
- return null;
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/ExplodedPrimitive.class.php
===================================================================
--- trunk/core/Form/ExplodedPrimitive.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/ExplodedPrimitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,43 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2005 by Sveta Smirnova *
- * *
- * 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$ */
-
- final class ExplodedPrimitive extends PrimitiveString
- {
- protected $separator;
-
- public function setSeparator($separator)
- {
- $this->separator = $separator;
-
- return $this;
- }
-
- public function getSeparator()
- {
- return $this->separator;
- }
-
- public function import(&$scope)
- {
- if (!$temp = parent::import($scope))
- return $temp;
-
- if ($this->value = explode($this->separator, $this->value)) {
- return true;
- } else {
- return false;
- }
-
- /* NOTREACHED */
- }
- }
-?>
\ No newline at end of file
Copied: trunk/core/Form/Filter/BaseFilter.class.php (from rev 1776, trunk/core/Form/BaseFilter.class.php)
===================================================================
--- trunk/core/Form/Filter/BaseFilter.class.php (rev 0)
+++ trunk/core/Form/Filter/BaseFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,19 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005 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$ */
+
+ /**
+ * Filter's template.
+ *
+ * @ingroup Filter
+ **/
+ abstract class BaseFilter extends Singleton implements Filtrator {/*_*/}
+?>
\ No newline at end of file
Copied: trunk/core/Form/Filter/Filter.class.php (from rev 1776, trunk/core/Form/Filter.class.php)
===================================================================
--- trunk/core/Form/Filter/Filter.class.php (rev 0)
+++ trunk/core/Form/Filter/Filter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,78 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005 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$ */
+
+ /**
+ * Factory for Filtrator implementations.
+ *
+ * @ingroup Form
+ **/
+ final class Filter extends StaticFactory
+ {
+ public static function textImport()
+ {
+ return
+ FilterChain::create()->
+ add(Filter::trim())->
+ add(Filter::stripTags());
+ }
+
+ public static function chain()
+ {
+ return new FilterChain();
+ }
+
+ public static function hash($binary = false)
+ {
+ return HashFilter::create($binary);
+ }
+
+ public static function pcre()
+ {
+ return PCREFilter::create();
+ }
+
+ public static function trim()
+ {
+ return Singleton::getInstance('TrimFilter');
+ }
+
+ public static function stripTags()
+ {
+ return StripTagsFilter::create();
+ }
+
+ public static function htmlSpecialChars()
+ {
+ return Singleton::getInstance('HtmlSpecialCharsFilter');
+ }
+
+ public static function urlencode()
+ {
+ return Singleton::getInstance('UrlEncodeFilter');
+ }
+
+ public static function urldecode()
+ {
+ return Singleton::getInstance('UrlDecodeFilter');
+ }
+
+ public static function replaceSymbols($search = null, $replace = null)
+ {
+ return StringReplaceFilter::create($search, $replace);
+ }
+
+ public static function removeSymbols()
+ {
+ return Singleton::getInstance('RemoveSymbolsFilter');
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Filter/FilterChain.class.php (from rev 1776, trunk/core/Form/FilterChain.class.php)
===================================================================
--- trunk/core/Form/Filter/FilterChain.class.php (rev 0)
+++ trunk/core/Form/Filter/FilterChain.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,47 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005 by Anton E. Lebedevich *
+ * *
+ * 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$ */
+
+ /**
+ * Chained Filtrator.
+ *
+ * @ingroup Form
+ **/
+ class FilterChain implements Filtrator
+ {
+ protected $chain = array();
+
+ public static function create()
+ {
+ return new self;
+ }
+
+ public function add(Filtrator $filter)
+ {
+ $this->chain[] = $filter;
+ return $this;
+ }
+
+ public function dropAll()
+ {
+ $this->chain = array();
+ return $this;
+ }
+
+ public function apply($value)
+ {
+ foreach ($this->chain as &$filter)
+ $value = $filter->apply($value);
+
+ return $value;
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Filter/Filtrator.class.php (from rev 1776, trunk/core/Form/Filtrator.class.php)
===================================================================
--- trunk/core/Form/Filter/Filtrator.class.php (rev 0)
+++ trunk/core/Form/Filter/Filtrator.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,22 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005 by Anton E. Lebedevich *
+ * *
+ * 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$ */
+
+ /**
+ * Interface for primitive's filters.
+ *
+ * @ingroup Filters
+ **/
+ interface Filtrator
+ {
+ public function apply($value);
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Filter/HashFilter.class.php (from rev 1776, trunk/core/Form/HashFilter.class.php)
===================================================================
--- trunk/core/Form/Filter/HashFilter.class.php (rev 0)
+++ trunk/core/Form/Filter/HashFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,42 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005 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$ */
+
+ /**
+ * SHA-1 based filter: passwords.
+ *
+ * @ingroup Filters
+ **/
+ class HashFilter implements Filtrator
+ {
+ private $binary = false;
+
+ public function __construct($binary = false)
+ {
+ $this->binary = ($binary === true);
+ }
+
+ public static function create($binary = false)
+ {
+ return new self($binary);
+ }
+
+ public function isBinary()
+ {
+ return $this->binary;
+ }
+
+ public function apply($value)
+ {
+ return sha1($value, $this->binary);
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Filter/HtmlSpecialCharsFilter.class.php (from rev 1776, trunk/core/Form/HtmlSpecialCharsFilter.class.php)
===================================================================
--- trunk/core/Form/Filter/HtmlSpecialCharsFilter.class.php (rev 0)
+++ trunk/core/Form/Filter/HtmlSpecialCharsFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,27 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005 by Anton E. Lebedevich *
+ * *
+ * 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$ */
+
+ /**
+ * HTML Special Characters replacer.
+ *
+ * @see FiltrablePrimitive::getDisplayValue()
+ *
+ * @ingroup Filters
+ **/
+ class HtmlSpecialCharsFilter extends BaseFilter
+ {
+ public function apply($value)
+ {
+ return htmlspecialchars($value);
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Filter/PCREFilter.class.php (from rev 1776, trunk/core/Form/PCREFilter.class.php)
===================================================================
--- trunk/core/Form/Filter/PCREFilter.class.php (rev 0)
+++ trunk/core/Form/Filter/PCREFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,39 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005 by Sveta Smirnova *
+ * *
+ * 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 Filters
+ **/
+ class PCREFilter implements Filtrator
+ {
+ private $search = null;
+ private $replace = null;
+
+ public static function create()
+ {
+ return new self;
+ }
+
+ public function setExpression($search, $replace)
+ {
+ $this->search = $search;
+ $this->replace = $replace;
+
+ return $this;
+ }
+
+ public function apply($value)
+ {
+ return preg_replace($this->search, $this->replace, $value);
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Filter/RemoveSymbolsFilter.class.php (from rev 1776, trunk/core/Form/RemoveSymbolsFilter.class.php)
===================================================================
--- trunk/core/Form/Filter/RemoveSymbolsFilter.class.php (rev 0)
+++ trunk/core/Form/Filter/RemoveSymbolsFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,44 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005 by Sveta Smirnova *
+ * *
+ * 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$ */
+
+ class RemoveSymbolsFilter implements Filtrator
+ {
+ private $symbols = array();
+
+ public static function create()
+ {
+ return new RemoveSymbolsFilter();
+ }
+
+ public function setSymbols(/* ... */)
+ {
+ $this->symbols = func_get_args();
+
+ return $this;
+ }
+
+ public function getSymbols()
+ {
+ return $this->symbols;
+ }
+
+ public function apply($value)
+ {
+ return
+ str_replace(
+ $this->symbols,
+ null,
+ $value
+ );
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Filter/StringReplaceFilter.class.php (from rev 1776, trunk/core/Form/StringReplaceFilter.class.php)
===================================================================
--- trunk/core/Form/Filter/StringReplaceFilter.class.php (rev 0)
+++ trunk/core/Form/Filter/StringReplaceFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,84 @@
+<?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 Filters
+ **/
+ final class StringReplaceFilter implements Filtrator
+ {
+ private $search = null;
+ private $replace = null;
+
+ private $count = null;
+
+ public static function create($search = null, $replace = null)
+ {
+ return new self($search, $replace);
+ }
+
+ public function __construct($search = null, $replace = null)
+ {
+ $this->search = $search;
+ $this->replace = $replace;
+ }
+
+ public function setSearch($search)
+ {
+ $this->search = $search;
+
+ return $this;
+ }
+
+ public function getSearch()
+ {
+ return $this->search;
+ }
+
+ public function setReplace($replace)
+ {
+ $this->replace = $replace;
+
+ return $this;
+ }
+
+ public function getReplace()
+ {
+ return $this->replace;
+ }
+
+ public function getCount()
+ {
+ return $this->count;
+ }
+
+ public function apply($value)
+ {
+ if(
+ $this->search === $this->replace
+ || (
+ $this->search === null
+ && $this->replace === null
+ )
+ ) {
+ return $value;
+ }
+
+ return
+ str_replace(
+ $this->search,
+ $this->replace,
+ $value,
+ $this->count
+ );
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Filter/StripTagsFilter.class.php (from rev 1776, trunk/core/Form/StripTagsFilter.class.php)
===================================================================
--- trunk/core/Form/Filter/StripTagsFilter.class.php (rev 0)
+++ trunk/core/Form/Filter/StripTagsFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,42 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005 by Anton E. Lebedevich *
+ * *
+ * 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 RegulatedPrimitive::addImportFilter()
+ *
+ * @ingroup Filters
+ **/
+ class StripTagsFilter implements Filtrator
+ {
+ private $exclude = null;
+
+ public static function create()
+ {
+ return new self;
+ }
+
+ public function setAllowableTags($exclude)
+ {
+ if (null !== $exclude)
+ Assert::isString($exclude);
+
+ $this->exclude = $exclude;
+
+ return $this;
+ }
+
+ public function apply($value)
+ {
+ return strip_tags($value, $this->exclude);
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Filter/TrimFilter.class.php (from rev 1776, trunk/core/Form/TrimFilter.class.php)
===================================================================
--- trunk/core/Form/Filter/TrimFilter.class.php (rev 0)
+++ trunk/core/Form/Filter/TrimFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,23 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005 by Anton E. Lebedevich *
+ * *
+ * 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 Filters
+ **/
+ class TrimFilter extends BaseFilter
+ {
+ public function apply($value)
+ {
+ return trim($value);
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Filter/UrlDecodeFilter.class.php (from rev 1776, trunk/core/Form/UrlDecodeFilter.class.php)
===================================================================
--- trunk/core/Form/Filter/UrlDecodeFilter.class.php (rev 0)
+++ trunk/core/Form/Filter/UrlDecodeFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,23 @@
+<?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 Filters
+ **/
+ final class UrlDecodeFilter extends BaseFilter
+ {
+ public function apply($value)
+ {
+ return urldecode($value);
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Filter/UrlEncodeFilter.class.php (from rev 1776, trunk/core/Form/UrlEncodeFilter.class.php)
===================================================================
--- trunk/core/Form/Filter/UrlEncodeFilter.class.php (rev 0)
+++ trunk/core/Form/Filter/UrlEncodeFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,23 @@
+<?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 Filters
+ **/
+ final class UrlEncodeFilter extends BaseFilter
+ {
+ public function apply($value)
+ {
+ return urlencode($value);
+ }
+ }
+?>
\ No newline at end of file
Deleted: trunk/core/Form/Filter.class.php
===================================================================
--- trunk/core/Form/Filter.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/Filter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,78 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2005 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$ */
-
- /**
- * Factory for Filtrator implementations.
- *
- * @ingroup Form
- **/
- final class Filter extends StaticFactory
- {
- public static function textImport()
- {
- return
- FilterChain::create()->
- add(Filter::trim())->
- add(Filter::stripTags());
- }
-
- public static function chain()
- {
- return new FilterChain();
- }
-
- public static function hash($binary = false)
- {
- return HashFilter::create($binary);
- }
-
- public static function pcre()
- {
- return PCREFilter::create();
- }
-
- public static function trim()
- {
- return Singleton::getInstance('TrimFilter');
- }
-
- public static function stripTags()
- {
- return StripTagsFilter::create();
- }
-
- public static function htmlSpecialChars()
- {
- return Singleton::getInstance('HtmlSpecialCharsFilter');
- }
-
- public static function urlencode()
- {
- return Singleton::getInstance('UrlEncodeFilter');
- }
-
- public static function urldecode()
- {
- return Singleton::getInstance('UrlDecodeFilter');
- }
-
- public static function replaceSymbols($search = null, $replace = null)
- {
- return StringReplaceFilter::create($search, $replace);
- }
-
- public static function removeSymbols()
- {
- return Singleton::getInstance('RemoveSymbolsFilter');
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/FilterChain.class.php
===================================================================
--- trunk/core/Form/FilterChain.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/FilterChain.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,47 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2005 by Anton E. Lebedevich *
- * *
- * 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$ */
-
- /**
- * Chained Filtrator.
- *
- * @ingroup Form
- **/
- class FilterChain implements Filtrator
- {
- protected $chain = array();
-
- public static function create()
- {
- return new self;
- }
-
- public function add(Filtrator $filter)
- {
- $this->chain[] = $filter;
- return $this;
- }
-
- public function dropAll()
- {
- $this->chain = array();
- return $this;
- }
-
- public function apply($value)
- {
- foreach ($this->chain as &$filter)
- $value = $filter->apply($value);
-
- return $value;
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/FiltrablePrimitive.class.php
===================================================================
--- trunk/core/Form/FiltrablePrimitive.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/FiltrablePrimitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,71 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2005 by Anton E. Lebedevich, 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$ */
-
- /**
- * Basis for Primitives which can be filtered.
- *
- * @ingroup Primitives
- **/
- abstract class FiltrablePrimitive extends RangedPrimitive
- {
- private $importFilter = null;
- private $displayFilter = null;
-
- public function __construct($name)
- {
- parent::__construct($name);
- $this->displayFilter = new FilterChain();
- $this->importFilter = new FilterChain();
- }
-
- public function addDisplayFilter(Filtrator $filter)
- {
- $this->displayFilter->add($filter);
- return $this;
- }
-
- public function dropDisplayFilters()
- {
- $this->displayFilter->dropAll();
- return $this;
- }
-
- public function getDisplayValue()
- {
- return $this->displayFilter->apply($this->getActualValue());
- }
-
- public function addImportFilter(Filtrator $filter)
- {
- $this->importFilter->add($filter);
- return $this;
- }
-
- public function dropImportFilters()
- {
- $this->importFilter->dropAll();
- return $this;
- }
-
- public function getImportFilter()
- {
- return $this->importFilter;
- }
-
- protected function selfFilter()
- {
- $this->value = $this->importFilter->apply($this->value);
-
- return $this;
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/Filtrator.class.php
===================================================================
--- trunk/core/Form/Filtrator.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/Filtrator.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,22 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2005 by Anton E. Lebedevich *
- * *
- * 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$ */
-
- /**
- * Interface for primitive's filters.
- *
- * @ingroup Filters
- **/
- interface Filtrator
- {
- public function apply($value);
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/HashFilter.class.php
===================================================================
--- trunk/core/Form/HashFilter.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/HashFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,42 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2005 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$ */
-
- /**
- * SHA-1 based filter: passwords.
- *
- * @ingroup Filters
- **/
- class HashFilter implements Filtrator
- {
- private $binary = false;
-
- public function __construct($binary = false)
- {
- $this->binary = ($binary === true);
- }
-
- public static function create($binary = false)
- {
- return new self($binary);
- }
-
- public function isBinary()
- {
- return $this->binary;
- }
-
- public function apply($value)
- {
- return sha1($value, $this->binary);
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/HtmlSpecialCharsFilter.class.php
===================================================================
--- trunk/core/Form/HtmlSpecialCharsFilter.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/HtmlSpecialCharsFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,27 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2005 by Anton E. Lebedevich *
- * *
- * 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$ */
-
- /**
- * HTML Special Characters replacer.
- *
- * @see FiltrablePrimitive::getDisplayValue()
- *
- * @ingroup Filters
- **/
- class HtmlSpecialCharsFilter extends BaseFilter
- {
- public function apply($value)
- {
- return htmlspecialchars($value);
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/IdentifiablePrimitive.class.php
===================================================================
--- trunk/core/Form/IdentifiablePrimitive.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/IdentifiablePrimitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,31 +0,0 @@
-<?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 Primitives
- **/
- abstract class IdentifiablePrimitive extends PrimitiveInteger
- {
- protected $className = null;
-
- abstract public function of($className);
-
- public function setValue($value)
- {
- $className = $this->className;
-
- Assert::isTrue($value instanceof $className);
-
- return parent::setValue($value);
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/ListedPrimitive.class.php
===================================================================
--- trunk/core/Form/ListedPrimitive.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/ListedPrimitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,21 +0,0 @@
-<?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 Primitives
- **/
- interface ListedPrimitive
- {
- /// @return plain array of possible primitive choices
- public function getList();
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/PCREFilter.class.php
===================================================================
--- trunk/core/Form/PCREFilter.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/PCREFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,39 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2005 by Sveta Smirnova *
- * *
- * 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 Filters
- **/
- class PCREFilter implements Filtrator
- {
- private $search = null;
- private $replace = null;
-
- public static function create()
- {
- return new self;
- }
-
- public function setExpression($search, $replace)
- {
- $this->search = $search;
- $this->replace = $replace;
-
- return $this;
- }
-
- public function apply($value)
- {
- return preg_replace($this->search, $this->replace, $value);
- }
- }
-?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/BasePrimitive.class.php (from rev 1776, trunk/core/Form/BasePrimitive.class.php)
===================================================================
--- trunk/core/Form/Primitive/BasePrimitive.class.php (rev 0)
+++ trunk/core/Form/Primitive/BasePrimitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,131 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2004-2005 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 every Primitive.
+ *
+ * @ingroup Primitives
+ **/
+ abstract class BasePrimitive
+ {
+ protected $name = null;
+ protected $default = null;
+ protected $value = null;
+
+ protected $required = false;
+
+ protected $raw = null;
+
+ public function __construct($name)
+ {
+ $this->name = $name;
+ }
+
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ public function setName($name)
+ {
+ $this->name = $name;
+
+ return $this;
+ }
+
+ public function getDefault()
+ {
+ return $this->default;
+ }
+
+ public function setDefault($default)
+ {
+ $this->default = $default;
+
+ return $this;
+ }
+
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ public function getRawValue()
+ {
+ return $this->raw;
+ }
+
+ public function getActualValue()
+ {
+ if (null !== $this->value)
+ return $this->value;
+ elseif (null !== $this->raw)
+ return $this->raw;
+
+ return $this->default;
+ }
+
+ public function setValue($value)
+ {
+ $this->value = $value;
+
+ return $this;
+ }
+
+ public function setRawValue($raw)
+ {
+ $this->raw = $raw;
+
+ return $this;
+ }
+
+ public function isRequired()
+ {
+ return $this->required;
+ }
+
+ public function setRequired($really = false)
+ {
+ $this->required = (true === $really ? true : false);
+
+ return $this;
+ }
+
+ public function required()
+ {
+ $this->required = true;
+
+ return $this;
+ }
+
+ public function optional()
+ {
+ $this->required = false;
+
+ return $this;
+ }
+
+ protected function import(&$scope)
+ {
+ if (
+ isset($scope[$this->name]) &&
+ $scope[$this->name] !== ''
+ ) {
+ $this->raw = $scope[$this->name];
+
+ return true;
+ }
+
+ return null;
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/ComplexPrimitive.class.php (from rev 1776, trunk/core/Form/ComplexPrimitive.class.php)
===================================================================
--- trunk/core/Form/Primitive/ComplexPrimitive.class.php (rev 0)
+++ trunk/core/Form/Primitive/ComplexPrimitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,83 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2004-2005 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$ */
+
+ /**
+ * Basis for primitives which can be scattered across import scope.
+ *
+ * @ingroup Primitives
+ **/
+ abstract class ComplexPrimitive extends RangedPrimitive
+ {
+ private $single = null; // single, not single or fsck it
+
+ public function __construct($name)
+ {
+ $this->single = new Ternary(null);
+ parent::__construct($name);
+ }
+
+ public function getState()
+ {
+ return $this->single;
+ }
+
+ public function setState(Ternary $ternary)
+ {
+ $this->single->setValue($ternary->getValue());
+
+ return $this;
+ }
+
+ public function setSingle()
+ {
+ $this->single->setTrue();
+
+ return $this;
+ }
+
+ public function setComplex()
+ {
+ $this->single->setFalse();
+
+ return $this;
+ }
+
+ public function setAnyState()
+ {
+ $this->single->setNull();
+
+ return $this;
+ }
+
+ // implement me, child :-)
+ abstract protected function importSingle(&$scope);
+ abstract protected function importMarried(&$scope);
+
+ public function import(&$scope)
+ {
+ parent::import($scope);
+
+ if ($this->single->isTrue())
+ return $this->importSingle($scope);
+ elseif ($this->single->isFalse())
+ return $this->importMarried($scope);
+ else {
+ if (!$this->importMarried($scope))
+ return $this->importSingle($scope);
+
+ return true;
+ }
+
+ /* NOTREACHED */
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/DateRangeList.class.php (from rev 1776, trunk/core/Form/DateRangeList.class.php)
===================================================================
--- trunk/core/Form/Primitive/DateRangeList.class.php (rev 0)
+++ trunk/core/Form/Primitive/DateRangeList.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,191 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005 by Konstantin V. Arkhipov, Igor V. Gulyaev *
+ * *
+ * 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 Primitives
+ **/
+ class DateRangeList extends BasePrimitive implements Stringable
+ {
+ public function import(&$scope)
+ {
+ if (
+ !isset($scope[$this->name])
+ || !is_array($scope[$this->name])
+ || empty($scope[$this->name])
+ ||
+ (
+ count($scope[$this->name]) == 1
+ && !current($scope[$this->name])
+ )
+ )
+ return null;
+
+ $array = $scope[$this->name];
+ $list = array();
+
+ foreach ($array as $string)
+ if (array() !== self::stringToDateRangeList($string))
+ foreach (self::stringToDateRangeList($string) as $range)
+ $list[] = $range;
+
+ $this->value = $list;
+
+ return ($this->value !== array());
+ }
+
+ public function toString()
+ {
+ if ($this->value) {
+ $out = array();
+
+ foreach ($this->value as $range)
+ $out[] = $range->toDateString();
+
+ return implode(', ', $out);
+ }
+
+ return null;
+ }
+
+ public static function stringToDateRangeList($string)
+ {
+ $list = array();
+
+ if (!empty($string)) {
+ if (strpos($string, ',') !== false)
+ $dates = explode(',', $string);
+ else
+ $dates = array($string);
+
+ foreach ($dates as $date) {
+ try {
+ $list[] = self::makeRange($date);
+ } catch (WrongArgumentException $e) {
+ // ignore?
+ }
+ }
+ }
+
+ return $list;
+ }
+
+ public static function printRange(DateRange $range, $delimiter = '-')
+ {
+ $rangeString = null;
+
+ if ($range->getStart())
+ $rangeString .= $range->getStart()->toDate($delimiter);
+
+ $rangeString .= ' - ';
+
+ if ($range->getEnd())
+ $rangeString .= $range->getEnd()->toDate($delimiter);
+
+ return $rangeString;
+ }
+
+ public static function makeRange($string)
+ {
+ if (
+ (substr_count($string, ' - ') === 1)
+ || (substr_count($string, '-'))
+ ) {
+ $delimiter = ' - ';
+
+ if (substr_count($string, '-') === 1)
+ $delimiter = '-';
+
+ list($start, $finish) = explode($delimiter, $string, 2);
+
+ $start = self::toDate(trim($start));
+ $finish = self::toDate(trim($finish));
+
+ if ($start || $finish) {
+
+ $range = new DateRange();
+
+ $range =
+ DateRange::create()->
+ lazySet($start, $finish);
+
+ return $range;
+
+ } elseif ($string == ' - ')
+ return DateRange::create();
+
+ } elseif ($single = self::toDate(trim($string)))
+ return
+ DateRange::create()->
+ setStart($single)->
+ setEnd($single);
+
+ throw new WrongArgumentException(
+ "unknown string format '{$string}'"
+ );
+ }
+
+ private static function toDate($date)
+ {
+ if (strpos($date, '.') !== false) {
+
+ $dots = substr_count($date, '.');
+
+ $year = null;
+
+ if ($dots == 2) {
+ list($day, $month, $year) = explode('.', $date, ($dots + 1));
+
+ if (strlen($day) > 2) {
+ $tmp = $year;
+ $year = $day;
+ $day = $tmp;
+ }
+ } else
+ list($day, $month) = explode('.', $date, ($dots + 1));
+
+ if (strlen($day) == 1)
+ $day = "0{$day}";
+
+ if ($month === null)
+ $month = date('m');
+ elseif (strlen($month) == 1)
+ $month = "0{$month}";
+
+ if ($year === null)
+ $year = date('Y');
+ // we're all die in 2100+ anyway
+ elseif (strlen($year) === 2)
+ $year = "20{$year}";
+
+ $date = $year.$month.$day;
+ }
+
+ $lenght = strlen($date);
+
+ try {
+ if ($lenght > 4)
+ return new Timestamp(strtotime($date));
+ elseif ($lenght === 4) {
+ $date = substr($date, 2).'-'.substr($date, 0, 2);
+
+ return new Timestamp(strtotime(date('Y-').$date));
+ } elseif (($lenght == 2) || ($lenght == 1)) {
+ return new Timestamp(strtotime(date('Y-m-').$date));
+ }
+ } catch (WrongArgumentException $e) {
+ // seems to be unparseable
+ }
+
+ return null;
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/ExplodedPrimitive.class.php (from rev 1776, trunk/core/Form/ExplodedPrimitive.class.php)
===================================================================
--- trunk/core/Form/Primitive/ExplodedPrimitive.class.php (rev 0)
+++ trunk/core/Form/Primitive/ExplodedPrimitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,46 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005 by Sveta Smirnova *
+ * *
+ * 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 Primitives
+ **/
+ final class ExplodedPrimitive extends PrimitiveString
+ {
+ protected $separator;
+
+ public function setSeparator($separator)
+ {
+ $this->separator = $separator;
+
+ return $this;
+ }
+
+ public function getSeparator()
+ {
+ return $this->separator;
+ }
+
+ public function import(&$scope)
+ {
+ if (!$temp = parent::import($scope))
+ return $temp;
+
+ if ($this->value = explode($this->separator, $this->value)) {
+ return true;
+ } else {
+ return false;
+ }
+
+ /* NOTREACHED */
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/FiltrablePrimitive.class.php (from rev 1776, trunk/core/Form/FiltrablePrimitive.class.php)
===================================================================
--- trunk/core/Form/Primitive/FiltrablePrimitive.class.php (rev 0)
+++ trunk/core/Form/Primitive/FiltrablePrimitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,71 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005 by Anton E. Lebedevich, 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$ */
+
+ /**
+ * Basis for Primitives which can be filtered.
+ *
+ * @ingroup Primitives
+ **/
+ abstract class FiltrablePrimitive extends RangedPrimitive
+ {
+ private $importFilter = null;
+ private $displayFilter = null;
+
+ public function __construct($name)
+ {
+ parent::__construct($name);
+ $this->displayFilter = new FilterChain();
+ $this->importFilter = new FilterChain();
+ }
+
+ public function addDisplayFilter(Filtrator $filter)
+ {
+ $this->displayFilter->add($filter);
+ return $this;
+ }
+
+ public function dropDisplayFilters()
+ {
+ $this->displayFilter->dropAll();
+ return $this;
+ }
+
+ public function getDisplayValue()
+ {
+ return $this->displayFilter->apply($this->getActualValue());
+ }
+
+ public function addImportFilter(Filtrator $filter)
+ {
+ $this->importFilter->add($filter);
+ return $this;
+ }
+
+ public function dropImportFilters()
+ {
+ $this->importFilter->dropAll();
+ return $this;
+ }
+
+ public function getImportFilter()
+ {
+ return $this->importFilter;
+ }
+
+ protected function selfFilter()
+ {
+ $this->value = $this->importFilter->apply($this->value);
+
+ return $this;
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/IdentifiablePrimitive.class.php (from rev 1776, trunk/core/Form/IdentifiablePrimitive.class.php)
===================================================================
--- trunk/core/Form/Primitive/IdentifiablePrimitive.class.php (rev 0)
+++ trunk/core/Form/Primitive/IdentifiablePrimitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,31 @@
+<?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 Primitives
+ **/
+ abstract class IdentifiablePrimitive extends PrimitiveInteger
+ {
+ protected $className = null;
+
+ abstract public function of($className);
+
+ public function setValue($value)
+ {
+ $className = $this->className;
+
+ Assert::isTrue($value instanceof $className);
+
+ return parent::setValue($value);
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/ListedPrimitive.class.php (from rev 1776, trunk/core/Form/ListedPrimitive.class.php)
===================================================================
--- trunk/core/Form/Primitive/ListedPrimitive.class.php (rev 0)
+++ trunk/core/Form/Primitive/ListedPrimitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -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 Primitives
+ **/
+ interface ListedPrimitive
+ {
+ /// @return plain array of possible primitive choices
+ public function getList();
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/Primitive.class.php (from rev 1776, trunk/core/Form/Primitive.class.php)
===================================================================
--- trunk/core/Form/Primitive/Primitive.class.php (rev 0)
+++ trunk/core/Form/Primitive/Primitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,90 @@
+<?php
+/****************************************************************************
+ * Copyright (C) 2004-2006 by Konstantin V. Arkhipov, Anton E. Lebedevich *
+ * *
+ * 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$ */
+
+ /**
+ * Factory for various Primitives.
+ *
+ * @ingroup Primitives
+ **/
+ final class Primitive extends StaticFactory
+ {
+ public static function spawn($primitive, $name)
+ {
+ return new $primitive($name);
+ }
+
+ public static function integer($name)
+ {
+ return new PrimitiveInteger($name);
+ }
+
+ public static function identifier($name)
+ {
+ return new PrimitiveIdentifier($name);
+ }
+
+ public static function enumeration($name)
+ {
+ return new PrimitiveEnumeration($name);
+ }
+
+ public static function date($name)
+ {
+ return new PrimitiveDate($name);
+ }
+
+ public static function string($name)
+ {
+ return new PrimitiveString($name);
+ }
+
+ public static function range($name)
+ {
+ return new PrimitiveRange($name);
+ }
+
+ public static function choice($name)
+ {
+ return new PrimitiveList($name);
+ }
+
+ public static function set($name)
+ {
+ return new PrimitiveArray($name);
+ }
+
+ public static function multiChoice($name)
+ {
+ return new PrimitiveMultiList($name);
+ }
+
+ public static function boolean($name)
+ {
+ return new PrimitiveBoolean($name);
+ }
+
+ public static function file($name)
+ {
+ return new PrimitiveFile($name);
+ }
+
+ public static function image($name)
+ {
+ return new PrimitiveImage($name);
+ }
+
+ public static function exploded($name)
+ {
+ return new ExplodedPrimitive($name);
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/PrimitiveArray.class.php (from rev 1776, trunk/core/Form/PrimitiveArray.class.php)
===================================================================
--- trunk/core/Form/Primitive/PrimitiveArray.class.php (rev 0)
+++ trunk/core/Form/Primitive/PrimitiveArray.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,35 @@
+<?php
+/****************************************************************************
+ * Copyright (C) 2004-2006 by Konstantin V. Arkhipov, Anton E. Lebedevich *
+ * *
+ * 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 Primitives
+ **/
+ class PrimitiveArray extends RangedPrimitive
+ {
+ public function import(&$scope)
+ {
+ if (!BasePrimitive::import($scope))
+ return null;
+
+ if (is_array($scope[$this->name]) &&
+ !($this->min && count($scope[$this->name]) < $this->min) &&
+ !($this->min && count($scope[$this->name]) > $this->max))
+ {
+ $this->value = $scope[$this->name];
+
+ return true;
+ }
+
+ return false;
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/PrimitiveBoolean.class.php (from rev 1776, trunk/core/Form/PrimitiveBoolean.class.php)
===================================================================
--- trunk/core/Form/Primitive/PrimitiveBoolean.class.php (rev 0)
+++ trunk/core/Form/Primitive/PrimitiveBoolean.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,28 @@
+<?php
+/****************************************************************************
+ * Copyright (C) 2004-2006 by Konstantin V. Arkhipov, Anton E. Lebedevich *
+ * *
+ * 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 Primitives
+ **/
+ class PrimitiveBoolean extends BasePrimitive
+ {
+ public function import(&$scope) // to be compatible with BasePrimitive
+ {
+ if (isset($scope[$this->name]))
+ $this->value = true;
+ else
+ $this->value = false;
+
+ return true;
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/PrimitiveDate.class.php (from rev 1776, trunk/core/Form/PrimitiveDate.class.php)
===================================================================
--- trunk/core/Form/Primitive/PrimitiveDate.class.php (rev 0)
+++ trunk/core/Form/Primitive/PrimitiveDate.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,152 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2004-2005 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 Primitives
+ **/
+ class PrimitiveDate extends ComplexPrimitive
+ {
+ const DAY = 'day';
+ const MONTH = 'month';
+ const YEAR = 'year';
+
+ const HOURS = 'hrs';
+ const MINUTES = 'min';
+ const SECONDS = 'sec';
+
+ // typeHinting commented out due to stupid E_STRICT
+ public function setValue(/* Timestamp */ $stamp)
+ {
+ Assert::isTrue($stamp instanceof Timestamp);
+
+ $this->value = $stamp;
+
+ return $this;
+ }
+
+ public function setMin(/* Timestamp */ $stamp)
+ {
+ Assert::isTrue($stamp instanceof Timestamp);
+
+ $this->min = $stamp;
+
+ return $this;
+ }
+
+ public function setMax(/* Timestamp */ $stamp)
+ {
+ Assert::isTrue($stamp instanceof Timestamp);
+
+ $this->max = $stamp;
+
+ return $this;
+ }
+
+ public function setDefault(/* Timestamp */ $stamp)
+ {
+ Assert::isTrue($stamp instanceof Timestamp);
+
+ $this->default = $stamp;
+
+ return $this;
+ }
+
+ public function importSingle(&$scope)
+ {
+ if (isset($scope[$this->name]) &&
+ is_string($scope[$this->name]) &&
+ $time = strtotime($scope[$this->name])
+ ) {
+ $tstamp = new Timestamp($time);
+ if (!($this->min && $this->min->toStamp() > $tstamp->toStamp())
+ && !($this->max && $this->max->toStamp() < $tstamp->toStamp())
+ ) {
+ $this->value = $tstamp;
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public function isEmpty(&$scope)
+ {
+ if ($this->getState()->isFalse()) {
+ return
+ empty($scope[$this->name][self::DAY]) ||
+ empty($scope[$this->name][self::MONTH]) ||
+ empty($scope[$this->name][self::YEAR]);
+ } else
+ return empty($scope[$this->name]);
+ }
+
+ public function importMarried(&$scope)
+ {
+ if (
+ isset(
+ $scope[$this->name][self::DAY],
+ $scope[$this->name][self::MONTH],
+ $scope[$this->name][self::YEAR]
+ )
+ && is_array($scope[$this->name])
+ && !empty($scope[$this->name][self::DAY])
+ && !empty($scope[$this->name][self::MONTH])
+ && !empty($scope[$this->name][self::YEAR])
+ ) {
+ $hours = $minutes = $seconds = 0;
+
+ if (isset($scope[$this->name][self::HOURS]))
+ $hours = (int) $scope[$this->name][self::HOURS];
+
+ if (isset($scope[$this->name][self::MINUTES]))
+ $minutes = (int) $scope[$this->name][self::MINUTES];
+
+ if (isset($scope[$this->name][self::SECONDS]))
+ $seconds = (int) $scope[$this->name][self::SECONDS];
+
+ try {
+ $stamp = mktime(
+ $hours, $minutes, $seconds,
+ (int) $scope[$this->name][self::MONTH],
+ (int) $scope[$this->name][self::DAY],
+ (int) $scope[$this->name][self::YEAR]
+ );
+ } catch (BaseException $e) {
+ // fsck wrong stamps
+ return false;
+ }
+
+ if (!($this->min && $this->min->toStamp() < $stamp) &&
+ !($this->max && $this->max->toStamp() > $stamp)
+ ) {
+ try {
+ $this->value = new Timestamp($stamp);
+
+ return true;
+ } catch (WrongArgumentException $e) {
+ return false;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public function import(&$scope)
+ {
+ if ($this->isEmpty($scope))
+ return null;
+
+ return parent::import($scope);
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/PrimitiveDumper.class.php (from rev 1776, trunk/core/Form/PrimitiveDumper.class.php)
===================================================================
--- trunk/core/Form/Primitive/PrimitiveDumper.class.php (rev 0)
+++ trunk/core/Form/Primitive/PrimitiveDumper.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,76 @@
+<?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$ */
+
+ /**
+ * Dumps primitives to desired HTML control.
+ *
+ * @ingroup Primitives
+ **/
+ final class PrimitiveDumper extends StaticFactory
+ {
+ private static $class = null;
+
+ public static function text(BasePrimitive $prm)
+ {
+ $class = self::$class;
+
+ return <<<EOT
+<input type="text" name="{$prm->getName()}" class="{$class}" value="{$prm->getActualValue()}">
+EOT;
+ }
+
+ public static function password(BasePrimitive $prm)
+ {
+ $class = self::$class;
+
+ return <<<EOT
+<intput type="password" name="{$prm->getName()}" class="{$class}" value="{$prm->getActualValue()}">
+EOT;
+ }
+
+ /**
+ * @param $prm target primitive
+ * @param $list array of identifiable stringable objects
+ **/
+ public static function select(BasePrimitive $prm, $list)
+ {
+ $value = $prm->getActualValue();
+
+ $out = '<select name="'.$prm->getName().'" class="'.self::$class.'">';
+
+ foreach ($list as $object) {
+ $id = $object->getId();
+
+ $out .=
+ '<option value="'.$id.'"'
+ .($value == $id ? ' selected' : null).'>'
+ .$object->toString().'</option>';
+ }
+
+ return $out.'</select>';
+ }
+
+ public static function textarea(BasePrimitive $prm)
+ {
+ $class = self::$class;
+
+ return <<<EOT
+<textarea name="{$prm->getName()}" class="{$class}">{$prm->getActualValue()}</textarea>
+EOT;
+ }
+
+ public static function setClass($class)
+ {
+ self::$class = $class;
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/PrimitiveEnumeration.class.php (from rev 1776, trunk/core/Form/PrimitiveEnumeration.class.php)
===================================================================
--- trunk/core/Form/Primitive/PrimitiveEnumeration.class.php (rev 0)
+++ trunk/core/Form/Primitive/PrimitiveEnumeration.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,74 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2006 by Ivan Y. Khvostishkov, 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 Primitives
+ **/
+ final class PrimitiveEnumeration
+ extends IdentifiablePrimitive
+ implements ListedPrimitive
+ {
+ public function getList()
+ {
+ if ($this->value)
+ return $this->value->getObjectList();
+ elseif ($this->default)
+ return $this->default->getObjectList();
+ else {
+ return new $this->className(
+ call_user_func(array($this->className, 'getAnyId'))
+ );
+ }
+
+ /* NOTREACHED */
+ }
+
+ public function of($className)
+ {
+ Assert::isTrue(
+ class_exists($className, true),
+ "knows nothing about '{$className}' class"
+ );
+
+ Assert::isTrue(
+ is_subclass_of($className, 'Enumeration'),
+ "non-enumeration child given"
+ );
+
+ $this->className = $className;
+
+ return $this;
+ }
+
+ public function import(&$scope)
+ {
+ if (!$this->className)
+ throw new WrongStateException(
+ "no class defined for PrimitiveEnumeration '{$this->name}'"
+ );
+
+ $result = parent::import($scope);
+
+ if ($result === true) {
+ try {
+ $this->value = new $this->className($this->value);
+ } catch (MissingElementException $e) {
+ return false;
+ }
+
+ return true;
+ }
+
+ return $result;
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/PrimitiveFile.class.php (from rev 1776, trunk/core/Form/PrimitiveFile.class.php)
===================================================================
--- trunk/core/Form/Primitive/PrimitiveFile.class.php (rev 0)
+++ trunk/core/Form/Primitive/PrimitiveFile.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,117 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2004-2005 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$ */
+
+ /**
+ * File uploads helper.
+ *
+ * @ingroup Primitives
+ **/
+ class PrimitiveFile extends RangedPrimitive
+ {
+ private $originalName = null;
+ private $mimeType = null;
+
+ private $allowedMimeTypes = array();
+
+ public function getOriginalName()
+ {
+ return $this->originalName;
+ }
+
+ public function getMimeType()
+ {
+ return $this->mimeType;
+ }
+
+ public function setAllowedMimeTypes($mimes)
+ {
+ Assert::isArray($mimes);
+
+ $this->allowedMimeTypes = $mimes;
+
+ return $this;
+ }
+
+ public function addAllowedMimeType($mime)
+ {
+ Assert::isString($mime);
+
+ $this->allowedMimeTypes[] = $mime;
+
+ return $this;
+ }
+
+ public function getAllowedMimeTypes()
+ {
+ return $this->allowedMimeType;
+ }
+
+ public function isAllowedMimeType()
+ {
+ if (count($this->allowedMimeTypes) > 0) {
+ return in_array($this->mimeType, $this->allowedMimeTypes);
+ } else
+ return true;
+ }
+
+ public function copyTo($path, $name)
+ {
+ if (is_readable($this->value) && is_writable($path)) {
+ return move_uploaded_file($this->value, $path.$name);
+ } else
+ throw new WrongArgumentException(
+ "can not move '{$this->value}' to '{($path"."$name)}'"
+ );
+ }
+
+ public function import(&$scope)
+ {
+ if (
+ !BasePrimitive::import($scope)
+ || !is_array($scope[$this->name])
+ || (
+ isset($scope[$this->name], $scope[$this->name]['error'])
+ && $scope[$this->name]['error'] == UPLOAD_ERR_NO_FILE
+ )
+ )
+ return null;
+
+ if (isset($scope[$this->name]['tmp_name']))
+ $file = $scope[$this->name]['tmp_name'];
+ else
+ return false;
+
+ if (is_readable($file) && is_uploaded_file($file))
+ $size = filesize($file);
+ else
+ return false;
+
+ $this->mimeType = $scope[$this->name]['type'];
+
+ if (!$this->isAllowedMimeType())
+ return false;
+
+ if (
+ isset($scope[$this->name])
+ && !($this->max && ($size > $this->max))
+ && !($this->min && ($size < $this->min))
+ ) {
+ $this->value = $scope[$this->name]['tmp_name'];
+ $this->originalName = $scope[$this->name]['name'];
+
+ return true;
+ }
+
+ return false;
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/PrimitiveIdentifier.class.php (from rev 1776, trunk/core/Form/PrimitiveIdentifier.class.php)
===================================================================
--- trunk/core/Form/Primitive/PrimitiveIdentifier.class.php (rev 0)
+++ trunk/core/Form/Primitive/PrimitiveIdentifier.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,65 @@
+<?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 Primitives
+ **/
+ final class PrimitiveIdentifier extends IdentifiablePrimitive
+ {
+ public function of($className)
+ {
+ Assert::isTrue(
+ class_exists($className, true),
+ "knows nothing about '{$className}' class"
+ );
+
+ $class = new ReflectionClass($className);
+
+ Assert::isTrue(
+ $class->implementsInterface('DAOConnected'),
+ "class '{$class->getName()}' should implement DAOConnected interface"
+ );
+
+ $this->className = $className;
+
+ return $this;
+ }
+
+ public function dao()
+ {
+ return call_user_func(array($this->className, 'dao'));
+ }
+
+ public function import(&$scope)
+ {
+ if (!$this->className)
+ throw new WrongStateException(
+ "no class defined for PrimitiveIdentifier '{$this->name}'"
+ );
+
+ $result = parent::import($scope);
+
+ if ($result === true) {
+ try {
+ $this->value = $this->dao()->getById($this->value);
+ } catch (ObjectNotFoundException $e) {
+ $this->value = null;
+ return false;
+ }
+
+ return true;
+ }
+
+ return $result;
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/PrimitiveImage.class.php (from rev 1776, trunk/core/Form/PrimitiveImage.class.php)
===================================================================
--- trunk/core/Form/Primitive/PrimitiveImage.class.php (rev 0)
+++ trunk/core/Form/Primitive/PrimitiveImage.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,103 @@
+<?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$ */
+
+ /**
+ * Image uploads helper.
+ *
+ * @ingroup Primitives
+ **/
+ class PrimitiveImage extends PrimitiveFile
+ {
+ private $width = null;
+ private $height = null;
+
+ private $maxWidth = null;
+ private $minWidth = null;
+
+ private $maxHeight = null;
+ private $minHeight = null;
+
+ private $type = null;
+
+ public function getWidth()
+ {
+ return $this->width;
+ }
+
+ public function getHeight()
+ {
+ return $this->height;
+ }
+
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ public function setMaxWidth($max)
+ {
+ $this->maxWidth = $max;
+
+ return $this;
+ }
+
+ public function setMinWidth($min)
+ {
+ $this->minWidth = $min;
+
+ return $this;
+ }
+
+ public function setMaxHeight($max)
+ {
+ $this->maxHeight = $max;
+
+ return $this;
+ }
+
+ public function setMinHeight($min)
+ {
+ $this->minHeight = $min;
+
+ return $this;
+ }
+
+ public function import(&$scope)
+ {
+ if ($result = parent::import($scope)) {
+
+ try {
+ list($width, $height, $type) = getimagesize($this->value);
+ } catch (BaseException $e) {
+ $this->value = null;
+ return false;
+ }
+
+ if (
+ !($this->maxWidth && ($width > $this->maxWidth))
+ && !($this->minWidth && ($width < $this->minWidth))
+ && !($this->maxHeight && ($height > $this->maxHeight))
+ && !($this->minHeight && ($height < $this->minHeight))
+ )
+ {
+ $this->type = new ImageType($type);
+ $this->width = $width;
+ $this->height = $height;
+
+ return true;
+ }
+ }
+
+ return $result;
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/PrimitiveInteger.class.php (from rev 1776, trunk/core/Form/PrimitiveInteger.class.php)
===================================================================
--- trunk/core/Form/Primitive/PrimitiveInteger.class.php (rev 0)
+++ trunk/core/Form/Primitive/PrimitiveInteger.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,43 @@
+<?php
+/****************************************************************************
+ * Copyright (C) 2004-2005 by Konstantin V. Arkhipov, Anton E. Lebedevich *
+ * *
+ * 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 Primitives
+ **/
+ class PrimitiveInteger extends FiltrablePrimitive
+ {
+ public function import(&$scope)
+ {
+ if (!BasePrimitive::import($scope))
+ return null;
+
+ try {
+ Assert::isInteger($scope[$this->name]);
+ } catch (WrongArgumentException $e) {
+ return false;
+ }
+
+ if (
+ !(null !== $this->min && $scope[$this->name] < $this->min) &&
+ !(null !== $this->max && $scope[$this->name] > $this->max)
+ ) {
+ $this->value = (int) $scope[$this->name];
+
+ $this->selfFilter();
+
+ return true;
+ }
+
+ return false;
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/PrimitiveList.class.php (from rev 1776, trunk/core/Form/PrimitiveList.class.php)
===================================================================
--- trunk/core/Form/Primitive/PrimitiveList.class.php (rev 0)
+++ trunk/core/Form/Primitive/PrimitiveList.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,54 @@
+<?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$ */
+
+ /**
+ * @ingroup Primitives
+ **/
+ class PrimitiveList extends BasePrimitive implements ListedPrimitive
+ {
+ protected $list = array();
+
+ public function getList()
+ {
+ return $this->list;
+ }
+
+ public function setList($list)
+ {
+ $this->list = $list;
+
+ return $this;
+ }
+
+ public function import(&$scope)
+ {
+ if (!parent::import($scope)) {
+ return null;
+ }
+
+ if (
+ (
+ is_string($scope[$this->name])
+ || is_integer($scope[$this->name])
+ )
+ && isset($this->list[$scope[$this->name]])
+ ) {
+ $this->value = $scope[$this->name];
+
+ return true;
+ } else
+ return false;
+
+ /* NOTREACHED */
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/PrimitiveMultiList.class.php (from rev 1776, trunk/core/Form/PrimitiveMultiList.class.php)
===================================================================
--- trunk/core/Form/Primitive/PrimitiveMultiList.class.php (rev 0)
+++ trunk/core/Form/Primitive/PrimitiveMultiList.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,51 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2004-2005 by Anton E. Lebedevich *
+ * *
+ * 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 Primitives
+ **/
+ class PrimitiveMultiList extends PrimitiveList
+ {
+ public function import(&$scope)
+ {
+ if (!BasePrimitive::import($scope))
+ return null;
+
+ if ($this->list) {
+ if (is_array($scope[$this->name])) {
+ $values = array();
+
+ foreach ($scope[$this->name] as $value)
+ if (isset($this->list[$value]))
+ $values[] = $value;
+
+ if (count($values))
+ $this->value = $values;
+ else
+ return false;
+
+ } else {
+ if (isset($this->list[$scope[$this->name]]))
+ $this->value = $scope[$this->name];
+ else
+ return false;
+ }
+ } else {
+ $this->value = $scope[$this->name];
+
+ return true;
+ }
+
+ /* NOTREACHED */
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/PrimitiveRange.class.php (from rev 1776, trunk/core/Form/PrimitiveRange.class.php)
===================================================================
--- trunk/core/Form/Primitive/PrimitiveRange.class.php (rev 0)
+++ trunk/core/Form/Primitive/PrimitiveRange.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,134 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2004-2005 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 Primitives
+ **/
+ class PrimitiveRange extends ComplexPrimitive
+ {
+ const MIN = 'min';
+ const MAX = 'max';
+
+ private $swapAllowed = true;
+
+ public function setSwapAllowed()
+ {
+ $this->swapAllowed = true;
+
+ return $this;
+ }
+
+ public function setSwapDisallowed()
+ {
+ $this->swapAllowed = false;
+
+ return $this;
+ }
+
+ // to be E_STRICT compatible
+ public function setValue(/* Range */ $range)
+ {
+ Assert::isTrue(
+ $range instanceof Range,
+ 'only ranges accepted today'
+ );
+
+ $this->value = $range;
+
+ return $this;
+ }
+
+ public function importSingle(&$scope)
+ {
+ if (!BasePrimitive::import($scope) || is_array($scope[$this->name]))
+ return null;
+
+ if (isset($scope[$this->name]) && is_string($scope[$this->name])) {
+ $arr = explode('-', $scope[$this->name], 2);
+
+ $range =
+ Range::buildObject(
+ ArrayUtils::getArrayVar($arr, 0),
+ ArrayUtils::getArrayVar($arr, 1),
+ $this->swapAllowed
+ );
+
+ if ($range &&
+ !(
+ ($this->min && $range->getMin()) &&
+ $range->getMin() < $this->min
+ ) &&
+ !(
+ ($this->max && $range->getMax()) &&
+ $range->getMax() > $this->max
+ )
+ ) {
+ $this->value = $range;
+
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public function importMarried(&$scope) // ;-)
+ {
+ $name = &$this->name;
+
+ if (
+ ($this->safeGet($scope, $name, self::MIN) === null) &&
+ ($this->safeGet($scope, $name, self::MAX) === null)
+ )
+ return null;
+
+ $range =
+ Range::buildObject(
+ $this->safeGet($scope, $name, self::MIN),
+ $this->safeGet($scope, $name, self::MAX),
+ $this->swapAllowed
+ );
+
+ if ($range &&
+ !(
+ ($this->min && $range->getMin()) &&
+ $range->getMin() < $this->min
+ ) &&
+ !(
+ ($this->max && $range->getMax()) &&
+ $range->getMax() > $this->max
+ )
+ ) {
+ $this->value = $range;
+
+ return true;
+ }
+
+ return false;
+ }
+
+ private function safeGet(&$scope, $firstDimension, $secondDimension)
+ {
+ if (isset($scope[$firstDimension]) && is_array($scope[$firstDimension])) {
+ if (
+ isset($scope[$firstDimension][$secondDimension])
+ && is_array($scope[$firstDimension])
+ && !empty($scope[$firstDimension][$secondDimension])
+ ) {
+ return $scope[$firstDimension][$secondDimension];
+ }
+ }
+
+ return null;
+ }
+ }
+?>
Copied: trunk/core/Form/Primitive/PrimitiveString.class.php (from rev 1776, trunk/core/Form/PrimitiveString.class.php)
===================================================================
--- trunk/core/Form/Primitive/PrimitiveString.class.php (rev 0)
+++ trunk/core/Form/Primitive/PrimitiveString.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,48 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2004-2005 by Konstantin V. Arkhipov, Sveta Smirnova *
+ * *
+ * 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 Primitives
+ **/
+ class PrimitiveString extends FiltrablePrimitive
+ {
+ private $pattern = null;
+
+ // hint: /^[^@]*\w+@[\w|\.|\-]+\.\w{2,6}$/
+ public function setAllowedPattern($pattern)
+ {
+ $this->pattern = $pattern;
+
+ return $this;
+ }
+
+ public function import(&$scope)
+ {
+ if (!BasePrimitive::import($scope))
+ return null;
+
+ if (is_string($scope[$this->name]) && !empty($scope[$this->name]) &&
+ !($this->max && mb_strlen($scope[$this->name]) > $this->max) &&
+ !($this->min && mb_strlen($scope[$this->name]) < $this->min) &&
+ (!$this->pattern || preg_match($this->pattern, $scope[$this->name]))
+ ) {
+ $this->value = (string) $scope[$this->name];
+
+ $this->selfFilter();
+
+ return true;
+ }
+
+ return false;
+ }
+ }
+?>
Copied: trunk/core/Form/Primitive/RangedPrimitive.class.php (from rev 1776, trunk/core/Form/RangedPrimitive.class.php)
===================================================================
--- trunk/core/Form/Primitive/RangedPrimitive.class.php (rev 0)
+++ trunk/core/Form/Primitive/RangedPrimitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,45 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2004-2005 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 Primitives
+ **/
+ abstract class RangedPrimitive extends BasePrimitive
+ {
+ protected $min = null;
+ protected $max = null;
+
+ public function getMin()
+ {
+ return $this->min;
+ }
+
+ public function setMin($min)
+ {
+ $this->min = $min;
+
+ return $this;
+ }
+
+ public function getMax()
+ {
+ return $this->max;
+ }
+
+ public function setMax($max)
+ {
+ $this->max = $max;
+
+ return $this;
+ }
+ }
+?>
\ No newline at end of file
Copied: trunk/core/Form/Primitive/TimeList.class.php (from rev 1776, trunk/core/Form/TimeList.class.php)
===================================================================
--- trunk/core/Form/Primitive/TimeList.class.php (rev 0)
+++ trunk/core/Form/Primitive/TimeList.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -0,0 +1,66 @@
+<?php
+/***************************************************************************
+ * Copyright (C) 2005-2006 by Konstantin V. Arkhipov, Igor V. Gulyaev *
+ * *
+ * 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 Primitives
+ **/
+ class TimeList extends BasePrimitive
+ {
+ public function import(&$scope)
+ {
+ if (
+ !isset($scope[$this->name])
+ || !is_array($scope[$this->name])
+ || empty($scope[$this->name])
+ )
+ return null;
+
+ $array = $scope[$this->name];
+ $list = array();
+
+ foreach ($array as $string)
+ if (array() !== self::stringToTimeList($string))
+ $list[] = self::stringToTimeList($string);
+
+ $this->value = $list;
+
+ return ($this->value !== array());
+ }
+
+ public function getActualValue()
+ {
+ if (is_array($this->value) && $this->value[0])
+ return $this->value;
+ elseif (is_array($this->raw) && $this->raw[0])
+ return $this->raw;
+
+ return array($this->default);
+ }
+
+ public static function stringToTimeList($string)
+ {
+ $list = array();
+
+ $times = split("([,; \n]+)", $string);
+
+ for ($i = 0, $size = count($times); $i < $size; ++$i) {
+ $time = mb_ereg_replace('[^0-9:]', ':', $times[$i]);
+
+ try {
+ $list[] = Time::create($time);
+ } catch (WrongArgumentException $e) {/* ignore */}
+ }
+
+ return $list;
+ }
+ }
+?>
\ No newline at end of file
Deleted: trunk/core/Form/Primitive.class.php
===================================================================
--- trunk/core/Form/Primitive.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/Primitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,90 +0,0 @@
-<?php
-/****************************************************************************
- * Copyright (C) 2004-2006 by Konstantin V. Arkhipov, Anton E. Lebedevich *
- * *
- * 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$ */
-
- /**
- * Factory for various Primitives.
- *
- * @ingroup Primitives
- **/
- final class Primitive extends StaticFactory
- {
- public static function spawn($primitive, $name)
- {
- return new $primitive($name);
- }
-
- public static function integer($name)
- {
- return new PrimitiveInteger($name);
- }
-
- public static function identifier($name)
- {
- return new PrimitiveIdentifier($name);
- }
-
- public static function enumeration($name)
- {
- return new PrimitiveEnumeration($name);
- }
-
- public static function date($name)
- {
- return new PrimitiveDate($name);
- }
-
- public static function string($name)
- {
- return new PrimitiveString($name);
- }
-
- public static function range($name)
- {
- return new PrimitiveRange($name);
- }
-
- public static function choice($name)
- {
- return new PrimitiveList($name);
- }
-
- public static function set($name)
- {
- return new PrimitiveArray($name);
- }
-
- public static function multiChoice($name)
- {
- return new PrimitiveMultiList($name);
- }
-
- public static function boolean($name)
- {
- return new PrimitiveBoolean($name);
- }
-
- public static function file($name)
- {
- return new PrimitiveFile($name);
- }
-
- public static function image($name)
- {
- return new PrimitiveImage($name);
- }
-
- public static function exploded($name)
- {
- return new ExplodedPrimitive($name);
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/PrimitiveArray.class.php
===================================================================
--- trunk/core/Form/PrimitiveArray.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/PrimitiveArray.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,35 +0,0 @@
-<?php
-/****************************************************************************
- * Copyright (C) 2004-2006 by Konstantin V. Arkhipov, Anton E. Lebedevich *
- * *
- * 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 Primitives
- **/
- class PrimitiveArray extends RangedPrimitive
- {
- public function import(&$scope)
- {
- if (!BasePrimitive::import($scope))
- return null;
-
- if (is_array($scope[$this->name]) &&
- !($this->min && count($scope[$this->name]) < $this->min) &&
- !($this->min && count($scope[$this->name]) > $this->max))
- {
- $this->value = $scope[$this->name];
-
- return true;
- }
-
- return false;
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/PrimitiveBoolean.class.php
===================================================================
--- trunk/core/Form/PrimitiveBoolean.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/PrimitiveBoolean.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,28 +0,0 @@
-<?php
-/****************************************************************************
- * Copyright (C) 2004-2006 by Konstantin V. Arkhipov, Anton E. Lebedevich *
- * *
- * 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 Primitives
- **/
- class PrimitiveBoolean extends BasePrimitive
- {
- public function import(&$scope) // to be compatible with BasePrimitive
- {
- if (isset($scope[$this->name]))
- $this->value = true;
- else
- $this->value = false;
-
- return true;
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/PrimitiveDate.class.php
===================================================================
--- trunk/core/Form/PrimitiveDate.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/PrimitiveDate.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,152 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2004-2005 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 Primitives
- **/
- class PrimitiveDate extends ComplexPrimitive
- {
- const DAY = 'day';
- const MONTH = 'month';
- const YEAR = 'year';
-
- const HOURS = 'hrs';
- const MINUTES = 'min';
- const SECONDS = 'sec';
-
- // typeHinting commented out due to stupid E_STRICT
- public function setValue(/* Timestamp */ $stamp)
- {
- Assert::isTrue($stamp instanceof Timestamp);
-
- $this->value = $stamp;
-
- return $this;
- }
-
- public function setMin(/* Timestamp */ $stamp)
- {
- Assert::isTrue($stamp instanceof Timestamp);
-
- $this->min = $stamp;
-
- return $this;
- }
-
- public function setMax(/* Timestamp */ $stamp)
- {
- Assert::isTrue($stamp instanceof Timestamp);
-
- $this->max = $stamp;
-
- return $this;
- }
-
- public function setDefault(/* Timestamp */ $stamp)
- {
- Assert::isTrue($stamp instanceof Timestamp);
-
- $this->default = $stamp;
-
- return $this;
- }
-
- public function importSingle(&$scope)
- {
- if (isset($scope[$this->name]) &&
- is_string($scope[$this->name]) &&
- $time = strtotime($scope[$this->name])
- ) {
- $tstamp = new Timestamp($time);
- if (!($this->min && $this->min->toStamp() > $tstamp->toStamp())
- && !($this->max && $this->max->toStamp() < $tstamp->toStamp())
- ) {
- $this->value = $tstamp;
- return true;
- }
- }
-
- return false;
- }
-
- public function isEmpty(&$scope)
- {
- if ($this->getState()->isFalse()) {
- return
- empty($scope[$this->name][self::DAY]) ||
- empty($scope[$this->name][self::MONTH]) ||
- empty($scope[$this->name][self::YEAR]);
- } else
- return empty($scope[$this->name]);
- }
-
- public function importMarried(&$scope)
- {
- if (
- isset(
- $scope[$this->name][self::DAY],
- $scope[$this->name][self::MONTH],
- $scope[$this->name][self::YEAR]
- )
- && is_array($scope[$this->name])
- && !empty($scope[$this->name][self::DAY])
- && !empty($scope[$this->name][self::MONTH])
- && !empty($scope[$this->name][self::YEAR])
- ) {
- $hours = $minutes = $seconds = 0;
-
- if (isset($scope[$this->name][self::HOURS]))
- $hours = (int) $scope[$this->name][self::HOURS];
-
- if (isset($scope[$this->name][self::MINUTES]))
- $minutes = (int) $scope[$this->name][self::MINUTES];
-
- if (isset($scope[$this->name][self::SECONDS]))
- $seconds = (int) $scope[$this->name][self::SECONDS];
-
- try {
- $stamp = mktime(
- $hours, $minutes, $seconds,
- (int) $scope[$this->name][self::MONTH],
- (int) $scope[$this->name][self::DAY],
- (int) $scope[$this->name][self::YEAR]
- );
- } catch (BaseException $e) {
- // fsck wrong stamps
- return false;
- }
-
- if (!($this->min && $this->min->toStamp() < $stamp) &&
- !($this->max && $this->max->toStamp() > $stamp)
- ) {
- try {
- $this->value = new Timestamp($stamp);
-
- return true;
- } catch (WrongArgumentException $e) {
- return false;
- }
- }
- }
-
- return false;
- }
-
- public function import(&$scope)
- {
- if ($this->isEmpty($scope))
- return null;
-
- return parent::import($scope);
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/PrimitiveDumper.class.php
===================================================================
--- trunk/core/Form/PrimitiveDumper.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/PrimitiveDumper.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,76 +0,0 @@
-<?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$ */
-
- /**
- * Dumps primitives to desired HTML control.
- *
- * @ingroup Primitives
- **/
- final class PrimitiveDumper extends StaticFactory
- {
- private static $class = null;
-
- public static function text(BasePrimitive $prm)
- {
- $class = self::$class;
-
- return <<<EOT
-<input type="text" name="{$prm->getName()}" class="{$class}" value="{$prm->getActualValue()}">
-EOT;
- }
-
- public static function password(BasePrimitive $prm)
- {
- $class = self::$class;
-
- return <<<EOT
-<intput type="password" name="{$prm->getName()}" class="{$class}" value="{$prm->getActualValue()}">
-EOT;
- }
-
- /**
- * @param $prm target primitive
- * @param $list array of identifiable stringable objects
- **/
- public static function select(BasePrimitive $prm, $list)
- {
- $value = $prm->getActualValue();
-
- $out = '<select name="'.$prm->getName().'" class="'.self::$class.'">';
-
- foreach ($list as $object) {
- $id = $object->getId();
-
- $out .=
- '<option value="'.$id.'"'
- .($value == $id ? ' selected' : null).'>'
- .$object->toString().'</option>';
- }
-
- return $out.'</select>';
- }
-
- public static function textarea(BasePrimitive $prm)
- {
- $class = self::$class;
-
- return <<<EOT
-<textarea name="{$prm->getName()}" class="{$class}">{$prm->getActualValue()}</textarea>
-EOT;
- }
-
- public static function setClass($class)
- {
- self::$class = $class;
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/PrimitiveEnumeration.class.php
===================================================================
--- trunk/core/Form/PrimitiveEnumeration.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/PrimitiveEnumeration.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,74 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2006 by Ivan Y. Khvostishkov, 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 Primitives
- **/
- final class PrimitiveEnumeration
- extends IdentifiablePrimitive
- implements ListedPrimitive
- {
- public function getList()
- {
- if ($this->value)
- return $this->value->getObjectList();
- elseif ($this->default)
- return $this->default->getObjectList();
- else {
- return new $this->className(
- call_user_func(array($this->className, 'getAnyId'))
- );
- }
-
- /* NOTREACHED */
- }
-
- public function of($className)
- {
- Assert::isTrue(
- class_exists($className, true),
- "knows nothing about '{$className}' class"
- );
-
- Assert::isTrue(
- is_subclass_of($className, 'Enumeration'),
- "non-enumeration child given"
- );
-
- $this->className = $className;
-
- return $this;
- }
-
- public function import(&$scope)
- {
- if (!$this->className)
- throw new WrongStateException(
- "no class defined for PrimitiveEnumeration '{$this->name}'"
- );
-
- $result = parent::import($scope);
-
- if ($result === true) {
- try {
- $this->value = new $this->className($this->value);
- } catch (MissingElementException $e) {
- return false;
- }
-
- return true;
- }
-
- return $result;
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/PrimitiveFile.class.php
===================================================================
--- trunk/core/Form/PrimitiveFile.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/PrimitiveFile.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,117 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2004-2005 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$ */
-
- /**
- * File uploads helper.
- *
- * @ingroup Primitives
- **/
- class PrimitiveFile extends RangedPrimitive
- {
- private $originalName = null;
- private $mimeType = null;
-
- private $allowedMimeTypes = array();
-
- public function getOriginalName()
- {
- return $this->originalName;
- }
-
- public function getMimeType()
- {
- return $this->mimeType;
- }
-
- public function setAllowedMimeTypes($mimes)
- {
- Assert::isArray($mimes);
-
- $this->allowedMimeTypes = $mimes;
-
- return $this;
- }
-
- public function addAllowedMimeType($mime)
- {
- Assert::isString($mime);
-
- $this->allowedMimeTypes[] = $mime;
-
- return $this;
- }
-
- public function getAllowedMimeTypes()
- {
- return $this->allowedMimeType;
- }
-
- public function isAllowedMimeType()
- {
- if (count($this->allowedMimeTypes) > 0) {
- return in_array($this->mimeType, $this->allowedMimeTypes);
- } else
- return true;
- }
-
- public function copyTo($path, $name)
- {
- if (is_readable($this->value) && is_writable($path)) {
- return move_uploaded_file($this->value, $path.$name);
- } else
- throw new WrongArgumentException(
- "can not move '{$this->value}' to '{($path"."$name)}'"
- );
- }
-
- public function import(&$scope)
- {
- if (
- !BasePrimitive::import($scope)
- || !is_array($scope[$this->name])
- || (
- isset($scope[$this->name], $scope[$this->name]['error'])
- && $scope[$this->name]['error'] == UPLOAD_ERR_NO_FILE
- )
- )
- return null;
-
- if (isset($scope[$this->name]['tmp_name']))
- $file = $scope[$this->name]['tmp_name'];
- else
- return false;
-
- if (is_readable($file) && is_uploaded_file($file))
- $size = filesize($file);
- else
- return false;
-
- $this->mimeType = $scope[$this->name]['type'];
-
- if (!$this->isAllowedMimeType())
- return false;
-
- if (
- isset($scope[$this->name])
- && !($this->max && ($size > $this->max))
- && !($this->min && ($size < $this->min))
- ) {
- $this->value = $scope[$this->name]['tmp_name'];
- $this->originalName = $scope[$this->name]['name'];
-
- return true;
- }
-
- return false;
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/PrimitiveIdentifier.class.php
===================================================================
--- trunk/core/Form/PrimitiveIdentifier.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/PrimitiveIdentifier.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,65 +0,0 @@
-<?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 Primitives
- **/
- final class PrimitiveIdentifier extends IdentifiablePrimitive
- {
- public function of($className)
- {
- Assert::isTrue(
- class_exists($className, true),
- "knows nothing about '{$className}' class"
- );
-
- $class = new ReflectionClass($className);
-
- Assert::isTrue(
- $class->implementsInterface('DAOConnected'),
- "class '{$class->getName()}' should implement DAOConnected interface"
- );
-
- $this->className = $className;
-
- return $this;
- }
-
- public function dao()
- {
- return call_user_func(array($this->className, 'dao'));
- }
-
- public function import(&$scope)
- {
- if (!$this->className)
- throw new WrongStateException(
- "no class defined for PrimitiveIdentifier '{$this->name}'"
- );
-
- $result = parent::import($scope);
-
- if ($result === true) {
- try {
- $this->value = $this->dao()->getById($this->value);
- } catch (ObjectNotFoundException $e) {
- $this->value = null;
- return false;
- }
-
- return true;
- }
-
- return $result;
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/PrimitiveImage.class.php
===================================================================
--- trunk/core/Form/PrimitiveImage.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/PrimitiveImage.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,103 +0,0 @@
-<?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$ */
-
- /**
- * Image uploads helper.
- *
- * @ingroup Primitives
- **/
- class PrimitiveImage extends PrimitiveFile
- {
- private $width = null;
- private $height = null;
-
- private $maxWidth = null;
- private $minWidth = null;
-
- private $maxHeight = null;
- private $minHeight = null;
-
- private $type = null;
-
- public function getWidth()
- {
- return $this->width;
- }
-
- public function getHeight()
- {
- return $this->height;
- }
-
- public function getType()
- {
- return $this->type;
- }
-
- public function setMaxWidth($max)
- {
- $this->maxWidth = $max;
-
- return $this;
- }
-
- public function setMinWidth($min)
- {
- $this->minWidth = $min;
-
- return $this;
- }
-
- public function setMaxHeight($max)
- {
- $this->maxHeight = $max;
-
- return $this;
- }
-
- public function setMinHeight($min)
- {
- $this->minHeight = $min;
-
- return $this;
- }
-
- public function import(&$scope)
- {
- if ($result = parent::import($scope)) {
-
- try {
- list($width, $height, $type) = getimagesize($this->value);
- } catch (BaseException $e) {
- $this->value = null;
- return false;
- }
-
- if (
- !($this->maxWidth && ($width > $this->maxWidth))
- && !($this->minWidth && ($width < $this->minWidth))
- && !($this->maxHeight && ($height > $this->maxHeight))
- && !($this->minHeight && ($height < $this->minHeight))
- )
- {
- $this->type = new ImageType($type);
- $this->width = $width;
- $this->height = $height;
-
- return true;
- }
- }
-
- return $result;
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/PrimitiveInteger.class.php
===================================================================
--- trunk/core/Form/PrimitiveInteger.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/PrimitiveInteger.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,43 +0,0 @@
-<?php
-/****************************************************************************
- * Copyright (C) 2004-2005 by Konstantin V. Arkhipov, Anton E. Lebedevich *
- * *
- * 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 Primitives
- **/
- class PrimitiveInteger extends FiltrablePrimitive
- {
- public function import(&$scope)
- {
- if (!BasePrimitive::import($scope))
- return null;
-
- try {
- Assert::isInteger($scope[$this->name]);
- } catch (WrongArgumentException $e) {
- return false;
- }
-
- if (
- !(null !== $this->min && $scope[$this->name] < $this->min) &&
- !(null !== $this->max && $scope[$this->name] > $this->max)
- ) {
- $this->value = (int) $scope[$this->name];
-
- $this->selfFilter();
-
- return true;
- }
-
- return false;
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/PrimitiveList.class.php
===================================================================
--- trunk/core/Form/PrimitiveList.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/PrimitiveList.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,54 +0,0 @@
-<?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$ */
-
- /**
- * @ingroup Primitives
- **/
- class PrimitiveList extends BasePrimitive implements ListedPrimitive
- {
- protected $list = array();
-
- public function getList()
- {
- return $this->list;
- }
-
- public function setList($list)
- {
- $this->list = $list;
-
- return $this;
- }
-
- public function import(&$scope)
- {
- if (!parent::import($scope)) {
- return null;
- }
-
- if (
- (
- is_string($scope[$this->name])
- || is_integer($scope[$this->name])
- )
- && isset($this->list[$scope[$this->name]])
- ) {
- $this->value = $scope[$this->name];
-
- return true;
- } else
- return false;
-
- /* NOTREACHED */
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/PrimitiveMultiList.class.php
===================================================================
--- trunk/core/Form/PrimitiveMultiList.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/PrimitiveMultiList.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,51 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2004-2005 by Anton E. Lebedevich *
- * *
- * 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 Primitives
- **/
- class PrimitiveMultiList extends PrimitiveList
- {
- public function import(&$scope)
- {
- if (!BasePrimitive::import($scope))
- return null;
-
- if ($this->list) {
- if (is_array($scope[$this->name])) {
- $values = array();
-
- foreach ($scope[$this->name] as $value)
- if (isset($this->list[$value]))
- $values[] = $value;
-
- if (count($values))
- $this->value = $values;
- else
- return false;
-
- } else {
- if (isset($this->list[$scope[$this->name]]))
- $this->value = $scope[$this->name];
- else
- return false;
- }
- } else {
- $this->value = $scope[$this->name];
-
- return true;
- }
-
- /* NOTREACHED */
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/PrimitiveRange.class.php
===================================================================
--- trunk/core/Form/PrimitiveRange.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/PrimitiveRange.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,134 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2004-2005 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 Primitives
- **/
- class PrimitiveRange extends ComplexPrimitive
- {
- const MIN = 'min';
- const MAX = 'max';
-
- private $swapAllowed = true;
-
- public function setSwapAllowed()
- {
- $this->swapAllowed = true;
-
- return $this;
- }
-
- public function setSwapDisallowed()
- {
- $this->swapAllowed = false;
-
- return $this;
- }
-
- // to be E_STRICT compatible
- public function setValue(/* Range */ $range)
- {
- Assert::isTrue(
- $range instanceof Range,
- 'only ranges accepted today'
- );
-
- $this->value = $range;
-
- return $this;
- }
-
- public function importSingle(&$scope)
- {
- if (!BasePrimitive::import($scope) || is_array($scope[$this->name]))
- return null;
-
- if (isset($scope[$this->name]) && is_string($scope[$this->name])) {
- $arr = explode('-', $scope[$this->name], 2);
-
- $range =
- Range::buildObject(
- ArrayUtils::getArrayVar($arr, 0),
- ArrayUtils::getArrayVar($arr, 1),
- $this->swapAllowed
- );
-
- if ($range &&
- !(
- ($this->min && $range->getMin()) &&
- $range->getMin() < $this->min
- ) &&
- !(
- ($this->max && $range->getMax()) &&
- $range->getMax() > $this->max
- )
- ) {
- $this->value = $range;
-
- return true;
- }
- }
-
- return false;
- }
-
- public function importMarried(&$scope) // ;-)
- {
- $name = &$this->name;
-
- if (
- ($this->safeGet($scope, $name, self::MIN) === null) &&
- ($this->safeGet($scope, $name, self::MAX) === null)
- )
- return null;
-
- $range =
- Range::buildObject(
- $this->safeGet($scope, $name, self::MIN),
- $this->safeGet($scope, $name, self::MAX),
- $this->swapAllowed
- );
-
- if ($range &&
- !(
- ($this->min && $range->getMin()) &&
- $range->getMin() < $this->min
- ) &&
- !(
- ($this->max && $range->getMax()) &&
- $range->getMax() > $this->max
- )
- ) {
- $this->value = $range;
-
- return true;
- }
-
- return false;
- }
-
- private function safeGet(&$scope, $firstDimension, $secondDimension)
- {
- if (isset($scope[$firstDimension]) && is_array($scope[$firstDimension])) {
- if (
- isset($scope[$firstDimension][$secondDimension])
- && is_array($scope[$firstDimension])
- && !empty($scope[$firstDimension][$secondDimension])
- ) {
- return $scope[$firstDimension][$secondDimension];
- }
- }
-
- return null;
- }
- }
-?>
Deleted: trunk/core/Form/PrimitiveString.class.php
===================================================================
--- trunk/core/Form/PrimitiveString.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/PrimitiveString.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,48 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2004-2005 by Konstantin V. Arkhipov, Sveta Smirnova *
- * *
- * 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 Primitives
- **/
- class PrimitiveString extends FiltrablePrimitive
- {
- private $pattern = null;
-
- // hint: /^[^@]*\w+@[\w|\.|\-]+\.\w{2,6}$/
- public function setAllowedPattern($pattern)
- {
- $this->pattern = $pattern;
-
- return $this;
- }
-
- public function import(&$scope)
- {
- if (!BasePrimitive::import($scope))
- return null;
-
- if (is_string($scope[$this->name]) && !empty($scope[$this->name]) &&
- !($this->max && mb_strlen($scope[$this->name]) > $this->max) &&
- !($this->min && mb_strlen($scope[$this->name]) < $this->min) &&
- (!$this->pattern || preg_match($this->pattern, $scope[$this->name]))
- ) {
- $this->value = (string) $scope[$this->name];
-
- $this->selfFilter();
-
- return true;
- }
-
- return false;
- }
- }
-?>
Deleted: trunk/core/Form/RangedPrimitive.class.php
===================================================================
--- trunk/core/Form/RangedPrimitive.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/RangedPrimitive.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,45 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2004-2005 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 Primitives
- **/
- abstract class RangedPrimitive extends BasePrimitive
- {
- protected $min = null;
- protected $max = null;
-
- public function getMin()
- {
- return $this->min;
- }
-
- public function setMin($min)
- {
- $this->min = $min;
-
- return $this;
- }
-
- public function getMax()
- {
- return $this->max;
- }
-
- public function setMax($max)
- {
- $this->max = $max;
-
- return $this;
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/RemoveSymbolsFilter.class.php
===================================================================
--- trunk/core/Form/RemoveSymbolsFilter.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/RemoveSymbolsFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,44 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2005 by Sveta Smirnova *
- * *
- * 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$ */
-
- class RemoveSymbolsFilter implements Filtrator
- {
- private $symbols = array();
-
- public static function create()
- {
- return new RemoveSymbolsFilter();
- }
-
- public function setSymbols(/* ... */)
- {
- $this->symbols = func_get_args();
-
- return $this;
- }
-
- public function getSymbols()
- {
- return $this->symbols;
- }
-
- public function apply($value)
- {
- return
- str_replace(
- $this->symbols,
- null,
- $value
- );
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/StringReplaceFilter.class.php
===================================================================
--- trunk/core/Form/StringReplaceFilter.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/StringReplaceFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,84 +0,0 @@
-<?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 Filters
- **/
- final class StringReplaceFilter implements Filtrator
- {
- private $search = null;
- private $replace = null;
-
- private $count = null;
-
- public static function create($search = null, $replace = null)
- {
- return new self($search, $replace);
- }
-
- public function __construct($search = null, $replace = null)
- {
- $this->search = $search;
- $this->replace = $replace;
- }
-
- public function setSearch($search)
- {
- $this->search = $search;
-
- return $this;
- }
-
- public function getSearch()
- {
- return $this->search;
- }
-
- public function setReplace($replace)
- {
- $this->replace = $replace;
-
- return $this;
- }
-
- public function getReplace()
- {
- return $this->replace;
- }
-
- public function getCount()
- {
- return $this->count;
- }
-
- public function apply($value)
- {
- if(
- $this->search === $this->replace
- || (
- $this->search === null
- && $this->replace === null
- )
- ) {
- return $value;
- }
-
- return
- str_replace(
- $this->search,
- $this->replace,
- $value,
- $this->count
- );
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/StripTagsFilter.class.php
===================================================================
--- trunk/core/Form/StripTagsFilter.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/StripTagsFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,42 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2005 by Anton E. Lebedevich *
- * *
- * 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 RegulatedPrimitive::addImportFilter()
- *
- * @ingroup Filters
- **/
- class StripTagsFilter implements Filtrator
- {
- private $exclude = null;
-
- public static function create()
- {
- return new self;
- }
-
- public function setAllowableTags($exclude)
- {
- if (null !== $exclude)
- Assert::isString($exclude);
-
- $this->exclude = $exclude;
-
- return $this;
- }
-
- public function apply($value)
- {
- return strip_tags($value, $this->exclude);
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/TimeList.class.php
===================================================================
--- trunk/core/Form/TimeList.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/TimeList.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,66 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2005-2006 by Konstantin V. Arkhipov, Igor V. Gulyaev *
- * *
- * 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 Primitives
- **/
- class TimeList extends BasePrimitive
- {
- public function import(&$scope)
- {
- if (
- !isset($scope[$this->name])
- || !is_array($scope[$this->name])
- || empty($scope[$this->name])
- )
- return null;
-
- $array = $scope[$this->name];
- $list = array();
-
- foreach ($array as $string)
- if (array() !== self::stringToTimeList($string))
- $list[] = self::stringToTimeList($string);
-
- $this->value = $list;
-
- return ($this->value !== array());
- }
-
- public function getActualValue()
- {
- if (is_array($this->value) && $this->value[0])
- return $this->value;
- elseif (is_array($this->raw) && $this->raw[0])
- return $this->raw;
-
- return array($this->default);
- }
-
- public static function stringToTimeList($string)
- {
- $list = array();
-
- $times = split("([,; \n]+)", $string);
-
- for ($i = 0, $size = count($times); $i < $size; ++$i) {
- $time = mb_ereg_replace('[^0-9:]', ':', $times[$i]);
-
- try {
- $list[] = Time::create($time);
- } catch (WrongArgumentException $e) {/* ignore */}
- }
-
- return $list;
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/TrimFilter.class.php
===================================================================
--- trunk/core/Form/TrimFilter.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/TrimFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,23 +0,0 @@
-<?php
-/***************************************************************************
- * Copyright (C) 2005 by Anton E. Lebedevich *
- * *
- * 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 Filters
- **/
- class TrimFilter extends BaseFilter
- {
- public function apply($value)
- {
- return trim($value);
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/UrlDecodeFilter.class.php
===================================================================
--- trunk/core/Form/UrlDecodeFilter.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/UrlDecodeFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,23 +0,0 @@
-<?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 Filters
- **/
- final class UrlDecodeFilter extends BaseFilter
- {
- public function apply($value)
- {
- return urldecode($value);
- }
- }
-?>
\ No newline at end of file
Deleted: trunk/core/Form/UrlEncodeFilter.class.php
===================================================================
--- trunk/core/Form/UrlEncodeFilter.class.php 2006-06-25 17:17:03 UTC (rev 1781)
+++ trunk/core/Form/UrlEncodeFilter.class.php 2006-06-25 17:26:10 UTC (rev 1782)
@@ -1,23 +0,0 @@
-<?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 Filters
- **/
- final class UrlEncodeFilter extends BaseFilter
- {
- public function apply($value)
- {
- return urlencode($value);
- }
- }
-?>
\ No newline at end of file
Received on Sun Jun 25 2006 - 21:26:12 MSD
This archive was generated by hypermail 2.2.0 : Sat Oct 27 2007 - 20:14:37 MSD