Download the PHP package xiifactors/azure-functions-bundle without Composer
On this page you can find all versions of the php package xiifactors/azure-functions-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xiifactors/azure-functions-bundle
More information about xiifactors/azure-functions-bundle
Files in xiifactors/azure-functions-bundle
Package azure-functions-bundle
Short Description Simplify running a Symfony app using Azure Functions
License MIT
Informations about the package azure-functions-bundle
Prereqs
- Composer
-
If using Homebrew you can run:
brew install azure-functions-core-tools@4
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
Step 3: Import the routes
Then, import the routes by adding the following
in the config/routes.yaml
file of your project:
Step 4: Import the services
Then, import the routes by adding the following
in the config/services.yaml
file of your project:
Step 5: Copy over required files
This repo includes example host.json
and local.settings.json
files (suffixed with .example
), as well as a bash script (run.sh
) that has a one-liner to execute the PHP webserver with the correct env vars.
Run the following in a terminal from the root of your project:
Step 6: Create the Azure Function HTTP Entrypoint
In the root of the project create a directory named HttpEntrypoint
.
Inside this directory create a function.json
file with the following contents:
Step 7: Create your first controller
You must use the ResponseDto
to help with formatting the response:
Step 8: Start the function
Run the following in your terminal:
You should now be able to run the following curl request locally:
and receive:
enableForwardingHttpRequest
This is a flag set in the host.json
file for the custom handler. Our host.json.example
has it enabled by default.
If this flag is false it mean that the Azure Function host will send a POST request to the URI /{NameOfFunction}
(e.g. /HttpEntrypoint
) including all details of the original request (like URI, method, params, etc) in the body. In this instance it is the job of HttpEntrypointController
to process that request and then send an internal request to the desired route.
But if the flag is set to true, it means that the function host will simply forward the original request onto our application. This bundle includes a ConvertResponseListener
(which will be enabled when you import the services - described in Step 4.) that will seamlessly handle both scenarios.
NOTE: When the flag is true it will improve performance, but be aware that the forwarding will only happen if the function is defined with an HTTP trigger "in" binding, and an HTTP "out" binding. If there are any additional bindings the request will not be forwarded and the behaviour reverts to that as if the flag is false - See the official documentation.
Output Bindings
The following example shows a function that receives an HTTP request and then uses an output binding to write a message to a queue. In this example you need to set the Outputs
property of the ResponseDto
object.
Note: This will mean that enableForwardingHttpRequest
will be nullified even if it is set to true
, as we have defined an extra binding.
The function.json
:
The controller:
Input Bindings
If you are only dealing with HTTP then you will just create controllers like the HealthController
above.
If you need to deal with other types of input, then it will be similar but note that the function host will POST to the name of the function, and the details of the input will be included in the request body. You can use the RequestDto
to map the request data if you want.
The function.json
:
The controller:
Deploying the function to Azure
There is more than one way to deploy the PHP function, the method offered here is to create a Docker image and then update the function app to use that image instead of its default one.
1. Create the Dockerfile:
2. Build and push the image to your ACR (Azure Container Registry)
3. Add any necessary environment variables to the function app
4. Deploy the new image
Within a couple of minutes the image should have been updated and new function deployed.
All versions of azure-functions-bundle with dependencies
ext-ctype Version *
ext-iconv Version *
phpdocumentor/reflection-docblock Version ^5.3
phpstan/phpdoc-parser Version ^1.23
symfony/console Version 6.3.*
symfony/dotenv Version 6.3.*
symfony/flex Version ^2
symfony/framework-bundle Version 6.3.*
symfony/property-access Version 6.3.*
symfony/property-info Version 6.3.*
symfony/runtime Version 6.3.*
symfony/serializer Version 6.3.*
symfony/twig-bundle Version 6.3.*
symfony/validator Version 6.3.*
symfony/yaml Version 6.3.*