Create text version of HTML message by changing line breaks to newlines and
stripping tags.

@param ComposerEvent $event
543694
public function generateTextBody(ComposerEvent $event)
    {
        $parts = $event->getBody()->getParts();

        $htmlBody = null;
        $htmlPart = null;
        $textBody = null;

        // locate HTML body
        foreach ($parts as $part) {
            foreach ($part->getHeadersArray() as $header) {
                if ($header[0] == 'Content-Type' && strpos($header[1], 'text/html') === 0) {
                    $htmlPart = $part;
                    $htmlBody = $part->getRawContent();
                } elseif ($header[0] == 'Content-Type' && strpos($header[1], 'text/plain') === 0) {
                    $textBody = $part->getRawContent();
                }
            }
        }

        if ($textBody || !$htmlBody) {
            // can only work if HTML body exists and text doesn't
            return;
        }

        // create and insert text body
        $textBody = strip_tags($this->br2nl($htmlBody));
        $textPart = new MimePart($textBody);
        $textPart->type = 'text/plain';
        $event->getBody()->setParts([$textPart, $htmlPart]);

        // force multipart/alternative content type
        $event->getMessage()->getHeaders()->get('content-type')->setType('multipart/alternative')
            ->addParameter('boundary', $event->getBody()->getMime()->boundary());
    }
1309903
protected function announceLabelEvent($event)
    {
        $target = $this->extractLabelTarget($event);

        $builder = new MessageBuilder();

        $builder->createAttachment()
            ->setColor('#' . $event->label->color)
            ->setTitle($event->label->name)
            ->setText(sprintf("%s by %s", $target->title, $target->user->login))
            ->setTitleLink($target->html_url)
            ->setFallback(sprintf(
                "%s (%s) %s",
                $target->title,
                $target->user->login,
                $event->label->name
            ))
            ->attach();

        $builder->setUsername(sprintf("[%s] #%s", $event->repository->name, $target->number));

        return $this->getSlack()->sendMessage($builder->getMessage());
    }
780142
public function renderText($content, $data = [])
    {
        if (!$content) {
            return '';
        }

        $text = $this->renderTwig($content, $data);

        $text = html_entity_decode(preg_replace("/[\r\n]{2,}/", "\n\n", $text), ENT_QUOTES, 'UTF-8');

        return $text;
    }
217162
protected function outputFormatTableEvent(array $events)
    {
        $header = array(
            $this->text('Text'),
            $this->text('Type'),
            $this->text('Severity'),
            $this->text('Created')
        );

        $rows = array();

        foreach ($events as $item) {
            $text = empty($item['translatable']) ? $item['text'] : $this->text($item['text']);
            $rows[] = array(
                $this->truncate($text, 50),
                $this->text($item['type']),
                $this->text($item['severity']),
                $this->date($item['created']),
            );
        }

        $this->outputFormatTable($rows, $header);
    }
295116
public function replaceMarkup(FilterResponseEvent $event)
    {
        $request = $event->getRequest();
        $response = $event->getResponse();
        $format = $request->getRequestFormat();
        $content = $response->getContent();

        if (!$content || !array_key_exists($format, $this->markupParser)) {
            return;
        }

        $response->setContent(
            $this->markupParser[$format]->parse($content, $request->getLocale())
        );
    }
1067513
public function msgText($text)
    {
        $this->isHTML(false);
        $text = self::html2text($text, true);
        $text = self::normalizeBreaks($text);
        $this->Body = $text;
    }
698766
public function construct(ConstructEvent $event)
    {
        if ($event->getTwig()->hasExtension(StringLoaderExtension::class)) {
            return;
        }

        // Twig core extensions
        $event->getTwig()->addExtension(new StringLoaderExtension());
        $event->getTwig()->addExtension(new DebugExtension());

        // CakePHP bridging extensions
        $event->getTwig()->addExtension(new Extension\I18n());
        $event->getTwig()->addExtension(new Extension\Time());
        $event->getTwig()->addExtension(new Extension\Basic());
        $event->getTwig()->addExtension(new Extension\Number());
        $event->getTwig()->addExtension(new Extension\Utils());
        $event->getTwig()->addExtension(new Extension\Arrays());
        $event->getTwig()->addExtension(new Extension\Strings());
        $event->getTwig()->addExtension(new Extension\Inflector());

        if (!Configure::check('WyriHaximus.TwigView.flags.potentialDangerous') ||
            (
                Configure::check('WyriHaximus.TwigView.flags.potentialDangerous') &&
                Configure::read('WyriHaximus.TwigView.flags.potentialDangerous') === true
            )
        ) {
            $event->getTwig()->addExtension(new Extension\PotentialDangerous());
        }

        // Markdown extension
        if (Configure::check('WyriHaximus.TwigView.markdown.engine') &&
            Configure::read('WyriHaximus.TwigView.markdown.engine') instanceof MarkdownEngineInterface
        ) {
            $engine = Configure::read('WyriHaximus.TwigView.markdown.engine');
            $event->getTwig()->addExtension(new MarkdownExtension($engine));
            $event->getTwig()->addTokenParser(new MarkdownTokenParser($engine));
        }

        // Third party cache extension
        $cacheProvider = new Cache();
        $cacheStrategy = new LifetimeCacheStrategy($cacheProvider);
        $cacheExtension = new CacheExtension($cacheStrategy);
        $event->getTwig()->addExtension($cacheExtension);

        // jasny/twig-extensions
        $event->getTwig()->addExtension(new DateExtension());
        $event->getTwig()->addExtension(new PcreExtension());
        $event->getTwig()->addExtension(new TextExtension());
        $event->getTwig()->addExtension(new ArrayExtension());
        // @codingStandardsIgnoreEnd
    }
