Overview

Namespaces

  • Nethgui
    • Adapter
    • Authorization
    • Component
    • Controller
      • Collection
      • Table
    • Exception
    • Log
    • Model
    • Module
      • Help
      • Notification
    • Renderer
    • Serializer
    • System
    • Test
      • Tool
      • Unit
        • Nethgui
          • Adapter
            • ParameterSet
          • Authorization
          • Log
          • Module
            • Notification
          • Renderer
          • Serializer
          • System
          • Utility
          • View
        • Test
          • Tool
    • Utility
    • View
    • Widget
      • Xhtml
  • None
  • Test
    • Tool

Classes

  • Nethgui\Adapter\ArrayAdapter
  • Nethgui\Adapter\LazyLoaderAdapter
  • Nethgui\Adapter\MultipleAdapter
  • Nethgui\Adapter\RecordAdapter
  • Nethgui\Adapter\RecordKeyAdapter
  • Nethgui\Adapter\ScalarAdapter
  • Nethgui\Adapter\TableAdapter
  • Nethgui\Adapter\TabularValueAdapter
  • Nethgui\Authorization\AuthorizedModuleSet
  • Nethgui\Authorization\JsonPolicyDecisionPoint
  • Nethgui\Authorization\LazyAccessControlResponse
  • Nethgui\Authorization\PolicyRule
  • Nethgui\Authorization\User
  • Nethgui\Controller\AbstractController
  • Nethgui\Controller\Collection\AbstractAction
  • Nethgui\Controller\CollectionController
  • Nethgui\Controller\CompositeController
  • Nethgui\Controller\ListComposite
  • Nethgui\Controller\NullRequest
  • Nethgui\Controller\RequestTest
  • Nethgui\Controller\Table\AbstractAction
  • Nethgui\Controller\Table\Help
  • Nethgui\Controller\Table\Modify
  • Nethgui\Controller\Table\PluggableAction
  • Nethgui\Controller\Table\PluginCollector
  • Nethgui\Controller\Table\Read
  • Nethgui\Controller\Table\RowAbstractAction
  • Nethgui\Controller\Table\RowPluginAction
  • Nethgui\Controller\TableController
  • Nethgui\Controller\TabsController
  • Nethgui\Framework
  • Nethgui\Log\AbstractLog
  • Nethgui\Log\Nullog
  • Nethgui\Log\Syslog
  • Nethgui\Model\StaticFiles
  • Nethgui\Model\SystemTasks
  • Nethgui\Model\UserNotifications
  • Nethgui\Model\ValidationErrors
  • Nethgui\Module\AbstractModule
  • Nethgui\Module\Composite
  • Nethgui\Module\CompositeModuleAttributesProvider
  • Nethgui\Module\Help
  • Nethgui\Module\Help\Common
  • Nethgui\Module\Help\Read
  • Nethgui\Module\Help\Renderer
  • Nethgui\Module\Help\Show
  • Nethgui\Module\Help\Template
  • Nethgui\Module\Help\Widget
  • Nethgui\Module\Language
  • Nethgui\Module\Login
  • Nethgui\Module\Logout
  • Nethgui\Module\Main
  • Nethgui\Module\Menu
  • Nethgui\Module\ModuleLoader
  • Nethgui\Module\Notification
  • Nethgui\Module\Notification\AbstractNotification
  • Nethgui\Module\Resource
  • Nethgui\Module\SimpleModuleAttributesProvider
  • Nethgui\Module\SystemModuleAttributesProvider
  • Nethgui\Module\Tracker
  • Nethgui\Renderer\AbstractRenderer
  • Nethgui\Renderer\Json
  • Nethgui\Renderer\ReadonlyView
  • Nethgui\Renderer\TemplateRenderer
  • Nethgui\Renderer\Xhtml
  • Nethgui\Serializer\ArrayAccessSerializer
  • Nethgui\Serializer\KeySerializer
  • Nethgui\Serializer\PropSerializer
  • Nethgui\System\AlwaysFailValidator
  • Nethgui\System\CallbackValidator
  • Nethgui\System\NethPlatform
  • Nethgui\System\Process
  • Nethgui\System\SessionDatabase
  • Nethgui\System\Validator
  • Nethgui\Test\Tool\DB
  • Nethgui\Test\Tool\MockFactory
  • Nethgui\Test\Tool\MockObject
  • Nethgui\Test\Tool\MockState
  • Nethgui\Test\Tool\PermissivePolicyDecisionPoint
  • Nethgui\Test\Tool\StaticPolicyDecisionPoint
  • Nethgui\Test\Unit\Nethgui\Adapter\ArrayAdapterTest
  • Nethgui\Test\Unit\Nethgui\Adapter\MultipleAdapterTest
  • Nethgui\Test\Unit\Nethgui\Adapter\ParameterSet\EmptyTest
  • Nethgui\Test\Unit\Nethgui\Adapter\ParameterSet\WithAdaptersTest
  • Nethgui\Test\Unit\Nethgui\Adapter\RecordAdapterTest
  • Nethgui\Test\Unit\Nethgui\Adapter\RecordAdapterTester
  • Nethgui\Test\Unit\Nethgui\Adapter\RecordKeyAdapterTest
  • Nethgui\Test\Unit\Nethgui\Adapter\ScalarAdapterTest
  • Nethgui\Test\Unit\Nethgui\Adapter\TableAdapter1Test
  • Nethgui\Test\Unit\Nethgui\Adapter\TableAdapter2Test
  • Nethgui\Test\Unit\Nethgui\Adapter\TabularValueAdapterDegradedTest
  • Nethgui\Test\Unit\Nethgui\Adapter\TabularValueAdapterTest
  • Nethgui\Test\Unit\Nethgui\Authorization\JsonPolicyDecisionPointTest
  • Nethgui\Test\Unit\Nethgui\Authorization\LazyAccessControlResponseTest
  • Nethgui\Test\Unit\Nethgui\Authorization\PolicyRuleTest
  • Nethgui\Test\Unit\Nethgui\Authorization\ResourceX
  • Nethgui\Test\Unit\Nethgui\Authorization\ResourceY
  • Nethgui\Test\Unit\Nethgui\Authorization\UserTest
  • Nethgui\Test\Unit\Nethgui\Log\AbstractLogTest
  • Nethgui\Test\Unit\Nethgui\Log\NullogTest
  • Nethgui\Test\Unit\Nethgui\Log\SyslogTest
  • Nethgui\Test\Unit\Nethgui\Module\AbstractControllerTest
  • Nethgui\Test\Unit\Nethgui\Module\CompositeTest
  • Nethgui\Test\Unit\Nethgui\Module\ConcreteCompositeModule1
  • Nethgui\Test\Unit\Nethgui\Module\ConcreteStandardModule1
  • Nethgui\Test\Unit\Nethgui\Module\ModuleLoaderTest
  • Nethgui\Test\Unit\Nethgui\Module\Notification\TextNotificationBoxTest
  • Nethgui\Test\Unit\Nethgui\Module\SimpleModuleAttributesProviderTest
  • Nethgui\Test\Unit\Nethgui\Renderer\HttpCommandReceiverTest
  • Nethgui\Test\Unit\Nethgui\Renderer\JsonTest
  • Nethgui\Test\Unit\Nethgui\Renderer\MarshallingReceiverTest
  • Nethgui\Test\Unit\Nethgui\Renderer\XhtmlTest
  • Nethgui\Test\Unit\Nethgui\Serializer\ArrayAccessSerializerTest
  • Nethgui\Test\Unit\Nethgui\Serializer\KeySerializerTest
  • Nethgui\Test\Unit\Nethgui\Serializer\PropSerializerTest
  • Nethgui\Test\Unit\Nethgui\System\EsmithDatabaseTest
  • Nethgui\Test\Unit\Nethgui\System\NethPlatformTest
  • Nethgui\Test\Unit\Nethgui\System\PhpWrapperExec
  • Nethgui\Test\Unit\Nethgui\System\SessionDatabaseTest
  • Nethgui\Test\Unit\Nethgui\System\TestSession
  • Nethgui\Test\Unit\Nethgui\System\ValidatorTest
  • Nethgui\Test\Unit\Nethgui\Utility\PamAuthenticatorTest
  • Nethgui\Test\Unit\Nethgui\View\CommandTest
  • Nethgui\Test\Unit\Nethgui\View\TranslatorTest
  • Nethgui\Test\Unit\Nethgui\View\TranslatorTestModule
  • Nethgui\Test\Unit\Nethgui\View\TranslatorTestPhpWrapper
  • Nethgui\Test\Unit\Nethgui\View\ViewCommandSequenceTest
  • Nethgui\Test\Unit\Nethgui\View\ViewGenericTest
  • Nethgui\Test\Unit\Test\Tool\MockStateTest
  • Nethgui\Utility\ArrayDisposable
  • Nethgui\Utility\HttpResponse
  • Nethgui\Utility\NullSession
  • Nethgui\Utility\PhpWrapper
  • Nethgui\View\LegacyCommandBag
  • Nethgui\View\Translator
  • Nethgui\View\View
  • Nethgui\Widget\AbstractWidget
  • Nethgui\Widget\Xhtml\Button
  • Nethgui\Widget\Xhtml\CheckBox
  • Nethgui\Widget\Xhtml\CollectionEditor
  • Nethgui\Widget\Xhtml\Columns
  • Nethgui\Widget\Xhtml\ElementList
  • Nethgui\Widget\Xhtml\ElementModule
  • Nethgui\Widget\Xhtml\ElementRenderer
  • Nethgui\Widget\Xhtml\Fieldset
  • Nethgui\Widget\Xhtml\FieldsetSwitch
  • Nethgui\Widget\Xhtml\FileUpload
  • Nethgui\Widget\Xhtml\Form
  • Nethgui\Widget\Xhtml\Hidden
  • Nethgui\Widget\Xhtml\ObjectPicker
  • Nethgui\Widget\Xhtml\ObjectsCollection
  • Nethgui\Widget\Xhtml\Panel
  • Nethgui\Widget\Xhtml\ProgressBar
  • Nethgui\Widget\Xhtml\RadioButton
  • Nethgui\Widget\Xhtml\Selector
  • Nethgui\Widget\Xhtml\Slider
  • Nethgui\Widget\Xhtml\Tabs
  • Nethgui\Widget\Xhtml\TextArea
  • Nethgui\Widget\Xhtml\TextInput
  • Nethgui\Widget\Xhtml\TextLabel
  • Nethgui\Widget\Xhtml\TextList
  • Nethgui\Widget\XhtmlWidget

