Analyzes an RFA section. Returns an array of parsed signatures on success. Undefined behaviour on failure.
@param string $input

@return array
337578
private function analyzeSection( $input ) {
		//Remove trailing sharp, if any
		$input = preg_replace( '/#\s*$/', '', $input );

		//Old preg_split regex: "/(^|\n)\s*\#[^\#\:\*]/"
		$parsed = preg_split( "/(^|\n)\#/", $input );
		//Shift off first empty element:
		array_shift( $parsed );

		foreach( $parsed as &$parsee ){ //Foreach line
			//If the line is empty for some reason, ignore
			$parsee = trim( $parsee );
			if( empty( $parsee ) ) continue;

			//If the line has been indented (disabled), or is a comment, ignore
			if( ( $parsee[0] == ':' ) || ( $parsee[0] == '*' ) || ( $parsee[0] == '#' ) ) {
				$parsee = '///###///';
				continue;
			}; //struck-out vote or comment

			$parsedsig = $this->findSigInLine( $parsee, $iffy ); //Find signature
			$orgsig = $parsee;
			$parsee = array();
			$parsee['context'] = $orgsig;
			if( $parsedsig === false ) {
				$parsee['error'] = 'Signature not found';
			} else {
				$parsee['name'] = $parsedsig;
			}
			if( @$iffy == 1 ) {
				$parsee['iffy'] = '1';
			}
		} //Foreach line

		if( ( count( $parsed ) == 1 ) && ( @trim( $parsed[0]['name'] ) == '' ) ) { //filters out placeholder sharp sign used in empty sections
			$parsed = array();
		}

		//Delete struck-out keys "continued" in foreach
		foreach( $parsed as $key => $value ){
			if( $value == '///###///' ) {
				unset( $parsed[$key] );
			}
		}

		return $parsed;
	}
400623
private function inputInOpenStringOrComment($input)
    {
        if (!$this->hasCode()) {
            return;
        }

        $code = $this->codeBuffer;
        \array_push($code, $input);
        $tokens = @\token_get_all('<?php ' . \implode("\n", $code));
        $last = \array_pop($tokens);

        return $last === '"' || $last === '`' ||
            (\is_array($last) && \in_array($last[0], [T_ENCAPSED_AND_WHITESPACE, T_START_HEREDOC, T_COMMENT]));
    }
1110234
public function markDeleted(array $input) : array {
		$input[\Object\Form\Parent2::BUTTON_SUBMIT_SAVE] = true;
		$input[\Object\Form\Parent2::BUTTON_SUBMIT_MARK_DELETED] = true;
		$this->form->form_object->addInput($input);
		$this->form->form_object->process();
		return $this->form->form_object->apiResult();
	}
872169
protected function doUnprocess($input)
    {
        $columns = [];
        $rows    = [];
        $cells   = [];

        $columnObjects = $input->getColumns();
        $rowObjects    = $input->getRows();

        $columnKey = 0;
        foreach ($columnObjects as $column) {
            $columns[$columnKey] = $column->getKey();
            $columnKey++;
        }

        $rowKey = 0;
        foreach ($rowObjects as $row) {
            $rows[$rowKey] = $row->getKey();

            $columnKey = 0;
            foreach ($columnObjects as $column) {
                $cells[$rowKey][$columnKey] = $row[$column];
                $columnKey++;
            }

            $rowKey++;
        }

        $data                           = [];
        $data[TableType::COLUMNS_FIELD] = $columns;

        if ($this->includeRows) {
            $data[TableType::ROWS_FIELD] = $rows;
        }

        $data[TableType::CELLS_FIELD] = $cells;


        return $data;
    }
188186
public static function extractHeadersAndBodyStartOffset($input)
    {
        self::_setup($input);

        if (self::PROCMODE_FILE === self::$_mode)
            self::_processFile();
        else if (self::PROCMODE_STRING === self::$_mode)
            self::_processString();
        else
            throw new \DomainException('CURLHeaderExtractor - Invalid state');

        return array(self::$_headers, self::$_bodyStartByteOffset);
    }
611800
public function parseType(string $input)
    {
        $matches = $properties = [];
        if (\preg_match(self::STRUCT, trim($input), $matches)) {
            /* Optional parse properties of the struct, could be empty complex types */
            \preg_match_all(self::PROPERTY, $matches['properties'], $properties);

            $struct = new Struct();
            $struct->setName($matches['name']);

            for ($x = 0, $max = count($properties['name']); $x < $max; $x++) {
                $type = $this->convertWsdlTypeToPhpType($properties['type'][$x]);
                $name = $this->covertNameToPhpName($properties['name'][$x]);
                $struct->addProperty(new Property($name, $type));
            }

            return $struct;
        } elseif (\preg_match(self::ARRAY_OF_COMPLEX_TYPE, trim($input), $matches)) {
            $struct = new Struct();
            $struct->setName($matches['name']);
            $struct->addProperty(new Property($matches['type'], $matches['type'] . '[]'));
            return $struct;
        } elseif (\preg_match(self::SIMPLE_TYPE, trim($input), $matches)) {
            return new Property($matches['name'], $matches['type']);
        } else {
            throw new \Exception(sprintf('Unable to parse input [%s]', $input));
        }
    }