278346
protected static function createCommand($event)
    {
        $extra = $event->getComposer()->getPackage()->getExtra();
        $command = 'ckeditor:install';

        if (isset($extra['ckeditor-path'])) {
            $command .= ' '.$extra['ckeditor-path'];
        }

        if (isset($extra['ckeditor-release'])) {
            $command .= ' --release='.$extra['ckeditor-release'];
        }

        if (isset($extra['ckeditor-tag'])) {
            $command .= ' --tag='.$extra['ckeditor-tag'];
        }

        if (isset($extra['ckeditor-clear'])) {
            $command .= ' --clear='.$extra['ckeditor-clear'];
        }

        if (isset($extra['ckeditor-exclude'])) {
            foreach ($extra['ckeditor-exclude'] as $exclude) {
                $command .= ' --exclude='.$exclude;
            }
        }

        return $command;
    }
141971
public function notify( $event )
	{
		if ( ! isset( $event['section'] ) || ! isset( $event['source'] ) ) return;
		$source = $event['section'];

		$source = array( 'message' => $event['message'], 'details' => $event['source'] );
		$this->addSection( $event['section'], $source );
	}
170439
function() {
      var that = this,
          oldHtml,
          cleanHtml;

      if (wysihtml5.browser.supportsModenPaste()) {
        this.on("paste:composer", function(event) {
          event.preventDefault();
          oldHtml = wysihtml5.dom.getPastedHtml(event);
          if (oldHtml) {
            that._cleanAndPaste(oldHtml);
          }
        });

      } else {
        this.on("beforepaste:composer", function(event) {
          event.preventDefault();
          wysihtml5.dom.getPastedHtmlWithDiv(that.composer, function(pastedHTML) {
            if (pastedHTML) {
              that._cleanAndPaste(pastedHTML);
            }
          });
        });

      }
    }
1232031
public function createVersions(Event $Event) {
		if ($this->_checkEvent($Event)) {
			$table = $Event->getSubject();
			$record = $Event->getData('record');
			$this->_createVersions($table, $record, $Event->getData('operations'));
			$Event->stopPropagation();
		}
	}
434288
public static function onPostCall(Event $event)
    {
        $response = $event->getResponse();
        if ($response->headers->get('content-type') === 'text/html') {
            return;
        }

        $application = $event->getApplication();
        $renderer = $application->getRenderer();
        $content = json_decode($response->getContent());

        $result = false;
        if ($content instanceof \StdClass) {
            if (isset($content->type) && isset($content->parameters)) {
                if (isset($content->parameters->rendermode)) {
                    $result = true;
                }
            }
        }

        if (!$result) {
            return;
        }

        $rendermodeParam = $content->parameters->rendermode;
        $classname =  AbstractClassContent::getClassnameByContentType($content->type);

        $modes = ['default' => 'Default mode'];
        foreach ($renderer->getAvailableRenderMode(new $classname()) as $mode) {
            $modes[$mode] = ucfirst(str_replace('_', ' ', $mode));
        }

        $rendermodeParam->options = $modes;

        $response->setContent(json_encode($content));
    }
617548
public function onPostSerialize(ObjectEvent $event)
    {
        $customUrl = $event->getObject();
        $visitor = $event->getVisitor();

        if (!$customUrl instanceof CustomUrlDocument) {
            return;
        }

        if (null !== $customUrl->getTargetDocument()) {
            $visitor->addData('targetTitle', $customUrl->getTargetDocument()->getTitle());
            $visitor->addData('targetDocument', $customUrl->getTargetDocument()->getUuid());
        }

        $visitor->addData(
            'customUrl',
            $this->generator->generate($customUrl->getBaseDomain(), $customUrl->getDomainParts())
        );

        $visitor->addData('creatorFullName', $this->userManager->getFullNameByUserId($customUrl->getCreator()));
        $visitor->addData('changerFullName', $this->userManager->getFullNameByUserId($customUrl->getChanger()));
    }
593999
public function encode(string $event, $data)
    {
        $packet = Packet::MESSAGE . Packet::EVENT;
        $shouldEncode = is_array($data) || is_object($data);
        $data = $shouldEncode ? json_encode($data) : $data;
        $format = $shouldEncode ? '["%s",%s]' : '["%s","%s"]';

        return $packet . sprintf($format, $event, $data);
    }
110040
public static function meatOnBones(Event $event)
    {
        $basePath = realpath(".");
        $handler = new ComposerHydrationHandler($event, $basePath);

        $handler->hydrate();
    }
1303774
public function prepareWordpressDriver($event)
    {
        $drivers = array_keys($this->wordpress->getDrivers());
        $driver  = $this->parameters['default_driver'];
        $tags    = array_merge($event->getFeature()->getTags(), $event->getScenario()->getTags());

        // If the scenario or outline is tagged with a specific driver, switch to it.
        foreach ($tags as $tag) {
            if (! in_array($tag, $drivers, true)) {
                continue;
            }

            $driver = $tag;
            break;
        }

        $this->wordpress->setDefaultDriverName($driver);
    }
710660
public function onPostCmdEvent(\Composer\Script\Event $event)
    {
        if (!empty($this->unsupportedPackages)) {
            $this->io->write(
                '<error>You are using Drupal packages that are not supported by the Drupal Security Team!</error>'
            );
            foreach ($this->unsupportedPackages as $package_name => $package) {
                $extra = $package->getExtra();
                $this->io->write(
                    "  - <comment>$package_name:{$package->getVersion()}</comment>: {$extra['drupal']['security-coverage']['message']}"
                );
            }
            $this->io->write(
                '<comment>See https://www.drupal.org/security-advisory-policy for more information.</comment>'
            );
        }
    }