Interfaces

  • Nethgui\Adapter\AdapterAggregateInterface
  • Nethgui\Adapter\AdapterAggregationInterface
  • Nethgui\Adapter\AdapterInterface
  • Nethgui\Adapter\ModifiableInterface
  • Nethgui\Authorization\AccessControlResponseInterface
  • Nethgui\Authorization\AuthorizationAttributesProviderInterface
  • Nethgui\Authorization\PolicyDecisionPointInterface
  • Nethgui\Authorization\PolicyEnforcementPointInterface
  • Nethgui\Authorization\UserInterface
  • Nethgui\Component\DependencyConsumer
  • Nethgui\Component\DependencyInjectorAggregate
  • Nethgui\Controller\Collection\ActionInterface
  • Nethgui\Controller\RequestHandlerInterface
  • Nethgui\Controller\RequestInterface
  • Nethgui\Controller\ValidationReportInterface
  • Nethgui\Log\LogConsumerInterface
  • Nethgui\Log\LogInterface
  • Nethgui\Module\ModuleAttributesInterface
  • Nethgui\Module\ModuleCompositeInterface
  • Nethgui\Module\ModuleInterface
  • Nethgui\Module\ModuleSetInterface
  • Nethgui\Renderer\WidgetFactoryInterface
  • Nethgui\Renderer\WidgetInterface
  • Nethgui\System\DatabaseInterface
  • Nethgui\System\MandatoryValidatorInterface
  • Nethgui\System\PlatformConsumerInterface
  • Nethgui\System\PlatformInterface
  • Nethgui\System\ProcessInterface
  • Nethgui\System\ValidatorInterface
  • Nethgui\Utility\DisposableInterface
  • Nethgui\Utility\PhpConsumerInterface
  • Nethgui\Utility\SessionConsumerInterface
  • Nethgui\Utility\SessionInterface
  • Nethgui\View\CommandReceiverInterface
  • Nethgui\View\TranslatorInterface
  • Nethgui\View\ViewableInterface
  • Nethgui\View\ViewInterface

