Generates PHP code

@return string PHP code
426892
private function compileConfiguration()
    {
        $code = '';
        $configurationByWrapper = [];
        foreach ($this->configurations as $key => $configuration) {
            if(!isset($configurationByWrapper[$configuration->getIdWrapper()])){
                $configurationByWrapper[$configuration->getIdWrapper()] = [];
            }
            $data = array();
            $data['key'] = $configuration->getKey();
            $data['value'] = $configuration->getValue();
            $data['active'] = $configuration->getActive();
            $data['id'] = $configuration->getId();
            $configurationByWrapper[$configuration->getIdWrapper()][] = $data;
        }
        foreach ($configurationByWrapper as $id => $data) {
            $code .= sprintf("'%s' => %s,",$id,var_export($data,true));
        }

        return $code;
    }
1033061
public function getCode() {
        $result = '';

        if ($this->options->getRenderContextDirective()) {
            $result .= $this->renderedCode->getContextDirective();
        }
        if ($this->options->getRenderDirectives()) {
            $result .= $this->renderedCode->getDirectives();
        }
        if ($this->options->getRenderGlobalCode()) {
            $result .= $this->renderedCode->getGlobalCode();
        }
        if ($this->options->getRenderMainFunction()) {
            $result .= $this->renderedCode->getMainFunction();
        }

        if ($this->options->getCompress()) {
            $result = $this->compress($result);
        }
        if ($this->options->getIncludeScriptTag()) {
            $result = $this->addScriptTag($result);
        }

        return $result;
    }
969895
protected function code()
    {
        $files = $out = [];

        if (isset($this->manifest->code->file)) {
            $files = array_map([$this, 'path'], (array) $this->manifest->code->file);
        } else {
            if (($cwd = getcwd()) !== false && chdir($this->dir)) {
                $files = (array) glob('*.php');
            }
        }

        $pathFrom = (string) new FindTextpattern() . '/index.php';

        foreach ($files as $path) {
            if (file_exists($path) && is_file($path) && is_readable($path)) {
                $includePath = $this->getRelativePath($pathFrom, realpath($path));

                if ($includePath !== $path) {
                    $out[] = "include txpath.'/".addslashes($includePath)."';";
                } else {
                    $out[] = "include '".addslashes($includePath)."';";
                }
            }
        }

        if (isset($cwd) && $cwd !== false) {
            chdir($cwd);
        }

        return implode("\n", $out);
    }
855895
private function generatePhpDocParameters(): void
  {
    $parameters = [];
    foreach ($this->routine['phpdoc']['parameters'] as $parameter)
    {
      $mangledName = $this->nameMangler->getParameterName($parameter['parameter_name']);

      $parameters[] = ['php_name'             => '$'.$mangledName,
                       'description'          => $parameter['description'],
                       'php_type'             => $parameter['php_type'],
                       'data_type_descriptor' => $parameter['data_type_descriptor']];
    }

    $this->enhancePhpDocParameters($parameters);

    if (!empty($parameters))
    {
      // Compute the max lengths of parameter names and the PHP types of the parameters.
      $max_name_length = 0;
      $max_type_length = 0;
      foreach ($parameters as $parameter)
      {
        $max_name_length = max($max_name_length, mb_strlen($parameter['php_name']));
        $max_type_length = max($max_type_length, mb_strlen($parameter['php_type']));
      }

      $this->codeStore->append(' *', false);

      // Generate phpDoc for the parameters of the wrapper method.
      foreach ($parameters as $parameter)
      {
        $format = sprintf(' * %%-%ds %%-%ds %%-%ds %%s', mb_strlen('@param'), $max_type_length, $max_name_length);

        $lines = explode(PHP_EOL, $parameter['description'] ?? '');
        if (!empty($lines))
        {
          $line = array_shift($lines);
          $this->codeStore->append(sprintf($format, '@param', $parameter['php_type'], $parameter['php_name'], $line), false);
          foreach ($lines as $line)
          {
            $this->codeStore->append(sprintf($format, ' ', ' ', ' ', $line), false);
          }
        }
        else
        {
          $this->codeStore->append(sprintf($format, '@param', $parameter['php_type'], $parameter['php_name'], ''), false);
        }

        if ($parameter['data_type_descriptor']!==null)
        {
          $this->codeStore->append(sprintf($format, ' ', ' ', ' ', $parameter['data_type_descriptor']), false);
        }
      }
    }
  }
