How to use Symfony Web Profiler from a separate container? - php

My application is split into 2 Docker containers: Frontend app (only static content, HTML, CSS, JS) and backend API (Symfony application). So the browser loads frontend app (http://localhost:8030) which then makes requests to the API on a different host/container (http://localhost:8031).
How can I use Symfony Web Profiler toolbar with this setup?
Normally Symfony injects HTML for the toolbar into each returned HTML response. But in my case Symfony never returns any HTML and acts only as the API for Json data.
I can see all requests in the profiler by going to http://localhost:8031/_profiler/search, but I'd like to have the full toolbar in the frontend app loaded through http://localhost:8030.
Is it possible to somehow manually inject profiler HTML code into responses returned not by Symfony application?

Related

Port a nextjs application into a php site

I have a nextjs app that I'm using to process stripe payments that I've deployed to Vercel. The app is simply a form with tons of functionality built in but requires the use of an api (which is why I'm using nextjs). What is the best way to get this into a php site? I need to access the nextjs api in order to communicate with stripe. Otherwise I would have just built the react app in the php site and rendered it on the page in question per usual. I've never done this before, so please any recommendations would be huge.
Here are the options I've come up with:
iframe. I've never been a huge fan of these, but figured this was an option. I can render my app via iframe on the php site.
use the vercel deployed nextjs app strictly for the api and build the react form into the php site. Then I would simply change the api requests to point to the vercel deployed nextjs app instead of a local api.
Are there better more efficient methods?
Try vercel-php, a PHP runtime for Vercel. Using the configuration described in the README, you can use a PHP repository as your backend and fetch data from there for your NextJS app.
Alternatively, you can use this directly in your NextJS repository and instead of having the api folder inside the pages directory, just have it as a top-level directory

Single Laravel application or 2(3?) seperate builds?

My main application is being built with Vue (mydomain.com), I also have a REST API (api.mydomain.com) and then my assets (assets.mydomain.com).
The API is unlikely to be used by other developers, and is only for my convenience when building the spa with Vue. Considering this: would it be better to build a single Laravel application that handles all three subdomains OR have a Laravel application that handles the API, a standalone Vue build for my main application and then serve the assets as a seperate build entirely?
What are the pros/cons for a single build vs three?
I haven't used Laravel in that context but I sure prefer the more modularized approach of having different builds for different functionality.
I normally use the approach with Node.js where I have both assets and api handled by the backend. (Express app etc) and then separate build fetching the data to render in the spa using React.
This build benefits scalability since you can easilly maintain, track and debug the code. Obviously it makes it also easier for unit testing. And the performance of the SPA isn't affected by the payload routing in the backend since it runs separately and only interact upon request (REST API in my case).
I hope I provided useful insight.

Simple Ionic workflow, does it work with backend without API?

This probably seems stupid question. But I'm new to ionic apps. I wanted to clear this before development.
Can we build ionic app without API? like we normally do for our website.
Example:
If you go to MySite.com, you will see the site running in php with normal rendering. Would Ionic work same way or it has to go through API Send/Receive request for data handling?
Ionic has no direct requirement on data access. It is built on AngularJS, which is in turn built on Javascript. Best practices would generally have you accessing JSON data from a server by using a mechanism that is Angular aware such as $http, $resource, Restangular, etc.
However, you can execute any javascript based browser command (or even load something like jQuery to perform the data access). However, as soon as you go outside of Angular, then you will have to deal with the additional complexity of making sure the digest cycle is run whenever you have updated values that may be reflected on your view because of data binding.
And, just to be clear, none of this has anything to do with what's happening on the server side. When you are asking about accessing "without API", do you mean accessing HTML files vs. JSON data? Ionic is built to be a SPA (single page application) that is installed on the mobile device and doesn't require internet access to run once it's installed.
Therefore, especially if external/live data isn't required (imagine some type of calculator where you enter values and results can be calculated with just the data in the app on the handset -- without the need for a live server at all), Ionic apps don't REQUIRE access to an external server at all.
You could provide traditional hyperlinks to other html files, but at that point it would no longer be running the packaged/installed files that form the basis of the installed app on the handset and would instead be a web app that is relying on an external server for all views. And, of course, even if it does require access to data from a server, the often massive increase in speed by not round tripping the server with a new HTML page (only a relatively tiny JSON payload in most situations) makes it feel much more like a true native app.
In ionic, the rendering happens on your phone. The server simply provides data. So if you need any data from a server (usually yes) then you need an API.
Ionic is focused on building native/hybrid mobile apps rather than
mobile websites.
– http://ionicframework.com/docs/overview/#browser-support
As per definition, an API only defines the way your ionic app can interact with your php script. In principle, there are no rules on how you design this interaction. So yes, you can keep it quite traditional/old-fashioned. Don't get the concept of an API mixed up with the concepts of RESTful or SOAP APIs etc.

Web to Native app - Request & Response - Listening service

This is a very general question, however I have done some research and believe I am simply missing some useful terminology of the concepts in question, and if someone could point me in the right direction it would be helpful.
Basically I am creating a PHP page, that will send a request - this will then be received by a native app. Where the user will either accept or decline the request. This will then be sent back to the PHP page.
So my queries..
What technologies or key concepts need to be applied here..
Main areas
-- PHP to send request
-- Native app to be listening for requests
-- PHP to be able to listen for the response
-- All needs to happen in real time i.e. user requests service, administrator confirms/declines, user receives response. All within in est. 60 seconds.
If you want to go into the right direction and you want all this to be on PHP, I would look at PHP RESTful service. Maybe
read up on this resource: http://www.amazon.com/RESTful-PHP-Services-Technologies-Solutions-ebook/dp/B005VQ8SB6/ref=sr_1_1?s=books&ie=UTF8&qid=1419012976&sr=1-1&keywords=9781847195531
You can also look into Symphony or Zend frameworks, there are other frameworks that has similar feature. If you need this quick, you can get it installed and test out what you're looking to accomplish.
Also take a look at Symphony snippet on Request & Response - Listening service
http://php-and-symfony.matthiasnoback.nl/2011/10/symfony2-how-to-create-a-custom-response-using-an-event-listener/
Something on previous post from Stackoverflow
symfony provides a solid framework for HTTP and restful API through which jQuery mobile can be configured and then if you extend TWIG for a template, then Symfony acts as the bundler and composer through with routing can take place. While Symfony does not run native apps, they need to retrieve and store data and on that front a framework such as Symfony works well. So one could argue that one could use APIs for multiple clients (iOS, Android and more) and then reuse controllers and use formats to generate XML/JSON thus theoretically it should work with Phonegap too.
#ref: Creating mobile app in Symfony2

Events in PHP slim web services

I am writing a web service in PHP using the Slim framework. I have a web application and a mobile application which uses the web service. My web application posts some data to the web service and web service writes it to a database. But I also wanted the web service to send a notification to my mobile application.
I assume this is some kind of an event based action. How to perform this for PHP slim web services? Or in general, for a PHP web service?
I personally use the symfony2 EventDispatcher component to achieve what you speak of. It's a clean way to, well, implement an event-based architecture. This particular implementation of the mediator pattern can make your code extensible with minimal overhead (and much organization).
Link: http://symfony.com/doc/current/components/event_dispatcher/introduction.html
Note: The EventDispatcher can be used independently of symfony2. The above link contains the packagist link of the component.
Edit: If you are a fan of global variables, you could look into the do_action function in WordPress.
I think there is no easy way to implement a direct event notification from Slim to a mobile device. To do such thing you need to open a socket between device and server so you can send direct notification to the device.
With Slim, the easiest way to achieve what you want is to use the list/queue pattern and tell the device to periodically ping your web service (like every 30 sec) and check if there is something new in the queue.

Categories