Skip to content

Instantly share code, notes, and snippets.

<?php
namespace Tentacode\App\Security;
trait ConnectedUser
{
/**
* @Inject
* @var Symfony\Component\Security\Core\SecurityContext
*/
@mrclay
mrclay / lazy_generic_list.php
Created July 31, 2014 02:41
Evil use of eval() + autoloading to use lists bound to arbitrary types without having to create them
<?php
// Basically makes a SplDoublyLinkedList<T>
abstract class ListOf extends SplDoublyLinkedList {
protected $T;
public function __construct() {
list(,$this->T) = explode('\\', get_class($this), 2);
}
@mrclay
mrclay / UFCOE_Elgg_UniqueEntitySet.php
Created May 7, 2014 13:48
Implements a unique set of Elgg entities, either holding GUIDs or entity objects
<?php
namespace UFCOE\Elgg;
/**
* Implements a unique set of entities, either holding GUIDs or ElggEntity objects
*/
class UniqueEntitySet {
/**
* @var \ElggEntity[]|int[]
@mrclay
mrclay / used-by.php
Created May 2, 2014 13:59
My argument for why phpDocumentor should allow explicit use of the @Used-By tag.
<?php
// Currently only @used can document consuming relationships, meaning the relationship
// cannot be documented from the side of the consumed resource. This limitation seems
// arbitrary. Consider this scenario:
// A framework function calls functions that were registered by plugins, but it
// can't know which functions it will call...
/**
@mrclay
mrclay / UFCOE_Elgg_Chunker.php
Last active August 29, 2015 14:00
Component for chunking the output of an iterator. Includes helper function for chunking the output of an ElggBatch object.
<?php
namespace UFCOE\Elgg;
/**
* Chunk the output of an iterator.
*
* <code>
* while ($rows = $chunker->getChunk(30)) {
* ... do something with up to 30 rows
@mrclay
mrclay / base64URL-test
Created February 24, 2014 14:42
Quick acid test for Base64 & Base64URL
ASCII : !@~%^~&*a)_+-={}|[~]\;',.~/<>?qwertyuiop
Base64 : IUB+JV5+JiphKV8rLT17fXxbfl1cOycsLn4vPD4/cXdlcnR5dWlvcA==
Base64URL: IUB-JV5-JiphKV8rLT17fXxbfl1cOycsLn4vPD4_cXdlcnR5dWlvcA
@mrclay
mrclay / LazyProxy.php
Created December 3, 2013 16:54
A lazy-loading proxy for an object. You supply a factory method that returns an object, and the proxy will wait to call the factory until directly before it's needed.
<?php
/**
* A lazy-loading proxy for an object
*
* You supply a factory method that returns an object, and the proxy will wait to call the factory
* until directly before it's needed.
*
* <code>
* // use dynamic method callback on a service that's not yet loaded
@mrclay
mrclay / Elgg_TagUtil.php
Created October 27, 2013 03:05
Elgg: alter a query $options array to filter entities having certain tags. This does not require the use of elgg_get_entities_by_metadata and can even be used to filter river queries.
<?php
namespace UFCOE\Elgg;
/**
* Utilities for altering queries based on matching optional/required tags
*
* <code>
* // alter $options so it requires entities to have the tags Foo and Bar:
* $ids = $tag_util->tagsToMetastringIds(array('Foo', 'Bar'));
@mrclay
mrclay / AclPopulator.php
Created August 26, 2013 13:41
Elgg: Populate an ACL based on users and existing ACLs (bypasses Elgg API: does not induce plugin hooks)
<?php
namespace UFCOE\Elgg;
/**
* Populate an ACL based on users and existing ACLs (bypasses Elgg API: does not induce plugin hooks)
*
* <code>
* $populator = new AclPopulator(23); // target
* $populator->addAcls(array(123, 456)); // merge in a couple existing lists
@mrclay
mrclay / TagUtil.php
Created August 26, 2013 13:38
Elgg: Utilities for altering queries based on matching optional/required tags
<?php
namespace UFCOE\Elgg;
/**
* Utilities for altering queries based on matching optional/required tags
*/
class TagUtil {
/**