Exceptions

  • Nethgui\Exception\AuthorizationException
  • Nethgui\Exception\HttpException

Functions

  • Nethgui\array_end
  • Nethgui\array_head
  • Nethgui\array_rest
  • Overview
  • Namespace
  • Class
  • Deprecated
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820: 821: 822: 823: 824: 825: 826: 827: 828: 829: 830: 831: 832: 833: 834: 835: 836: 837: 838: 839: 840: 841: 842: 843: 844: 845: 846: 847: 848: 849: 850: 851: 852: 853: 854: 855: 856: 857: 858: 859: 860: 861: 862: 863: 864: 865: 866: 867: 868: 869: 870: 871: 872: 873: 874: 875: 876: 877: 878: 879: 880: 881: 882: 883: 884: 885: 886: 887: 888: 889: 890: 891: 892: 893: 894: 895: 896: 897: 898: 899: 900: 901: 902: 903: 904: 905: 906: 907: 908: 909: 910: 911: 
<?php
namespace Nethgui\System;

/*
 * Copyright (C) 2011 Nethesis S.r.l.
 * 
 * This script is part of NethServer.
 * 
 * NethServer 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 3 of the License, or
 * (at your option) any later version.
 * 
 * NethServer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with NethServer.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * This interface will be merged into ValidatorInterface
 *
 * @api
 * @since 1.3
 * @deprecated
 * @author Davide Principi <davide.principi@nethesis.it>
 */
interface MandatoryValidatorInterface extends ValidatorInterface
{