666638
public function generate()
    {
        $output = $this->generateIdeHelperOutput();
        $this->writeIdeHelperFile($output, '.ide-helper.php');

        $outputForPhpStormIde = $this->generatePhpStormIdeHelperOutput();
        $this->writeIdeHelperFile($outputForPhpStormIde, '.phpstorm.meta.php/oxid.meta.php');
    }
303822
public function generate()
    {
        $code = '';

        if ($this->type !== null) {
            $code .= $this->type . ' ';
        }

        if ($this->passByReference === true) {
            $code .= '&';
        }

        $code .= '$' . $this->name;

        if ($this->defaultValue !== null) {
            if ($this->isDefaultValueConstant() === true) {
                $code .= ' = ' . $this->getDefaultValueConstantName();
            } else {
                $this->defaultValue->setOutputMode(ValueGenerator::OUTPUT_SINGLE_LINE);
                $code .= ' = ' . $this->defaultValue;
            }
        }

        return $code;
    }
353380
public static function generate ()
		{
			$data = random_bytes(16);

			$data[ 6 ] = chr(ord($data[ 6 ]) & 0x0f | 0x40); // set version to 0100
			$data[ 8 ] = chr(ord($data[ 8 ]) & 0x3f | 0x80); // set bits 6-7 to 10

			return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
		}
26002
public function generate_query() {
        $query = '';
        $this->query->each(function($statement) use(&$query) {
            if (count($statement) == 1) {
                $query .= $statement[0];
            } else {
                if($statement[1] === null){
                    $query .= $statement[0];
                }else{
                    $query .= $statement[0].' "'.$statement[1].'"';
                }
            }
            $query .= ' ';

        });

        $this->raw_query = trim($query);

        return $this->raw_query;
    }
1018289
public function generate()
	{
		$arrOptions = array();
		$strClass = 'tl_select';
		$strStyle = '<style>.group-result {padding-top: 5px !important; line-height: 20px !important;}';
		$count = 1;

		if ($this->multiple)
		{
			$this->strName .= '[]';
			$strClass = 'tl_mselect';
		}

		// Add an empty option (XHTML) if there are none
		if (empty($this->arrOptions))
		{
			$this->arrOptions = array(array('value'=>'', 'label'=>'-'));
		}
		
		foreach ($this->arrOptions as $strKey=>$arrOption)
		{
			if (isset($arrOption['value']))
			{
				$arrOptions[] = sprintf('<option value="%s"%s>%s</option>',
										 \StringUtil::specialchars($arrOption['value']),
										 $this->isSelected($arrOption),
										 $arrOption['label']);

				if (isset($GLOBALS['TL_CTB_IMG'][$arrOptgroup['value']]))
				{
					$objImage = \FilesModel::findByUuid($GLOBALS['TL_CTB_IMG'][$arrOptgroup['value']]);
				}
				
				if ($objImage === null)
				{
					$strStyle .= '#ctrl_type_chzn_o_'.$count.' {position: relative; padding-left: 90px; line-height: 41px;}#ctrl_type_chzn_o_'.$count++.'::before {content: ""; position: absolute; left: 20px; top:2px; width: 60px; height: 40px; border: 1px solid #ccc; background: #eee; background-size: 60px 40px;}';
				}
				else
				{
					$strStyle .= '#ctrl_type_chzn_o_'.$count.' {position: relative; padding-left: 90px; line-height: 41px;}#ctrl_type_chzn_o_'.$count++.'::before {content: ""; position: absolute; left: 20px; top:2px; width: 60px; height: 40px; border: 1px solid #ccc; background: #eee url('.$objImage->path.'); background-size: 60px 40px;}';
				}
			}
			else
			{
				$arrOptgroups = array();

				foreach ($arrOption as $arrOptgroup)
				{
					$arrOptgroups[] = sprintf('<option value="%s"%s>%s</option>',
											   \StringUtil::specialchars($arrOptgroup['value']),
											   $this->isSelected($arrOptgroup),
											   $arrOptgroup['label']);

					if (isset($GLOBALS['TL_CTB_IMG'][$arrOptgroup['value']]))
					{
						$objImage = \FilesModel::findByUuid($GLOBALS['TL_CTB_IMG'][$arrOptgroup['value']]);
					}

					if ($objImage === null)
					{
						$strStyle .= '#ctrl_type_chzn_o_'.$count.' {position: relative; padding-left: 90px; line-height: 41px;}#ctrl_type_chzn_o_'.$count++.'::before {content: ""; position: absolute; left: 20px; top:2px; width: 60px; height: 40px; border: 1px solid #ccc; background: #eee; background-size: 60px 40px;}';
					}
					else
					{
						$strStyle .= '#ctrl_type_chzn_o_'.$count.' {position: relative; padding-left: 90px; line-height: 41px;}#ctrl_type_chzn_o_'.$count++.'::before {content: ""; position: absolute; left: 20px; top:2px; width: 60px; height: 40px; border: 1px solid #ccc; background: #eee url('.$objImage->path.'); background-size: 60px 40px;}';
					}

				}

				$arrOptions[] = sprintf('<optgroup label="&nbsp;%s">%s</optgroup>', \StringUtil::specialchars($strKey), implode('', $arrOptgroups));
				$count++;
			}
		}

		// Chosen
		if ($this->chosen)
		{
			$strClass .= ' tl_chosen';
		}


		$strStyle .= '</style>';
	
		return sprintf('%s<select name="%s" id="ctrl_%s" class="%s%s"%s onfocus="Backend.getScrollOffset()">%s</select>%s',
						($this->multiple ? '<input type="hidden" name="'. rtrim($this->strName, '[]') .'" value="">' : ''),
						$this->strName,
						$this->strId,
						$strClass,
						(($this->strClass != '') ? ' ' . $this->strClass : ''),
						$this->getAttributes(),
						implode('', $arrOptions),
						$strStyle);
	}
