This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://getcomposer.org/doc/articles/vendor-binaries.md#finding-the-composer-autoloader-from-a-binary | |
if (isset($GLOBALS['_composer_autoload_path'])) { | |
// As of Composer 2.2... | |
$_composer_autoload_path = $GLOBALS['_composer_autoload_path']; | |
} | |
else { | |
// < Composer 2.2 | |
foreach ([ | |
__DIR__ . '/../../autoload.php', | |
__DIR__ . '/../vendor/autoload.php', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# @file | |
# Xdebug Lando Controller (Supports Xdebug versions 2 and 3) | |
# | |
# Save this file to: ./install/lando/xdebug_controller.sh. | |
# | |
# This script is meant to be used for Lando tooling to control Xdebug. When | |
# using with version 2, use the version 3 syntax and it will be properly |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @code | |
* // Print a shortened, nice-to-read path when possible. | |
* echo (new GetShortPath(getcwd())($long_path) | |
* @endcode | |
*/ | |
class GetShortPath { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use InvalidArgumentException; | |
/** | |
* Rotate an image DataURI string. | |
* | |
* Because I'm working with a string, not a file, the Drupal image API | |
* (image.factory) didn't seem to be an appropriate solution, therefor I'm using | |
* the native PHP GD library. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$augmented_message = $exception->getMessage() . "\nMy augementation"; | |
$reflected_exception = new \ReflectionObject($exception); | |
$message_property = $reflected_exception->getProperty('message'); | |
$message_property->setAccessible(TRUE); | |
$message_property->setValue($exception, $augmented_message); | |
throw $exception; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countPalindromes($word) { | |
$palindromes = 0; | |
$word_length = strlen($word); | |
for ($chunk_size = $word_length; $chunk_size > 0; --$chunk_size) { | |
for ($pos = 0; $pos <= ($word_length - $chunk_size); $pos++) { | |
$substr = substr($word, $pos, $chunk_size); | |
if ($substr === strrev($substr)) { | |
++$palindromes; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FormatPhoneNumber { | |
const FORMAT = '(%d) %d-%d'; | |
const SMS_FORMAT = '+1%d%d%d'; | |
public function __invoke(string $number, string $format = NULL) { | |
$number = preg_replace('#[^0-9]#', '', $number); | |
preg_match('#(.+)?(\d{3})(\d{3})(\d{4})$#', $number, $matches); | |
array_shift($matches); | |
array_shift($matches); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\paragraphs\ParagraphInterface; | |
/** | |
* Get the delta on the host entity for a paragraph. | |
*/ | |
class GetHostDelta { | |
public function __invoke(ParagraphInterface $paragraph): ?string { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\se_core\Traits; | |
use Drupal\Core\Form\FormStateInterface; | |
use Drupal\Core\Entity\Entity\EntityFormDisplay; | |
trait GetFormModeTrait { | |
protected function getFormMode(FormStateInterface $form_state): string { |
NewerOlder