611022
public function getLibraryFiles($input)
    {
        // assume the result is the same string as the input
        $result = array($input);

        // just change if method for changing/translation exists
        if (method_exists($this, 'getRequiredLibraryFiles')) {
            $result = $this->getRequiredLibraryFiles($input);
        }

        // and finally return the resulting string
        return $result;
    }
851834
private function convert($input)
    {
        if (is_array($data = json_decode($input, true))) {
            if (array_key_exists('signatures', $data) || array_key_exists('recipients', $data)) {
                return $data;
            } elseif (array_key_exists('signature', $data)) {
                return $this->fromFlattenedSerializationSignatureToSerialization($data);
            } elseif (array_key_exists('ciphertext', $data)) {
                return $this->fromFlattenedSerializationRecipientToSerialization($data);
            }
        } elseif (is_string($input)) {
            return $this->fromCompactSerializationToSerialization($input);
        }

        throw new \InvalidArgumentException('Unsupported input');
    }
1277076
protected function findSigInLine( $input, &$iffy ) {
		$iffy = 0;

		$parsee_array = explode( "\n", $input );
		for( $n = 0; $n < count( $parsee_array ); $n++ ){ //This for will terminate when a sig is found.
			$parsee = $parsee_array[$n];
			//Okay, let's try and remove "copied from above" messages. If the line has more than one timestamp, we'll disregard anything after the first.
			//Note: we're ignoring people who use custom timestamps - if these peoples' votes are moved, the mover's name will show up as having voted.

			//If more than one timestamp is found in the first portion of the vote:
			$tsmatches = array();
			$dummymatches = array();
			if( preg_match_all( '/' . "[0-2][0-9]\:[0-5][0-9], [1-3]?[0-9] (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{4} \(UTC\)" . '/', $parsee, $tsmatches, PREG_OFFSET_CAPTURE ) > 1 ) {
				//Go through each timestamp-section, looking for a signature
				foreach( $tsmatches[0] as $minisection ){
					$temp = substr( $parsee, 0, $minisection[1] );
					//If a signature is found, stop and use it as voter
					if( $this->findSig( $temp, $dummymatches ) != 0 ) { //KNOWN ISSUE: Write description later
						$parsee = $temp;
						break;
					}
				}
			}

			//Start the main signature-finding:
			$matches = array();
			if( $this->findSig( $parsee, $matches ) == 0 ) {
				//Okay, signature not found. Let's try the backup regex
				if( $this->findSigAlt( $parsee, $matches ) == 0 ) {
					//Signature was not found in this iteration of the main loop :(
					continue; //Go on to next newline (may be iffy)
				} else {
					$merged = array_merge( $matches[1], $matches[2] );
				}
			} else {
				//Merge the match arrays:
				$merged = array_merge( $matches[5], $matches[1], $matches[3], $matches[2], $matches[4] );
			}
			//Remove blank values and arrays of the form ('',-1):
			foreach( $merged as $key => $value ){
				if( is_array( $value ) && ( $value[0] == '' ) && ( $value[1] == -1 ) ) {
					unset( $merged[$key] );
				} elseif( $value == "" ) {
					unset( $merged[$key] );
				}
			}

			//Let's find out the real signature
			$keys = array();
			$values = array();
			foreach( $merged as $mergee ){
				$keys[] = $mergee[0];
				$values[] = $mergee[1];
			}
			//Now sort:
			array_multisort( $values, SORT_DESC, SORT_NUMERIC, $keys );
			//Now we should have the most relevant match (i.e., the sig) at the top of $keys
			$i = 0;
			$foundsig = '';
			while( $foundsig == '' ){
				$foundsig = trim( $keys[$i++] );
				if( $i == count( $keys ) ) break; //If we can only find blank usernames in the sig, catch overflow
				//Also fires when the first sig is also the last sig, so not an error
			}

			//Set iffy flag (level 1) if went beyond first line
			if( $n > 0 ) {
				$iffy = 1;
			}
			return $foundsig;
		}

		return false;
	}
