Merge defaults with a view model object.

Returns $params verbatim if they are not an object.

When merging, provided parameters have precedence.

@param mixed $params
@param array $defaults
@return object|mixed
550381
private function mergeObjectParams($params, array $defaults)
    {
        if (! is_object($params)) {
            return;
        }

        foreach ($defaults as $key => $value) {
            if (! isset($params->{$key}) && ! method_exists($params, $key)) {
                $params->{$key} = $value;
            }
        }

        return $params;
    }
770708
public function mergeParams($method, Array $params = [])
    {
        $result = parent::mergeParams($method, $params);

        foreach ($this->map as $oldKey => $newKey)
        {
            if (array_key_exists($oldKey, $result[$method])) {
                $result[$method][$newKey] = $result[$method][$oldKey];
                $result[$method][$oldKey] = null;
                unset($result[$method][$oldKey]);
            }
        }

        return $result;
    }
662927
public function setDefaults(array $defaults): self
    {
        foreach ((array)$defaults as $key => $value) {
            if (isset($this->defaults[$key])) {
                $this->defaults[$key] = $value;
            } else {
                throw new Exception('Invalid route default', Exception::HTTP_INTERNAL_SERVER_ERROR);
            }
        }

        return $this;
    }
835595
protected static function compile_properties(array $properties, $defaults = true)
	{
		$p = $properties;
		$properties = [];

		foreach ($p as $key => $value)
		{
			if (is_int($key))
			{
				$key = $value;
				$value = [];
			}

			// Get property defaults
			if ($defaults and $property = static::property($key, false))
			{
				$value = array_replace_recursive($property, $value);
			}

			$properties[$key] = $value;
		}

		return $properties;
	}
892682
public function mergeRequests(array $parameters = [])
    {
        $data = $this->client->mergeRequests()->all($this->id, $parameters);

        $mrs = array();
        foreach ($data as $mr) {
            $mrs[] = MergeRequest::fromArray($this->getClient(), $this, $mr);
        }

        return $mrs;
    }
1371344
public function create(array $params = array())
    {
        $defaults = array(
            'name'      => null,
            'devurl'    => null,
            'is_active' => true,
            'is_public' => false,
        );

        $params = array_filter(
            array_merge($defaults, $params),
            array($this, 'isNotNull')
        );

        if(
            !isset($params['name'])
         || !isset($params['devurl'])
        ) {
            throw new \Exception('Missing mandatory parameters');
        }
        $data = array('project'=>$params);

        return $this->post('/projects.json', $data);
    }
1090436
protected function getRequestOptions(array $defaults = []) {

        $defaults = array_merge($this->getDefaultOptions(), $defaults);

        $page = $this->hasRequestParameter('page') ? $this->getRequestParameter('page') : $defaults['page'];
        $rows = $this->hasRequestParameter('rows') ? $this->getRequestParameter('rows') : $defaults['rows'];
        $sortBy = $this->hasRequestParameter('sortby') ? $this->getRequestParameter('sortby') : $defaults['sortby'];
        $sortOrder = $this->hasRequestParameter('sortorder') ? $this->getRequestParameter('sortorder') : $defaults['sortorder'];
        $filter = $this->hasRequestParameter('filter') ? $this->getRequestParameter('filter') : $defaults['filter'];
        $filterquery = $this->hasRequestParameter('filterquery') ? $this->getRequestParameter('filterquery') : $defaults['filter'];
        $periodStart = $this->hasRequestParameter('periodStart') ? $this->getRequestParameter('periodStart') : $defaults['periodStart'];
        $periodEnd = $this->hasRequestParameter('periodEnd') ? $this->getRequestParameter('periodEnd') : $defaults['periodEnd'];
        $detailed = $this->hasRequestParameter('detailed') ? $this->getRequestParameter('detailed') : 'false';
        $detailed = filter_var($detailed, FILTER_VALIDATE_BOOLEAN);

        return array(
            'page' => $page,
            'rows' => $rows,
            'sortBy' => $sortBy,
            'sortOrder' => $sortOrder,
            'filter' => $filter ? $filter : $filterquery,
            'periodStart' => $periodStart,
            'detailed' => $detailed,
            'periodEnd' => $periodEnd
        );

    }
