/** * Creates images from local filesystem path * * @param Path $path Path passed by the shell * @param string $filename Filename * @param string $type Media Type * @return Image */ public function fromLocalPath(Path $path, $filename, $type = '') { // Replace backslash by regular slash in file path (otherwise breaks the parser) $filename = str_replace('\\', '/', $filename); $imagePath = $path->getRoot() . DS . $filename; $parts = pathinfo($imagePath); $this->setData(['binary_data' => file_get_contents($imagePath), 'full_path' => $imagePath, 'relative_path' => $path->getDirectory() . DS . $filename, 'file_name' => $parts['filename'], 'file_extension' => $parts['extension'], 'type' => $type]); // Retrieve binary contents $this->setId($this); return $this; }
/** * Checks if group from path is declared in manifest. * Manifest is valid if path ends with: configuration/website/[group], * where group is declared in manifest. * * @param \DOMDocument $xml * @param Path $path * @return bool */ public function isValidForPath(\DOMDocument $xml, Path $path) { $allowedGroups = []; $groupsNode = $xml->getElementsByTagName('allowed_groups'); if (!$groupsNode->length) { return false; } // get all allowed group for manifest foreach ($groupsNode->item(0)->childNodes as $group) { if ($group->nodeName === 'group') { $allowedGroups[] = (string) $group->textContent; } } $search = $path->getDirectory() . '/' . $path->getGroup(); $pattern = "#{$search}[/]?\$#"; // skip if group is invalid (allowed groups from manifest) // or if config do not ends with configuration/[website]/[group] if (!in_array($path->getGroup(), $allowedGroups) || 1 !== preg_match($pattern, $path->getParamPath(), $matches)) { return false; } return true; }
/** * @covers ::getDirectory * @covers ::_processPath */ public function test_getDirectory_should_return_proper_value() { $paramPath = 'configuration/eset/path/'; $path = new Path($paramPath, 'whatever', 'rootdir'); $this->assertEquals('configuration/eset', $path->getDirectory()); }