Get project version

@option string $format Output format (table, list, csv, json, xml)
@option string $fields Limit output to given fields, comma-separated

@return PropertyList result
347440
public function projectVersion($opts = ['format' => 'table', 'fields' => ''])
    {
        $result = $this->taskDotenvReload()->run();

        $envVersion = getenv('GIT_BRANCH');
        if (!empty($envVersion)) {
            return new PropertyList(['version' => $envVersion]);
        }

        $result = $this->taskGitHash()->run();
        if ($result->wasSuccessful()) {
            return new PropertyList(['version' => $result->getData()['data'][0]['message'] ]);
        }

        return new PropertyList(['version' => 'Unknown']);
    }
408077
public function collection(string $collection, ?string $format = null) : string {
        list($collection, $extension) = preg_split('/\.(css|js)/', $collection, 2, PREG_SPLIT_DELIM_CAPTURE);

        $group = $extension == 'css' ? 'stylesheets' : 'javascripts';

        return $this->serve($collection, $group, $format);
    }
276408
public function FieldHolder($properties = array())
    {
        $columns = $this->getColumns();

        $list = $this->getManipulatedList();

        $content = array(
            'before' => '',
            'after' => '',
            'header' => '',
            'footer' => '',
        );

        foreach ($this->getComponents() as $item) {
            if ($item instanceof GridField_HTMLProvider) {
                $fragments = $item->getHTMLFragments($this);

                if ($fragments) {
                    foreach ($fragments as $fragmentKey => $fragmentValue) {
                        $fragmentKey = strtolower($fragmentKey);

                        if (!isset($content[$fragmentKey])) {
                            $content[$fragmentKey] = '';
                        }

                        $content[$fragmentKey] .= $fragmentValue . "\n";
                    }
                }
            }
        }

        foreach ($content as $contentKey => $contentValue) {
            $content[$contentKey] = trim($contentValue);
        }

        // Replace custom fragments and check which fragments are defined. Circular dependencies
        // are detected by disallowing any item to be deferred more than 5 times.

        $fragmentDefined = array(
            'header' => true,
            'footer' => true,
            'before' => true,
            'after' => true,
        );
        $fragmentDeferred = [];

        // TODO: Break the below into separate reducer methods

        // Continue looping if any placeholders exist
        while (array_filter($content, function ($value) {
            return preg_match(self::FRAGMENT_REGEX, $value);
        })) {
            foreach ($content as $contentKey => $contentValue) {
                // Skip if this specific content has no placeholders
                if (!preg_match_all(self::FRAGMENT_REGEX, $contentValue, $matches)) {
                    continue;
                }
                foreach ($matches[1] as $match) {
                    $fragmentName = strtolower($match);
                    $fragmentDefined[$fragmentName] = true;

                    $fragment = '';

                    if (isset($content[$fragmentName])) {
                        $fragment = $content[$fragmentName];
                    }

                    // If the fragment still has a fragment definition in it, when we should defer
                    // this item until later.

                    if (preg_match(self::FRAGMENT_REGEX, $fragment, $matches)) {
                        if (isset($fragmentDeferred[$contentKey]) && $fragmentDeferred[$contentKey] > 5) {
                            throw new LogicException(sprintf(
                                'GridField HTML fragment "%s" and "%s" appear to have a circular dependency.',
                                $fragmentName,
                                $matches[1]
                            ));
                        }

                        unset($content[$contentKey]);

                        $content[$contentKey] = $contentValue;

                        if (!isset($fragmentDeferred[$contentKey])) {
                            $fragmentDeferred[$contentKey] = 0;
                        }

                        $fragmentDeferred[$contentKey]++;

                        break;
                    } else {
                        $content[$contentKey] = preg_replace(
                            sprintf('/\$DefineFragment\(%s\)/i', $fragmentName),
                            $fragment,
                            $content[$contentKey]
                        );
                    }
                }
            }
        }

        // Check for any undefined fragments, and if so throw an exception.
        // While we're at it, trim whitespace off the elements.

        foreach ($content as $contentKey => $contentValue) {
            if (empty($fragmentDefined[$contentKey])) {
                throw new LogicException(sprintf(
                    'GridField HTML fragment "%s" was given content, but not defined. Perhaps there is a supporting GridField component you need to add?',
                    $contentKey
                ));
            }
        }

        $total = count($list);

        if ($total > 0) {
            $rows = array();

            foreach ($list as $index => $record) {
                if ($record->hasMethod('canView') && !$record->canView()) {
                    continue;
                }

                $rowContent = '';

                foreach ($this->getColumns() as $column) {
                    $colContent = $this->getColumnContent($record, $column);

                    // Null means this columns should be skipped altogether.

                    if ($colContent === null) {
                        continue;
                    }

                    $colAttributes = $this->getColumnAttributes($record, $column);

                    $rowContent .= $this->newCell(
                        $total,
                        $index,
                        $record,
                        $colAttributes,
                        $colContent
                    );
                }

                $rowAttributes = $this->getRowAttributes($total, $index, $record);

                $rows[] = $this->newRow($total, $index, $record, $rowAttributes, $rowContent);
            }
            $content['body'] = implode("\n", $rows);
        }

        // Display a message when the grid field is empty.
        if (empty($content['body'])) {
            $cell = HTML::createTag(
                'td',
                array(
                    'colspan' => count($columns),
                ),
                _t('SilverStripe\\Forms\\GridField\\GridField.NoItemsFound', 'No items found')
            );

            $row = HTML::createTag(
                'tr',
                array(
                    'class' => 'ss-gridfield-item ss-gridfield-no-items',
                ),
                $cell
            );

            $content['body'] = $row;
        }

        $header = $this->getOptionalTableHeader($content);
        $body = $this->getOptionalTableBody($content);
        $footer = $this->getOptionalTableFooter($content);

        $this->addExtraClass('ss-gridfield grid-field field');

        $fieldsetAttributes = array_diff_key(
            $this->getAttributes(),
            array(
                'value' => false,
                'type' => false,
                'name' => false,
            )
        );

        $fieldsetAttributes['data-name'] = $this->getName();

        $tableId = null;

        if ($this->id) {
            $tableId = $this->id;
        }

        $tableAttributes = array(
            'id' => $tableId,
            'class' => 'table grid-field__table',
            'cellpadding' => '0',
            'cellspacing' => '0'
        );

        if ($this->getDescription()) {
            $content['after'] .= HTML::createTag(
                'span',
                array('class' => 'description'),
                $this->getDescription()
            );
        }

        $table = HTML::createTag(
            'table',
            $tableAttributes,
            $header . "\n" . $footer . "\n" . $body
        );

        return HTML::createTag(
            'fieldset',
            $fieldsetAttributes,
            $content['before'] . $table . $content['after']
        );
    }
