{"id":26984632,"url":"https://github.com/dneustadt/majima","last_synced_at":"2025-04-03T17:48:38.784Z","repository":{"id":56970423,"uuid":"102198808","full_name":"dneustadt/majima","owner":"dneustadt","description":"majima is a lightweight PHP framework","archived":false,"fork":false,"pushed_at":"2017-09-06T22:14:45.000Z","size":57,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-18T09:10:16.930Z","etag":null,"topics":["assets","micro-framework","mysql","php","template-inheritance"],"latest_commit_sha":null,"homepage":"http://softcoder.de","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dneustadt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-02T13:35:00.000Z","updated_at":"2018-04-28T06:39:06.000Z","dependencies_parsed_at":"2022-08-21T06:40:26.545Z","dependency_job_id":null,"html_url":"https://github.com/dneustadt/majima","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dneustadt%2Fmajima","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dneustadt%2Fmajima/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dneustadt%2Fmajima/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dneustadt%2Fmajima/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dneustadt","download_url":"https://codeload.github.com/dneustadt/majima/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247052501,"owners_count":20875681,"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":["assets","micro-framework","mysql","php","template-inheritance"],"created_at":"2025-04-03T17:48:38.149Z","updated_at":"2025-04-03T17:48:38.772Z","avatar_url":"https://github.com/dneustadt.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# majima\n\n[![Scrutinizer](https://scrutinizer-ci.com/g/dneustadt/majima/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/dneustadt/majima/?branch=master)\n[![Join the chat at https://gitter.im/majima-framework/Lobby](https://badges.gitter.im/majima-framework/Lobby.svg)](https://gitter.im/majima-framework/Lobby?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n- **License**: MIT\n- **Github Repository**: \u003chttps://github.com/dneustadt/majima\u003e\n\nmajima is a lightweight PHP framework that is based on [Symfony](https://github.com/symfony/symfony) \ncomponents. It features a plugin system that relies heavily on the concept of dependency injection \nand should suffice as a foundation for most web applications.\n\n### Features\n\n* Plugin System\n  * Template inheritance\n  * Collectors for JS and LESS compiling\n  * install and update routines\n* Template Engine\n  * functions for inheriting, routing and asset linking\n  * HTML bootstrap template\n* Query Builder\n* User Provider\n\n### Server requirements\n\n- PHP 5.6.4 or above\n- [Apache 2.2 or 2.4](https://httpd.apache.org/)\n- Apache's `mod_rewrite` module\n- MySQL 5.5.0 or above\n\n#### Required PHP extensions\n\n-   \u003ca href=\"http://php.net/manual/en/book.json.php\" target=\"_blank\"\u003ejson\u003c/a\u003e\n-   \u003ca href=\"http://php.net/manual/en/book.mbstring.php\" target=\"_blank\"\u003embstring\u003c/a\u003e\n-   \u003ca href=\"http://php.net/manual/en/book.session.php\" target=\"_blank\"\u003esession\u003c/a\u003e\n-   \u003ca href=\"http://php.net/manual/en/ref.pdo-mysql.php\" target=\"_blank\"\u003ePDO/MySQL\u003c/a\u003e\n\n### Installation\n\n1.) Clone the git repository to the desired location using:\n\n    git clone https://github.com/dneustadt/majima.git\n    \nor use composer\n\n    composer require dneustadt/majima\n\n2.) Set the correct directory permissions:\n\n    chmod -R 755 var\n    chmod -R 755 web\n    chmod -R 755 upload\n    \n3.) Install dependencies from the same directory\n\n    composer install\n    \n4.) Create a new MySQL database\n\n5.) Run the majima installation script by accessing the URL in a web browser. \nThis should be the URL where you uploaded the majima files.\n* If you installed majima in the root directory, you should visit: `http://example.com/install`\n* If you installed majima in its own subdirectory called `majima`, for example, \nyou should visit: `http://example.com/majima/install`\n\n### Plugins\n\n**For a real life examples see the demo plugins:**\n* \u003chttps://github.com/dneustadt/majima-grid\u003e\n* \u003chttps://github.com/dneustadt/majima-pages\u003e\n\nTo create a new plugin first make a new directory under the `plugins` directory. In this example\nit will be `MyPlugin`. Create a new class `MyPlugin.php` within that new directory. The name of\nthe file must match the name of the containing folder.\n\nBy extending `PluginAbstract` you will gain access to the `ContainerBuilder` reference\n\n    $this-\u003econtainer // returns instance of ContainerBuilder\n    \n#### Example of a Plugin class:    \n\n```php\nnamespace Plugins\\MyPlugin;\n \nclass MyPlugin extends PluginAbstract\n{\n    private $priority = 0;\n    \n    private $version = '1.0.0';\n \n    public function getPriority()\n    {\n        return $this-\u003epriority;\n    }\n```    \n\nReturn an integer for the priority in which order plugins should be loaded. default is 1\n\n```php\n    public function getVersion()\n    {\n        return $this-\u003eversion;\n    }\n```\n\nReturns the version of the plugin. default is 1.0.0. If the version is newer than what is\nsaved in the database, the method `update()` will be called.\n\n```php\n    public function update()\n    {\n    }\n    \n    public function install()\n    {\n    }\n```\n\nDo something if the plugin isn't registered in database yet, e.g. create tables.\n\n```php\n    public function build()\n    {\n    }\n```\n\nUse this method and `$this-\u003econtainer` to add compiler passes, set container services or parameters.\n\n```php\n    public function registerControllers()\n    {\n        return new ControllerCollection([\n            'my_plugin.my_controller' =\u003e MyController::class,\n            'majima.admin_controller' =\u003e AdminControllerDecorator::class,\n        ]);\n    }\n```\n\nUse this method to register new controllers or decorate existing ones. Since the id `majima.admin_controller`\nis already set, the service for that controller will be decorated. The new id for the decorated service\nwill then be prepended by snake case of the plugin class name, so in this case it would be \n`my_plugin.majima.admin_controller`\n\n```php\n    public function setRoutes()\n    {\n        $routeCollection = new RouteCollection();\n        $routeCollection-\u003eaddRoute(\n            new RouteConfig(\n                'myPlugin_index',\n                '/hello/world/',\n                'my_plugin.my_controller:indexAction'\n            )\n        );\n        $routeCollection-\u003eaddRoute(\n            new RouteConfig(\n                'admin_new',\n                '/admin/new/',\n                'my_plugin.majima.admin_controller:newAction'\n            )\n        );\n        return $routeCollection;\n    }\n```\n\nEnhance the routes to actions of controllers for the routing. The name/id of a route, e.g. `myPlugin_index`,\nwill also determine, where the view for that action will be looked for. Underscores will be converted\nto slashes and the first letter will be capitalized. So in this example majima would look for a template\n`MyPlugin/index.tpl`\n\n```php\n    public function setViewResources()\n    {\n        $viewCollection = new ViewCollection(join(DIRECTORY_SEPARATOR, [__DIR__, 'Resources']));\n        $viewCollection-\u003esetViews(['views']);\n        return $viewCollection;\n    }\n \n    public function setCssResources()\n    {\n        $assetCollection = new AssetCollection(join(DIRECTORY_SEPARATOR, [__DIR__, 'Resources', 'css', 'src']));\n        $assetCollection-\u003esetFrontendAssets([\n            join(DIRECTORY_SEPARATOR, ['frontend', 'all.scss']),\n        ]);\n        $assetCollection-\u003esetBackendAssets([\n            join(DIRECTORY_SEPARATOR, ['backend', 'all.scss']),\n        ]);\n        return $assetCollection;\n    }\n    \n    public function setJsResources()\n    {\n        $assetCollection = new AssetCollection(join(DIRECTORY_SEPARATOR, [__DIR__, 'Resources', 'js', 'src']));\n        $assetCollection-\u003esetFrontendAssets([\n            join(DIRECTORY_SEPARATOR, ['frontend', 'jquery.js']),\n        ]);\n        $assetCollection-\u003esetBackendAssets([\n            join(DIRECTORY_SEPARATOR, ['backend', 'jquery.plugin.js']),\n        ]);\n        return $assetCollection;\n    }\n}\n```\n\nCollect views for routes and assets for compilation. Assets can be separated for use in frontend and backend\ncontext (when user is logged in).\n\n##### Controller Example\n\nBy extending `MajimaController` you will gain access to the following references\n\n    $this-\u003econtainer //returns instance of DependencyInjection\\Container\n    $this-\u003edbal //returns instance of FluentPDO\n    $this-\u003eengine //returns instance of Dwoo\\Core\n\n```php\nclass MyController extends MajimaController\n{\n    /**\n     * @param Request $request\n     */\n    public function indexAction(Request $request)\n    {\n        $bar = $this-\u003edbal-\u003efrom('foo')-\u003efetchAll();\n    \n        $this-\u003eassign(\n            [\n                'foo' =\u003e $bar,\n            ]\n        );\n    }\n}\n```\n\n[FluentPDO](https://github.com/envms/fluentpdo) is a query builder  \n[Dwoo](https://github.com/dwoo-project/dwoo) is the template engine of majima  \nUse `assign` to pass an array of data to views.  \n\nIf the route to the action can be resolved as a path to a template (see above),\nyou don't have to return anything in your action. If you're outside of the\nconventions, you can render a template and return a response yourself:\n\n```php\n    // returns Response with rendered content\n    return $this-\u003eengine-\u003erender('/path/to/my/template.tpl');\n```    \n\n##### Template functions\n\nAdding to Dwoo's own functions majima introduces a few more:\n\n    {inherits \"Index/index.tpl\"}\n\nVirtually the same as Dwoo's `extends` but allows you to inherit templates\nfrom the majima's base HTML bootstrap and views of previously loaded plugins.\n\n    {url \"index_index\" array('foo' =\u003e $bar)}\n    \nWill generate the url of a registered route. Optionally pass\nan array of GET parameters.\n\n    {link \"/web/css/style.min.css\", $.cache_buster}\n    \nGet the absolute path to an asset. Optionally pass a cache buster value.\nYou can use the global `$.cache_buster` which will be regenerated once the\ncache is emptied.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdneustadt%2Fmajima","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdneustadt%2Fmajima","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdneustadt%2Fmajima/lists"}