Skip to content

Instantly share code, notes, and snippets.

@nanotronic
nanotronic / doctrine-dql-type-function.php
Last active March 1, 2022 18:14 — forked from jasonhofer/doctrine-dql-type-function.php
Doctrine TYPE() function for DQL. Provides a way to access an entity's discriminator field in DQL queries.
<?php
namespace Query\Functions;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\Query\SqlWalker;
;(function($) {
// Add inner and outer width to zepto (adapted from https://gist.github.com/alanhogan/3935463)
var ioDim = function(dimension, includeBorder) {
return function (includeMargin) {
var sides, size, elem;
if (this) {
elem = this;
size = elem[dimension]();
sides = {
width: ["left", "right"],
Element.prototype.matchesSelector || (Element.prototype.matchesSelector = Element.prototype.webkitMatchesSelector || Element.prototype.mozMatchesSelector || function(selecta) {
var els = document.querySelectorAll(selecta);
for ( var i=0, L=els.length; i<L; i++ ) {
if ( els[i] == this ) {
return true;
}
}
return false;
});
var _hasOwnProperty = Object.prototype.hasOwnProperty;
if(!Element.prototype.matchesSelector) {
Element.prototype.matchesSelector =
Element.prototype.matches ||
Element.prototype.webkitMatchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector ||
Element.prototype.oMatchesSelector || function(selector) {
if(!selector)return false;
@nanotronic
nanotronic / can.control.route
Created March 19, 2013 16:11
Allowing optional parameters for can.Control.route. E.g.: docs/:section(/:subsection) > create two routes: docs/:section and docs/:section/:subsection docs(/:section)(/:subsection) > create three routes: docs, docs/:section and docs/:section/:subsection
define(['can/util/library', 'can/route', 'can/control'], function (can) {
var optionalParam = /\((.*?)\)/g,
escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
var getOptionalParam = function(route){
return route.replace(escapeRegExp, '\\$&').match(optionalParam);
};
// ## control/route.js