{"id":28490447,"url":"https://github.com/alexdodonov/mezon-application","last_synced_at":"2025-10-11T13:39:30.949Z","repository":{"id":62527569,"uuid":"241466953","full_name":"alexdodonov/mezon-application","owner":"alexdodonov","description":"Simple class for creating applictions","archived":false,"fork":false,"pushed_at":"2023-08-17T18:14:08.000Z","size":128,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-23T17:50:04.699Z","etag":null,"topics":["application","mvc","mvc-framework","mvp-architecture","mvp-pattern","php","php-framework","php-mvc","php-mvc-framework","web-application"],"latest_commit_sha":null,"homepage":"https://twitter.com/mezonphp","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexdodonov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-02-18T21:03:37.000Z","updated_at":"2023-12-08T22:29:25.000Z","dependencies_parsed_at":"2023-09-26T03:47:26.604Z","dependency_job_id":null,"html_url":"https://github.com/alexdodonov/mezon-application","commit_stats":{"total_commits":103,"total_committers":2,"mean_commits":51.5,"dds":0.009708737864077666,"last_synced_commit":"1ea62e7dc9f7f551006852f49206e69e706054fa"},"previous_names":[],"tags_count":71,"template":false,"template_full_name":null,"purl":"pkg:github/alexdodonov/mezon-application","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdodonov%2Fmezon-application","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdodonov%2Fmezon-application/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdodonov%2Fmezon-application/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdodonov%2Fmezon-application/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexdodonov","download_url":"https://codeload.github.com/alexdodonov/mezon-application/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdodonov%2Fmezon-application/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262518769,"owners_count":23323374,"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":["application","mvc","mvc-framework","mvp-architecture","mvp-pattern","php","php-framework","php-mvc","php-mvc-framework","web-application"],"created_at":"2025-06-08T07:09:01.552Z","updated_at":"2025-10-11T13:39:30.885Z","avatar_url":"https://github.com/alexdodonov.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Base application class\n\n[![Build Status](https://travis-ci.com/alexdodonov/mezon-application.svg?branch=master)](https://travis-ci.com/alexdodonov/mezon-application) [![codecov](https://codecov.io/gh/alexdodonov/mezon-application/branch/master/graph/badge.svg)](https://codecov.io/gh/alexdodonov/mezon-application) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/alexdodonov/mezon-application/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/alexdodonov/mezon-application/?branch=master)\n\n## Intro\n\nAll your applications will be derived from this class or will be using classes which are siblings of this Application class.\n\n## Functionality\n\nThis class provides:\n\n- routing\n- transformation actionActionName methods into static routes /action-name/ which handles GET and POST methods\n- loading routes from config file (php or json)\n\n### Loading routes from config file\n\nWith time your application will grow and number of routes will increase. So we have provided convenient way to store all routes in a standalone config file. So it is not necessary to initialize all routes in an Application (or any derived class) object's constructor.\n\nLet's find out how you can use it.\n\nFirst of all create config file ./conf/routes.php in your projects directory. It must look like this:\n\n```PHP\n$callbackProvider = new SomeCallbackClass();\n\nreturn \n    [\n        [\n            'route' =\u003e '/news/' ,  // your route\n            'callback' =\u003e 'displayNewsLine'    // this must be the method name of your \n                                               // Application derived class\n        ] , \n        [\n            'route' =\u003e '/news/[i:news_id]/' ,    // your route\n            'callback' =\u003e 'displayExactNews' ,   // this must be the method name of your \n            'method' =\u003e 'POST'                   // Application derived class\n        ] , \n        [\n            'route' =\u003e '/some-route/' , \n            'method' =\u003e 'GET' , \n            'callback' =\u003e [  // here we specify callback as pair [object, method]\n                callbackProvider , \n        \t'someMethod'\n            ]        \t\n        ]\n    ];\n```\n\nNote that the 'method' field is not set then it will be defaulted to GET.\n\nYou can also specify your own config file.\n\nThen just call Application::loadRoutesFromConfig()\n\n\n\n```PHP\n$app-\u003eloadRoutesFromConfig( './conf/my-config.php' );\n```\n## Common application class\n\n### Intro\n\nThis class provides simple application routine with more complex rendering and error handling. \n\n### Extended routes processing\n\nIn [Application](https://github.com/alexdodonov/mezon-application) class routes may return only strings. But CommonApplication class allows you to return arrays of string which will be placed in the template placeholders.\n\nSimple example:\n\n```PHP\nclass ExampleApplication extends CommonApplication\n{\n    /**\n     * Constructor.\n     */\n    function __construct( $template )\n    {\n        parent::__construct( $template );\n    }\n\n    function actionSimplePage()\n    {\n        return [ \n            'title' =\u003e 'Route title' , \n            'main' =\u003e 'Route main'\n        ];\n    }\n}\n```\n\nHere route's handler generates two parts of the page /simple-page/ - 'title' and 'main'. These two part will be inserted into {title} and {main} placeholders respectively.\n\nMore complex example:\n\n```PHP\nclass ExampleApplication extends CommonApplication\n{\n    /**\n     * Constructor.\n     */\n    function __construct($template)\n    {\n        parent::__construct($template);\n    }\n\n    function actionSimplePage()\n    {\n        return [ \n            'title' =\u003e 'Route title' , \n            'main' =\u003e new View('Generated main content')\n        ];\n    }\n}\n```\n\nHere we pass instance of the class View (or any class derived from View) to the application page compilator. It will call View::render method which must return compiled html content.\n\n### Routes config\n\nYou can also keep al routes in configs. You can use json configs:\n\n```JS\n[\n    {\n        \"route\": \"/route1/\",\n\t\"callback\": \"route1\",\n\t\"method\": \"GET\"\n    },\n    {\n\t\"route\": \"/route2/\",\n\t\"callback\": \"route2\",\n\t\"method\": [\"GET\",\"POST\"]\n    }\n]\n```\n\nThis data must be stored in the './conf/' dir of your project. Or load configs explicitly as shown below (using method loadRoutesFromConfig).\n\nAnd we also need these methods in the application class.\n\n```PHP\nclass ExampleApplication extends CommonApplication\n{\n    /**\n     * Constructor.\n     */\n    function __construct($template)\n    {\n        parent::__construct($template);\n\n\t// loading config on custom path\n\t$this-\u003eloadRoutesFromConfig('./my-routes.json');\n    }\n\n    function route1()\n    {\n        return [ \n            // here result\n        ];\n    }\n\n    function route2()\n    {\n        return [ \n            // here result\n        ];\n    }\n}\n```\n\nNote that you can load multiple configs with one call of the method loadRoutesFromConfigs\n\n```PHP\nfunction __construct($template)\n{\n    parent::__construct($template);\n\n    $this-\u003eloadRoutesFromConfigs(['./conf/my/routes.json', './conf/my-routes.php']);\n}\n```\n\nOr the same:\n\n```PHP\nfunction __construct($template)\n{\n    parent::__construct($template);\n\n    $this-\u003eloadRoutesFromDirectory('./conf');\n}\n```\n\n## Action messages\n\nYou can create file with the list of messages which will be substituted in the template variable `action-message`\n\nThis file must be stored in the directory `%your-application-class-directory%/res/action-messages.json`\n\nThen if the class will find `$_GET['action-message']` parameter, then `action-message` substitution will be triggered.\n\n# View\n\n## Static view\nYou can simply output content of the *.tpl file as common view. It can be usefull if you need to render static pages or static page parts. It will let you to avoid creating separate class and separate view methods for these purposes.\n\nIt is quite simple:\n\n```php\n// here $template is an instance of the \\Mezon\\HtmlTemplate\\HtmlTemplate class\n// and 'block-name' is a block name in this class\n$view = new \\Mezon\\Application\\ViewStatic($template, 'block-name');\n```\n\nFor more details about Mezon templates [see](https://github.com/alexdodonov/mezon-html-template)\n\n# Controller\n\ntba\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexdodonov%2Fmezon-application","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexdodonov%2Fmezon-application","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexdodonov%2Fmezon-application/lists"}