    /**
     * Tell if an empty value is NOT allowed.
     *
     * @api
     * @return boolean FALSE if empty is allowed, TRUE otherwise.
     */
    public function isMandatory();
}

/**
 * Check a list of conditions that must be satisfied.
 *
 * @author Davide Principi <davide.principi@nethesis.it>
 */
class Validator implements \Nethgui\System\MandatoryValidatorInterface
{
    private $chain = array();
    private $failureInfo;

    /**
     *
     * @var PlatformInterface
     */
    private $platform;

    public function __construct(PlatformInterface $platform)
    {
        $this->platform = $platform;
    }

    /**
     *
     * @param \Nethgui\System\ValidatorInterface $v1
     * @param \Nethgui\System\ValidatorInterface $v2
     * @return \Nethgui\System\Validator
     */
    public function orValidator(\Nethgui\System\ValidatorInterface $v1, \Nethgui\System\ValidatorInterface $v2)
    {
        $this->chain[] = new OrValidator($v1, $v2);
        return $this;
    }

    /**
     * If the first and only argument is an array checks if current value is
     * in that array.
     *
     * Otherwise you can pass arbitrary arguments. It will be checked if the
     * current value matches any of them.
     *
     * @return  \Nethgui\System\Validator
     */
    public function memberOf()
    {
        $args = func_get_args();

        if (isset($args[0]) && is_array($args[0]) && count($args) == 1) {
            $set = $args[0];
        } else {
            $set = $args;
        }

        if (count($set) > 5) {
            $setToShow = array_slice($set, 0, 3);
            $setToShow[] = '... ';
            $setToShow = array_merge($setToShow, array_slice($set, -2, 2));
        } else {
            $setToShow = $set;
        }

        $messageTemplate = array('valid_memberOf', array(implode(', ', $setToShow)));

        return $this->addToChain(__FUNCTION__, $messageTemplate, $set);
    }

    /**
     * @see preg_match
     * @param string $e A PHP preg_match compatible regular expression
     * @param string $meaning The error message template
     * @return \Nethgui\System\Validator
     */
    public function regexp($e, $meaning='valid_regexp')
    {
        $messageTemplate = array($meaning, array($e));
        return $this->addToChain(__FUNCTION__, $messageTemplate, $e);
    }

    /**
     * Checks if current value is not empty
     * 
     * @see PHP empty
     * @return \Nethgui\System\Validator
     */
    public function notEmpty()
    {
        return $this->addToChain(__FUNCTION__);
    }

    /**
     * Checks if current value is empty
     * 
     * @see PHP empty
     * @return \Nethgui\System\Validator
     */
    public function isEmpty()
    {
        return $this->addToChain(__FUNCTION__);
    }

    /**
     * Force the evaluation result
     * @param bool exit status
     * @return \Nethgui\System\Validator
     */
    public function forceResult($result)
    {
        $this->chain[] = ($result === TRUE);
        return $this;
    }

    /**
     * Check if the given value is a valid IPv4 address
     * @return \Nethgui\System\Validator
     */
    public function ipV4Address()
    {
        return $this->addToChain(__FUNCTION__);
    }

    /**
     * Check if the given value is a valid host name
     * @param int $minDots Default 0
     * @param int $maxDots Default PHP_INT_MAX
     * @return \Nethgui\System\Validator
     */
    public function hostname($minDots = 0, $maxDots = PHP_INT_MAX)
    {
        if ($minDots > $maxDots) {
            throw new \LogicException(sprintf('%s: hostname validator: the minDots argument must be less than or equal to maxDots', __CLASS__), 1334737472);
        }

        $message = 'valid_hostname';
        if ($minDots === 0 && $maxDots === 0) {
            $message = 'valid_hostname_simple';
        } elseif ($minDots === 0 && $maxDots === PHP_INT_MAX) {
            $message = 'valid_hostname';
        } elseif ($minDots === 1 && $maxDots === PHP_INT_MAX) {
            $message = 'valid_hostname_fqdn';
        } elseif ($minDots > 1 && $maxDots === PHP_INT_MAX) {
            $message = 'valid_hostname_fqdn_long';
        } else {
            $message = 'valid_hostname_fqdn_exact';
        }

        return $this
                ->minLength(1)
                ->maxLength(255)
                ->addToChain(__FUNCTION__, array($message, array($minDots, $maxDots)), $minDots, $maxDots)
        ;
    }

    /**
     * @todo
     * @return \Nethgui\System\Validator
     */
    public function ipV6Address()
    {
        return $this->notImplemented(__FUNCTION__);
    }

    /**
     * @todo
     * @return \Nethgui\System\Validator
     */
    public function ipV4Netmask()
    {
        return $this->addToChain(__FUNCTION__);
    }

