{"id":15063277,"url":"https://github.com/jaxon-php/jaxon-symfony","last_synced_at":"2025-04-10T10:46:10.020Z","repository":{"id":50617405,"uuid":"60751746","full_name":"jaxon-php/jaxon-symfony","owner":"jaxon-php","description":"Jaxon library integration for the Symfony framework https://www.jaxon-php.org.","archived":false,"fork":false,"pushed_at":"2024-12-14T12:54:20.000Z","size":85,"stargazers_count":2,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-24T09:38:42.437Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaxon-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-09T05:24:44.000Z","updated_at":"2025-01-08T13:49:20.000Z","dependencies_parsed_at":"2024-07-14T10:29:39.857Z","dependency_job_id":"e1ffd36d-922c-44d8-80ae-3ae0a99b1f6c","html_url":"https://github.com/jaxon-php/jaxon-symfony","commit_stats":{"total_commits":91,"total_committers":2,"mean_commits":45.5,"dds":0.01098901098901095,"last_synced_commit":"499ab8eb4e5a817ed0dd6fe79a7149d95c6c9e89"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaxon-php%2Fjaxon-symfony","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaxon-php%2Fjaxon-symfony/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaxon-php%2Fjaxon-symfony/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaxon-php%2Fjaxon-symfony/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaxon-php","download_url":"https://codeload.github.com/jaxon-php/jaxon-symfony/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248201357,"owners_count":21064104,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T23:54:25.373Z","updated_at":"2025-04-10T10:46:09.998Z","avatar_url":"https://github.com/jaxon-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Jaxon integration for Symfony\n=============================\n\nThis package integrates the [Jaxon library](https://github.com/jaxon-php/jaxon-core) into the Symfony framework.\n\nInstallation\n------------\n\nAdd the following lines in the `composer.json` file, and run the `composer update` command.\n\n```json\n\"require\": {\n    \"jaxon-php/jaxon-symfony\": \"^5.0\"\n}\n```\n\nOr run the `composer require jaxon-php/jaxon-symfony ^5.0` command.\n\nAdd the Jaxon bundle in the `config/bundle.php` file.\n\n```php\nreturn [\n    ...\n\n    Jaxon\\Symfony\\JaxonBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\nCreate and edit the `packages/config/jaxon.yaml` file to suit the needs of your application.\nA sample config file is available [in this repo](https://github.com/jaxon-php/jaxon-symfony/blob/master/config/jaxon.yaml).\n\nAdd the following settings in the `config/services.yaml` file, to configure the Jaxon library.\n\n```yaml\nimports:\n    ...\n    - { resource: packages/jaxon.yaml }\n```\n\nThis config file by default registers Jaxon classes in the `jaxon/ajax` directory with the `\\Jaxon\\Ajax` namespace.\n\nThe Jaxon library must be setup on all pages that need to show Jaxon related content, using an event subscriber for example.\n\n```php\n\u003c?php\n\n// src/EventSubscriber/JaxonSubscriber.php\nnamespace App\\EventSubscriber;\n\nuse App\\Controller\\DemoController;\nuse App\\Controller\\JaxonController;\nuse Jaxon\\Symfony\\App\\Jaxon;\nuse Symfony\\Component\\EventDispatcher\\EventSubscriberInterface;\nuse Symfony\\Component\\HttpKernel\\Event\\ControllerEvent;\nuse Symfony\\Component\\HttpKernel\\KernelEvents;\n\nuse function is_array;\n\nclass JaxonSubscriber implements EventSubscriberInterface\n{\n    public function __construct(private Jaxon $jaxon)\n    {}\n\n    public function onKernelController(ControllerEvent $event)\n    {\n        $controller = $event-\u003egetController();\n\n        // when a controller class defines multiple action methods, the controller\n        // is returned as [$controllerInstance, 'methodName']\n        if (is_array($controller)) {\n            $controller = $controller[0];\n        }\n\n        // Select the controllers with Jaxon related content.\n        if ($controller instanceof JaxonController || $controller instanceof DemoController) {\n            $this-\u003ejaxon-\u003esetup();\n        }\n    }\n\n    public static function getSubscribedEvents()\n    {\n        return [\n            KernelEvents::CONTROLLER =\u003e 'onKernelController',\n        ];\n    }\n}\n```\n\nDefine a controller action to process Jaxon ajax requests.\n\n```php\nuse Jaxon\\Symfony\\App\\Jaxon;\nuse Symfony\\Component\\Routing\\Annotation\\Route;\nuse Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController;\n\nclass JaxonController extends AbstractController\n{\n    #[Route('jaxon', name: 'jaxon.ajax', methods: ['POST'])]\n    public function __invoke(Jaxon $jaxon)\n    {\n        if(!$jaxon-\u003ecanProcessRequest())\n        {\n            return; // Todo: return an error message\n        }\n\n        $jaxon-\u003eprocessRequest();\n        return $jaxon-\u003ehttpResponse();\n    }\n}\n```\n\nInsert Jaxon js and css codes in the pages that need to show Jaxon related content, using the `Twig` functions provided by the Jaxon bundle.\n\n```php\nuse Symfony\\Component\\Routing\\Annotation\\Route;\nuse Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController;\n\nuse function Jaxon\\rq;\n\nclass DemoController extends AbstractController\n{\n    #[Route('/', name: 'demo.home')]\n    public function __invoke()\n    {\n        // Print the page\n        return $this-\u003erender('demo/index.html.twig', [\n            'pageTitle' =\u003e \"Symfony Framework\",\n        ]);\n    }\n}\n```\n\n```php\n// templates/demo/index.html.twig\n\n\u003c!-- In page header --\u003e\n\n{{ jxnCss() }}\n\u003c/head\u003e\n\n\u003cbody\u003e\n\n\u003c!-- Page content here --\u003e\n\n\u003c/body\u003e\n\n\u003c!-- In page footer --\u003e\n\n{{ jxnJs() }}\n\n{{ jxnScript() }}\n```\n\nConfiguration\n------------\n\nThe settings in the `config/package/jaxon.yml` config file are separated into two sections.\nThe options in the `lib` section are those of the Jaxon core library, while the options in the `app` sections are those of the Symfony application.\n\nThe following options can be defined in the `app` section of the config file.\n\n| Name | Description |\n|------|---------------|\n| directories | An array of directory containing Jaxon application classes |\n| views   | An array of directory containing Jaxon application views |\n| | | |\n\nBy default, the `views` array is empty. Views are rendered from the framework default location.\nThere's a single entry in the `directories` array with the following values.\n\n| Name | Default value | Description                               |\n|------|---------------|-------------------------------------------|\n| directory | jaxon/ajax    | The directory of the Jaxon classes        |\n| namespace | \\Jaxon\\Ajax   | The namespace of the Jaxon classes        |\n| separator | .             | The separator in Jaxon js class names     |\n| protected | empty array   | Prevent Jaxon from exporting some methods |\n| |               |                                           |\n\nUsage\n-----\n\n### The Jaxon classes\n\nThe Jaxon classes can inherit from `\\Jaxon\\App\\CallableClass`.\nBy default, they are located in the `jaxon/ajax` dir of the Symfony application, and the associated namespace is `\\Jaxon\\Ajax`.\n\nThis is a simple example of a Jaxon class, defined in the `jaxon/Ajax/HelloWorld.php` file.\n\n```php\nnamespace Jaxon\\Ajax;\n\nclass HelloWorld extends \\Jaxon\\App\\CallableClass\n{\n    public function sayHello()\n    {\n        $this-\u003eresponse-\u003eassign('div2', 'innerHTML', 'Hello World!');\n        return $this-\u003eresponse;\n    }\n}\n```\n\n### Dependency injection\n\nServices in Symfony can be declared as public or private, and [injected in Jaxon classes](https://www.jaxon-php.org/docs/v3x/advanced/dependency-injection.html).\n\nSince Jaxon uses a container to fetch to the Symfony services that are injected in his classes, by default it will be able to get access only to services declared as public.\n\nA service locator can be defined for Jaxon in the `config/services.yaml` file, in order to provide access to private services.\n\n```yaml\nservices:\n  ...\n    jaxon.service_locator:\n        public: true\n        class: Symfony\\Component\\DependencyInjection\\ServiceLocator\n        tags: ['container.service_locator']\n        arguments:\n            -\n                Twig\\Environment: '@twig'\n```\n\nThe service locator must be declared as public, and take all the services that can be passed to Jaxon classes as arguments.\nSee the [Symfony service locators documentation](https://symfony.com/doc/4.4/service_container/service_subscribers_locators.html).\n\nContribute\n----------\n\n- Issue Tracker: github.com/jaxon-php/jaxon-symfony/issues\n- Source Code: github.com/jaxon-php/jaxon-symfony\n\nLicense\n-------\n\nThe package is licensed under the BSD license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaxon-php%2Fjaxon-symfony","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaxon-php%2Fjaxon-symfony","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaxon-php%2Fjaxon-symfony/lists"}