List an object's properties in a nicely formatted table

@param   mixed       $values
@param   string      $options
@return  string
359654
public static function ls($values, $options = '')
		{
			$opts = new Options($options);
			$data =
			[
				'values'    => $values,
				'style'     => $opts->get('style', ''),
				'class'     => $opts->get('class', ''),
			];
			if($opts->pre === 1)
			{
				$data['class'] .= ' pre';
			}
			if($opts->wide)
			{
				$data['style'] .= ';width:100%;';
			}
			return view('sketchpad::html.list', $data);
		}
103617
public function getIdFromOptions(array $options) : string
    {
        $optionsResolver = new OptionsResolver();
        $optionsResolver->setRequired('id');

        $options = $optionsResolver->resolve($options);

        return $options['id'];
    }
19462
public function apply($value, $options = [])
    {
        $type = isset($options[0]) ? $options[0] : null;
        switch ($type) {
            case 'int':
            case 'integer':
                return (int) $value;
            case 'real':
            case 'float':
            case 'double':
                return (float) $value;
            case 'string':
                return (string) $value;
            case 'bool':
            case 'boolean':
                return (bool) $value;
            case 'object':
                return is_array($value) ? (object) $value : json_decode($value, false);
            case 'array':
                return json_decode($value, true);
            case 'collection':
                $array = is_array($value) ? $value : json_decode($value, true);
                return new Collection($array);
            default:
                throw new \InvalidArgumentException("Wrong Sanitizer casting format: {$type}.");
        }
    }
81665
public function renderValue($value, array $options = []): string
    {
        $object = isset($options['object']) ? $options['object'] : null;
        $column = isset($options['column']) ? $options['column'] : null;
        $attributeCode = isset($options['attribute']) ? $options['attribute'] : null;
        if ($column instanceof Column && null === $attributeCode) {
            $attributeCode = $column->getPropertyPath();
        }

        if ($object instanceof DataInterface && $attributeCode) {
            try {
                $attribute = $object->getFamily()->getAttribute($attributeCode);
            } catch (\Exception $e) {
                // do nothing, it's okay
                return $this->parent->renderValue($value, $options);
            }
            $formOptions = $attribute->getFormOptions();
            if (!isset($formOptions['choices'])
                || !\in_array($attribute->getType()->getCode(), $this->choiceTypes, true)
            ) {
                return $this->parent->renderValue($value, $options);
            }
            $key = array_search($value, $formOptions['choices'], true);
            if (false !== $key) {
                $translationDomain = null;
                if (array_key_exists('choice_translation_domain', $formOptions)) {
                    $translationDomain = $formOptions['choice_translation_domain'];
                }
                if (false === $translationDomain) {
                    return $key;
                }

                return $this->translator->trans($key, [], $translationDomain);
            }
        }

        return $this->parent->renderValue($value, $options);
    }
393309
public static function listFormat($model, $attribute, $options = [])
    {
        $listFunction = function ($model, $attribute) {
            $method = static::listName($attribute);
            $key = get_class($model) . $attribute;
            return static::$lists[$key] = method_exists(get_class($model), $method) && isset(static::$lists[$key])
                ? static::$lists[$key] : $model->$method();
        };

        $list = $listFunction($model, $attribute);
        return array_merge([
            'attribute' => $attribute,
            'format' => 'raw',
            'value' => !$model->isNewRecord
                ? @$list[$model->$attribute]
                : function ($data) use ($listFunction, $attribute) {
                    return @$listFunction($data, $attribute)[$data->$attribute];
                },
            'filter' => $list ? : null,
            'visible' => $model->isAttributeSafe($attribute),
        ], $options);
    }
24747
public function filter($value, array $options = [])
    {
        return is_string($value)
            ? filter_var(Str::lower(trim($value)), FILTER_SANITIZE_EMAIL)
            : $value;
    }
