Skip to content

Instantly share code, notes, and snippets.

View sdboyer's full-sized avatar

sam boyer sdboyer

View GitHub Profile
<?php
class AssetLibraryRepository {
protected function initialize() {
if ($this->initialized) {
return;
}
$this->initialized = TRUE;
$library_collector = new AssetLibraryCollector($this);
foreach ($this->moduleHandler->getImplementations('library_info') as $module) {
<?php
class PageContentAccessChecker implements AccessCheckInterface {
public function applies(Route $route) {
return array_key_exists('_page_content_access_method', $route->getRequirements());
}
public function access(Route $route, Request $request) {
$content_controller = $request->attributes->get('_content_object');
return $content_controller->access();
}
@sdboyer
sdboyer / gist:5920080
Last active December 19, 2015 07:39 — forked from EclipseGc/gist:5919630
<?php
/**
* @Page(
* id = "my_page",
* title = @Translation("My page")
* routes = {
* @Route("/another/page/{foo}")
* @Route("/my/page/{foo}", "SomeOtherClass::access")
* }
@sdboyer
sdboyer / DirectedAdjacencyGraph.php
Last active December 21, 2015 03:49
graph algo for calculating a TSL based on a DAG, but respecting optimal groupings
<?php
namespace Gliph;
class DirectedAdjacencyGraph {
protected $vertices;
protected $vertexTypes;
public function __construct() {
<?php
$refl = new \ReflectionClass($object);
foreach ($refl->getProperties() as $prop) {
if (!$prop->isPublic()) {
$prop->setAccessible(TRUE);
}
$this->props[$prop->getName()] = $prop->getValue($object);
}
@sdboyer
sdboyer / AssetGraph.php
Last active December 23, 2015 00:19
new grouper
<?php
/**
* @file
* Contains \Drupal\Core\Asset\AssetGraph.
*/
namespace Drupal\Core\Asset;
use Gliph\Graph\DirectedAdjacencyGraph;
<?php
/**
* @file
* Contains Drupal\Core\Asset\AssetCollector.
*/
namespace Drupal\Core\Asset\Factory;
use Drupal\Core\Asset\AssetInterface;
use Drupal\Core\Asset\Bag\AssetBagInterface;
@sdboyer
sdboyer / ExtensionGraph.php
Created September 27, 2013 11:09
ExtensionGraph pseudocode
<?php
use Gliph\Graph\DirectedAdjacencyList;
use Gliph\Exception\InvalidVertexTypeException;
use Drupal\Something\ExtensionInterface;
class ExtensionGraph extends DirectedAdjacencyList {
protected $extensionCollection;
<?php
class ExtensionFinder {
protected $factory;
const MODULE = 0x1;
const THEME = 0x2;
const PROFILE = 0x4;
public function __construct(ExtensionFactory $factory) {
<?php
use \Gliph\Graph\DirectedAdjacencyList;
use \Gliph\Traversal\DepthFirst;
$graph = new DirectedAdjacencyList();
foreach ($entity_list as $entity) {
if ($entity->has('embedded')) {
foreach ($entity->get('embedded') as $embedded) {