Dieses Blog durchsuchen

Samstag, 31. Dezember 2016

Symfony get container from everywhere

In some situations your context is not container aware. For instance you are somewhere in your application and you want to dispatch an event. Without container you won't get the configured dispatcher.

One solution is to build your container with containerbuilder. But that only builds your module container. If you have dependencies to other libs it's hard to resolve all the dependencies. Another drawback is, that you build your container multiple times.

On simple solution is to use your AppKernel directly to get the container. AppKernel extends abstract Kernel. So you can override getContainer and save the container in a static field.

Add this 2 methods and the static field inside your AppKernel.php

After that you can get the loaded and configured container like that:

AppKernel::getContainerStatic()

Freitag, 30. Dezember 2016

Symfony 3: add eventlistener by configuration

After triing arround to implement eventhandling in Symfony3 and I came up with a following solution.

Given: There is a event "thumbnail.finedata.created".

You have a listenerclass :
"Mittax\MediaConverterBundle\Event\Listener\Thumbnail\FineDataCreated"

And a method : onFineDataCreated() which takes the event.

In Symfony 3 there is a simple way to configure the eventlistener in default config.yml without to register the event in custom code.

The eventlistener is simply a tagged service. So Symfony knows it's event listeners by configuration.



Step 1:

This yaml snippet can be placed in a file "custom_events.yml" in app/config

Step 2: 

Import the new file in app/config.yml after service.yml

That`s it.

Now you can check your event with
php bin/console debug:event-dispatcher <your eventname>

Thx to mablae for this tut.


Donnerstag, 29. Dezember 2016

Upgrade Symfony to 3.2.x

Today I stucked on this exception:
Error: Call to undefined method AppKernel::setAnnotatedClassCache()

after I upgraded from 3.1 to 3.2.1.

The cause was an old app/boostrap.php.cache.

Just delete the file and regenerate it with the following command:


 php vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php


Donnerstag, 22. Dezember 2016

Samstag, 17. Dezember 2016

PHP7: a mimetype to extension list

For everyone who needs an array with all  mimetypes map to the corresponding extension


Have fun with it

Montag, 12. Dezember 2016

Supported ffmpeg video formats / extensions

For everyone who is searching a comma seperated list of video extensions ffmpeg  supports:

RoQ,ac3,aiff,alaw,alsa,amr,asf,ass,au,avi,dau,dirac,dnxh,dts,dv,eac3,f32be,f32le,f64be,f64le,ffm,flac,flv,gxf,h261,h263,h264,image2,image2pipe,m4v,matroska,mjpeg,mmf,mp3,mpeg,mpegts,mulaw,mxf,nut,ogg,oss,rawvi,rm,s16be,s16le,s24be,s24le,s32be,s32le,s8,swf,u16be,u16le,u24be,u24le,u32be,u32le,u8,voc,wav,yuv4mpegpipe,3g2,3gp,4xm,IFF,ISS,MTV,aac,adts,apc,ape,asf_stream,avm2,avs,bethsoftvi,bfi,c93,cavsvi,crc,dsicin,dv1394,dv,dxa,a,a_cdata,film_cpk,framecrc,gif,gsm,idcin,ingenient,ipmovie,ipo,libdc1394,lmlm4,mlp,mm,mov,mp2,mp4,mpc,mpc8,mpeg1vi,mpeg2vi,mpegtsraw,mpegvi,mpjpeg,msnwctcp,mvi,mxf_d10,nc,nsv,null,nuv,oma,psp,psxstr,pva,r3,rcv,redir,rl2,rpl,rtp,rtsp,sdp,shn,siff,smk,sol,svc,thp,tiertexseq,tta,tx,vc1,vc1test,vc,vi,vi,vm,vob,wc3movie,wsau,wsvqa,wv,x11grab,xa,mp4,m4a,3gp,3g2,mj2

And here are imagemagick extensions:
ART,AVI,AVS,BMP,CGM,CMYK,CUT,DCM,DCX,DIB,DPX,EMF,EPDF,EPI,EPS,EPS2,EPS3,EPSF,EPSI,EPT,FAX,FIG,FITS,FPX,GIF,GPLT,GRAY,HPGL,HTML,ICO,JBIG,JNG,JP2,JPC,JPEG,MAN,MAT,MIFF,MONO,MNG,MPEG,M2V,MPC,MSL,MTV,MVG,OTB,P7,PALM,PBM,PCD,PCDS,PCL,PCX,PDB,PDF,PFA,PFB,PGM,PICON,PICT,PIX,PNG,PNM,PPM,PS,PS2,PS3,PSD,PTIF,PWP,RAD,RGB,RGBA,RLA,RLE,SCT,SFW,SGI,SHTML,SUN,SVG,TGA,TIFF,TIM,TTF,TXT,UIL,UYVY,VICAR,VIFF,WBMP,WMF,WPG,XBM,XCF,XPM,XWD,YUV

Donnerstag, 8. Dezember 2016

Dienstag, 6. Dezember 2016

ES6 unittests with jest-cli

After 2 days fighting with babel and mocha , I couldnt figure out why none of my module exports worked.

Now I found jest-cli on a video on Egghead.io with Kent C. Dodds, which does the job of my unittest of ES6 classes.

1) install npm dependencies. Download package.json and run npm install

2) save .babelrc with following content in the root of your project:


3) save following content to your root as sum.js
   
4) save following content to your root as sum.test.js

5) run npm test

That`s all. Now you are able to test ES6 classes. Here are the souces on github: https://github.com/pboethig/unittest-es6-javascript