Dieses Blog durchsuchen

Montag, 31. Oktober 2016

symfony 3: get bundleconfiguration from everywhere. Authenticationprovider

In some cases you need to access your bundleconfiguration in contexts, where you have no container, or the container does not contain the configuration, because you are in a firewall livecycle like in the authentication provider context.

So there is hope. After 2 hours dumping arround, I found a working solution.

We simply have to install a Bundleextension in your bundle and implement the "PrependExtensionInterface". This one allows to prepend configurations.


Step 1) Add a BundleExtension to your bundle like that:


As you can see, there is a prepend method. This method loads your bundleconfiguration and adds the needed items to the container from which you can get the config item later. In Authenticationcontexts the bundleconfig isn`t loaded by default, so you have to do that all to inject the configitems.


Step 2) Add a config.yml to <Bundlename>/Resources/config:
This is done to keep your bundleconfigs only in the bundlecontext. So you can later access your bundleconfig. And only that.

Step 3) Now you can get your config:

At last we have to publish our new configitems in the <BundleName>/DependencyInjection/Configuration.php

That is it!

symfony 3: get bundleconfiguration from everywhere. Authenticationprovider

In some cases you need to access your bundleconfiguration in contexts, where you have no container, or the container does not contain the configuration, because you are in a firewall livecycle like in the authentication provider context.

So there is hope. After 2 hours dumping arround, I found a working solution.

We simply have to install a Bundleextension in your bundle and implement the "PrependExtensionInterface". This one allows to prepend configurations.


Step 1) Add a BundleExtension to your bundle like that:


As you can see, there is a prepend method. This method loads your bundleconfiguration and adds the needed items to the container from which you can get the config item later. In Authenticationcontexts the bundleconfig isn`t loaded by default, so you have to do that all to inject the configitems.


Step 2) Add a config.yml to <Bundlename>/Resources/config:
This is done to keep your bundleconfigs only in the bundlecontext. So you can later access your bundleconfig. And only that.

Step 3) Now you can get your config:

At last we have to publish our new configitems in the <BundleName>/DependencyInjection/Configuration.php

That is it!

Freitag, 28. Oktober 2016

Munich: must have visited

This is a little offtopic I think, but I want to share my impressions of munich with you.So, if you are onetimes in Munich, feel free to follow my route there.

ASADO Parsing
My first restaurant in Munich was the steakhouse ASADO Parsing. It`s on the Parsinger Bahnhofsplatz 3. This is directly in the near of the Mainstation Munich Parsing.

The Steaks are perhaps a little small, but excelent in quality. It`s fresh and good.
But the secret tip is the young sexy waitress. She is what a man wants. Sweet small with wonderful blue eyes, long black hairs and a perfect body. A beautyful smile and a overvelming charm.

Now I got my first location where I want to get my steak from.

http://www.asado-steak.de/pasing.html

Feel free to enjoy!


Sonntag, 23. Oktober 2016

symfony 3: 404 routing nginx

If your routing does not work, even if the debug:router shows the correct routing and all other configurations seems to be correct.

Try to delete the <root>/var folder and run composer install again.

This will recreate the var/ datas.

After that your can try to give more rights on the var folder

That solved my problem

Donnerstag, 20. Oktober 2016

php7: install xhprof un ubuntu 16.04

On ubuntu we want to install xhprof as our default profiler

Install dependencies
apt-get install pear
sed -i "s/ -n / /" $(which pecl)
sudo apt-get install php7.0-dev
sudo pecl install xhprof
thats it

pear pecl: fix warnings on php7

On ubuntu 16.04 ann error might occure when you install pecl with pear and xhprof Here is a line which fixes that
sed -i "s/ -n / /" $(which pecl) 

Sonntag, 16. Oktober 2016

php: run a local inbuild webserver

If you want to start a local webserver on your terminal you can simply type:
php -S localhost:9000 -t web
This will start a webserver on directory "web"

php: calling protected methods without inheritance

Sometimesyou need to call a protected method without inherit from it.
This can be done by integrating the magic method __call()

Here is an example from php.net

yield_something(function($data) use (&$self)
   {
     $self->debug("Doing stuff to the data");
     // do something with $data
     $self->debug("Finished doing stuff with the data.");
   });
}

// Ah-Ha!
public function __call($method, $args = array())
{
   if(is_callable(array($this, $method)))
     return call_user_func_array(array($this, $method), $args);
}
}

$fun = new Fun();
echo $fun->having_fun();

?>

Samstag, 15. Oktober 2016

laravel 5: create professional api with automatic api-docs and rest clients with swagger

Prerequisits

We need some things installed on the local machine.

An Api is nothing without a good documention. Without Api-docs every consumer stands infront of a black box. Its is very hard to discover the api methods and to find out how all works. Even if the api is well coded an the developers know hoow to use it. I will always need support and training to give your api consumers / partners an idea how to manage your api.

This is where swagger and swagger-ui comes into the game.

Swagger is an defacto industry standard to unifiy Rest Apis over the internet. Swagger defines Standard metadatina for  each of your Api methods in JSON format.
No worry, you dont have to write JSON to get it on. You will "only" have to annotate your Api Classes and its methods.

Swagger UI generates a very useful UI for your REST-API by parsing the swagger.json definition


As you can see, this is a User API with 2 Methods in it. 1 User/list and 1 User/get method.

Swagger UI takes the swagger.json output and turns it inti this nice HTML Pages.

On the top of each Item you can display more information or even a REST Client like that:

Generate REST Clients out of the box



This is really awesome.

