SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/TreenodeRedirectMatcher.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers;
  15.  
  16. /**
  17. * @package Tree
  18. **/
  19.  
  20. /**
  21. * Matches a node which has a specific key matching a specific value
  22. **/
  23. class TreenodeRedirectMatcher implements TreenodeMatcher
  24. {
  25. private $argument = null;
  26.  
  27. /**
  28.   * Constructor
  29.   **/
  30. public function __construct($argument = null)
  31. {
  32. $this->argument = $argument;
  33. }
  34.  
  35. /**
  36.   * Does the match
  37.   *
  38.   * @param TreeNode $node The treenode to do matching against
  39.   * @return True if the node matches, false otherwise
  40.   **/
  41. public function match($node)
  42. {
  43. if ($node['controller_entrance'] != Router::$controller) return false;
  44. if ($this->argument !== null and $node['controller_argument'] != $this->argument) return false;
  45.  
  46. return true;
  47. }
  48.  
  49. /**
  50.   * Returns true if the children of the specified node should be searched, false otherwise.
  51.   *
  52.   * @param TreeNode $node The treenode which is about to be descended into
  53.   * @return True descending should proceed, false otherwise
  54.   **/
  55. public function descend($node)
  56. {
  57. return true;
  58. }
  59.  
  60. /**
  61.   * Called after children have been processed
  62.   *
  63.   * @param TreeNode $node The treenode which has just ascended.
  64.   **/
  65. public function ascend ($node) {}
  66. }
  67.  
  68.  
  69.