PHPackages                             xiifactors/azure-functions-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. xiifactors/azure-functions-bundle

ActiveSymfony-bundle

xiifactors/azure-functions-bundle
=================================

Simplify running a Symfony app using Azure Functions

0.1.6(2y ago)07MITPHPPHP &gt;=8.1

Since Jul 26Pushed 2y ago1 watchersCompare

[ Source](https://github.com/xiifactors/azure-functions-bundle)[ Packagist](https://packagist.org/packages/xiifactors/azure-functions-bundle)[ RSS](/packages/xiifactors-azure-functions-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (17)Versions (8)Used By (0)

Prereqs
=======

[](#prereqs)

- [Composer](https://getcomposer.org/doc/00-intro.md)
- [Azure Functions Core Tools](https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=linux%2Cportal%2Cv2%2Cbash&pivots=programming-language-csharp#install-the-azure-functions-core-tools)

    If using Homebrew you can run: `brew install azure-functions-core-tools@4`

---

Installation
------------

[](#installation)

### Step 1: Download the Bundle

[](#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:

```
$ composer require xiifactors/azure-functions-bundle
```

### Step 2: Enable the 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:

```
// config/bundles.php

return [
    // ...
    XIIFactors\AzureFunctions\AzureFunctionsBundle::class => ['all' => true],
];
```

### Step 3: Import the routes

[](#step-3-import-the-routes)

Then, import the routes by adding the following in the `config/routes.yaml` file of your project:

```
// config/routes.yaml

app_annotations:
    resource: '@AzureFunctionsBundle/src/Controller/'
    type: annotation
```

### Step 4: Import the services

[](#step-4-import-the-services)

Then, import the routes by adding the following in the `config/services.yaml` file of your project:

```
// config/services.yaml

imports:
    - { resource: '@AzureFunctionsBundle/config/services.yaml' }
```

### Step 5: Copy over required files

[](#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:

```
cp vendor/xiifactors/azure-functions-bundle/host.json.example host.json
cp vendor/xiifactors/azure-functions-bundle/local.settings.json.example local.settings.json
cp vendor/xiifactors/azure-functions-bundle/run.sh .
```

### Step 6: Create the Azure Function HTTP Entrypoint

[](#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:

```
// HttpEntrypoint/functions.json

{
    "disabled": false,
    "bindings": [
        {
            "name": "req",
            "authLevel": "anonymous",
            "type": "httpTrigger",
            "direction": "in",
            "route": "{path}",
            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"]
        },
        {
            "name": "$return",
            "type": "http",
            "direction": "out"
        }
    ]
}
```

### Step 7: Create your first controller

[](#step-7-create-your-first-controller)

You must use the `ResponseDto` to help with formatting the response:

```
// src/Controller/HealthController.php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use XIIFactors\AzureFunctions\Dto\ResponseDto;

#[
    Route(
        path: '/api/health',
        name: 'myapp.health',
        defaults: ['_format' => 'json'],
        methods: ['GET'],
    )
]
class HealthController extends AbstractController
{
    public function __invoke(): Response
    {
        return new JsonResponse(new ResponseDto(
            ReturnValue: json_encode([
                'success' => true,
            ])
        ));
    }
}
```

### Step 8: Start the function

[](#step-8-start-the-function)

Run the following in your terminal:

```
func start
```

You should now be able to run the following curl request locally:

```
curl -vvv http://localhost:7071/api/health
```

and receive:

```
{
    "success": true
}
```

enableForwardingHttpRequest
---------------------------

[](#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](https://learn.microsoft.com/en-us/azure/azure-functions/functions-custom-handlers#http-only-function).

Output Bindings
---------------

[](#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`:

```
// ./Example/function.json

{
  "disabled": false,
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "route": "example"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    },
    {
      "type": "queue",
      "direction": "out",
      "name": "exampleItem",
      "queueName": "example-queue",
      "connection": "AzureWebJobsStorage"
    }
  ]
}
```

The controller:

```
// src/Controller/ExampleController.php

namespace App\Controller;

use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use XIIFactors\AzureFunctions\Dto\ResponseDto;

#[
    Route(
        path: '/api/example',
        name: 'myapp.output_example',
        defaults: ['_format' => 'json'],
        methods: ['POST'],
    )
]
class ExampleController extends AbstractController
{
    public function __invoke(): Response
    {
        return new JsonResponse(new ResponseDto(
            // Sends the message to the "example" queue via the "exampleItem" output binding
            Outputs: ['exampleItem' => json_encode(['subject' => 'example'])],
            ReturnValue: json_encode([
                'success' => true,
            ])
        ));
    }
}
```

Input Bindings
--------------

[](#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`:

```
// ./QueueFunction/function.json

{
    "disabled": false,
    "bindings": [
        {
            "type": "queueTrigger",
            "direction": "in",
            "name": "exampleItem",
            "queueName": "example"
        },
        {
            "type": "blob",
            "direction": "out",
            "name": "outputBlob",
            "path": "example/{rand-guid}"
        }
    ]
}
```

The controller:

```
// src/Controller/QueueFunctionController.php

namespace App\Controller;

use RuntimeException;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Annotation\Route;
use XIIFactors\AzureFunctions\Dto\RequestDto;
use XIIFactors\AzureFunctions\Dto\ResponseDto;

#[
    Route(
        path: '/QueueFunction',
        name: 'myapp.input_example',
        defaults: ['_format' => 'json'],
        methods: ['POST'],
    )
]
class QueueFunctionController extends AbstractController
{
    public function __invoke(#[MapRequestPayload] RequestDto $rd): Response
    {
        // Grab the queue item
        $queueItem = $rd->Data['exampleItem'] ?? throw new RuntimeException('Queue item is missing');

        // Do something with queue item...
        $decoded = json_decode($queueItem, true);

        // Write queue item to blob storage
        return new JsonResponse(new ResponseDto(
            Outputs: ['outputBlob' => $queueItem]
        ));
    }
}
```

Deploying the function to Azure
-------------------------------

[](#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:

[](#1-create-the-dockerfile)

```
# ./Dockerfile

FROM mcr.microsoft.com/azure-functions/dotnet:4-appservice
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

# Install PHP 8.1
RUN apt -y install lsb-release apt-transport-https ca-certificates
RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
RUN apt update && apt install php8.1 php8.1-xml -y

# Get Composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

# Copy codebase into web root
COPY . /home/site/wwwroot

# Install composer deps and the bundle public/bundles/azurefunctions/index.php (see run.sh)
RUN cd /home/site/wwwroot && \
    composer install -o --no-scripts && \
    bin/console assets:install
```

### 2. Build and push the image to your ACR (Azure Container Registry)

[](#2-build-and-push-the-image-to-your-acr-azure-container-registry)

```
az login --identity
az acr login --name {YOUR_ACR_NAME}

az acr build \
  --registry {YOUR_REGISTRY_ID} \
  --image {YOUR_REGISTRY_ID}.azurecr.io/examplefunction:{YOUR_IMAGE_TAG}
```

### 3. Add any necessary environment variables to the function app

[](#3-add-any-necessary-environment-variables-to-the-function-app)

```
az login --identity

az functionapp config appsettings set \
  --resource-group {YOUR_RESOURCE_GROUP} \
  --name {YOUR_FUNCTION_NAME} \
  --settings APP_ENV=${APP_ENV} APP_DEBUG=${APP_DEBUG}
```

### 4. Deploy the new image

[](#4-deploy-the-new-image)

```
az login --identity

az functionapp config container set \
  --resource-group {YOUR_RESOURCE_GROUP} \
  --name {YOUR_FUNCTION_NAME} \
  --image {YOUR_REGISTRY_ID}.azurecr.io/examplefunction:{YOUR_IMAGE_TAG}
```

Within a couple of minutes the image should have been updated and new function deployed.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

7

Last Release

1020d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/df9fac1c891e71562168567560c86d2ac4e910abcd1cb179b4b81248b2f67e0e?d=identicon)[xiifactors](/maintainers/xiifactors)

---

Tags

azurefunctionsserverless

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/xiifactors-azure-functions-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/xiifactors-azure-functions-bundle/health.svg)](https://phpackages.com/packages/xiifactors-azure-functions-bundle)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[kadirov/api-starter-kit

443.9k](/packages/kadirov-api-starter-kit)[easycorp/easyadmin-demo

EasyAdmin Demo Application

145.7k](/packages/easycorp-easyadmin-demo)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
