Helper for `Layer::process()`.

@param array $parent The node instance tor process.
356028
protected function _processTree($parent)
    {
        foreach ($parent->tree as $node) {
            if ($node->processable && $node->type === 'class' && $node->extends) {
                $namespace = $node->namespace->name . '\\';
                $parent = $node->extends;
                $extends = ltrim($parent[0] === '\\' ? $parent : $namespace . $parent, '\\');

                if (!isset($this->_override[$extends])) {
                    continue;
                }
                $layerClass = $node->name . $this->_suffix;
                $node->extends = $layerClass;
                $pattern = preg_quote($parent);
                $node->body = preg_replace("~(extends\s+){$pattern}~", "\\1{$layerClass}", $node->body);

                $code = Double::generate([
                    'class'    => $layerClass,
                    'extends'  => $extends,
                    'openTag'  => false,
                    'closeTag' => false,
                    'layer'    => true
                ]);

                $parser = $this->_classes['parser'];
                $root = $parser::parse($code, ['php' => true]);
                $node->close .= str_replace("\n", '', $parser::unparse($this->_pointcut->process($root)));
            } elseif (!empty($node->tree)) {
                $this->_processTree($node);
            }
        }
    }
677128
public function setParent(&$parent)
	{
		JLog::add('JNode::setParent() is deprecated.', JLog::WARNING, 'deprecated');

		if ($parent instanceof JNode || is_null($parent))
		{
			$hash = spl_object_hash($this);

			if (!is_null($this->_parent))
			{
				unset($this->_parent->children[$hash]);
			}

			if (!is_null($parent))
			{
				$parent->_children[$hash] = & $this;
			}

			$this->_parent = & $parent;
		}
	}
366077
private function FetchFields($parent)
    {
        $child= $this->tree->FirstChildOf($parent);
        while ($child)
        {
            $this->HandleField($child);
            $this->FetchFields($child);
            $child = $this->tree->NextOf($child);   
        }
    }
160780
final public function prepare($stanza, $parent = false)
    {
        if($parent === false) {
            $this->packet->from = current(explode('/',(string)$stanza->attributes()->from));
        } else {
            $this->packet->from = current(explode('/',(string)$parent->attributes()->from));
        }
    }
66828
private static function _traverse($node, $parent, $callback) {
        if (in_array($node->getName(), array("feature", "and", "or", "alt")))
            call_user_func($callback, $node, $parent);

        foreach ($node->children() as $child)
            self::_traverse($child, $node, $callback);
    }
40505
public function process($node, $path = null)
    {
        if (!$this->_override) {
            return;
        }
        $this->_processTree($node);
        return $node;
    }
83240
protected function _processTree($nodes)
    {
        foreach ($nodes as $node) {
            if ($node->hasMethods && $node->type !== 'interface') {
                $this->_processMethods($node->tree);
            } elseif (count($node->tree)) {
                $this->_processTree($node->tree);
            }
        }
    }
34356
public function setParent(Node $parent)
    {
        $this->_parent = $parent;
        if ($id = $parent->getId()) {
            $this->updateParentId($id);
        }
        $parent->getChildren()->append($this);
        return $this;
    }
1070875
protected function updateNodeParent($nodeId, $parent)
    {
        $config = $this->config;
        $this->getFluent()
                ->update($config['table'])
                ->set($config['prt'], $parent)
                ->where($config['id'], $nodeId)
                ->execute();
    }
257868
public function process()
    {
        parent::process();

        if ($this->value === null) {
            $this->path = array();
        } else {
            $this->path = $this->value;
            $this->value = end($this->path);
        }
    }
953339
public function setParent(AbstractParentNode $parent)
    {
        if (null !== $this->parent) {
            throw new \InvalidArgumentException('Node already got a parent!');
        }

        $this->parent = $parent;
    }