    /**
     * @todo
     * @return \Nethgui\System\Validator
     */
    public function macAddress()
    {
        return $this->addToChain(__FUNCTION__);
    }

    /**
     * @todo
     * @return \Nethgui\System\Validator
     */
    public function ipV6Netmask()
    {
        return $this->notImplemented(__FUNCTION__);
    }

    public function integer()
    {
        return $this->addToChain(__FUNCTION__);
    }

    public function positive()
    {
        return $this->addToChain(__FUNCTION__);
    }

    public function negative()
    {
        return $this->addToChain(__FUNCTION__);
    }

    public function lessThan($cmp)
    {
        $template = array('valid_lessThan', array($cmp));
        return $this->addToChain(__FUNCTION__, $template, $cmp);
    }

    public function greatThan($cmp)
    {
        $template = array('valid_greatThan', array($cmp));
        return $this->addToChain(__FUNCTION__, $template, $cmp);
    }

    public function equalTo($cmp)
    {
        $template = array('valid_equalTo', array($cmp));
        return $this->addToChain(__FUNCTION__, $template, $cmp);
    }

    public function minLength($length)
    {
        $template = array('valid_minLength', array($length));
        return $this->addToChain(__FUNCTION__, $template, $length);
    }

    public function maxLength($length)
    {
        $template = array('valid_maxLength', array($length));
        return $this->addToChain(__FUNCTION__, $template, $length);
    }

    /**
     * Invert the evaluation result for the next rule.
     * @return \Nethgui\System\Validator
     */
    public function not()
    {
        $this->chain[] = -1;
        return $this;
    }

    /**
     * Check if the value is a valid Unix user name
     * @return \Nethgui\System\Validator
     */
    public function username()
    {
        return $this->addToChain(__FUNCTION__);
    }

    /**
     * Valid date
     *
     * Default format is given by the current user language settings.
     *
     * @see #513
     */
    public function date($format = NULL)
    {
        if (is_null($format)) {
            $format = $this->platform->getDateFormat();
        }

        $template = array('valid_date', array($format));
        return $this->addToChain(__FUNCTION__, $template, $format);
    }

    /**
     * Valid time 24-hours format HH:MM(:SS)?
     *
     * @see #513
     */
    public function time()
    {
        return $this->addToChain(__FUNCTION__);
    }

    /**
     * Check if the value is collection of elements satisfying the given validator
     * @param Validator $v Member validator
     * @return Validator 
     */
    public function collectionValidator(Validator $v)
    {
        $this->chain[] = new CollectionValidator($v);
        return $this;
    }

    /**
     * Invoke an external validation script
     * @param type $validatorName
     * @return Validator
     * @throws \InvalidArgumentException
     */
    public function platform($validatorName)
    {
        $arguments = func_get_args();

        if ( ! is_string($validatorName) && $validatorName !== '') {
            throw new \InvalidArgumentException(sprintf("%s: must supply a validator name argument", __CLASS__), 1333012309);
        }

        array_unshift($arguments, __FUNCTION__, FALSE);
        return call_user_func_array(array($this, 'addToChain'), $arguments);
    }

    /**
     * The restricted mail address validator
     * 
     * @see #1249
     * @return Validator
     */
    public function email()
    {
        return $this->addToChain(__FUNCTION__, FALSE);
    }


    public function cidrBlock()
    {
        return $this->addToChain(__FUNCTION__);
    }

    public function getFailureInfo()
    {
        return $this->failureInfo;
    }

    public function evaluate($value)
    {
        $this->failureInfo = array();

        if (empty($this->chain)) {
            return FALSE;
        }

        $notFlag = FALSE;

        foreach ($this->chain as $expression) {
            if (is_integer($expression) && $expression < 0) {
                // set $notFlag flag. Next $expression will be inverted: NOT(exp)
                $notFlag = TRUE;
                continue;
            } elseif (is_array($expression) && is_callable($expression[1])) {
                // $expression is an array of four elements
                // 0. the original method name, as a string
                // 1. a callable
                // 2. an optional array of arguments
                // 3. the error message template plus arguments

                list($methodName, $evalFunction, $argList, $errorTemplate) = $expression;

                if ( ! is_array($argList)) {
                    $argList = array();
                }

                array_unshift($argList, $value);

                $isValid = call_user_func_array($evalFunction, $argList);

                if (($isValid XOR $notFlag) === FALSE) {
                    if (is_array($errorTemplate)) {
                        $this->addFailureInfo($errorTemplate[0], $errorTemplate[1]);
                    }
                    return FALSE;
                }
            } elseif ($expression instanceof \Nethgui\System\ValidatorInterface) {
                $isValid = $expression->evaluate($value);
                if (($isValid XOR $notFlag) === FALSE) {
                    $this->mergeFailureInfo($expression);
                    return FALSE;
                }
            } elseif ($expression === FALSE) {
                $this->addFailureInfo('valid_forced_failure');
                return FALSE;
            } elseif ($expression === TRUE) {
                break;
            }

            // reset $notFlag flag
            $notFlag = FALSE;
        }

        return TRUE;
    }

