Пример #1
0
 public function schema($schema = null)
 {
     if ($schema === null) {
         if ($this->_schema === null) {
             $customFieldsEndpoint = new CustomFieldsEndpoint(['connection' => $this->connection()]);
             $this->_schema = $customFieldsEndpoint->alterSchema($this->baseSchema());
         }
         return $this->_schema;
     }
     return parent::schema($schema);
 }
 protected function _transformResource(array $result, Endpoint $endpoint)
 {
     $properties = [];
     foreach ($result as $field => $value) {
         if ($field === 'custom_fields') {
             // Loop over custom fields
             foreach ($value as $customField) {
                 // Get the alias for the custom field
                 $customFieldField = Schema::nameToField($customField['name']);
                 // Lookup the field in the schema
                 $column = $endpoint->schema()->column($customFieldField);
                 // If no value has been given set it to null
                 if (!isset($customField['value'])) {
                     $properties[$customFieldField] = null;
                     continue;
                 }
                 // Cast value to correct type and set it as property
                 $properties[$customFieldField] = $this->castValue($customField['value'], $column['type']);
             }
             continue;
         }
         $column = $endpoint->schema()->column($field);
         if (!$column) {
             $properties[$field] = $value;
             continue;
         }
         $properties[$field] = $this->castValue($value, $column['type']);
     }
     return $this->_createResource($endpoint->resourceClass(), $properties);
 }