Path: blob/master/src/applications/diviner/atomizer/DivinerAtomizer.php
12262 views
<?php12/**3* Generate @{class:DivinerAtom}s from source code.4*/5abstract class DivinerAtomizer extends Phobject {67private $book;8private $fileName;9private $atomContext;1011/**12* If you make a significant change to an atomizer, you can bump this version13* to drop all the old atom caches.14*/15public static function getAtomizerVersion() {16return 1;17}1819final public function atomize($file_name, $file_data, array $context) {20$this->fileName = $file_name;21$this->atomContext = $context;22$atoms = $this->executeAtomize($file_name, $file_data);2324// Promote the `@group` special to a property. If there's no `@group` on25// an atom but the file it's in matches a group pattern, associate it with26// the right group.27foreach ($atoms as $atom) {28$group = null;29try {30$group = $atom->getDocblockMetaValue('group');31} catch (Exception $ex) {32// There's no docblock metadata.33}3435// If there's no group, but the file matches a group, use that group.36if ($group === null && isset($context['group'])) {37$group = $context['group'];38}3940if ($group !== null) {41$atom->setProperty('group', $group);42}43}4445return $atoms;46}4748abstract protected function executeAtomize($file_name, $file_data);4950final public function setBook($book) {51$this->book = $book;52return $this;53}5455final public function getBook() {56return $this->book;57}5859protected function newAtom($type) {60return id(new DivinerAtom())61->setBook($this->getBook())62->setFile($this->fileName)63->setType($type);64}6566protected function newRef($type, $name, $book = null, $context = null) {67$book = coalesce($book, $this->getBook());6869return id(new DivinerAtomRef())70->setBook($book)71->setContext($context)72->setType($type)73->setName($name);74}7576}777879