コード例 #1
0
ファイル: DateSelect.php プロジェクト: coolms/common
 /**
  * {@inheritDoc}
  */
 public function getInputSpecification()
 {
     $inputSpec = parent::getInputSpecification();
     $inputSpec['filters'][] = ['name' => 'DateSelect', 'options' => ['null_on_empty' => !!$this->shouldCreateEmptyOption()]];
     if ($date = $this->getMinDate()) {
         $inputSpec['validators'][] = ['name' => 'GreaterThan', 'options' => ['messages' => [Validator\GreaterThan::NOT_GREATER_INCLUSIVE => 'The date ' . 'must be not earlier than %min% inclusive'], 'messageVariables' => ['min' => ['abstractOptions' => 'fmt']], 'min' => $date->format('Y-m-d'), 'fmt' => $this->format($date), 'inclusive' => true, 'break_chain_on_failure' => true]];
     }
     if ($date = $this->getMaxDate()) {
         $inputSpec['validators'][] = ['name' => 'LessThan', 'options' => ['messages' => [Validator\LessThan::NOT_LESS_INCLUSIVE => 'The date ' . 'must be not later than %max% inclusive'], 'messageVariables' => ['max' => ['abstractOptions' => 'fmt']], 'max' => $date->format('Y-m-d'), 'fmt' => $this->format($date), 'inclusive' => true, 'break_chain_on_failure' => true]];
     }
     return $inputSpec;
 }
コード例 #2
0
ファイル: DateSelect.php プロジェクト: Andyyang1981/pi
 /**
  * {@inheritDoc}
  */
 public function getInputSpecification()
 {
     $spec = parent::getInputSpecification();
     $spec['filters'] = array(array('name' => 'Callback', 'options' => array('callback' => function ($date) {
         // Convert the date to a specific format
         if (is_array($date)) {
             $date = array_filter($date);
             if ($date) {
                 $date = $date['year'] . '-' . $date['month'] . '-' . $date['day'];
             } else {
                 $date = '';
             }
         }
         return $date;
     })));
     return $spec;
 }
コード例 #3
0
ファイル: DateSelectTest.php プロジェクト: rajanlamic/IntTest
 public function testProvidesInputSpecificationThatIncludesValidatorsBasedOnAttributes()
 {
     $element = new DateSelectElement();
     $inputSpec = $element->getInputSpecification();
     $this->assertArrayHasKey('validators', $inputSpec);
     $this->assertInternalType('array', $inputSpec['validators']);
     $expectedClasses = array('Zend\\Validator\\Date');
     foreach ($inputSpec['validators'] as $validator) {
         $class = get_class($validator);
         $this->assertTrue(in_array($class, $expectedClasses), $class);
         switch ($class) {
             case 'Zend\\Validator\\Date':
                 $this->assertEquals('Y-m-d', $validator->getFormat());
                 break;
             default:
                 break;
         }
     }
 }