1058542
protected function parseTable($input)
    {
        $input = (array) $input;

        return array_map(function ($key, $value) {
            $bytes = ['used_memory', 'free_memory', 'wasted_memory', 'buffer_size'];
            $times = ['start_time', 'last_restart_time'];

            if (in_array($key, $bytes)) {
                $value = number_format($value / 1048576, 2).' MB';
            } elseif (in_array($key, $times)) {
                $value = date('Y-m-d H:i:s', $value);
            }

            return [
                'key'       => $key,
                'value'     => $value,
            ];
        }, array_keys($input), $input);
    }
373521
public function refreshAuthority($inputs)
    {
        $result = $this->restCall('RefreshAuthority.json', $inputs);

        if ($result['Status'] == 100 || $result['Status'] == 101) {
            return ['Status' => 'success', 'refreshed' => true];
        } else {
            return ['Status' => 'error', 'error' => $result['Status']];
        }
    }
650594
public function check(array $input)
    {
        // Automatic reset
        if (count($this->pending) === 0) {
            foreach (Arr::keys($this->nodes) as $name) {
                if (count($this->incomingEdges[$name]) === 0) {
                    $this->pending[] = $name;
                }
            }

            $this->checked = [];
            $this->results = [];
            $this->failed = false;
        }

        // Actual process
        while (count($this->checked) < count($this->nodes)) {
            if (count($this->pending) === 0) {
                throw new CoreException('Unable to resolve constraint graph.');
            }

            $this->iterate($input);

            if ($this->failed) {
                $this->pending = [];
                break;
            }
        }

        // Aggregate results
        $missing = [];
        $failed = [];

        array_map(function (SpecResult $result) use (&$missing, &$failed) {
            $missing[] = $result->getMissing();
            $failed[] = $result->getFailed();
        }, $this->checked);

        return new SpecResult(
            Arr::mergev($missing),
            Arr::mergev($failed),
            $this->failed ? SpecResult::STATUS_FAIL : SpecResult::STATUS_PASS
        );
    }
535183
public function get(array $input) : array {
		$this->form->form_object->addInput($input);
		$this->form->form_object->process();
		return $this->form->form_object->apiResult();
	}
1022510
private function extractIds($input)
    {
        if ($input instanceof Collection) {
            return $input->modelKeys();
        }

        if ($input instanceof Media) {
            return [$input->getKey()];
        }

        return (array) $input;
    }
570082
protected function loc($input){
    $input = urlencode($input);
    $urlindex =  '/authorities/subjects/suggest/?q=' . $input;
    $baseurl = 'https://id.loc.gov';
    $remoteUrl = $baseurl.$urlindex;
    $options['headers']=['Accept' => 'application/json'];
    $body = $this->getRemoteJsonData($remoteUrl, $options);

    $jsondata = [];
    $results = [];
    $jsondata = json_decode($body, TRUE);
    $json_error = json_last_error();
    if ($json_error == JSON_ERROR_NONE) {
      //LoC will always return at least one, the query string
      if (count($jsondata) > 1) {
        foreach ($jsondata[1] as $key => $label) {
          $results[] = [
            'value' => $jsondata[3][$key],
            'label' => $label
          ];
        }
      }
      else {
          $results[] = [
            'value' => NULL,
            'label' => 'Sorry no Match from LoC Subject Headings'
          ];
        }
      return  $results;
    }
    $this->messenger->addError(
      $this->t('Looks like data fetched from @url is not in JSON format.<br> JSON says: @$jsonerror <br>Please check your URL!',
        [
          '@url' => $remoteUrl,
          '@$jsonerror' => $json_error
        ]
      )
    );
    return [];
  }
680488
protected function getInputValue($input)
    {
        if ($input->attr('type') == 'checkbox' or $input->attr('type') == 'radio') {
            $values = [];

            foreach ($input->filter(':checked') as $checkbox) {
                $values[] = $checkbox->getAttribute('value');
            }

            return $values;
        }

        return (new InputFormField($input->getNode(0)))->getValue();
    }
67570
public function extractToAssociativeArray($input)
    {
        $output = array_reduce($input, function($commands, array $item) {
            array_walk($item, function($values, $name) use (&$commands) {
                if (isset($commands[$name]) && !is_array($commands[$name]) && is_array($values)) {
                    $values[] = $values;
                    $commands[$name] = $values;
                } else if (isset($commands[$name]) && is_array($commands[$name]) && is_array($values)) {
                    $commands[$name] = array_merge($commands[$name], $values);
                } else if (isset($commands[$name])) { // if $commands[$name] is set, turn it into an array
                    $commands[$name] = [ $commands[$name], $values ];
                } else { // if $commands[$name] is not set
                    $commands[$name] = $values;
                }
            });

            return $commands;
        }, []);

        return $output;
    }