コード例 #1
0
ファイル: PropertyMapper.php プロジェクト: karwana/penelope
 public function split(Object $object, $delimiter = ',')
 {
     $value = $object->getProperty($this->property_name)->getValue();
     // If it's already an array, join and re-split.
     if (is_array($value)) {
         $value = implode($delimiter, $value);
     }
     if (is_string($value)) {
         $value = explode($delimiter, $value);
     }
     if (!empty($value)) {
         $value = array_map(function ($value) {
             return trim($value);
         }, $value);
     }
     if (!empty($value)) {
         $value = array_filter($value);
     }
     return array($this->property_name => $value);
 }
コード例 #2
0
ファイル: ObjectController.php プロジェクト: karwana/penelope
 private function processFile(Object $object, $name, $file, array &$transient_properties, &$has_errors)
 {
     $object_schema = $object->getSchema();
     if (!$object_schema->hasProperty($name)) {
         return;
     }
     $property_schema = $object_schema->getProperty($name);
     // When a file is resubmitted as a serialized form value, it would be present the $_POST array.
     // Therefore it would have already been set as a transient property.
     if (isset($transient_properties[$name])) {
         $transient_property = $transient_properties[$name];
     } else {
         $transient_property = new TransientProperty($property_schema);
         $transient_properties[$name] = $transient_property;
     }
     // Check if each uploaded file was "OK" and if so set the value on the transient propert.
     // Otherwise, set an error.
     if ($property_schema->isMultiValue()) {
         $this->processMultiFile($transient_property, $file);
     } else {
         if (UPLOAD_ERR_OK === $file['error']) {
             try {
                 $perm_name = UploadController::move($file['tmp_name'], $file['name']);
             } catch (\RuntimeException $e) {
                 $transient_property->setError($e);
             }
             if ($perm_name) {
                 $transient_property->setValue(array($perm_name, $file['name']));
             }
         } else {
             if (UPLOAD_ERR_NO_FILE !== $file['error'] or $transient_property->getSchema()->getOption('required')) {
                 $transient_property->setError(new Exceptions\UploadException($file['error']));
             }
         }
     }
     if ($transient_property->hasError()) {
         $has_errors = true;
         return;
     }
     try {
         $object->getProperty($name)->setValue($transient_property->getValue());
     } catch (Exceptions\TypeException $e) {
         $transient_property->setError($e);
         $has_errors = true;
     }
 }