ドメイン名のサブドメインを指定した文字列で置き換えます。

@param unknown $subject
@param unknown $replacement
489049
public function replaceSubDomain ($replacement, $protocol = null, $domain_name = null) {
		$domain_name = $domain_name !== null ? $domain_name : $_SERVER['HTTP_HOST'];

		if (preg_match("@^https?://@", $domain_name, $match) !== false) {
			$domain_name = str_replace($match[1], '', $domain_name);
		} else {
			preg_match("@^https?://@", $_SERVER['HTTP_HOST'], $match);
		}
		$protocol = $protocol !== null ? $protocol . '://' : $match[1];

		$domain = explode('.', $domain_name);
		$length = count($domain);

		$offset = in_array($domain[$length - 1], [
			'co',
			'or',
			'ne',
			'ac',
			'ad',
			'ed',
			'go',
			'gr',
			'lg',
		], true) ? 3 : 2;

		return sprintf('%s%s.%s', $protocol, $replacement, implode('.', array_slice($domain, $length - $offset, $length)));
	}
1364954
public static function replaceInFile($filename, $replacements){
		$content = \file_get_contents($filename);
		foreach ($replacements as $find => $replace) {
			$content = \str_replace($find, $replace, $content);
		}
		\file_put_contents($filename, $content);
	}
759728
public static function removeFirst(string $subject, string $search, bool $caseSensitive = true): string
    {
        return static::replaceFirst($subject, $search, '', $caseSensitive);
    }
367786
public function setAutoReply($emailFieldName, $text, $subject = NULL) {
    $this->autoReply = (object) array(
      'emailField'=>$emailFieldName,
      'subject'=>$subject,
      'text'=>$text
    );
  }
584094
public function setSubject( $subject )
    {
        $translator = $this->getTranslator();
        $this->subject = $translator ? $translator->trans( $subject ) : $subject;
    }
187121
public function injectMessageReplacements($message, $subject, $substitutions) {
		// Handle empty messages
		if(empty($subject) && empty($message)) return array(null, null);

		// Check if there's a role specific message
		$subjectText = str_replace(
			array_keys($substitutions),
			array_values($substitutions),
			$subject ?: $message
		);
		$messageText = str_replace(
			array_keys($substitutions),
			array_values($substitutions),
			$message ?: $subject
		);
		return array($subjectText, $messageText);
	}
820708
public function update(SplSubject $subject)
    {
        if ($this->hasMethod('__update') && is_callable([$this, '__update'])) {
            $this->__update($subject);
        }
    }
470370
public function setSubject($subject = '')
    {
        $this->subject = $subject;
        $this->debug->debug(__FUNCTION__, 'setSubject: ', $this->subject);
    }
412603
public function replace($search, $replacement) {
        $regexEncoding = mb_regex_encoding();
        mb_regex_encoding($this->encoding);

        // Don't want the args being parsed as regex
        $search = preg_quote($search);
        $replacement = preg_quote($replacement);

        $str = mb_ereg_replace($search, $replacement, $this->str);
        mb_regex_encoding($regexEncoding);

        return self::create($str, $this->encoding);
    }
280636
public static function replace(string $subject, $pattern, $replacement = null, int $limit = -1): string
    {
        if (\is_object($replacement) || \is_array($replacement)) {
            if (!\is_callable($replacement, false, $textual)) {
                throw new RegexpException("Callback '$textual' is not callable.");
            }

            return static::pcre('preg_replace_callback', [$pattern, $replacement, $subject, $limit]);

        }

        if ($replacement === null && \is_array($pattern)) {
            $replacement = \array_values($pattern);
            $pattern = \array_keys($pattern);
        }

        return static::pcre('\preg_replace', [$pattern, $replacement, $subject, $limit]);
    }
584265
public function replaceInFile($source, $original, $replacement) {
    $source_path = $this->getRepoRoot() . '/' . $source;
    if ($this->getFileSystem()->exists($source)) {
      $contents = file_get_contents($source_path);
      $new_contents = str_replace($original, $replacement, $contents);
      file_put_contents($source_path, $new_contents);
    }
  }
1245011
protected function replaceFirstOne($search, $replace, $subject, $encoding, &$count, &$offset = 0, $lenSearch = null)
	{
		$offset = mb_strpos($subject, $search, $offset, $encoding);

		if ($offset === false)
			return $subject;


		$lenSearch = is_null($lenSearch) ? mb_strlen($search, $encoding) : $lenSearch;

		$before = mb_substr($subject, 0, $offset, $encoding);
		$after = mb_substr($subject, $offset+$lenSearch, null, $encoding);

		$offset += mb_strlen($replace, $encoding);
		++$count;

		return $before.$replace.$after;
	}
297904
public static function replaceFirstOccurrence($search, $replace, $subject)
    {
        if (!$search) {
            return $subject;
        }

        $pos = mb_strpos($subject, $search);
        if ($pos !== false) {
            $subject = static::mb_substr_replace($subject, $replace, $pos, mb_strlen($search));
        }


        return $subject;
    }
500405
public function match($pattern, $subject)
    {
        if (! $this->validate($pattern)) {
            return false;
        }
        
        return $this->getInstance()->match($pattern, $subject);
    }
886661
public static function replaceWith($replacement): callable
    {
        return function (&$val) use ($replacement) : bool{
            if (empty($val)) {
                $val = $replacement;
            }

            return true;
        };
    }
1086492
public function replace(Text $text, $replacement, $location = null)
    {
        $input = array(
            'text' => $text,
            'location' => $location,
            'replacement' => $replacement,
        );
        $this->commandInvoker->run('replace', $input);
    }
520923
public function replaceName(
        string $replacement,
        string $filePath,
        $findName = AbstractGenerator::FIND_ENTITY_NAME
    ): self {
        $this->findReplace($findName, $replacement, $filePath);
        $this->findReplace(\lcfirst($findName), \lcfirst($replacement), $filePath);
        $this->findReplace(\strtoupper($findName), \strtoupper($replacement), $filePath);
        $this->findReplace(
            \strtoupper(Inflector::tableize($findName)),
            \strtoupper(Inflector::tableize($replacement)),
            $filePath
        );

        return $this;
    }