947949
public function jsonSerialize()
    {
        $output = [];
        foreach ($this::getReflection()->getProperties() as $propertyName => $property) {

            $value = $this->{$propertyName};
            if ($value instanceof Entity\Collection || $value instanceof Entity) {
                $output[$propertyName] = $value->jsonSerialize();
            } elseif ($value instanceof \DateTime
                && $property->getType() === Entity\Reflection\Property::TYPE_DATE
            ) {
                $output[$propertyName] = (array) $value;
                $output[$propertyName]["date"] = $value->format(self::$dateFormat);
            } else {
                $output[$propertyName] = $value;
            }
        }

        return $output;
    }
251995
public function get($field) {
        if ($field == 'format') {
            return portfolio_format_object($this->format);
        } else if ($field == 'formatclass') {
            return $this->format;
        }
        if (property_exists($this, $field)) {
            return $this->{$field};
        }
        $a = (object)array('property' => $field, 'class' => get_class($this));
        throw new portfolio_export_exception($this, 'invalidproperty', 'portfolio', null, $a);
    }
451491
public function Field($properties = [])
    {
        $label = $this->valueToLabel();
        if (!is_null($label)) {
            $attrValue = Convert::raw2xml($label);
            $inputValue = $this->value;
        } else {
            $attrValue = '<i>(' . _t('SilverStripe\\Forms\\FormField.NONE', 'none') . ')</i>';
            $inputValue = '';
        }

        $properties = array_merge($properties, array(
            'AttrValue' => DBField::create_field('HTMLFragment', $attrValue),
            'InputValue' => $inputValue
        ));

        return parent::Field($properties);
    }
140753
private function headersFromFormat($format)
	{
		$type = gettype($format);
		if($type === 'array')
		{
			$headers = $format;
		}
		else if($type === 'string')
		{
			$headers = array();
			switch ($format) 
			{
				case 'json':
					$contentType = 'application/json';
					break;
				case 'jsonp':
					$contentType = 'application/javascript';
					break;
				default:
					$contentType = 'text/plain';
					break;
			}
			$headers['Content-Type'] = $contentType;
		}
		return $headers;
	}
897916
protected function getValuesJSON() {
		$value = $this->value;
		if($value instanceof SS_List) {
			$values = $value->column($this->idField);
		}
		else if(is_array($value)) {
			$values = array_keys($value);
		}
		else if(is_string($value)) {
			$values = explode(',', $value);
			$values = str_replace('{comma}', ',', $values);
		}

		return $this->formatJSON($this->source->filter(array(
			$this->idField => $values
		)));
	}
