{"id":21570818,"url":"https://github.com/snowlaboratory/nucleus","last_synced_at":"2025-03-18T06:14:48.603Z","repository":{"id":65826812,"uuid":"600790565","full_name":"SnowLaboratory/Nucleus","owner":"SnowLaboratory","description":"Micro PHP framework for shared hosting","archived":false,"fork":false,"pushed_at":"2023-02-15T14:09:43.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-24T12:45:40.568Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/SnowLaboratory.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-12T16:01:02.000Z","updated_at":"2023-02-12T16:49:40.000Z","dependencies_parsed_at":"2023-07-29T10:16:27.827Z","dependency_job_id":null,"html_url":"https://github.com/SnowLaboratory/Nucleus","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SnowLaboratory%2FNucleus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SnowLaboratory%2FNucleus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SnowLaboratory%2FNucleus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SnowLaboratory%2FNucleus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SnowLaboratory","download_url":"https://codeload.github.com/SnowLaboratory/Nucleus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244166760,"owners_count":20409179,"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-11-24T11:13:50.726Z","updated_at":"2025-03-18T06:14:48.595Z","avatar_url":"https://github.com/SnowLaboratory.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Nucleus\n\nPHP Micro Framework written using service provider architecture.\n\n## Features\n- Environment Files\n- Configuration Files\n- Service Containers\n- Supports Multiple App Instances\n- Configurable Folder Structure\n\n\n## Installation\nPlace the `Nucleus` folder anywhere in your project. Then create a `index.php` file\nwhich creates a new app.\n\n```php\nrequire_once NUCLEUS . \"/bootstrap.php\";\n\n$app = new Nucleus();\n\n$app-\u003eboot();\n```\n\n## Extending Behavior\n\nNext you can register custom packages by passing a class which extends the base ServiceProvider class. This is where you instantiate new classes and require dependencies.\n\n```php\nclass RouteServiceProvider extends ServiceProvider\n{\n\n    public function __construct($app)\n    {\n        parent::__construct($app);\n    }\n\n    public function register()\n    {\n        // called immediately after instantiation \n    }\n\n    public function boot()\n    {\n        // called after all packages are registered\n    }\n}\n```\n\n### Create factories without boilerplate\nThe core of the app is based on a container which can store a recipe for creating a new instance of a class. This allows you to make a new instance of your class in the future without all the work. For example if your database class depends on a config file. You could do something like the following.\n\n```php\nclass DatabaseServiceProvider extends ServiceProvider\n{\n\n    public function register()\n    {\n        $this-\u003eapp-\u003ebind(Mysql::class, function () {\n            $config = config('db.mysql');\n            return new MySqlConnector($config);\n        });\n    }\n\n    //...\n}\n```\n\nThen anywhere else in your application you could create a new MySqlConnector by resolving the string.\n```php\n$db = resolve(MySql::class)\n$db-\u003equery(...)\n```\n\nIf you do not want to create a new instance every time the class is resolved, then register it as a singleton by changing `bind` to `singleton`.\n\n```php\nclass DatabaseServiceProvider extends ServiceProvider\n{\n\n    public function register()\n    {\n        $this-\u003eapp-\u003esingleton(Mysql::class, function () {\n            $config = config('db.mysql');\n            return new MySqlConnector($config);\n        });\n    }\n\n    //...\n}\n```\n\n## Registering a new provider\nYou must register your service provider if you want the app to have access to the new behavior. You can manually register the class using the `register` method. \n\n```php\n$app = new Nucleus();\n\n$app-\u003eregister(RouteServiceProvider::class);\n$app-\u003eregister(MysqlServiceProvider::class);\n\n$app-\u003eboot();\n```\n\nOr if you are using the `ConfigServiceProvider` you can define a list of providers in your `app/config/app.php` file by default. \n\n```php\n// app/config/app.php\n\u003c?php\n\nreturn [\n\n    \"providers\" =\u003e [\n        \\App\\Providers\\RouteServiceProvider::class,\n        \\App\\Providers\\MysqlServiceProvider::class,\n    ],\n\n];\n```\n\n\n## Routing\nRouting is the entry point into your application. Each route registers a path and a closure. When the URI path and method match the route, the code will run.\n\n```php\n$route-\u003eget('/', function () {\n    echo \"Hello Nucleus\";\n    echo \"\u003cbr\u003e\";\n    echo \"APP_ENV: \" .  config('app.env');\n});\n```\n\n### Route Groups\nRoutes can be prefixed with a route by configuring the router in the `RouteServiceProvider` to load routes under a prefix. This is useful if you have an API but you don't want to specify the prefix for every route.\n\n```php\n$this-\u003erouter()-\u003eload_routes(\n    routes: app_path('routes/api.php'),\n    prefix: '/api'\n);\n```\n\n### Model Binding\nRoutes are invoked using `Introspection::invoke()` which autowires the parameters using reflection. If the reflected type is a Model class, it will try to find a model where the column `Model::getRouteAccessor` matches the route parameter. More simply put, you can magically query the database by type-hinting your route function.\n\n```php\n// dumb route\n$route-\u003eget('/users/{user_id}', function ($user_id) {\n    // $user_id returns anything before the next slash;\n    \n    $user = User::where('id', $user_id)-\u003efirst();\n\n    // must check user for null;\n    if (!isset($user)) abort_raw(404, 'model not found');\n\n    //...\n});\n\n// magic route binding\n$route-\u003eget('/users/{user}', function (User $user) {\n    // $user returns pre-populated model if it exists, otherwise it fails with 404;\n\n    // guarantees user is a model; user will never be null;\n    echo \"{$user-\u003efirst_name}\"\n});\n```\n\n## Todo\n- [ ] Database drivers\n- [ ] View Rendering\n- ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnowlaboratory%2Fnucleus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsnowlaboratory%2Fnucleus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnowlaboratory%2Fnucleus/lists"}