Skip to content

Commit

Permalink
add getters to tagGroupBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
jygaulier committed May 16, 2024
1 parent be8f1fd commit 07310e6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
32 changes: 29 additions & 3 deletions lib/PHPExiftool/ClassUtils/tagGroupBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public function setWritable(bool $writable)
}
}

public function getFlags(): int
{
return array_key_exists('flags', $this->properties) ? $this->properties["flags"] : 0;
}

/**
* reconciliate "count" attribute : keep value if same for all tags
* @param int $count
Expand Down Expand Up @@ -134,14 +139,31 @@ public function setFlags(array $flags)
}
}

public function isWritable(): bool
{
return ($this->writable === 1);
}

public function getCount(): int
{
return is_null($this->count) ? 0 : max(0, $this->count);
}

public function getDescriptions()
{
return $this->descriptions;
}



public function computeProperties(): Builder
{
$this->properties['phpType'] = $this->php_type ?: "mixed";
$this->properties['isWritable'] = ($this->writable === 1);
$this->properties['isWritable'] = $this->isWritable();
$this->properties['description'] = $this->descriptions;
$this->properties['tags'] = $this->tags;
if(!is_null($this->count)) { // 0 = default parent value
$this->properties['count'] = max(0, $this->count);
if(!is_null($this->count)) { // 0 = default parent value, don't write in child
$this->properties['count'] = $this->getCount();
}
// flags
$binFlags = 0;
Expand All @@ -154,6 +176,10 @@ public function computeProperties(): Builder
}
}
}
// also add "writable" as a flag
if($this->isWritable()) {
$binFlags |= AbstractTagGroup::FLAG_WRITABLE;
}
if($binFlags !== 0) { // 0 is the default parent value
$this->properties["flags"] = $binFlags;
}
Expand Down
1 change: 1 addition & 0 deletions lib/PHPExiftool/Driver/AbstractTagGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ abstract class AbstractTagGroup implements TagGroupInterface
public const FLAG_BAG = 256;
public const FLAG_SEQ = 512;
public const FLAG_ALT = 1024;
public const FLAG_WRITABLE = 2048;

// public const GROUP_ID = '';
protected string $id = '';
Expand Down
14 changes: 8 additions & 6 deletions lib/PHPExiftool/InformationDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function setLogger(LoggerInterface $logger)
* @return DOMDocument
* @throws Exception
*/
public function listDatas(string $type = self::LISTTYPE_SUPPORTED_XML, array $options = []): DOMDocument
public function listDatas(string $type = self::LISTTYPE_SUPPORTED_XML, array $options = [], array $lngs): DOMDocument
{
if (!is_array($options)) {
throw new InvalidArgumentException('options must be an array');
Expand All @@ -109,8 +109,10 @@ public function listDatas(string $type = self::LISTTYPE_SUPPORTED_XML, array $op
}
$command[] = '-f';
// $command[] = '-s';
//$command[] = '-lang';
//$command[] = 'en';
foreach ($lngs as $lng) {
$command[] = '-lang';
$command[] = $lng;
}
$command[] = '-list' . $type;

$xml = $this->exiftool->executeCommand($command);
Expand All @@ -122,7 +124,7 @@ public function listDatas(string $type = self::LISTTYPE_SUPPORTED_XML, array $op

public function dumpClasses(array $options, array $lngs, callable $callback = null)
{
$dom = $this->listDatas(InformationDumper::LISTTYPE_SUPPORTED_XML, $options);
$dom = $this->listDatas(InformationDumper::LISTTYPE_SUPPORTED_XML, $options, $lngs);

$nTags = 0;

Expand Down Expand Up @@ -200,8 +202,8 @@ public function dumpClasses(array $options, array $lngs, callable $callback = nu
}
*/

$tag_flags = $tag_crawler->attr('flags');
$flags = explode(',', strtolower($tag_flags));
$tag_flags = strtolower(trim($tag_crawler->attr('flags') ?: ''));
$flags = $tag_flags ? explode(',', $tag_flags) : [];

// $namespace = $table_name . '\\ID' . $tag_id;
// if (!is_null($tag_index)) {
Expand Down
4 changes: 3 additions & 1 deletion lib/PHPExiftool/Tool/Command/ClassesBuilderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$options[] = InformationDumper::LISTOPTION_MWG;
}


$path = realpath($input->getOption('path'));
if($path === false) {
throw new Exception(sprintf('Path "%s" does not exists.', $input->getOption('path')));
}
$subPath = $path . '/' . PHPExiftool::SUBDIR; // security : do NOT rm passed cli option
@mkdir($subPath, 0755, true);
$logger->info(sprintf('Erasing previous files "%s/*" ', $subPath));
Expand Down

0 comments on commit 07310e6

Please sign in to comment.