スキップしてメイン コンテンツに移動

投稿

2月, 2014の投稿を表示しています

Check Youtube Video Existance by ID

I have managed a lot of youtube videos (not owned by me) by youtube video ID to show them on my web page. But sometimes videos were unavailable suddenly (because of copyright issues or simply deleted etc.) So I have created tiny program for check availablitiy of youtube videos by youtube video ID. Here is the code. // print out unavailable videos String[] ids = new String[]{"id1", "id2"}; for(String id : ids) { Thread.sleep(1000); if(!checkExistance(id)) { System.out.println(id); } } public static String checkExistance(String id) { try{ // any method is fine as long as you can get contents from url getStringContentsFromURL("https://gdata.youtube.com/feeds/api/videos/"+id, "utf-8"); } catch(Exception e) { return false; } return true; } Example implementation for getStringContentsFromURL method. Sorry the implementation is a bit circumlocutory because I designed the co

Static Access to Symfony2 Logger

If you would like to use logging functionality in Symfony2, you should access logger service via container. For example in controller, you can easily access container and access logger service. $logger = $this->get('logger'); $logger->info('I just got the logger'); $logger->error('An error occurred'); Well, that's it. However, this is big however for me, what should I do when accessing logger not from controller class? Of course you can pass container or logger service itself to the class in service.yml service_use_logger: class: LoggingExample\Service\ServiceUsingLogger arguments: - @logger A bit pain everytime we should passing logger to the service class if you would like to use logger. For Java or .Net, I have never seen general logging functionality is provided from dependency injection container. For Almost all logging library, logger can be accessible as static - for example log4j. I tried to make logging functio

Override Symfony2 Original Request Class

Have you ever wanted to override Symfony2 core Request class? I am the one of them. Actually what I have would liked to do is overriding isSecure method in Request class bceause of our server configuration was a bit tricky. I have googled a bit and found useful article on Symfony2 ofiicial document . It says &quotyou should use setFactoryMethod&quot. HOWEVER &quotThe setFactory() method was added in Symfony 2.4&quot. I have used Symfony2.3.X because that version has long maintenance term. I have googled and finally found the solution for Symfony 2.3.X. You just modify request creation part in web/app.php (and web/app_dev.php). require_once __DIR__.'/../app/AppKernel.php'; //require_once __DIR__.'/../app/AppCache.php'; $kernel = new AppKernel('prod', false); $kernel->loadClassCache(); //$kernel = new AppCache($kernel); // You should modify here... // ORIGINAL // $request = Request::createFromGlobals(); // I have added my original r

Symfony2: Switching URL for Different Environment

Issue For Symfony2, if you would like to setup different url based on environment but using same action in controller, what should we do? In my case, I would have liked to setup different url based on different country enviroment but would have liked to use same action becaseu the functionality itself is completely same. Solution Setup routing.yml for each environment. Symfony2 porvides mailnly 2 ways to setup routing configuration - routing.yml and annotation on controller. I think using annotation is better way because you can easily check functionality and routing relation in controller class. However if you would like to setup different url based on different environment, using routing.yml is better way. Ok now I will show you my approach.... 1) You should prepare routing_shared.yml for common shared routing between environment. 2) You should preare routing.yml for rach enviroment which is depends on the environment, like routing_env_1.yml, routing_env_2.yml, etc. And