StackTemplateVariableGenerator
a Class & cows:DirectoryTemplateVariableGeneratorInterface in phpMAE
Public PHP Methods
-
getTemplateVariables($coid)
Get a key-value array of template variables for an object.
@param string $coid The COID of the object.
Source Code
<?php use CloudObjects\SDK\NodeReader, CloudObjects\SDK\ObjectRetriever; use ML\IRI\IRI; /** * Implementation for coid://phpmae.dev/StackTemplateVariableGenerator * Using interface coid://cloudobjects.io/DirectoryTemplateVariableGeneratorInterface */ class StackTemplateVariableGenerator implements DirectoryTemplateVariableGeneratorInterface { private $retriever; private $reader; public function __construct(ObjectRetriever $retriever) { $this->retriever = $retriever; $this->reader = new NodeReader([ 'prefixes' => [ 'co' => 'coid://cloudobjects.io/', 'phpmae' => 'coid://phpmae.dev/' ] ]); } /** * Get a key-value array of template variables for an object. * @param string $coid The COID of the object. */ public function getTemplateVariables($coid) { $coid = new IRI($coid); $object = $this->retriever->getObject($coid); if (!isset($object) || !$this->reader->hasType($object, 'phpmae:Stack')) return false; // Retrieve files $composerFile = json_decode($this->retriever->getAttachment($coid, $this->reader->getFirstValueString($object, 'phpmae:hasAttachedComposerFile')), true); $lockFile = json_decode($this->retriever->getAttachment($coid, $this->reader->getFirstValueString($object, 'phpmae:hasAttachedLockFile')), true); // Compile output $output = [ 'defined' => [], 'actual' => [] ]; foreach ($composerFile['require'] as $name => $version) { $output['defined'][] = [ 'name' => $name, 'version' => $version ]; } foreach ($lockFile['packages'] as $package) { $output['actual'][] = [ 'name' => $package['name'], 'version' => $package['version'], 'defined' => isset($composerFile['require'][$package['name']]) ]; } return $output; } }
Meta
- URI / COID
- coid://phpmae.dev/StackTemplateVariableGenerator content_copy
- Revision
- 3-f9afbe10149a94d6a95587734fde6efb content_copy
- Short ID
- phpmae:StackTemplateVariableGenerator content_copy
- Reference URL
- https://coid.link/phpmae.dev/StackTemplateVariableGenerator content_copy
- Last updated
- 2021-04-19 16:09 (UTC)
- Created at
- 2021-04-19 16:04 (UTC)
RDF
Objects in this namespace
- phpMAE
- AccountContext
- Class
- ClassDependency
- DefaultStack
- Dependency
- DirectoryTemplateVariableGenerator
- HTTPInvokableClass
- Interface
- Route
- Router
- Stack
- StackTemplateVariableGenerator
- StaticTextDependency
- TwigTemplateDependency
- WebAPIDependency
- allowsCORSOrigin
- allowsGETRequests
- enableCORSWithOrigin
- hasAAUID
- hasAPI
- hasAccessToken
- hasClass
- hasClassMailerDSN
- hasDefinitionFile
- hasDependency
- hasGlobalMailerDSN
- hasKey
- hasRoute
- hasRouter
- hasSourceFile
- hasValue
- includeParameterWithDefault
- proxiesRequestsToBaseURL
- redirectsToBaseURL
- redirectsToURL
- runsClass
- runsMethod
- servesStaticFileAttachment
- usesAttachedFile
- usesAttachedTwigFile
- usesStack
- usesStaticAccountContext
- whitelistsClassname