Append scope to data

@param  mixed $data
@param  string $scope
@return array
@access protected
331915
protected function scopedData($data, /*# string */ $scope)/*# : array */
    {
        if (is_array($data) && isset($data['class'])) {
            $data['scope'] = $scope;
        } else {
            $data = ['class' => $data, 'scope' => $scope];
        }
        return $data;
    }
960909
public function withScope($scope)
    {
        if ($scope == Grid\Exporter::SCOPE_ALL) {
            return $this;
        }

        list($scope, $args) = explode(':', $scope);

        if ($scope == Grid\Exporter::SCOPE_CURRENT_PAGE) {
            $this->grid->model()->usePaginate(true);
        }

        if ($scope == Grid\Exporter::SCOPE_SELECTED_ROWS) {
            $selected = explode(',', $args);
            $this->grid->model()->whereIn($this->grid->getKeyName(), $selected);
        }

        return $this;
    }
1346732
public static function insert($data)
    {
        $self  = self::getInstance();
        $table = $self->table_name;

        if (isset($data[0])) {
            $make      = $self->makeMultipleInsert($table, $data);
            $statement = $make[0];
            $value     = $make[1];
        } else {
            $newData    = $self->makeInsertParameter($data);
            $column     = implode(",", array_keys($data));
            $paramValue = implode(",", array_keys($newData));
            $statement  = "INSERT INTO {$table} ({$column}) VALUES({$paramValue});";
            $value      = $newData;
        }

        $execute   = $self->exec($statement, $value);

        return $execute;
    }
304245
public function append($path, $data)
	{
		if ($this->exists($path))
		{
			return $this->write($path, $this->read($path) . $data);
		}

		return $this->write($path, $data);
	}
1239507
public function all($scope = null)
    {
        if ($scope === null) {
            return array_values($this->messages);
        }

        $messages = array();
        foreach ($this->messages as $message) {
            if ($message['scope'] === $scope) {
                $messages[] = $message;
            }
        }

        return $messages;
    }
17513
public function load($data, $formName = null)
    {
        $ret = parent::load($data, $formName); // TODO: Change the autogenerated stub
        $scope = $formName === null ? (new DataProperties())->formName() : $formName;
        if ($scope === '' && !empty($data)) {
            $this->dataProperties->setAttributes($data);
        } elseif (isset($data[$scope])) {
            $_data = $data[$scope];
            if(!empty($_data)) $this->dataProperties->setAttributes($_data);
        }
        return $ret;
    }
345435
public function fetch($scope = null)
    {
        $messages = $this->all($scope);
        $this->clear($scope);

        return $messages;
    }
328156
public function renderScopeElement($scope)
    {
        $params = ['scope' => $scope];

        switch ($scope->type) {
            case 'date':
                if ($scope->value && $scope->value instanceof Carbon) {
                    $params['dateStr'] = Backend::dateTime($scope->value, ['formatAlias' => 'dateMin']);
                    $params['date']    = $scope->value->format('Y-m-d H:i:s');
                }

                break;
            case 'daterange':
                if ($scope->value && is_array($scope->value) && count($scope->value) === 2 &&
                    $scope->value[0] && $scope->value[0] instanceof Carbon &&
                    $scope->value[1] && $scope->value[1] instanceof Carbon
                ) {
                    $after = $scope->value[0]->format('Y-m-d H:i:s');
                    $before = $scope->value[1]->format('Y-m-d H:i:s');

                    if(strcasecmp($after, '0000-00-00 00:00:00') > 0) {
                        $params['afterStr'] = Backend::dateTime($scope->value[0], ['formatAlias' => 'dateMin']);
                        $params['after']    = $after;
                    }
                    else {
                        $params['afterStr'] = '∞';
                        $params['after']    = null;
                    }

                    if(strcasecmp($before, '2999-12-31 23:59:59') < 0) {
                        $params['beforeStr'] = Backend::dateTime($scope->value[1], ['formatAlias' => 'dateMin']);
                        $params['before']    = $before;
                    }
                    else {
                        $params['beforeStr'] = '∞';
                        $params['before']    = null;
                    }
                }

                break;
            case 'number':
                if (is_numeric($scope->value)) {
                    $params['number'] = $scope->value;
                }

                break;

            case 'numberrange':
                if ($scope->value && is_array($scope->value) && count($scope->value) === 2 &&
                    $scope->value[0] &&
                    $scope->value[1]
                ) {
                    $min = $scope->value[0];
                    $max = $scope->value[1];

                    $params['minStr'] = $min ?: '';
                    $params['min'] = $min ?: null;

                    $params['maxStr'] = $max ?: '∞';
                    $params['max'] = $max ?: null;
                }

                break;

            case 'text':
                $params['value'] = $scope->value;
                $params['size'] = array_get($scope->config, 'size', 10);

                break;
        }

        return $this->makePartial('scope_'.$scope->type, $params);
    }