815991
private function parametrize($fields = [])
    {
        return (string) implode(', ', array_map(function ($field) {
            $field = $this->reference->usesPropertyConstants()
                ? $this->pivot->getQualifiedUserClassName().'::'.strtoupper($field)
                : $field;

            return Dumper::export($field);
        }, $fields));
    }
787694
public static function getFormattedOrphans($format = 'ini')
    {
        $formatter = StructureHelper::getFormatClass($format);

        $returns = [];
        $options = [];

        switch (strtolower($format)) {
            case 'ini':
                $orphans = static::getAutoHandledOrphans();

                foreach ($orphans as $key => $value) {
                    $key2 = explode('.', $key);

                    if (isset($key2[1])) {
                        $returns[$key2[1]][$key] = $value;

                        continue;
                    }

                    $returns[$key] = $value;
                }

                break;

            case 'yaml':
            case 'yml':
                $options['inline'] = 99;
            // No break
            default:
                $orphans = static::getAutoHandledOrphans(false);
                $returns = $orphans;
        }

        return $formatter::structToString($returns, $options);
    }
1182535
public function optionVersion()
    {
        if (property_exists($this, 'commandVersion')) {
            if ( ! empty($this->commandVersion)) {
                // Show Name & Version Line
                output()->write(
                    (new Format())
                        ->setContextualClass(Format::INFO)
                        ->setString(ucfirst($this->commandName) . ' v' . $this->commandVersion)
                        ->setNewLinesAfter(1)
                );
            }
        }
    }
509520
protected function parsedFormProperties()
    {
        if ($this->parsedFormProperties === null) {
            $this->finalizeStructure();

            $groupProperties     = $this->groupProperties();
            $availableProperties = $this->structProperties();

            $structProperties = [];
            if (!empty($groupProperties)) {
                foreach ($groupProperties as $propertyIdent => $propertyMetadata) {
                    if (is_string($propertyMetadata)) {
                        $propertyIdent    = $propertyMetadata;
                        $propertyMetadata = null;
                    }

                    if (!isset($availableProperties[$propertyIdent])) {
                        continue;
                    }

                    if (is_array($propertyMetadata)) {
                        $propertyMetadata = array_merge($propertyMetadata, $availableProperties[$propertyIdent]);
                    } else {
                        $propertyMetadata = $availableProperties[$propertyIdent];
                    }

                    $structProperties[$propertyIdent] = $propertyMetadata;
                }
            }

            if (empty($structProperties)) {
                $structProperties = $availableProperties;
            }

            $this->parsedFormProperties = $structProperties;
        }

        return $this->parsedFormProperties;
    }
974520
public function convertDataObjectSet(SS_List $set, $fields = null)
    {
        Controller::curr()->getResponse()->addHeader("Content-Type", "text/xml");
        $className = $this->sanitiseClassName(get_class($set));

        $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
        $xml .= (is_numeric($this->totalSize)) ? "<$className totalSize=\"{$this->totalSize}\">\n" : "<$className>\n";
        foreach ($set as $item) {
            $xml .= $this->convertDataObjectWithoutHeader($item, $fields);
        }
        $xml .= "</$className>";

        return $xml;
    }
898688
public function convertToCSVRecord(array $fields): string
    {
        $csv = new \SplTempFileObject();
        $csv->fputcsv($fields);
        $csv->rewind();
        return rtrim($csv->fgets(), "\r\n");
    }
529463
public function projectBranch($opts = ['format' => 'table', 'fields' => ''])
    {
        $result = $this->taskProjectBranch()
            ->run();

        if (!$result->wasSuccessful()) {
            $this->exitError("Failed to run command");
        }

        $data = $result->getData();
        return new PropertyList(['branch' => $data['data'][0]['message']]);
    }
303775
public function Field($properties = array())
    {
        $options = array();

        foreach ($this->getOptions()->filter('Selected', true) as $option) {
            $options[] = $option->Title;
        }

        $field = ReadonlyField::create($this->name . '_Readonly', $this->title);

        $field->setForm($this->form);
        $field->setValue(implode(', ', $options));
        return $field->Field();
    }
857504
public function format()
    {
        $ret = '';

        foreach (self::$formats as $key => $format) {
            $value = $this->get($key);

            // -stable is not added to the version, it is implied
            if ($key == self::STABILITY && $value == end(self::$stabilities)) {
                break;
            }

            $ret .= sprintf($format, $value);

            // -dev has no stability increments
            if ($key == self::STABILITY && $value == self::$stabilities[0]) {
                break;
            }
        }

        return $ret;
    }