PHP code example of silktide / syringe

1. Go to this page and download the library: Download silktide/syringe library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

silktide / syringe example snippets


$container = Syringe::build([
    "paths" => [__DIR__]
    "files" => ["file.yml"]
]);
$container["bar"] = "chicken";

Syringe::build([
    "paths" => [__DIR__]
    "files" => ["file.yml"],
    "parameters" => [
        "bar" => "chicken"
    ]
]);

use Silktide\Syringe\Syringe;

$container = \Silktide\Syringe\Syringe::build([
	"files" => ["config/syringe.yml"]
]);

use Silktide\Syringe\Syringe;

$container = \Silktide\Syringe\Syringe::build([
	"cache" => new FileCache(sys_get_temp_dir())
]);

$configFiles = [
  "foo_namespace" => "foo.yml",
  "bar_namespace" => "bar.yml"
];

$container = \Silktide\Syringe\Syringe::build([
   "paths" => ["/var/www/app"]
	"files" => ["config/syringe.yml"]
]);

$container = \Silktide\Syringe\Syringe::build([
   "appDir" => "my/application/directory", # Application Directory
   "appDirKey" => "myAppParameterKey"
]);

$container = \Silktide\Syringe\Syringe::build([
   "containerClass" => "Silex\Application::class"
]);

use Silktide\Syringe\Loader\LoaderInterface;

class XmlLoader implements LoaderInterface
{
    public function getName()
    {
        return "XML Loader";
    }
    
    public function supports($file)
    {
        return pathinfo($file, PATHINFO_EXTENSION) == "xml";
    }
    
    public function loadFile($file)
    {
        // load and decode the file, returning the configuration array
    }
}