/** * @param Context $context * @throws Exception */ public function __construct(Context $context) { $this->nodes = $context->getNodes(); foreach ($this->nodes as $node) { if (!$node->hasType()) { throw new Exception('Detected non-resolved node in result context'); } $this->nodesById[$node->getId()] = $node; } }
/** * Resolves arbitrary data into a debug Result * * @param mixed $data * @return Result */ public function debug($data) { // First initialize all the required resolvers // The chaining resolver will loop through all it's argument resolvers until one matches, and use that one // The recursive resolver will make sure that the process is repeated for newly created child nodes $resolver = new RecursiveResolver(new ChainingResolver([new ArrayResolver(), new ResourceResolver(), new ClosureResolver(), new SerializableResolver(), new ObjectResolver(), new PrimitiveTypeResolver()])); // The context will keep track of processed objects to prevent circular reference issues, and manages // node identification $context = new Context(); $rootNode = $context->getNodeForData($data); $resolver->resolve($rootNode, $context); // Since the context tracks all the nodes in the resolving process, it contains all data needed for a result return new Result($context); }
/** * @param Node $node * @param Context $context * @throws TypeNotSupportedException * @return Node the resolved node */ public function resolve(Node $node, Context $context) { if (!$node->hasType()) { $data = $node->getData(); if ($this->supports($data)) { $node->setType($this->getType()); foreach ($this->getProperties($data) as $key => $value) { $childNode = $context->getNodeForData($value); $node->addChildNode($key, $childNode); } } else { throw new TypeNotSupportedException(); } } return $node; }
/** * @expectedException \EdeMeijer\SerializeDebugger\Resolver\TypeNotSupportedException */ public function testItThrowsExceptionWhenTypeIsNotSupported() { $this->givenTypeSupportedReturns(false); $node = $this->context->getNodeForData(null); $this->SUT->resolve($node, $this->context); }