1338600
protected function process()
    {

        // load the parent/child SKUs
        $parentSku = $parentSku = $this->getValue($parentSkuColumnName = $this->getParentSkuColumnName());
        $childSku = $childSku = $this->getValue($childSkuColumnName = $this->getChildSkuColumnName());

        // query whether or not the product relation has already been processed
        if ($this->hasBeenProcessedRelation($parentSku, $childSku)) {
            return;
        }

        try {
            // try to load and map the parent ID
            $this->parentId = $this->mapSku($parentSku);
        } catch (\Exception $e) {
            throw $this->wrapException(array($parentSkuColumnName), $e);
        }

        try {
            // try to load and map the child ID
            $this->childId = $this->mapChildSku($childSku);
        } catch (\Exception $e) {
            throw $this->wrapException(array($childSkuColumnName), $e);
        }

        try {
            // prepare and persist the product relation
            if ($productRelation = $this->initializeProductRelation($this->prepareProductRelationAttributes())) {
                $this->persistProductRelation($productRelation);
            }

            // mark the product relation as processed
            $this->addProcessedRelation($parentSku, $childSku);
        } catch (\Exception $e) {
            // prepare a more detailed error message
            $message = $this->appendExceptionSuffix(
                sprintf(
                    'Product relation with SKUs %s => %s can\'t be created',
                    $parentSku,
                    $childSku
                )
            );

            // if we're NOT in debug mode, re-throw a more detailed exception
            $wrappedException = $this->wrapException(
                array($parentSkuColumnName, $childSkuColumnName),
                new \Exception($message, null, $e)
            );

            // query whether or not, debug mode is enabled
            if ($this->isDebugMode()) {
                // log a warning and return immediately
                $this->getSystemLogger()->warning($wrappedException->getMessage());
                return;
            }

            // else, throw the exception
            throw $wrappedException;
        }
    }
78418
public function handleGetChildren($parent)
	{
		$this->setDataSource(
			call_user_func($this->tree_view_children_callback, $parent)
		);

		if ($this->getPresenter()->isAjax()) {
			$this->getPresenter()->payload->_datagrid_url = $this->refresh_url;
			$this->getPresenter()->payload->_datagrid_tree = $parent;

			$this->redrawControl('items');

			$this->onRedraw();
		} else {
			$this->getPresenter()->redirect('this');
		}
	}
