Skip to content

Instantly share code, notes, and snippets.

View donquixote's full-sized avatar

Andreas Hennings donquixote

View GitHub Profile
@donquixote
donquixote / callable-performance-statistics-result.md
Last active June 13, 2023 02:05
Performance comparison for php callables
Horse Implementations Med./ns Avg/ns Dev/%
convert-only-firstclass class.closure.traditional.array 33.10 33.28 0.315
convert-only-firstclass class.closure.firstclass.array 33.12 33.17 0.272
convert-only-firstclass class.closure.traditional.string 33.13 33.22 0.260
convert-only-firstclass class.closure.firstclass.1 33.15 33.31 0.340
convert-only-firstclass function.closure.traditional 33.18 33.33 0.303
convert-only-firstclass class.closure.firstclass.0 33.23 33.31 0.273
convert-only-firstclass function.closure.firstclass 33.39 33.69 0.404
convert-only-traditional class.closure.traditional.array 36.07 36.30 0.242
<!DOCTYPE html>
<html>
<head>
<style>
div {
--varname: '5';
unknown_property: '5';
content: 'hello';
float: left;
}
<?php
// A "stream" represents a CSV file or another data source.
// "streams" exist on different levels. And a higher-level stream can use a lower-level stream as a data source.
// Problem: Find better nomenclature.
// Currently: RowStream, (AssocRowStream), AssocStream, ObjectStream.
assert($rowStream instanceof RowStreamInterface);
$rows = [];
while (false !== $row = $rowStream->fetchRow()) {
<?php
// See http://stackoverflow.com/questions/4465046/whats-faster-ifreturnelse-return-or-ifreturn-return
function else1($x) {
if ($x === true) {
return true;
}
else {
return false;
}
<?php
function file_scan_directory($dir, $mask, $options = array(), $depth = 0) {
[..]
if ($options['nomask'] === NULL
&& $options['recurse']
// Detect patterns like '/\.tpl\.php$/' or '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\.module$/'.
// The first part is
<?php
/**
* Recursively scans a directory and its subdirectories, to collect all files
* that end with the specified extension.
*
* The result is keyed by file basename.
*
* @param string $dir
* E.g. 'sites/all/modules'
<?php
/**
* @return string[][]
* Format: $[$suffix][$prefix] = $function
* Example: $['menu_alter']['system'] = 'system_menu_alter'
*/
function _drupal_get_structured_function_list() {
static $functions_by_suffix_and_prefix = array();
@donquixote
donquixote / gist:918c2e3059c225aad437
Last active August 29, 2015 14:01
D8 bootstrap + ModuleHandler + DIC dependencies..

Currently we have some confusing circular dependencies in D8 core.

  • A lot of things spawn from the generated DIC.
  • Expecially, ModuleHandler is provided by the generated DIC.
  • The generated DIC depends on enabled modules.
  • Enabled modules are managed with ModuleHandler.
  • ModuleHandler::getImplementations() and friends depend on enabled modules.
  • Available modules depend on hook_system_info_alter(), which depends on enabled modules.
  • If you call ModuleHandler->install(), the instance of Drupal::moduleHandler() and even the entire DIC will be replaced. This is dangerous, we need to deal with outdated services etc.
  • Bootstrap is still a mess with lots of legacy code from D7.
<?php
// Old, see https://github.com/donquixote/drupal/blob/8.x/core/lib/Drupal/Core/Entity/EntityManager.php#L142
$this->discovery = new AnnotatedClassDiscovery('Entity', $namespaces, 'Drupal\Core\Entity\Annotation\EntityType');
$this->discovery = new InfoHookDecorator($this->discovery, 'entity_type_build');
$this->discovery = new AlterDecorator($this->discovery, 'entity_type');
$this->discovery = new CacheDecorator($this->discovery, 'entity_type:' . $this->languageManager->getCurrentLanguage()->id, 'cache', Cache::PERMANENT, array('entity_types' => TRUE));
// New, factory option chaining
@donquixote
donquixote / README.md
Last active December 26, 2015 04:29
PSR-4 yet another try.

[..]

  1. The organization of resources must follow an assumed relationship that associates namespace prefixes with resource bases, such that:

  2. At least one namespace prefix of each autoloadable class name MUST occur in the assumed relationship. (that is, be associated with a resource base)

  3. Every autoloadable class can be loaded by an autoloader that is aware of the