    protected function mergeFailureInfo(\Nethgui\System\ValidatorInterface $validator)
    {
        foreach ($validator->getFailureInfo() as $elem) {
            $this->addFailureInfo($elem[0], $elem[1]);
        }
        return $this;
    }

    protected function addFailureInfo($template, $args = array())
    {
        if ( ! is_string($template)) {
            throw new \InvalidArgumentException(sprintf('%s: $template argument must be a string', __CLASS__), 1337766431);
        } elseif ( ! is_array($args)) {
            throw new \InvalidArgumentException(sprintf('%s: $args argument must be an array', __CLASS__), 1337766432);
        }
        $this->failureInfo[] = array($template, $args);
        return $this;
    }

    /**
     * In development environment a not implemented rule is simply ignored,
     * otherwise an exception is raised.
     * 
     * @codeCoverageIgnore
     * @param string $method
     * @return \Nethgui\System\Validator
     */
    private function notImplemented($method)
    {
        throw new \LogicException(sprintf('%s: %s() is not implemented.', get_class($this), $method), 1322150359);
    }

    /**
     * Add an eval function to the chain. 
     * 
     * The invoked function name is "eval" + $originalMethodName
     * 
     * The second argument is an array of two elements
     * 
     * - The message text template
     * 
     * - The array of placeholders for the template
     * 
     * If the 2nd argument is NULL generate a default template is generated. This
     * is for single failure reason.
     * 
     * If the 2nd argument is FALSE, you must provide the failure message in
     * the "eval*" function, calling addFailureInfo(). This is useful for multiple
     * failure reasons.
     * 
     * @param string the calling Method name
     * @param mixed Optional the default error message template: other values NULL and FALSE.
     * @param mixed Optional - First argument to evaluation function
     * @param mixed Optional - Second argument to evaluation function
     * @param mixed Optional - ...
     * @return Validator
     */
    private function addToChain($originalMethodName, $errorMessageTemplate = NULL)
    {
        $args = array_slice(func_get_args(), 2);

        // if only the method name is passed, add a default template
        if (is_null($errorMessageTemplate)) {
            $errorMessageTemplate = array('valid_' . $originalMethodName, array());
        }

        $methodName = 'eval' . ucfirst($originalMethodName);

        $this->chain[] = array(
            $originalMethodName, // 0 
            array($this, $methodName), // 1
            $args, // 2 
            $errorMessageTemplate, // 3
        );

        return $this;
    }

    private function evalNotEmpty($value)
    {
        if($value instanceof \Countable) {
            return $value->count() > 0;
        }
        return empty($value) ? FALSE : TRUE;
    }

    private function evalIsEmpty($value)
    {
        if($value instanceof \Countable) {
            return $value->count() == 0;
        }
        return empty($value) ? TRUE : FALSE;
    }

    private function evalRegexp($value, $exp)
    {
        return (preg_match($exp, $value) > 0);
    }

    private function evalMemberOf($value, $args)
    {
        return in_array($value, $args, TRUE);
    }

    /**
     * Validate IP Address
     *
     * Updated version suggested by Geert De Deckere
     *
     * @access       public
     * @param        string
     * @return       string
     * @author CodeIgniter
     */
    private function evalIpV4Address($value)
    {
        $ip_segments = explode('.', $value);

        // Always 4 segments needed
        if (count($ip_segments) != 4) {
            return FALSE;
        }

        // Check each segment
        foreach ($ip_segments as $segment) {
            // IP segments must be digits and can not be
            // longer than 3 digits or greater then 255
            if ($segment == '' OR ! preg_match("/^(0|[1-9][0-9]?[0-9]?)$/", $segment) OR $segment > 255 OR strlen($segment) > 3) {
                return FALSE;
            }
        }

        return TRUE;
    }

    /**
     * Check if $value starts with a letter and contains only alphanumeric
     * characters plus "-", "_", "."
     * @param string $value 
     */
    private function evalUsername($value)
    {
        return strlen($value) < 256 && $this->evalRegexp($value, '/^[a-z][-_\.a-z0-9]*$/');
    }

    /**
     * Check if $value is a string of digits
     * @param string $value
     */
    private function evalInteger($value)
    {
        return preg_match('/^(0|-?[1-9][0-9]*)$/', $value) === 1;
    }

    private function evalNumeric($value)
    {
        return $this->evalInteger($value) || preg_match('/^-?(0|[1-9][0-9]*)\.[0-9]+$/', $value) === 1;
    }