386588
protected function processEncryptedNode(ProtocolNode $node)
    {
        if ($this->parent->getAxolotlStore() == null) {
            return;
        }
    //is a chat encrypted message
    $from = $node->getAttribute('from');
        if (strpos($from, Constants::WHATSAPP_SERVER) !== false) {
            $author = ExtractNumber($node->getAttribute('from'));

            $version = $node->getChild(0)->getAttribute('v');
            $encType = $node->getChild(0)->getAttribute('type');
            $encMsg = $node->getChild('enc')->getData();
            if (!$this->parent->getAxolotlStore()->containsSession($author, 1)) {
                //we don't have the session to decrypt, save it in pending and process it later
         $this->parent->addPendingNode($node);
                $this->parent->logFile('info', 'Requesting cipher keys from {from}', ['from' => $author]);
                $this->parent->sendGetCipherKeysFromUser($author);
            } else {
                //decrypt the message with the session
           if ($node->getChild('enc')->getAttribute('count') == '') {
               $this->parent->setRetryCounter($node->getAttribute('id'), 1);
           }

                if ($version == '2') {
                    if (!in_array($author, $this->parent->getv2Jids())) {
                        $this->parent->setv2Jids($author);
                    }
                }

                $plaintext = $this->decryptMessage($from, $encMsg, $encType, $node->getAttribute('id'), $node->getAttribute('t'));

          //$plaintext ="A";
          if ($plaintext === false) {
              $this->parent->sendRetry($this->node, $from, $node->getAttribute('id'), $node->getAttribute('t'));
              $this->parent->logFile('info', 'Couldn\'t decrypt message with {id} id from {from}. Retrying...', ['id' => $node->getAttribute('id'), 'from' => ExtractNumber($from)]);

              return $node; // could not decrypt
          }
                if (isset($this->parent->retryNodes[$node->getAttribute('id')])) {
                    unset($this->parent->retryNodes[$node->getAttribute('id')]);
                }
                if (isset($this->parent->retryCounters[$node->getAttribute('id')])) {
                    unset($this->parent->retryCounters[$node->getAttribute('id')]);
                }
                switch ($node->getAttribute('type')) {
            case 'text':
              $node->addChild(new ProtocolNode('body', null, null, $plaintext));
              break;
            case 'media':

              switch ($node->getChild('enc')->getAttribute('mediatype')) {
                case 'image':
                  $image = new ImageMessage();
                  $image->parseFromString($plaintext);
                  $keys = (new HKDFv3())->deriveSecrets($image->getRefKey(), hex2bin('576861747341707020496d616765204b657973'), 112);
                  $iv = substr($keys, 0, 16);
                  $keys = substr($keys, 16);
                  $parts = str_split($keys, 32);
                  $key = $parts[0];
                  $macKey = $parts[1];
                  $refKey = $parts[2];

                  //should be changed to nice curl, no extra headers :D
                  $file_enc = file_get_contents($image->getUrl());
                  //requires mac check , last 10 chars
                  $mac = substr($file_enc, -10);
                  $cipherImage = substr($file_enc, 0, strlen($file_enc) - 10);
                  $decrypted_image = pkcs5_unpad(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $cipherImage, MCRYPT_MODE_CBC, $iv));
                  //$save_file = tempnam(sys_get_temp_dir(),"WAIMG_");
                  //file_put_contents($save_file,$decrypted_image);
                  $child = new ProtocolNode('media',
                    [
                        'size'     => $image->getLength(),
                        'caption'  => $image->getCaption(),
                        'url'      => $image->getUrl(),
                        'mimetype' => $image->getMimeType(),
                        'filehash' => bin2hex($image->getSha256()),
                        'width'    => 0,
                        'height'   => 0,
                        'file'     => $decrypted_image ?: $file_enc,
                        'type'     => 'image',
                      ], null, $image->getThumbnail());
                  $node->addChild($child);
                break;
                case 'location':
                  $location = new Location();
                  $data = $node->getChild('enc')->getData();
                  $location->parseFromString($plaintext);
                  $child = new ProtocolNode('media',
                    [
                        'type'      => 'location',
                        'encoding'  => 'raw',
                        'latitude'  => $location->getLatitude(),
                        'longitude' => $location->getLongitude(),
                        'name'      => $location->getName(),
                        'url'       => $location->getUrl(),
                    ], null, $location->getThumbnail());
                  $node->addChild($child);
                break;
                case 'url':
                   $mediaUrl = new MediaUrl();
                   $mediaUrl->parseFromString($plaintext);
                   $node->addChild(new ProtocolNode('body', null, null, $mediaUrl->getMessage()));
                break;
                case 'document':
                   $document = new DocumentMessage();
                   $a = ord($plaintext[0]);
                   //prepad?
                   if (substr($plaintext, 0, $a) == str_repeat($plaintext[0], $a)) {
                       $plaintext = substr($plaintext, $a);
                   }
                   $document->parseFromString($plaintext);

                   $keys = (new HKDFv3())->deriveSecrets($document->getRefKey(), hex2bin('576861747341707020446f63756d656e74204b657973'), 112);
                   $iv = substr($keys, 0, 16);
                   $keys = substr($keys, 16);
                   $parts = str_split($keys, 32);
                   $key = $parts[0];
                   $macKey = $parts[1];
                   $refKey = $parts[2];
                   //should be changed to nice curl, no extra headers :D
                   $file_enc = file_get_contents($document->getUrl());
                   //requires mac check , last 10 chars
                   $mac = substr($file_enc, -10);
                   $cipherDocument = substr($file_enc, 0, strlen($file_enc) - 10);
                   $uncrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $cipherDocument, MCRYPT_MODE_CBC, $iv);
                   $decrypted_document = pkcs5_unpad($uncrypted);
                   file_put_contents('/tmp/'.$document->getFilename(), $decrypted_document);
                   if (strlen($document->getThumbnail() > 0)) {
                       //is posible to not have thumbnail
                     file_put_contents('/tmp/'.$document->getName(), $document->getThumbnail());
                   }
                 break;
              }
            break;

          }
                $this->parent->logFile('info', 'Decrypted message with {id} from {from}', ['id' => $node->getAttribute('id'), 'from' => ExtractNumber($from)]);

                return $node;
            }
        }
     //is a group encrypted message
     else {
         $author = ExtractNumber($node->getAttribute('participant'));
         $group_number = ExtractNumber($node->getAttribute('from'));
         $childs = $node->getChildren();
         foreach ($childs as $child) {
             if ($child->getAttribute('type') == 'pkmsg' || $child->getAttribute('type') == 'msg') {
                 if (!$this->parent->getAxolotlStore()->containsSession($author, 1)) {
                     $this->parent->addPendingNode($node);

                     $this->parent->sendGetCipherKeysFromUser($author);
                     break;
                 } else {

             //decrypt senderKey and save it
             $encType = $child->getAttribute('type');
                     $encMsg = $child->getData();
                     $from = $node->getAttribute('participant');
                     $version = $child->getAttribute('v');
                     if ($node->getChild('enc')->getAttribute('count') == '') {
                         $this->parent->setRetryCounter($node->getAttribute('id'), 1);
                     }

                     if ($version == '2') {
                         if (!in_array($author, $this->parent->getv2Jids())) {
                             $this->parent->setv2Jids($author);
                         }
                     }
                     $skip_unpad = $node->getChild('enc', ['type' => 'skmsg']) == null;
                     $senderKeyBytes = $this->decryptMessage($from, $encMsg, $encType, $node->getAttribute('id'), $node->getAttribute('t'), $node->getAttribute('from'), $skip_unpad);
                     if ($senderKeyBytes) {
                         if (!$skip_unpad) {
                             $senderKeyGroupMessage = new SenderKeyGroupMessage();
                             $senderKeyGroupMessage->parseFromString($senderKeyBytes);
                         } else {
                             $senderKeyGroupMessage = new SenderKeyGroupData();
                             try {
                                 $senderKeyGroupMessage->parseFromString($senderKeyBytes);
                             } catch (Exception $ex) {
                                 try {
                                     $senderKeyGroupMessage->parseFromString(substr($senderKeyBytes, 0, -1));
                                 } catch (Exception $ex) {
                                     return $node;
                                 }
                             }
                             $message = $senderKeyGroupMessage->getMessage();
                             $senderKeyGroupMessage = $senderKeyGroupMessage->getSenderKey();
                         }
                         $senderKey = new SenderKeyDistributionMessage(null, null, null, null, $senderKeyGroupMessage->getSenderKey());
                         $groupSessionBuilder = new GroupSessionBuilder($this->parent->getAxolotlStore());
                         $groupSessionBuilder->processSender($group_number.':'.$author, $senderKey);
                         if (isset($message)) {
                             $this->parent->sendReceipt($node, 'receipt', $this->parent->getJID($this->phoneNumber));
                             $node->addChild(new ProtocolNode('body', null, null, $message));
                         }
                     }
                 }
             } elseif ($child->getAttribute('type') == 'skmsg') {
                 $version = $child->getAttribute('v');
                 if ($version == '2') {
                     if (!in_array($author, $this->parent->v2Jids)) {
                         $this->parent->setv2Jids($author);
                     }
                 }

                 $plaintext = $this->decryptMessage([$group_number, $author], $child->getData(), $child->getAttribute('type'), $node->getAttribute('id'), $node->getAttribute('t'));

                 if (!$plaintext) {
                     $this->parent->sendRetry($this->node, $from, $node->getAttribute('id'), $node->getAttribute('t'), $node->getAttribute('participant'));
                     $this->parent->logFile('info', 'Couldn\'t decrypt group message with {id} id from {from}. Retrying...', ['id' => $node->getAttribute('id'), 'from' => $from]);

                     return $node; // could not decrypt
                 } else {
                     if (isset($this->parent->retryNodes[$node->getAttribute('id')])) {
                         unset($this->parent->retryNodes[$node->getAttribute('id')]);
                     }
                     if (isset($this->parent->retryCounters[$node->getAttribute('id')])) {
                         unset($this->parent->retryCounters[$node->getAttribute('id')]);
                     }
                     $this->parent->logFile('info', 'Decrypted group message with {id} from {from}', ['id' => $node->getAttribute('id'), 'from' => $from]);
                     $this->parent->sendReceipt($node, 'receipt', $this->parent->getJID($this->phoneNumber));
                     $node->addChild(new ProtocolNode('body', null, null, $plaintext));
                 }
             }
         }
     }

        return $node;
    }