326165
public function generate()
    {
        $str     = '';
        $keysize = strlen($this->_alphabet);

        for ($i = 0; $i < $this->_length; ++$i) {
            $str .= $this->_alphabet[\Sodium\randombytes_uniform($keysize)];
        }

        return $str;
    }
1318922
function compile() {
		$code = $this->match_code($this->value) ;

		$id = $this->varid() ;

		if ( $this->optional ) {
			$code = PHPBuilder::build()
				->l(
				$this->save($id),
				$code->replace( array( 'FAIL' => $this->restore($id,true) ))
				);
		}

		if ( $this->zero_or_more ) {
			$code = PHPBuilder::build()
				->b( 'while (true)',
					$this->save($id),
					$code->replace( array(
						'MATCH' => NULL,
						'FAIL' =>
							$this->restore($id,true)
							->l( 'break;' )
					))
				)
				->l(
				'MATCH'
				);
		}

		if ( $this->one_or_more ) {
			$code = PHPBuilder::build()
				->l(
				'$count = 0;'
				)
				->b( 'while (true)',
					$this->save($id),
					$code->replace( array(
						'MATCH' => NULL,
						'FAIL' =>
							$this->restore($id,true)
							->l( 'break;' )
					)),
					'$count += 1;'
				)
				->b( 'if ($count > 0)', 'MATCH' )
				->b( 'else',            'FAIL' );
		}

		if ( $this->positive_lookahead ) {
			$code = PHPBuilder::build()
				->l(
				$this->save($id),
				$code->replace( array(
					'MATCH' =>
						$this->restore($id)
						->l( 'MATCH' ),
					'FAIL' =>
						$this->restore($id)
						->l( 'FAIL' )
				)));
		}

		if ( $this->negative_lookahead ) {
			$code = PHPBuilder::build()
				->l(
				$this->save($id),
				$code->replace( array(
					'MATCH' =>
						$this->restore($id)
						->l( 'FAIL' ),
					'FAIL' =>
						$this->restore($id)
						->l( 'MATCH' )
				)));
		}

		if ( $this->tag && !($this instanceof TokenRecurse ) ) {
			$code = PHPBuilder::build()
				->l(
				'$stack[] = $result; $result = $this->construct( $matchrule, "'.$this->tag.'" ); ',
				$code->replace(array(
					'MATCH' => PHPBuilder::build()
						->l(
						'$subres = $result; $result = array_pop($stack);',
						'$this->store( $result, $subres, \''.$this->tag.'\' );',
						'MATCH'
						),
					'FAIL' => PHPBuilder::build()
						->l(
						'$result = array_pop($stack);',
						'FAIL'
						)
				)));
		}

		return $code ;
	}
