1. Go to this page and download the library: Download vanilla/garden-sites 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/ */
vanilla / garden-sites example snippets
use Garden\Sites\LaravelProviderFactory;
// This will inject your env variables into laravel config.
return LaravelProviderFactory::createLaravelConfigFromEnv("env");
use Garden\Sites\LaravelProviderFactory;use Garden\Sites\SiteProvider;
/** @var SiteProvider $provider */
$provider = LaravelProviderFactory::providerFromLaravelConfig([\Config::class, 'get'])
/**
* Site providers do various caching of results. By default an in-memory cache is used, but especially with an orch-client
* it is recommended to configure a persistent cache like memcached or redis.
* Caches must implement {@link CacheInterface}
*/
$cache = new RedisAdapter(/** Configuration here. */);
// or
$cache = new MemcachedAdapter(/** Configuration here. */);
$siteProvider->setCache($cache);
use Garden\Sites\Exceptions\ClusterNotFoundException;
use Garden\Sites\Exceptions\SiteNotFoundException;
use Garden\Sites\SiteProvider;
function doSomethingWithProvider(SiteProvider $siteProvider)
{
/**
* Look up a site by ID.
* Can throw an {@link SiteNotFoundException}
*/
$site = $siteProvider->getSite(100);
// List all sites
$allSites = $siteProvider->getSites();
/**
* Look up a cluster by ID.
* Can throw an {@link ClusterNotFoundException}
*/
$cluster = $siteProvider->getCluster("cl10001");
// List all clusters
$allClusters = $siteProvider->getClusters();
}
use Garden\Sites\Site;
use Garden\Sites\Cluster;
function doSomethingWithCluster(Cluster $cluster)
{
// A few getters
$clusterID = $cluster->getClusterID();
$regionID = $cluster->getRegionID();
}
function doSomethingWithSite(Site $site)
{
// A few getters
$siteID = $site->getSiteID();
$accountID = $site->getAccountID();
$clusterID = $site->getClusterID();
$baseUrl = $site->getBaseUrl();
// HTTP Requests
// This is a `garden-http` configured with the site's baseUrl
// and set to throw on errors.
$response = $site->httpClient()->get("/url", ["query" => "params"]);
$response = $site->httpClient()->post("/url", ["body" => "here"]);
$response = $site->httpClient()->patch("/url", ["body" => "here"]);
$response = $site->httpClient()->put("/url", ["body" => "here"]);
$response = $site->httpClient()->delete("/url");
// System auth for an http request
$site
->httpClient()
->withSystemAuth()
->get("/some-resource");
// Ensure there is no auth on a request
$site
->httpClient()
->withNoAuth()
->get("/some-resource");
// Access the cluster
$cluster = $site->getCluster();
// Configs
$configVal = $site->getConfigValueByKey("some.key.here", "fallback");
// Configs are cached on the `Garden\Sites\Site` instance
// You can clear them here.
$site->clearConfigCache();
// Check services hostnames the site should be using.
$baseUrl = $site->getQueueServiceBaseUrl();
$baseUrl = $site->getSearchServiceBaseUrl();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.