Skip to content

Instantly share code, notes, and snippets.

View alcaeus's full-sized avatar

Andreas Braun alcaeus

View GitHub Profile
@alcaeus
alcaeus / DataObject\PostCount.php
Created May 25, 2015 15:53
Hydrated aggregation results with Doctrine ODM
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
@alcaeus
alcaeus / debug.sh
Created May 28, 2015 09:07
Remote debugging for CLI processes with PHPStorm
#!/bin/bash
# Configure these two values
ideServerName=server
xdebugPort=9000
# As long as you don't really know what you're doing, leave this alone.
export PHP_IDE_CONFIG=serverName=$ideServerName
php -dxdebug.remote_autostart=On -dxdebug.remote_enable=On -dxdebug.remote_port=$xdebugPort $*
@alcaeus
alcaeus / ConfigHydrator.php
Created June 18, 2015 07:17
EmbedOne hydrator
<?php
/** @EmbedOne */
if (isset($data['missionStatement'])) {
$embeddedDocument = $data['missionStatement'];
$className = $this->unitOfWork->getClassNameForAssociation($this->class->fieldMappings['missionStatement'], $embeddedDocument);
$embeddedMetadata = $this->dm->getClassMetadata($className);
$return = $embeddedMetadata->newInstance();
$embeddedData = $this->dm->getHydratorFactory()->hydrate($return, $embeddedDocument, $hints);
@alcaeus
alcaeus / Document.php
Last active August 29, 2015 14:27
ID mapping with generator overriding custom_id
<?php
namespace My\Custom;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
class Document {
/**
* This works
*
<?php
namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
class GH1229Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest
{
/**
@alcaeus
alcaeus / .mongorc.js
Created January 13, 2016 06:33
Show all fields in DBRef objects
DBRef.prototype.toString = function () {
var r = ['"$ref": ' + tojson(this.$ref), '"$id": ' + tojson(this.$id)];
var o = this;
for (var p in o) {
if (p !== '$ref' && p !== '$id' && typeof o[p] !== 'function') {
var t = typeof o[p];
r.push('"' + p + '": ' +
(t == 'object' ? 'object: {...}' : '"' + o[p] + '"'));
}
}
php > var_dump(2+"2");
int(4)
php > var_dump("2"+[]);
PHP Fatal error: Unsupported operand types in php shell code on line 1
PHP Stack trace:
PHP 1. {main}() php shell code:0
Fatal error: Unsupported operand types in php shell code on line 1
Call Stack:
@alcaeus
alcaeus / composer.version
Created February 25, 2016 06:59
Tests of different composer.json settings for mongo-php-adapter
$ composer --version
Composer version 1.0.0-alpha11 2015-11-14 16:21:07
@alcaeus
alcaeus / README.md
Last active April 19, 2021 14:26
Enable GPG for git commits

Enable GPG for git commits

Generate a key

  1. Install gpg and gpg-agent: brew install gpg gpg-agent
  2. Generate a new key: run gpg --gen-key and follow the instructions
  3. Write down the ID of the key. To do this, run gpg --list-keys. The output will look like this:
pub   4096R/E9468C9A 2016-04-20 [expires: 2016-07-19]
uid Andreas B. 
<?php
class Foo
{
/**
* @return self
*/
public function foo()
{
return $this;