817796
protected function replaceRefs($key, &$scope)
    {
        if (is_array($scope)) {
            foreach (array_keys($scope) as $subkey) {
                $this->replaceRefs(
                    implode($this->delimiter, [$key, $subkey]),
                    $scope[$subkey]
                );
            }
        } else {
            $this->getByRef($key, $scope);
        }
    }
530594
public function newQueryWithoutScope($scope)
    {
        $this->getGlobalScope($scope)->remove($query = $this->getQuery(), $this);

        return $query;
    }
1180251
protected function appendSecurity(&$data)
    {
        if ($this->security) {
            $this->appendData($data, 'policy',    $this->security->policy);
            $this->appendData($data, 'signature', $this->security->signature);
        }
    }
351193
private function figureOutWhichIncludes(Scope $scope)
    {
        $includes = $this->getDefaultIncludes();

        foreach ($this->getAvailableIncludes() as $include) {
            if ($scope->isRequested($include)) {
                $includes[] = $include;
            }
        }

        foreach ($includes as $include) {
            if ($scope->isExcluded($include)) {
                $includes = array_diff($includes, [$include]);
            }
        }

        return $includes;
    }
1116134
function _append($data)
	{
		if (strlen($data) - 4 > $this->_limit) {
			$data = $this->_addContinue($data);
		}
		$this->_data		.= $data;
		$this->_datasize	+= strlen($data);
	}
636175
public function scopeRequestAppend($query, Request $request)
    {
        if ($request->has('append')) {
            $query->append($request->input('append'));
        }

        return $query;
    }
1163761
public function addScope($scope)
  {
      if (!is_array($scope)) {
          $scope = explode(' ', $scope);
      }

      $this->scopes = array_unique(array_merge($this->scopes, $scope));

      return $this;
  }
943913
public static function append($storage, $data = [])
    {
        if (!is_array($storage) || !is_array($data)) {
            throw new ArrayStorageException('Invalid parameters specified');
        }
        foreach ($data as $setting => $value) {
            if (array_key_exists($setting, $storage) &&
                is_array($storage[$setting]) &&
                is_array($value)
            ) {
                $storage[$setting] = self::append($storage[$setting], $value);
            } else {
                $storage[$setting] = $value;
            }
        }
        return $storage;
    }
1126003
protected function transformData(Scope $scope, $data): array
    {
        $transformer = $scope->transformer();

        // Handle when no transformer is present
        if (empty($transformer)) {
            // No transformation
            return (array) $data;
        }

        // Handle when transformer is a callable
        if (\is_callable($transformer)) {
            // Simply run callable on the data and return the result
            return (array) $transformer($data);
        }

        // Ensure we're working with a real transformer from this point forward.
        if (!($transformer instanceof TransformerInterface)) {
            throw new InvalidTransformerException('Expected a valid transformer');
        }

        // Transform the data, and filter any sparse field-set for the scope.
        $transformedData = $scope->filterData($transformer->getTransformedData($data));

        // Add includes to the payload.
        $includeMap = $scope->includeMap();
        foreach ($scope->resolvedIncludeKeys() as $includeKey) {
            $child = $this->executeTransformerInclude($scope, $includeKey, $includeMap[$includeKey], $data);

            // Create a new child scope.
            $childScope = new Scope($child, $scope->includes()->splice($includeKey), $scope);

            // If working with a ResourceInterface, use it's own key (if present).
            $childKey = $child instanceof ResourceInterface && $child->getResourceKey() ?
                $child->getResourceKey() : $includeKey;

            ArrayHelper::mutate(
                $transformedData,
                $childKey,
                $this->transform($childScope)
            );
        }

        return $transformedData;
    }