{"id":23387235,"url":"https://github.com/wp-forge/container","last_synced_at":"2025-04-11T05:09:13.062Z","repository":{"id":57082029,"uuid":"249281147","full_name":"wp-forge/container","owner":"wp-forge","description":"A lightweight, PHP 7.0+ compatible, PSR-11 dependency injection container.","archived":false,"fork":false,"pushed_at":"2023-04-30T01:03:19.000Z","size":14,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T05:09:07.587Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wp-forge.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}},"created_at":"2020-03-22T22:05:19.000Z","updated_at":"2024-10-04T07:42:06.000Z","dependencies_parsed_at":"2022-08-24T14:42:32.059Z","dependency_job_id":null,"html_url":"https://github.com/wp-forge/container","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Fcontainer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Fcontainer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Fcontainer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Fcontainer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wp-forge","download_url":"https://codeload.github.com/wp-forge/container/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345266,"owners_count":21088244,"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-12-22T01:15:21.340Z","updated_at":"2025-04-11T05:09:13.038Z","avatar_url":"https://github.com/wp-forge.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Container\n\nA lightweight, PHP 8.0+ compatible, PSR-11 dependency injection container.\n\n## Usage\n\nBasic manipulation of items.\n\n```php\n\u003c?php\n\nuse WP_Forge\\Container\\Container;\n\n// Create a new instance\n$container = new Container();\n\n// Set a value\n$container-\u003eset('email', 'webmaster@site.com');\n\n// Check if a value exists\n$exists = $container-\u003ehas('email');\n\n// Get a value\n$value = $container-\u003eget('email');\n\n// Delete a value\n$container-\u003edelete('email');\n```\n\nBasic manipulation of items using array syntax.\n\n```php\n\u003c?php\n\nuse WP_Forge\\Container\\Container;\n\n// Create a new instance\n$container = new Container();\n\n// Set a value\n$container['email'] = 'webmaster@site.com';\n\n// Check if a value exists\n$exists = isset( $container['email'] );\n\n// Get a value\n$value = $container['email'];\n\n// Delete a value\nunset( $container['email'] );\n```\n\nRegister a factory. Factories return a new class instance every time you fetch them.\n\n```php\n\u003c?php\n\nuse WP_Forge\\Container\\Container;\n\n// Create a new instance\n$container = new Container();\n\n// Add a factory\n$container-\u003eset( 'session', $container-\u003efactory( function( Container $c ) {\n    return new Session( $c-\u003eget('session_id') );\n} ) );\n\n// Get a factory instance.\n$factory = $container-\u003eget( 'session' );\n\n// Check if an item is a factory\n$isFactory = $container-\u003eisFactory( $factory );\n```\n\nRegister a service. Services return the same class instance every time you fetch them.\n\n```php\n\u003c?php\n\nuse WP_Forge\\Container\\Container;\n\n// Create a new instance\n$container = new Container();\n\n// Add a service\n$container-\u003eset( 'session', $container-\u003eservice( function( Container $c ) {\n    return new Session( $c-\u003eget('session_id') );\n} ) );\n\n// Get a service instance.\n$service = $container-\u003eget( 'session' );\n\n// Check if an item is a service\n$isService = $container-\u003eisService( $service );\n```\n\nRegister a computed value callback. \n\n```php\n\u003c?php\n\nuse WP_Forge\\Container\\Container;\n\n$container = new Container( [\n\t'first_name'  =\u003e 'John',\n\t'last_name'   =\u003e 'Doe',\n] );\n\n$container-\u003eset( 'full_name', $container-\u003ecomputed( function ( Container $container ) {\n\treturn implode( ' ', array_filter( [\n\t\t$container-\u003ehas( 'first_name' ) ? $container-\u003eget( 'first_name' ) : '',\n\t\t$container-\u003ehas( 'last_name' ) ? $container-\u003eget( 'last_name' ) : '',\n\t] ) );\n} ) );\n\n$full_name = $container-\u003eget( 'full_name' );\n```\n\nExtend a previously registered factory or service.\n\n```php\n\u003c?php\n\n$container-\u003eextend( 'session', function( $instance, Closure $c ) {\n\n    $instance-\u003esetShoppingCart( $c-\u003eget('shopping_cart') );\n\n    return $instance;\n} );\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-forge%2Fcontainer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwp-forge%2Fcontainer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-forge%2Fcontainer/lists"}