627384
public function setParent($parent)
	{
		if ($parent instanceof JCategoryNode || is_null($parent))
		{
			if (!is_null($this->_parent))
			{
				$key = array_search($this, $this->_parent->_children);
				unset($this->_parent->_children[$key]);
			}

			if (!is_null($parent))
			{
				$parent->_children[] = & $this;
			}

			$this->_parent = $parent;

			if ($this->id != 'root')
			{
				if ($this->parent_id != 1)
				{
					$this->_path = $parent->getPath();
				}

				$this->_path[] = $this->id . ':' . $this->alias;
			}

			if (count($parent->_children) > 1)
			{
				end($parent->_children);
				$this->_leftSibling = prev($parent->_children);
				$this->_leftSibling->_rightsibling = & $this;
			}
		}
	}
462975
public function setParent($parent)
    {
        if ($parent !== null && !$parent instanceof self) {
            throw new \InvalidArgumentException('An entry may only have another entry as parent');
        }

        $this->parent = $parent;
    }
1055956
public function invoke($node, NodeInterface $parent): void
    {
        if (! $node instanceof Doc || ! $parent instanceof DocumentationInterface) {
            throw new Exception('DocumentationNodeParser is made to parse a documentation node');
        }

        $documentation = $node->getText();
        $parent->setDocumentation($documentation);

        $this->annotationParser->invoke($parent, $documentation);
    }