867063
private function generateAndSaveCode()
    {
        $code = $this->randomMath->getRandomString(32);
        $this->config->saveConfig(
            \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE,
            $code,
            'default',
            '0'
        );
    }
107248
protected function generateCode()
    {
        $answer = '';
        if ($this->type == "1") {
            $code   = md5(time());
            $code   = substr($code, rand(3, 5), $this->length);
            $code   = str_replace(['2', '0', 'o', '1', 'i'], ['Z', '9', '8', 'L', 'A'], $code);
            $code   = strtoupper($code);
            $answer = $code;
        } else {
            $operate               = ['+', '-'];
            $opindex               = rand(0, 1);
            $opnum1                = rand(0, 9);
            $opnum2                = rand(0, 9);
            list($opnum1, $opnum2) = ($opindex == 1 ? [max($opnum1, $opnum2), min($opnum1, $opnum2)] : [$opnum1, $opnum2]);
            $code                  = $opnum1 . $operate[$opindex] . $opnum2 . '=?';
            $answer                = $opindex == 1 ? ($opnum1 - $opnum2) : ($opnum1 + $opnum2);
        }
        return [$code, $answer];
    }
44567
public function generate()
    {
        $alphabetLastIndex = strlen($this->alphabet) - 1;
        $code = '';
        for ($i = 0; $i < $this->length; $i++) {
            $code .= $this->alphabet[rand(0, $alphabetLastIndex)];
        }

        return $code;
    }
94249
private function generateConsts()
    {
        $result = '<?php' . PHP_EOL;
        foreach($this->ref->getConstants() as $name => $value)
        {
            $value = var_export($value, true);
            $result .= <<<CODE
define('{$name}', {$value});

CODE;
        }
        file_put_contents($this->savePath . '/consts.php', $result);
    }
928441
public function to_smarty_php()
    {
        $code = '';
        foreach ($this->subtrees as $subtree) {
            if ($code !== "") {
                $code .= ".";
            }
            if ($subtree instanceof _smarty_tag) {
                $more_php = $subtree->assign_to_var();
            } else {
                $more_php = $subtree->to_smarty_php();
            }

            $code .= $more_php;

            if (!$subtree instanceof _smarty_dq_content) {
                $this->parser->compiler->has_variable_string = true;
            }
        }

        return $code;
    }
572649
public function generate()
    {
        $code = array();

        if ($this->namespace !== null) {
            $code[] = $this->getIndentation() . 'namespace ' . $this->namespace;
            $code[] = '{';
            $code[] = null;

            // Temporarily add one more level of indentation.
            $this->addIndentationLevel(1);
        }

        $code = array_merge($code, $this->renderUsesLines());

        $indentation = $this->getIndentation();

        $doc = $this->generateDocumentation();
        if ($doc !== null) {
            $code[] = $doc;
        }

        $line = $indentation . 'interface ' . $this->name;
        if (count($this->extends) > 0) {
            $line .= ' extends ' . implode(', ', $this->extends);
        }

        $code[] = $line;
        $code[] = $indentation . '{';

        // Interface constants.
        $interfaceElements = $this->generateConstantsLines();

        // Interface methods.
        foreach ($this->methods as $method) {
            if ($method->getVisibility() !== Modifiers::VISIBILITY_PUBLIC) {
                throw new RuntimeException('The visibility of methods must be public.');
            }

            $method->setIndentationString($this->getIndentationString());
            $method->setIndentationLevel($this->getIndentationLevel() + 1);

            $doc = $method->generateDocumentation();
            if ($doc !== null) {
                $interfaceElements[] = $doc;
            }

            $interfaceElements[] = $method->generateSignature() . ';';
            $interfaceElements[] = null;
        }

        if (count($interfaceElements) > 0) {
            $code[] = null;
            $code = array_merge($code, $interfaceElements);
            // Remove last empty line.
            array_pop($code);
        }

        $code[] = $indentation . '}';

        if ($this->namespace !== null) {
            // Set back the indentation.
            $this->addIndentationLevel(-1);

            $code[] = $this->getIndentation() . '}';
        }

        return implode($this->getLineFeed(), $code);
    }