57017
public function definitionList(array $data, array $options = []): string
    {
        $options = Hash::merge([
            'class' => 'dl-horizontal',
            'escape' => true,
        ], $options);
        $ret = '<dl class="' . $options['class'] . '">';
        foreach ($data as $key => $value) {
            $ret .= '<dt>' . $key . '</dt>';
            $ret .= '<dd>' . (empty($value) ? '&nbsp;' : ($options['escape'] ? h($value) : $value)) . '</dd>';
        }
        $ret .= '</dl>';

        return $ret;
    }
141747
public function tryGetOptionsForValues(array $values): array
    {
        if ($this->specificFieldOptionLoader) {
            return array_filter(array_map($this->specificFieldOptionLoader, $values));
        } else {
            return (new ArrayFieldOptions(call_user_func($this->fieldOptionsLoader)))->tryGetOptionsForValues($value);
        }
    }
1201581
protected function getCacheKey($value, $options)
    {
        if (is_scalar($value)) {
            $data = $value;
        } elseif (is_array($value) && 'eq' == strtolower($value[0])) {
            $data = $value[1];
        }

        if (isset($data)) {
            return 'mongo:' . $options['table'] . '|' . $data;
        } else {
            return md5(serialize($options));
        }
    }
716897
public function listing($options = []) {
		$this->getController()->set('users', $this->getController()->paginate($this->UserTable, $options));
		$this->getController()->set('_serialize', ['users']);
	}
766840
public function renderValue($value, array $options = []): string
    {
        $resolver = new OptionsResolver();
        $this->configureOptions($resolver);
        $options = $resolver->resolve($options);

        if ($value instanceof \DateTimeInterface) {
            if (null !== $options['date_format']) {
                return (string) $value->format($options['date_format']);
            }
            if ($value->format('H:i') === '00:00') {
                $options['time_type'] = \IntlDateFormatter::NONE;
            }
            $dateFormatter = new \IntlDateFormatter(
                $this->translator->getLocale(),
                $options['date_type'],
                $options['time_type']
            );

            return (string) $dateFormatter->format($value);
        }
        if (\is_int($value)) {
            return (string) $value;
        }
        if (\is_float($value)) {
            if (null !== $options['decimals'] || null !== $options['dec_point'] || null !== $options['thousands_sep']) {
                return number_format(
                    $value,
                    $options['decimals'] ?: 2,
                    $options['dec_point'] ?: '.',
                    $options['thousands_sep'] ?: ','
                );
            }
            $numberFormatter = new \NumberFormatter($this->translator->getLocale(), $options['number_format']);

            return (string) $numberFormatter->format($value);
        }
        if (\is_iterable($value)) {
            $items = [];
            /** @noinspection ForeachSourceInspection */
            foreach ($value as $key => $item) {
                $rendered = $this->renderValue($item, $options);
                if (!is_numeric($key)) {
                    $rendered = $key.$options['key_value_separator'].$rendered;
                }
                $items[] = $rendered;
            }

            return implode($options['array_glue'], $items);
        }
        if (\is_bool($value)) {
            if ($options['bool_use_translator']) {
                return (string) $this->translator->trans(
                    $value ? $options['bool_true'] : $options['bool_false']
                );
            }

            return $value ? $options['bool_true'] : $options['bool_false'];
        }

        return (string) $value;
    }
1209268
protected function getListValues($values)
    {
        // Empty values
        if (empty($values)) {
            return array();
        }

        // Direct array
        if (is_array($values)) {
            return array_values($values);
        }

        // Extract lists
        if ($values instanceof SS_List) {
            return $values->column('ID');
        }

        return array(trim($values));
    }
1029370
public function getWhereIn($column, array $values, array $options = [])
    {
        $query = $this->createBaseBuilder($options);

        $query->whereIn($column, $values);

        return $query->get();
    }
308275
static public function renderField($value, array $options, $item)
    {
        if (empty($options['name'])) {
            return '';
        }
        if (empty($value) || !is_array($value)) {
            return '';
        }

        if (!$item instanceof EntityInterface) {
            return '';
        }

        $output = field_view_field($item->getEntityTypeId(), $item, $options['name'], self::LIST_VIEW_MODE);

        return drupal_render($output);
    }