    private function evalPositive($value)
    {
        return $this->evalNumeric($value) && $value > 0;
    }

    private function evalNegative($value)
    {
        return $this->evalNumeric($value) && $value < 0;
    }

    private function evalLessThan($value, $cmp)
    {
        return $this->evalNumeric($value) && ($value < $cmp);
    }

    private function evalGreatThan($value, $cmp)
    {
        return $this->evalNumeric($value) && ($value > $cmp);
    }

    private function evalEqualTo($value, $cmp)
    {
        return ($this->evalNumeric($value) && $value == $cmp) || strcmp($value, $cmp) === 0;
    }

    private function evalMinLength($s, $min)
    {
        if ( ! is_string($s)) {
            throw new \InvalidArgumentException(sprintf("%s: Invalid type `%s`. Value must be a string.", get_class($this), gettype($s)), 1322150360);
        }
        return strlen($s) >= $min;
    }

    private function evalMaxLength($s, $max)
    {
        if ( ! is_string($s)) {
            throw new \InvalidArgumentException(sprintf("%s: Invalid type `%s`. Value must be a string.", get_class($this), gettype($s)), 1322150361);
        }
        return strlen($s) <= $max;
    }

    private function evalHostname($value, $minDots, $maxDots)
    {
        $parts = explode('.', $value);

        $dotsCount = count($parts) - 1;

        if ($dotsCount < $minDots || $dotsCount > $maxDots) {
            return FALSE;
        }

        // letter-case ignored.
        // FIXME: allow underscore (_) in hostname?
        $pattern = '/^[a-z0-9]([-a-z0-9]*)$/i';

        foreach ($parts as $part) {
            if (strlen($part) > 63) {
                return FALSE;
            }

            if (preg_match($pattern, $part) == 0) {
                return FALSE;
            }
        }

        return TRUE;
    }

    private function evalDate($value, $format)
    {
        if ($format == 'dd/mm/YYYY') {
            list($day, $month, $year) = explode('/', $value) + array(0, 0, 0);
        } elseif ($format == 'mm-dd-YYYY') {
            list($month, $day, $year) = explode('-', $value) + array(0, 0, 0);
        } elseif ($format == 'YYYY-mm-dd') {
            list($year, $month, $day) = explode('-', $value) + array(0, 0, 0);
        } else {
            throw new \InvalidArgumentException(sprintf("%s: Unknown date format `%s`", get_class($this), $format), 1322150419);
        }

        return checkdate(intval($month), intval($day), intval($year));
    }

    private function evalTime($value)
    {
        $parts = array();
        $pattern = '|^(\d\d):(\d\d)(?:\:(\d\d))?$|';

        if (preg_match($pattern, $value, $parts) == 0) {
            return FALSE;
        };

        $parts = $parts + array('00', '00', '00');

        list($h, $m, $s) = array_map('intval', $parts);

        if (($h >= 0 && $h < 24)
            && ($m >= 0 && $m < 60)
            && ($s >= 0 && $s < 60)) {
            return TRUE;
        }

        return FALSE;
    }

    private function evalIpV4Netmask($value)
    {
        $pattern = '/^(((0|128|192|224|240|248|252|254)\.0\.0\.0)|(255\.(0|128|192|224|240|248|252|254)\.0\.0)|(255\.255\.(0|128|192|224|240|248|252|254)\.0)|(255\.255\.255\.(0|128|192|224|240|248|252|254|255)))$/i';
        return preg_match($pattern, $value);
    }

    private function evalMacAddress($value)
    {
        $pattern = '/^[0-9a-f]{2}(:[0-9a-f]{2}){5}$/i';
        return preg_match($pattern, $value);
    }

    private function evalPlatform($value)
    {
        $args = func_get_args();

        // remove the first argument: $value ..
        array_shift($args);

        // .. append to last position
        $args[] = $value;

        $process = $this->platform->exec('/usr/bin/sudo /sbin/e-smith/validate ${@}', $args);

        if ($process->getExitCode() !== 0 && $this->platform instanceof \Nethgui\Log\LogConsumerInterface) {
            NETHGUI_DEBUG && $this->platform->getLog()->notice(sprintf('platformValidator (%s): %s', implode(', ', $args), strtr($process->getOutput(), "\n", " ")));
            $outputArray = $process->getOutputArray();
            $reason = array_pop($outputArray);
            // inject reason message in failure template arguments. Refs #1058
            $args['${reason}'] = substr(implode("\n", $outputArray), 0, 64);
            $this->addFailureInfo('valid_platform,' . $reason, $args);
        }

        return $process->getExitCode() === 0;
    }

