ensureArray() публичный статический Метод

Converts a value to array type. If the value is a string and it is in the form (a,b,c) then an array consisting of each of the elements will be returned. If the value is a string and it is not in this form then an array consisting of just the string will be returned. If the value is not a string then
public static ensureArray ( $value ) : array
Результат array
Пример #1
0
 /**
  * Validates if the parameter is a valid data source.
  * If it is a string or an array, it will be converted as a TList object.
  * @param Traversable|array|string data source to be validated
  * @return Traversable the data that is traversable
  * @throws TInvalidDataTypeException if the data is neither null nor Traversable
  */
 protected function validateDataSource($value)
 {
     if (is_string($value)) {
         $list = new TList();
         foreach (TPropertyValue::ensureArray($value) as $key => $value) {
             if (is_array($value)) {
                 $list->add($value);
             } else {
                 $list->add(array($value, is_string($key) ? $key : $value));
             }
         }
         return $list;
     } else {
         if (is_array($value)) {
             return new TMap($value);
         } else {
             if ($value instanceof TDbDataReader) {
                 // read array from TDbDataReader since it's forward-only stream and can only be traversed once
                 return $value->readAll();
             } else {
                 if ($value instanceof \Traversable || $value === null) {
                     return $value;
                 } else {
                     throw new TInvalidDataTypeException('databoundcontrol_datasource_invalid', get_class($this));
                 }
             }
         }
     }
 }
Пример #2
0
 /**
  * Sets the interval such that those rating values within the interval
  * will be considered as a half star rating.
  * @param array rating display half value interval, default is array(0.3, 0.7);
  */
 public function setHalfRatingInterval($value)
 {
     $this->setViewState('HalfRating', TPropertyValue::ensureArray($value), array(0.3, 0.7));
 }
Пример #3
0
 /**
  * @param array Active Record primary key value to be edited.
  */
 public function setRecordPk($value)
 {
     $this->clearRecordObject();
     $val = TPropertyValue::ensureArray($value);
     $this->setViewState('PK', count($val) > 0 ? $val : null);
 }
Пример #4
0
 /**
  * Sets the Css class name that this container can accept.
  * @param string comma delimited css class names.
  */
 public function setAcceptCssClass($value)
 {
     $this->setViewState('Accepts', TPropertyValue::ensureArray($value), '');
 }
Пример #5
0
 public function setCustomTranslations($value)
 {
     return $this->setViewState('CustomTranslations', TPropertyValue::ensureArray($value));
 }
Пример #6
0
 /**
  * @param array search parameters
  */
 public function setSearchParameters($value)
 {
     $this->setViewState('SearchParameters', TPropertyValue::ensureArray($value), array());
 }
Пример #7
0
 /**
  * Sets the possible values that the slider can take.
  * If this is set, {@link setStepSize StepSize} will be ignored. The latter
  * generates a set of evenly distributed candidate values.
  * @param array list of allowed values the slider can take
  */
 public function setValues($value)
 {
     $this->setViewState('Values', TPropertyValue::ensureArray($value), array());
 }