Skip to content

Instantly share code, notes, and snippets.

@mattsches
mattsches / configuration.yaml
Created May 8, 2017 21:35
Beispiel für RESTful Sensor in Home Assistant zur Abfrage des luftdaten.info API
sensor:
- platform: rest
resource: http://api.luftdaten.info/v1/sensor/1777
value_template: >
{% if value_json is sequence %}
{% set sensor = value_json | last %}
{% else %}
{% set sensor = value_json %}
{% endif %}
{% for sdv in sensor.sensordatavalues %}

Found an example there is a thing in laravel called FormRequest. Sometimes, I need extra validation. So I need to use some service there somehow. What options I have

  1. facade
  2. service locator via app() global function
  3. I also have instance of container there via $this->container

which one is the best here? I suppose instance of container

I can't do constructor injection. Why? Because for me, it seams that there are too many arguments on the __construct method

@mattsches
mattsches / Roman.php
Created January 30, 2013 08:06
PHP Roman Numerals Code Kata solution. A collaborative effort of the people @ PHP User Group Rheinhessen, Jan '13.
<?php
/**
* Converts Roman numbers to integers
*/
class Roman
{
/**
* @var array
*/
<?php
/**
* Class LuftdatenApi
*/
class LuftdatenApi
{
const BASE_URL = 'http://api.luftdaten.info/v1/sensor/';
/**
@mattsches
mattsches / Album.php
Created April 24, 2016 14:53
Example entity for DoctrineRestDriver issue
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* This annotation marks the class as managed entity:
*
* @ORM\Entity
@mattsches
mattsches / fritzbox.ini
Created November 1, 2013 16:06
Sample Config, um mit der FRITZ!Box 7320 (Firmware-Version: 100.05.51) einen VPN-Tunnel aufzubauen. Mehr in meinem Blogpost unter http://blog.sperr-objekt.de/content/1000423-VPN-Tunnel-mit-der-FRITZ!Box-7320-und-Linux.html
vpncfg {
connections {
enabled = yes;
conn_type = conntype_user;
name = "MEINVPN";
always_renew = no;
reject_not_encrypted = no;
dont_filter_netbios = yes;
localip = 0.0.0.0;
local_virtualip = 0.0.0.0;
@mattsches
mattsches / layered.inc.php
Last active December 20, 2015 21:48 — forked from onli/layered.inc.php
Added charset to connection adapter
<?php
use Zend\Db\Sql\Sql;
use Zend\Db\Sql\Select;
use Zend\Db\Adapter\Adapter;
$result = null;
/**
* Tells the DB Layer to start a DB transaction.
*
* @access public
@mattsches
mattsches / .filelist.txt
Created December 13, 2015 13:16
Liste von PHP-Dateien der Fotoverwaltung Lychee, die von Phan in dieser Reihenfolge eingelesen werden sollen.
data/config.php
php/define.php
php/autoload.php
php/modules/Album.php
php/modules/Database.php
php/modules/Import.php
php/modules/Log.php
php/modules/Module.php
php/modules/Photo.php
php/modules/Plugins.php
@mattsches
mattsches / sf2tt_001.php
Created June 16, 2012 14:02
EventListener mit PRE_SET_DATA-Event in Symfony2
/* ... */
public function buildForm(FormBuilder $builder, array $options)
{
$builder->addEventListener(FormEvents::PRE_SET_DATA,
function (DataEvent $event) use ($builder)
{
$form = $event->getForm();
/* @var \Sperrobjekt\Sf2ttBundle\Entity\Category $data */
$data = $event->getData();
@mattsches
mattsches / test.php
Created February 22, 2012 12:05 — forked from rodneyrehm/test.php
PHPGangsta: Doppelte Array-Einträge entfernen
<?php
if (extension_loaded('xdebug')) {
echo "WARNING: xdebug is enabled\n";
}
function _count()
{
$array = array(1, 5, 8, 'Michael', 5, 4, 9, 'Martin', 18, 12, 'Michael', 4, 12);