private static function isTagRoleInScope(NodeSchema $schema, $partials_string, $role) { $role = strtolower(ltrim($role, '#')); if (empty($partials_string)) { return false; } else { $partials = self::unserializePartials('tags', $partials_string); $all = false; $allfieldlike = false; if ($partials == 'all' || ($x = array_search('all', $partials)) !== false) { $all = true; } else { if (($x = array_search('fields', $partials)) !== false) { $allfieldlike = true; unset($partials[$x]); } } try { $tagDef = $schema->getTagDef($role); } catch (SchemaException $se) { return false; } if ($all) { return true; } if ($allfieldlike && $tagDef->isFieldlike()) { return true; } $inScope = false; foreach ($partials as $partial) { if ($partial->getTagRole() == strtolower($role)) { return true; } } } return false; }
protected function validateTagPartials($direction, $partials_string, $tags, NodeSchema $schema) { if (empty($partials_string)) { if (count($tags) > 0) { $this->Logger->debug('Removing all out-of-scope tags.'); return array(); //$this->getErrors()->reject(ucfirst($direction) . " tags specified, even though none are in scope."); } } else { switch ($direction) { case 'in': $partials = PartialUtils::unserializeInPartials($partials_string); break; case 'out': $partials = PartialUtils::unserializeOutPartials($partials_string); break; default: throw new Exception("Unknown direction {$direction} for partials."); } $all = false; $allfieldlike = false; if ($partials == 'all' || ($x = array_search('all', $partials)) !== false) { $all = true; } else { if (($x = array_search('fields', $partials)) !== false) { $allfieldlike = true; unset($partials[$x]); } } foreach ($tags as $k => $tag) { $id = $tag->getTagRole(); if (empty($id)) { throw new Exception(ucfirst($direction) . " Tag passed without a TagRole"); } $tagDef = $schema->getTagDef($id); if ($all) { continue; } if ($allfieldlike && $tagDef->isFieldlike()) { continue; } $inScope = false; foreach ($partials as $partial) { if ($this->TagsHelper->matchPartial($partial, $tag)) { $inScope = true; break; } } if (!$inScope) { $this->Logger->debug('Silently removing out-of-scope tag: ' . $tag->toString()); unset($tags[$k]); } // $this->getErrors()->reject(ucfirst($direction) ." Tag: " . $tag->toString() . ' is out of scope.'); } } return $tags; }