예제 #1
0
 public function testFilter()
 {
     $filter = new ArrayFilter(new Alnum());
     $this->assertEquals(true, $filter->apply(array('foo')));
     $this->assertEquals(false, $filter->apply(array('12 3')));
     $this->assertEquals(false, $filter->apply(array('foo', '12 3')));
     $this->assertEquals(false, $filter->apply('foo'));
     $filter = new ArrayFilter(new Sha1());
     $this->assertEquals(array('0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'), $filter->apply(array('foo')));
     // test error message
     $this->assertErrorMessage($filter->getErrorMessage());
 }
예제 #2
0
 /**
  * Apply all of the callbacks for this filter.
  *
  * @param mixed $data
  * @param int $offset
  * @return mixed
  * @throws \TypeError
  */
 public function applyCallbacks($data = null, int $offset = 0)
 {
     if ($offset === 0) {
         if (\is_null($data)) {
             return parent::applyCallbacks($data, 0);
         } elseif (!\is_array($data)) {
             throw new \TypeError(\sprintf('Expected an array of booleans (%s).', $this->index));
         }
         if (!\is1DArray($data)) {
             throw new \TypeError(\sprintf('Expected a 1-dimensional array (%s).', $this->index));
         }
         foreach ($data as $key => $val) {
             if (\is_array($val)) {
                 throw new \TypeError(\sprintf('Unexpected array at index %s (%s).', $key, $this->index));
             }
             if (\is_null($data) || $data === '') {
                 $data[$key] = null;
             } else {
                 $data[$key] = !empty($val);
             }
         }
         return parent::applyCallbacks($data, 0);
     }
     return parent::applyCallbacks($data, $offset);
 }
예제 #3
0
 /**
  * Apply all of the callbacks for this filter.
  *
  * @param mixed $data
  * @param int $offset
  * @return mixed
  * @throws \TypeError
  */
 public function applyCallbacks($data = null, int $offset = 0)
 {
     if ($offset === 0) {
         if (\is_null($data)) {
             return parent::applyCallbacks([], 0);
         } elseif (!\is_array($data)) {
             throw new \TypeError(\sprintf('Expected an array of string (%s).', $this->index));
         }
         if (!\is1DArray($data)) {
             throw new \TypeError(\sprintf('Expected a 1-dimensional array (%s).', $this->index));
         }
         foreach ($data as $key => $val) {
             if (\is_array($val)) {
                 throw new \TypeError(\sprintf('Expected a string at index %s (%s).', $key, $this->index));
             }
             if (\is_null($val)) {
                 $data[$key] = '';
             } elseif (\is_numeric($val)) {
                 $data[$key] = (string) $val;
             } elseif (!\is_string($val)) {
                 throw new \TypeError(\sprintf('Expected a string at index %s (%s).', $key, $this->index));
             }
         }
         return parent::applyCallbacks($data, 0);
     }
     return parent::applyCallbacks($data, $offset);
 }
예제 #4
0
 /**
  * Apply all of the callbacks for this filter.
  *
  * @param mixed $data
  * @param int $offset
  * @return mixed
  * @throws \TypeError
  */
 public function applyCallbacks($data = null, int $offset = 0)
 {
     if ($offset === 0) {
         if (\is_null($data)) {
             return parent::applyCallbacks($data, 0);
         } elseif (!\is_array($data)) {
             throw new \TypeError(\sprintf('Expected an array of floats (%s).', $this->index));
         }
         if (!\is1DArray($data)) {
             throw new \TypeError(\sprintf('Expected a 1-dimensional array (%s).', $this->index));
         }
         foreach ($data as $key => $val) {
             if (\is_array($val)) {
                 throw new \TypeError(\sprintf('Expected a float at index %s (%s).', $key, $this->index));
             }
             if (\is_int($val) || \is_float($val)) {
                 $data[$key] = (double) $val;
             } elseif (\is_null($val) || $val === '') {
                 $data[$key] = (double) $this->default;
             } elseif (\is_string($val) && \is_numeric($val)) {
                 $data[$key] = (double) $val;
             } else {
                 throw new \TypeError(\sprintf('Expected a float at index %s (%s).', $key, $this->index));
             }
         }
         return parent::applyCallbacks($data, 0);
     }
     return parent::applyCallbacks($data, $offset);
 }
예제 #5
0
 public function testFilter()
 {
     $arrayFilter = new ArrayFilter();
     /** @var \Zend_Filter_Interface $filterMock */
     /** This filter should be applied to all fields values */
     $filterMock = $this->getMock('Zend_Filter_Interface', [], [], '', false);
     $filterMock->expects($this->exactly(3))->method('filter')->will($this->returnCallback(function ($input) {
         return '(' . $input . ')';
     }));
     $arrayFilter->addFilter($filterMock);
     /** @var \Zend_Filter_Interface $fieldFilterMock */
     /** This filter should be applied to 'field2' field value only */
     $fieldFilterMock = $this->getMock('Zend_Filter_Interface', [], [], '', false);
     $fieldFilterMock->expects($this->exactly(1))->method('filter')->will($this->returnCallback(function ($input) {
         return '[' . $input . ']';
     }));
     $arrayFilter->addFilter($fieldFilterMock, 'field2');
     /** Execute SUT and ensure that array items were filtered correctly */
     $inputArray = ['field1' => 'value1', 'field2' => 'value2', 'field3' => 'value3'];
     $expectedOutput = ['field1' => '(value1)', 'field2' => '[(value2)]', 'field3' => '(value3)'];
     $this->assertEquals($expectedOutput, $arrayFilter->filter($inputArray), 'Array was filtered incorrectly.');
 }
예제 #6
0
파일: index.php 프로젝트: MrFabioS/kim
			.ui-datepicker-buttonpane{
				padding: 5px 5px;  
			}
		</style>
	</head>
	<body>
		<div class="ui-layout-north" id="north"></div>
		<div class="ui-layout-center" id="center">
			<table whidth=*>
				<tr>
					<th class="horario dark" whidth="200px">Horário</th>
					<th class="acao dark" whidth=*>Ações</th>
				</tr>
				<?php 
for ($i = 1; $i <= 24; $i++) {
    $horario = new ArrayFilter($_SESSION['resultadoDB']);
    $horario->filter(':horario=="' . $i . '" AND :data=="' . $_SESSION['date'] . '"');
    $resultadoHora = $horario->result;
    $td_class = $i % 2 == 0 ? 'dark' : 'light';
    ?>
				<tr>
					<td class="<?php 
    echo $td_class;
    ?>
"><?php 
    echo $i . 'h';
    ?>
</td>
					<td class="<?php 
    echo $td_class;
    ?>