示例#1
0
 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
文件: Edge.php 项目: karwana/penelope
 public function save()
 {
     $start_node = $this->start_node;
     $end_node = $this->end_node;
     if (!$start_node) {
         throw new \LogicException('Cannot save an edge with no start node.');
     }
     if (!$end_node) {
         throw new \LogicException('Cannot save an edge with no end node.');
     }
     if (!$start_node->hasId()) {
         $start_node->save();
     }
     if (!$end_node->hasId()) {
         $end_node->save();
     }
     // Make an edge if this edge is new.
     if (!$this->hasId($this->id)) {
         $client_edge = $this->client->makeRelationship();
         $client_edge->setType($this->schema->getName());
         $this->client_object = $client_edge;
     } else {
         if (!$this->client_object) {
             $this->fetch();
         }
     }
     $client_edge = $this->client_object;
     $client_edge->setStartNode($start_node->getClientObject());
     $client_edge->setEndNode($end_node->getClientObject());
     parent::save();
 }
示例#3
0
文件: Node.php 项目: karwana/penelope
 public function delete()
 {
     $client_node = $this->getClientObject();
     // Remove the full text index.
     $index = new Neo4j\Index\NodeFulltextIndex($this->client, 'full_text');
     $index->remove($client_node);
     $index->save();
     // Orphan the node.
     $client_edges = $client_node->getRelationships();
     if ($client_edges) {
         foreach ($client_edges as $client_edge) {
             $client_edge->delete();
         }
     }
     parent::delete();
 }
示例#4
0
 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;
     }
 }