1184796
public function withParams(array $params): ParamHolderInterface
    {
        $param_holder = clone $this;
        $param_holder->params = array_merge($param_holder->params, $params);
        return $param_holder;
    }
733607
public function add($object, $defaults = [])
    {
        if (!is_array($defaults)) {
            $defaults = ['name' => $defaults];
        }

        $defaults['join'] = $this;

        return $this->owner->add($object, $defaults);
    }
263093
protected function params(Request $request, array $params, $default = null)
    {
        $data = [];
        foreach ($params as $param) {
            $data[$param] = $request->getParam($param, $default);
        }

        return $data;
    }
1289536
public function UnifiedOrder($params)
    {
        $this->input = new UnifiedOrder();
        $params = array_merge($this->configs, $params);
        $this->setParams($params);
        return Api::unifiedOrder($this->input);
    }
1189977
public function mergeArgsAndParams(array $args, array $params = null)
    {

        if ($params) {
            foreach ($args as &$arg) {
                if (is_array($arg)) {
                    foreach ($params as &$param) {
                        if (is_array($param)) {
                            $arg = $param;
                            unset($param);
                            break;
                        }
                    }
                }
            }
        }

        if (is_array($params)) {
            return array_merge($args, $params);
        }

        return $args;
    }
403937
public function merge($opts)
    {
        $primary_opts = self::parse($opts);
        if ($primary_opts->apiKey === null) {
            $primary_opts->apiKey = $this->apiKey;
        }
        $primary_opts->headers = array_merge($this->headers, $primary_opts->headers);
        return $primary_opts;
    }
311485
private function setStatementIndex(array $params)
    {
        if (isset($params['index']) and $params['index']) {
            return $params;
        }

        // merge the default index with the given params if the index is not set.
        return array_merge($params, ['index' => $this->getDefaultIndex()]);
    }
595320
public static function mergeWithDefaultParams(&$params, $name = 'params')
    {
        $callers = debug_backtrace();

        if (isset($callers[1]['class'])) {
            $method = new ReflectionMethod($callers[1]['class'], $callers[1]['function']);
        } elseif (isset($callers[1]['function'])) {
            $method = new \ReflectionFunction($callers[1]['function']);
        } else {
            Throw new \Exception('Cannot resolve params merging');
        }

        $defParams = array();

        foreach ($method->getParameters() as $param) {
            if ($param->name == $name) {
                $defParams = $param->getDefaultValue();
            }
        }

        $params = array_merge($defParams, $params);

        return $params;
    }
172765
protected function getParam($param = null, $defaultValue = null)
    {
        $request = $this->getRequest();
        if ($param === null) {
            return array_merge($request->getQuery(), $request->getParams());
        }

        $value = $request->getParam($param);
        if ($value === null) {
            return $request->getQuery($param, $defaultValue);
        }

        return $value;
    }
790354
public function Merged($Key = NULL, $Default = NULL) {
      $Merged = array();
      $QueryOrder = array(
         self::INPUT_CUSTOM,
         self::INPUT_GET,
         self::INPUT_POST,
         self::INPUT_FILES,
         self::INPUT_SERVER,
         self::INPUT_ENV,
         self::INPUT_COOKIES
      );
      $NumDataTypes = sizeof($QueryOrder);
      for ($i=$NumDataTypes; $i > 0; $i--) {
         $DataType = $QueryOrder[$i-1];
         if (!array_key_exists($DataType, $this->_RequestArguments)) continue;
         $Merged = array_merge($Merged, $this->_RequestArguments[$DataType]);
      }
      
      return (is_null($Key)) ? $Merged : GetValue($Key, $Merged, $Default);
   }