<commit_before><?php

class sfSympalMenuSiteManager
{
  protected
    $_menuItems = array(),
    $_rootNames = array(),
    $_rootMenuItems = array(),
    $_hierarchies = array(),
    $_menus = array(),
    $_initialized = false;

  protected static $_instance;

  public function __construct()
  {
    $this->initializeMenus();
  }

  public static function getInstance()
  {
    if (!self::$_instance)
    {
      self::$_instance = new sfSympalMenuSiteManager();
    }
    return self::$_instance;
  }

  public function getHierarchies()
  {
    $this->initializeMenus();

    return $this->_hierarchies;
  }

  public function refresh()
  {
    $this->_menuItems = array();
    $this->_rootNames = array();
    $this->_rootMenuItems = array();
    $this->_hierarchies = array();
    $this->_menus = array();
    $this->_initialized = false;
    $this->initializeMenus();
  }

  public static function getMenu($name, $showChildren = true, $class = null)
  {
    return self::getInstance()->_getMenu($name, $showChildren, $class);
  }

  protected function _getMenu($name, $showChildren = true, $class = null)
  {
    if (!$name)
    {
      return false;
    }

    $this->initializeMenus();

    if ($name instanceof MenuItem)
    {
      $menuItem = $name;
      $name = $this->_rootNames[$name['root_id']];
    }

    if (!isset($this->_menus[$name]))
    {
      $rootId = array_search($name, $this->_rootNames);
      $rootMenuItem = $this->_rootMenuItems[$rootId];

      $class = $class ? $class:'sfSympalMenuSite';
      $menu = new $class($name);
      $menu->setMenuItem($rootMenuItem);

      if (!$rootId)
      {
        return false;
      }
      $hierarchy = $this->_hierarchies[$rootId];
      $this->_buildMenuHierarchy($hierarchy, $menu);

      $this->_menus[$name] = $menu;
    } else {
      $menu = $this->_menus[$name];
    }

    if (isset($menuItem))
    {
      $return = $menu->getMenuItemSubMenu($menuItem);
    } else {
      $return = $menu;
    }

    if ($return)
    {
      $return->callRecursively('showChildren', $showChildren);

      $event = sfProjectConfiguration::getActive()->getEventDispatcher()->notifyUntil(new sfEvent($return, 'sympal.load_'.$name.'_menu', array('name' => $name, 'showChildren' => $showChildren, 'class' => $class)));
      if ($event->isProcessed() && $return = $event->getReturnValue())
      {
        return $return;
      }

      return $return;
    } else {<commit_msg>[1.0] sfSympalPlugin: Fixing issue with cached menu objects<commit_after><?php

class sfSympalMenuSiteManager
{
  protected
    $_menuItems = array(),
    $_rootNames = array(),
    $_rootMenuItems = array(),
    $_hierarchies = array(),
    $_initialized = false;

  protected static $_instance;

  public function __construct()
  {
    $this->initializeMenus();
  }

  public static function getInstance()
  {
    if (!self::$_instance)
    {
      self::$_instance = new sfSympalMenuSiteManager();
    }
    return self::$_instance;
  }

  public function getHierarchies()
  {
    $this->initializeMenus();

    return $this->_hierarchies;
  }

  public function refresh()
  {
    $this->_menuItems = array();
    $this->_rootNames = array();
    $this->_rootMenuItems = array();
    $this->_hierarchies = array();
    $this->_initialized = false;
    $this->initializeMenus();
  }

  public static function getMenu($name, $showChildren = true, $class = null)
  {
    return self::getInstance()->_getMenu($name, $showChildren, $class);
  }

  protected function _getMenu($name, $showChildren = true, $class = null)
  {
    if (!$name)
    {
      return false;
    }

    $this->initializeMenus();

    if ($name instanceof MenuItem)
    {
      $menuItem = $name;
      $name = $this->_rootNames[$name['root_id']];
    }

    $rootId = array_search($name, $this->_rootNames);
    $rootMenuItem = $this->_rootMenuItems[$rootId];

    $class = $class ? $class:'sfSympalMenuSite';
    $menu = new $class($name);
    $menu->setMenuItem($rootMenuItem);

    if (!$rootId)
    {
      return false;
    }
    $hierarchy = $this->_hierarchies[$rootId];
    $this->_buildMenuHierarchy($hierarchy, $menu);

    if (isset($menuItem))
    {
      $return = $menu->getMenuItemSubMenu($menuItem);
    } else {
      $return = $menu;
    }

    if ($return)
    {
      $return->callRecursively('showChildren', $showChildren);

      $event = sfProjectConfiguration::getActive()->getEventDispatcher()->notifyUntil(new sfEvent($return, 'sympal.load_'.$name.'_menu', array('name' => $name, 'showChildren' => $showChildren, 'class' => $class)));
      if ($event->isProcessed() && $return = $event->getReturnValue())
      {
        return $return;
      }

      return $return;
    } else {
{'fraction_non_alphanumeric': 0.1649724692926726, 'fraction_numerical': 0.00042354934349851756, 'mean_word_length': 3.0821089023336214, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6745634', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1488, 'n_words': 286}