    private function evalEmail($value)
    {
        if (\filter_var($value, \FILTER_VALIDATE_EMAIL) === FALSE) {
            $this->addFailureInfo('valid_email,generic_failure');
            return FALSE;
        }
        return TRUE;
    }

    private function evalCidrBlock($value)
    {
        $parts = explode('/', $value);
        $validMask = isset($parts[1]) && preg_match('/^[0-9]+$/', $parts[1]) && (($parts[1] > 1 && $parts[1] < 33) || $parts[1] === "0");
        return $validMask && $this->evalIpV4Address($parts[0]);
    }

    protected function setMandatoryConditional($value)
    {
        if ( ! isset($this->mandatory)) {
            $this->mandatory = $value;
        }
        return $this;
    }

    public function isMandatory()
    {
        $notFlag = FALSE;
        foreach ($this->chain as $expression) {
            if (is_integer($expression) && $expression < 0) {
                $notFlag = TRUE;
                continue;
            } elseif (is_array($expression) && is_callable($expression[1])) {
                list($methodName, $evalFunction, $argList, $errorTemplate) = $expression;

                if ( ! is_array($argList)) {
                    $argList = array();
                }
                
                if ($methodName === 'maxLength' && $argList[0] >= 0 ) {
                    return FALSE;
                } else {
                    return (preg_match('/^isEmpty$/', $methodName) === 0) XOR $notFlag;
                }

            } elseif ($expression instanceof \Nethgui\System\MandatoryValidatorInterface) {
                return $expression->isMandatory();
            } elseif (is_bool($expression)) {
                return FALSE;
            }
            // reset $notFlag flag
            $notFlag = FALSE;
        }

        return TRUE;
    }

}

/**
 * @author Davide Principi <davide.principi@nethesis.it>
 * @internal
 */
class CollectionValidator implements \Nethgui\System\MandatoryValidatorInterface
{
    /**
     *
     * @var \Nethgui\System\ValidatorInterface
     */
    private $memberValidator;
    private $failureInfo;

    /**
     *
     * @var \Iterator
     */
    private $iterator;

    public function __construct(\Nethgui\System\ValidatorInterface $memberValidator)
    {
        $this->memberValidator = $memberValidator;
    }

    public function evaluate($iterableObject)
    {
        $this->failureInfo = array();

        if (is_array($iterableObject)) {
            $iterableObject = new \ArrayObject($iterableObject);
            $this->iterator = $iterableObject->getIterator();
        } elseif ($iterableObject instanceof \IteratorAggregate) {
            $this->iterator = $iterableObject->getIterator();
        } elseif ($iterableObject instanceof \Iterator) {
            $this->iterator = $iterableObject;
        } else {
            $this->failureInfo[] = array("Not a collection", array());
            return FALSE;
        }

        foreach ($this->iterator as $e) {
            if ($this->memberValidator->evaluate($e) === FALSE) {
                $this->failureInfo = array_merge($this->failureInfo, $this->memberValidator->getFailureInfo());
                return FALSE;
            }
        }


        return TRUE;
    }

    public function getFailureInfo()
    {
        return $this->failureInfo;
    }

    public function isMandatory()
    {
        if ($this->memberValidator instanceof MandatoryValidatorInterface) {
            return $this->memberValidator->isMandatory();
        }
        return TRUE;
    }

}

/**
 * @author Davide Principi <davide.principi@nethesis.it>
 * @see Validator::orValidator()
 * @internal
 */
class OrValidator implements \Nethgui\System\MandatoryValidatorInterface
{
    /**
     *
     * @var \Nethgui\System\ValidatorInterface
     */
    private $v1;

    /**
     *
     * @var \Nethgui\System\ValidatorInterface
     */
    private $v2;
    private $failureInfo;

    public function __construct(\Nethgui\System\ValidatorInterface $v1, \Nethgui\System\ValidatorInterface $v2)
    {
        $this->v1 = $v1;
        $this->v2 = $v2;
    }

    public function evaluate($value)
    {
        $this->failureInfo = array();
        $e1 = $this->v1->evaluate($value);

        if ($e1 === FALSE) {
            $e2 = $this->v2->evaluate($value);

            if ($e2 === FALSE) {
                $this->failureInfo = array_merge($this->failureInfo, $this->v1->getFailureInfo(), $this->v2->getFailureInfo());
                return FALSE;
            }
            return TRUE;
        }

        return TRUE;
    }

    public function getFailureInfo()
    {
        return $this->failureInfo;
    }

    public function isMandatory()
    {
        $m1 = ($this->v1 instanceof MandatoryValidatorInterface) ? $this->v1->isMandatory() : TRUE;
        $m2 = ($this->v2 instanceof MandatoryValidatorInterface) ? $this->v2->isMandatory() : TRUE;
        return ($m1 && $m2);
    }

}
Nethgui Framework API documentation generated by ApiGen