views:

35

answers:

1

I have a requirement where a process can be implemented in 2 different situation. One situation would be where the start date cannot be in the past and the other would be where it can.

Currently we utilise Value Objects where we perform a series of a validation items on each field submitted using Zend Validate objects.

The validation extends a base class e.g.

class ValueObject_test1 extends filter()

Filter is made up of: -

class filter {
    protected $_filter;
    protected $_filterRules = array();
    protected $_validatorRules = array();
    protected $_data = array();
    protected $_objData = array();
    protected $_options = array(Zend_Filter_Input::ESCAPE_FILTER => 'StripTags');
    protected $_runValidation = true;
    protected function _setFilter()
    protected function _addFilter()
    protected function _addValidator()
    protected function _addData()
    protected function _addObject()
    protected function _addOption()
    public function getData()   
    public function hasErrors()
    public function getMessages()
    public function getValidationState()
    public function __get() 
    public function __isset()
    public function __set()
}

ValueObject_test1 is made up of:

class ValueObject_test1 extends filter {    
    public function __construct($testVar) {
        $this->_setData(testVar);       
        $this->_setFilters();
        $this->_setValidators();        
        if($this->_runValidation) {
            $this->_setFilter();
        }       
    }   
    protected function _setFilters(){
        $this->_addFilter("*", "StringTrim");
    }   
    protected function _setData($testVar) {     
        $this->_addData('testVar', $testVar);       
    }   
    protected function _setValidators() {       
        $this->_addValidator('testVar', array(new Zend_Validate(), 'presence'=>'required', 'messages'=>'Enter something'));
    }   
}

What I'm trying to achieve is an extension of ValueObject_test1 so that my second situation will have an additional validation item as well as the items in ValueObject_test1()

I've written the following for my second situation:-

<?php

class ValueObject_test2 extends ValueObject_test1 { 
    public function __construct($testVar, $testVar2) {
        $this->_setData($testVar, $testVar2);       
        $this->_setFilters();
        $this->_setValidators();        
        if($this->_runValidation) {
            $this->_setFilter();
        }       
    }   
    protected function _setFilters(){
        $this->_addFilter("*", "StringTrim");
    }   
    protected function _setData($testVar, $testVar2) {  
        $this->_addData('testVar', $testVar);   
        $this->_addData('testVar2', $testVar2);     
    }
    protected function _setValidators() {       
        $this->_addValidator('testVar2', array(new Zend_Validate(), 'presence'=>'required', 'messages'=>'Enter something'));
    }
}

The issue i'm having is that the output from this only appears to validate my second situation validation and nothing on the second. I'm under the impression that by setting both variables in _setData() the validation should occur for items in ValueObject_test1 and the items in my ValueObject_test2?

+2  A: 
Oxyrubber
Clarification: the "parent" keyword acts like "$this", except will only execute the inherited version of functions.
Oxyrubber