Add swagger and swagger-ui to your project

Now lets bring it together with laravel

At first you need l5-swagger. This is a cli extension for laravel

Add "darkaonline/l5-swagger": "~3.0 to your composer.json and make "composer update"

Add module creator to your cli

add "artem-schander/l5-modular": "^1.3" to your composer.json and make "composer update"

At first you need l5-swagger. This is a cli extension for laravel

Add "darkaonline/l5-swagger": "~3.0 to your composer.json and make "composer update"

Generate a module

Switch to your laravel project root

php artisan make:module Api 
This will create a Module Api under "app/modules"

Add annotation to your controller

Swagger annotations will describe your Api in a json format. So that it can be used to create a nice webapplication for your Api methods including a complete documentation.

Add a controller like that

As you can see you a lot of annotation there. Do not feel overvelmed from that. It is definetly worth a try. The benefit is a really smooth webui for your documentation within a REST Client for each method. This will definetly be a sales pitch for your Apis.

If you have set the routing to reach you api methods, you can generate the swagger.json by calling the artisan cli like that
php artisan l5-swagger:generate

This will generate a file "<approot>/storage/api-docs/api-docs.json"

Point your browser to that file and copy the url


Start swagger-ui

Open your browser and open a file "<swagger-ui/dist/index.htm>" from the filemenu in your browser

At that you will get the swagger ui.
Now you can paste the swagger.json url to the searchfield an hit "explore"


Now you will see your api documentation:

Thats awesome


apache: enable cors in htaccess

In some cases your javascripts want work if you try to make xhttp requests via ajax.

The browsers stuck on the CORS Policy wich rejects requests across different domains, to prevent xss.

In some cases you want to allow such requests. For instance in a trusted SOA enviroment, where you have to request accross different domains or subdomains.

If you are using apache as your webserver, you can  modify your headers and allow your browser to request via script from a other domain.

Here is how it works.

Add a .htaccess  for your directory where you want to request to:

Enable headers in apache with:
a2enmod headers

You can restrict the request methods by removing it from the list with allowed verbs to stricten security.





git: add / delete / modify a file on your last commit with --amend. Manipulate your history

Sometimes you forget an important change on your last commit and you have to commit a further change to your repo. This will look ugly in your commit history.

Here is a trick to let the forgotten change look like it was added in your last commit. This prevents discussions in your team about the last commits.


git add <forgotten filename>
git commit --amend --no-edit 

If you make a:

git log --graph --all --stat --decorate
It will show up only your last commit with both changes in it. The prevois and the last commit.

Please do only use that on your local history. History manipulation on remote repositories breaks codebases and causes trouble in your dev-team

git: protect you from history overrides and history manipulation

Sometimes you will get in the situation, that your changes simply disapear, even if you are 100% sure, that your have pushed your changes and merged them into master. In the history you cant find your commits.

Well, it seems, that someone has tampered the history with a rebase.

Thats really frustrating, because its hard to proof, and at the end you are looking dump.

Here is a way to protect you from tampering the history or using none fast forwards or deleting history

Edit your ~/.gitconfig


git: let git learn how to solve conflicts automaticly: rerere

Once you have solved a conflict, you can git tell to learn from you.
Activate rerere and next time the same conflicts occures git will solve this conflicts automaticly

git config --global rerere.enabled true

git: add a commited file to .gitignore

Everyones, how anoying it is to have files in the remote repository, which has to be on the .gitignorelist.

Git simply ignores every .gitignore entry, wich was committed already.

Here is a simple trick wich helps you out

git update-index --assume-unchanged <filename> 


Freitag, 14. Oktober 2016

laravel 5: json response with

In Laravell 5 PS7 support is missing. So it is a little bit tricky to return a json response with a statuscode and a content type.

Here is a simple controller which does the trick


Montag, 10. Oktober 2016

git: add p4merge as diff and mergetool to console

On windows its useful to use a difftool like p4merge.exe to compare 2 versions of a file.

Lets configure git to use p4merge

Prerequisits

We need some things installed on the local machine.

Edit .gitconfig

open a terminal
git config --global merge.tool p4merge
git config --global mergetool.p4merge.path "<path/to/p4merge.exe>"
git config --global mergetool.prompt false
git config --global diff.tool p4merge
git config --global difftool.p4merge.path "<path/to/p4merge.exe>"
git config --global difftool.prompt false
 
This will make git use p4merge for diff and merging your files visualy

You can test this new difftool by comparing unstaged changes like that:
git difftool
 

git: add a custom shortcut for long commands

Some commands in git are some kind of complicated. Look at this command:
It will simply print the grap history

git log --oneline --graph --decorate

To shorten that, you can setup a alias.

Prerequisits

We need some things installed on the local machine.
  • git bash installed

Add a shortcut

open a terminal
git config --global alias.hist "git log --oneline --graph --decorate"

This will add an alias "hist" to your git console

You can test it with:
git hist

git: add notepadd++ as default editor

If you are on Windows and you want to use notepad++ as the default editor you can follow this instructions 

Prerequisits

We need some things installed on the local machine.
  • git bash installed
  • notepadd++ installed

Add notepadd++ to git config

Open GitBash and type:
git config --global "notepad++ -multiInst -nosession"

You can test it with:
git config --global -e

nginx: tuning nginx and meter performance

Today i found a very good tutorial from Bajamin Cane.
He tunes an nginx x and metered it with ApacheBench

https://blog.codeship.com/tuning-nginx/

And a Second page based on the first:

https://www.webcodegeeks.com/web-development/pregenerating-static-web-pages-better-performance/