Skip to content

Instantly share code, notes, and snippets.

View Thinkscape's full-sized avatar

Arthur Bodera Thinkscape

View GitHub Profile
<?php
namespace Foo {
class Bar {
public function baz() {
return strlen('Regarding the overhead: Just keep in mind, that a typical application calls built-in functions many thousand times. Even if the difference is small: It exists.');
}
}
$start = microtime(true);
$foo = new Bar;
string(50) "The url we are looking for: https://github.com?abc"
string(46) "The url after parsing: https://github.com?abc="
URL has been broken during parsing
string(42) "Url before sending: https://github.com?100"
string(42) "Url after sending: https://github.com?100="
URL has been changed when sending request!
<?php
namespace My\App;
use Zend\Filter\FilterChain;
use Zend\InputFilter\Factory;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Validator\ValidatorChain;
/**
@Thinkscape
Thinkscape / bug-method-class.php
Last active December 29, 2015 13:49
WI-17404
<?php
namespace Foo {
class Bar {
public function baz(){}
}
}
namespace Jira {
use Foo\Bar;
#!/usr/bin/env php
<?php
/**
* PHP 5.4 Short Array Syntax Converter
*
* Command-line script to convert PHP's "array()" syntax to PHP 5.4's
* short array syntax "[]" using PHP's built-in tokenizer.
*
* This script is free software; you can redistribute it and/or
@Thinkscape
Thinkscape / AbstractCello.php
Last active December 24, 2015 05:29
For Julian
<?php
abstract class AbstractCello
{
/**
* @var EventManager
*/
protected $em;
protected function triggerPre($methodName, $params)
@Thinkscape
Thinkscape / EagerQuoteStrategy.php
Last active March 14, 2023 11:58
Doctrine2 ORM strategy for quoting all identifiers by default.
<?php
namespace Doctrine\ORM\Mapping;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
* A set of rules for determining the physical column, alias and table quotes
*/
class EagerQuoteStrategy implements QuoteStrategy
@Thinkscape
Thinkscape / SimpleXMLElement-node-existence.php
Last active June 11, 2021 02:53
How to check if a <child> node exists in SimpleXMLElement document ? Comparison of different approaches.
<?php
/**
* The only reliable way of determining if a child exists
* in SimpleXMLElement is to use count(). All other methods
* do not work reliably in global or local NS.
*
* NOTE: Error suppresion on @count() is used to suppress
* "PHP Warning: count(): Node no longer exists"
*/
if(!class_exists('SimpleXMLElement')) die("Bonkers");
@Thinkscape
Thinkscape / xml-to-json-problem.php
Last active August 10, 2023 10:36
Problem with using json_encode() to transform XML into array.
<?php
$xml = new \SimpleXMLElement('<xml>
<node attr="bar">second</node>
</xml>');
$array = json_decode(json_encode($xml), true);
print_r($array);
/*
Array
@Thinkscape
Thinkscape / JsonResponseVisitor.php
Created August 15, 2013 12:27
Guzzle path-enabled json response visitor.
<?php
namespace Guzzle\Service\Command\LocationVisitor\Response;
use Guzzle\Http\Message\Response;
use Guzzle\Service\Command\CommandInterface;
use Guzzle\Service\Description\Parameter;
class JsonPathVisitor extends JsonVisitor
{
public function visit(