1282816
protected function databaseValue($values)
    {
        if (!is_array($values)) {
            throw ODMException::invalidValueForType('List', ['array', 'null'], $values);
        }

        //re-index numerically
        $values = array_values($values); //TODO: Remove me? handle in CollectionPersister?

        return $values;
    }
870313
public static function toFloat($value, array $options = array())
    {
        $options['number_format'] = Zend_Locale_Format::STANDARD;
        return self::toNumber($value, $options);
    }
514633
final public function get($options = []) {
		// process parameters
		$parameters = [];
		$options['where'] = $options['where'] ?? [];
		if (!empty($this->parameters)) {
			$this->parameters = \Object\Data\Common::processDomainsAndTypes($this->parameters);
			foreach ($this->parameters as $k => $v) {
				// if we have a parameter
				if (array_key_exists($k, $options['where'])) {
					if (!empty($v['multiple_column'])) {
						if (!is_array($options['where'][$k])) $options['where'][$k] = [$options['where'][$k]];
						$parameters[$k] = [];
						foreach ($options['where'][$k] as $v2) {
							$result = \Object\Table\Columns::validateSingleColumn($k, $v, $v2);
							if (!$result['success']) {
								Throw new \Exception("Datasource: " . get_called_class() . " parameter: {$k} error" . implode(', ', $result['error']));
							} else {
								$parameters[$k][] = $result['data'][$k];
							}
						}
					} else {
						$result = \Object\Table\Columns::validateSingleColumn($k, $v, $options['where'][$k]);
						if (!$result['success']) {
							Throw new \Exception("Datasource: " . get_called_class() . " parameter: {$k} error" . implode(', ', $result['error']));
						} else {
							$parameters[$k] = $result['data'][$k];
						}
					}
				}
				// required
				if (!empty($v['required']) && empty($parameters[$k])) {
					return [];
					//Throw new \Exception("Datasource: " . get_called_class() . " parameter: {$k} error" . i18n(null, \Object\Content\Messages::required_field));
				}
			}
		}
		// we need to push existing values to parameters
		if (!empty($options['existing_values']) && !empty($this->parameters['existing_values'])) {
			$parameters['existing_values'] = $options['existing_values'];
		}
		$where = $options['where'] ?? [];
		unset($options['where']);
		// process primary model
		if (!empty($this->primary_model)) {
			$model = new $this->primary_model();
			$this->db_link = $model->db_link;
			if (empty($this->pk)) $this->pk = $model->pk;
			$this->cache_tags = array_merge($this->cache_tag ?? [], $model->cache_tags);
			if (!empty($this->primary_params)) {
				$options = array_merge_hard($options, $this->primary_params);
			}
			$options['where'] = $where[$this->primary_model] ?? [];
			unset($where[$this->primary_model]);
			foreach ($where as $k => $v) {
				if (strpos($k, '\\') === 0) {
					$options['where'][$k] = $v;
				}
			}
			// query
			$this->query = call_user_func_array([$this->primary_model, 'queryBuilderStatic'], [$options])->select();
		}
		// we need to determine db link
		if (empty($this->db_link)) {
			// get from flags first
			if (!empty($this->db_link_flag)) {
				$this->db_link = \Application::get($this->db_link_flag);
			}
			// get default link
			if (empty($this->db_link)) {
				$this->db_link = \Application::get('flag.global.default_db_link');
			}
			// if we could not determine the link we throw exception
			if (empty($this->db_link)) {
				Throw new \Exception('Could not determine db link in datasource!');
			}
		}
		// create empty query object
		if (empty($this->query)) {
			$this->query = new \Object\Query\Builder($this->db_link, $options);
			$this->query->select();
		}
		// add settings to query
		$query_settings = [];
		foreach (['pk', 'columns', 'limit', 'orderby', 'single_row', 'single_value'] as $v) {
			if (array_key_exists($v, $options)) {
				$query_settings[$v] = $options[$v];
			} else if (isset($this->{$v})) {
				$query_settings[$v] = $this->{$v};
			}
		}
		if (isset($query_settings['columns'])) $this->query->columns($query_settings['columns']);
		if (isset($query_settings['limit'])) $this->query->limit($query_settings['limit']);
		if (isset($query_settings['orderby'])) $this->query->limit($query_settings['orderby']);
		if (!empty($query_settings['single_row']) || !empty($query_settings['single_value'])) $this->query->limit(1);
		// fix variables
		$query_settings['pk'] = $query_settings['pk'] ?? null;
		if (empty($this->cache_tags)) $this->cache_tags = [];
		// check if we have query method
		if (!method_exists($this, 'query')) {
			Throw new \Exception('You must specify sql in query method!');
		}
		// process query
		$sql = $this->query($parameters, $options);
		if (!empty($sql)) {
			$db_object = new \Db($this->db_link);
			$this->sql_last_query = $sql;
		} else {
			$db_object = $this->query->db_object;
			$this->sql_last_query = $this->query->sql();
			// grab cache tags from query object
			if (!empty($this->query->cache_tags)) {
				$this->cache_tags = array_unique(array_merge($this->cache_tags, $this->query->cache_tags));
			}
		}
		// determine caching strategy
		if (method_exists($this, 'process')) {
			// retrive data from the cache
			if ($this->cache && !empty($db_object->object->options['cache_link'])) {
				$cache_id = !empty($options['cache_id']) ? $options['cache_id'] : 'Db_DataSource_' . trim(sha1($this->sql_last_query . serialize($query_settings['pk'])));
				// if we cache this query
				$cache_object = new \Cache($db_object->object->options['cache_link']);
				$cached_result = $cache_object->get($cache_id, true);
				if ($cached_result !== false) {
					// if we are debugging
					if (\Debug::$debug) {
						\Debug::$data['sql'][] = $cached_result;
					}
					return $cached_result['rows'];
				}
			} else {
				$this->cache = false;
			}
		}
		$query_options = [
			'cache' => $this->cache,
			'cache_tags' => array_unique($this->cache_tags)
		];
		// if we need to return a query
		if (!empty($options['return_query_only'])) {
			if (empty($sql)) {
				$sql = $this->query->sql();
			}
			// wrap into tabs
			if ($options['return_query_only'] == 'wrap') {
				$object = new \Object\Query\Builder($this->db_link, []);
				$sql = '(' . $object->wrapSqlIntoTabs($sql) . ')';
			}
			return [
				'sql' => $sql,
				'cache_tags' => array_unique($this->cache_tags)
			];
		}
		// if we have SQL
		if (!empty($sql)) {
			$result = $db_object->query($sql, $query_settings['pk'], $query_options);
		} else { // query builder
			$result = $this->query->query($query_settings['pk'], $query_options);
		}
		if (!$result['success']) {
			Throw new \Exception(implode(", ", $result['error']));
		}
		// put parameters beck into options
		$options['parameters'] = $parameters;
		// process data
		if (method_exists($this, 'process')) {
			$data = $this->process($result['rows'], $options);
			// if we are caching
			if ($this->cache) {
				// the same cache structure as in Db classes
				$cache_data = [
					'success' => true,
					'error' => [],
					'errno' => 0,
					'rows' => $data,
					'num_rows' => is_bool($data) ? 0 : count($data),
					'affected_rows' => 0,
					'structure' => [],
					// debug attributes
					'cache' => true,
					'cache_tags' => [],
					'time' => microtime(true),
					'sql' => $this->sql_last_query,
					'key' => $query_settings['pk'],
					'backtrace' => null
				];
				if (\Debug::$debug) {
					$cache_data['backtrace']  = implode("\n", \Object\Error\Base::debugBacktraceString());
					$cache_data['cache_tags'] = $this->cache_tags;
				}
				$cache_object->set($cache_id, $cache_data, null, $this->cache_tags);
			}
		} else {
			$data = $result['rows'];
		}
		// process not cached
		if (method_exists($this, 'processNotCached')) {
			$data = $this->processNotCached($data, $options);
		}
		// single row
		if (!empty($query_settings['single_row']) && !empty($data)) {
			$data = current($data);
		}
		// single value
		if (!empty($query_settings['single_value']) && !empty($data)) {
			$data = current($data);
			if (!empty($data)) {
				$data = current($data);
			}
		}
		return $data;
	}