Inheritance: extends eZ\Publish\Core\FieldType\Value
 /**
  * Get hashes and their respective converted values.
  *
  * This is a PHPUnit data provider
  *
  * The returned records must have the the input hash assigned to the
  * first index and the expected value result to the second. For example:
  *
  * <code>
  * array(
  *      array(
  *          array( 'myValue' => true ),
  *          new MyValue( true ),
  *      ),
  *      // ...
  * );
  * </code>
  *
  * @return array
  */
 public function provideFromHashData()
 {
     $dateTime = new DateTime();
     return array(array(array('timestamp' => $dateTime->setTimestamp(123456)->setTime(0, 0, 0)->getTimestamp(), 'rfc850' => $rfc850 = $dateTime->format(DateTime::RFC850)), DateValue::fromString($rfc850)), array(array('timestamp' => $dateTime->setTimestamp($timestamp = 123456)->setTime(0, 0, 0)->getTimestamp(), 'rfc850' => null), DateValue::fromTimestamp($timestamp)));
 }
示例#2
0
 /**
  * Data provider for valid input to acceptValue().
  *
  * Returns an array of data provider sets with 2 arguments: 1. The valid
  * input to acceptValue(), 2. The expected return value from acceptValue().
  * For example:
  *
  * <code>
  *  return array(
  *      array(
  *          null,
  *          null
  *      ),
  *      array(
  *          __FILE__,
  *          new BinaryFileValue( array(
  *              'path' => __FILE__,
  *              'fileName' => basename( __FILE__ ),
  *              'fileSize' => filesize( __FILE__ ),
  *              'downloadCount' => 0,
  *              'mimeType' => 'text/plain',
  *          ) )
  *      ),
  *      // ...
  *  );
  * </code>
  *
  * @return array
  */
 public function provideValidInputForAcceptValue()
 {
     $dateTime = new DateTime();
     return array(array(null, new DateValue()), array($dateString = '2012-08-28 12:20 EST', new DateValue(new DateTime($dateString))), array($timestamp = 1346149200, new DateValue(clone $dateTime->setTimestamp($timestamp))), array(DateValue::fromTimestamp(1372895999), new DateValue($dateTime->setTimestamp(1372895999)->setTime(0, 0, 0))), array($dateTime = new DateTime(), new DateValue($dateTime)));
 }
示例#3
0
 /**
  * Converts an $hash to the Value defined by the field type
  *
  * @param mixed $hash Null or associative array containing timestamp and optionally date in RFC850 format.
  *
  * @return \eZ\Publish\Core\FieldType\Date\Value $value
  */
 public function fromHash($hash)
 {
     if ($hash === null) {
         return $this->getEmptyValue();
     }
     if (isset($hash["rfc850"]) && $hash["rfc850"]) {
         return Value::fromString($hash["rfc850"]);
     }
     return Value::fromTimestamp((int) $hash["timestamp"]);
 }