Skip to content

Instantly share code, notes, and snippets.

@xemoe
Last active April 11, 2016 18:07
Show Gist options
  • Save xemoe/52ba33c60fff1ff21fbabf7e10db5ce2 to your computer and use it in GitHub Desktop.
Save xemoe/52ba33c60fff1ff21fbabf7e10db5ce2 to your computer and use it in GitHub Desktop.
Draft update xemoe/php 1.1.0

Draft

Definitions of Env and Configurations properties.

  1. Configuration properties is REPLACED magic values used inside classes.
  2. Env properties is arguments for any configurations properties, E.g. app_path().

Abstracts

  • Xemoe/Contracts/EnvLoaderContract

    interface EnvLoaderContract
    {
      loadEnv(array $env);
      loadFileEnv($filepath);
      getEnv();
    }
  • Xemoe/Contracts/LoggingContainerContract

    interface LoggingContainerContract
    {
      setLogger(LoggerInterface $logger);
      getLogger();
    }
  • Xemoe/Contracts/CachingContainerContract

    interface CachingContainerContract
    {
      setCache(CacheItemPoolInterface $cacher);
      getCache();
    }
@xemoe
Copy link
Author

xemoe commented Apr 10, 2016

Draft - ActiveMenu

Definitions of ActiveMenu

  1. ActiveMenu is create for read menu configuration and current uri to validate which menu is active.
  2. ActiveMenu has 2 main properties [ParentMenu, ChildMenu] properties, and base on MenuItem class.
  3. MenuItem class has properties, [name, label, link and active closure]

Abstracts

  • Xemoe/Contracts/MenuContainerContract

    interface MenuContainerContract
    {
        public static function addMenu(ParentItemContract $parent);
        public static function getMenuArray($uri);
        public static function clean();
    }
  • Xemoe/Menu/Contracts/MenuItemContract

    interface MenuItemContract
    {
        public function getName();
        public function getLabel();
        public function getLink();
        public function setActiveRule($callable);
        public function getActiveRule();
        public function isActive();
        public function setTemplate(StringTemplateContract $template);
        public function getTemplate();
        public function setUri($uri);
        public function getUri();
        public function toArray();
    }
  • Xemoe/Menu/Contracts/ParentItemContract

    interface ParentItemContract
    {
        public function addChild(MenuItemContract $item);
        public function getChild();
        public function hasActiveChild();
    }

Testcase

  • Unit/Menu/MenuItemTest

    [x] testIsActive_withExpectedUri_shouldReturnTrue
    [x] testIsActive_withEmptyUri_shouldReturnFalse
    [x] testIsActive_withAnotherUri_shouldReturnFalse
    [x] testToArray_withActive_shouldReturnExpectedArray
    [x] testToArray_withInactive_shouldReturnExpectedArray
    
  • Unit/Menu/ParentItemTest

    [x] testHasActiveChild_withActiveChild_shouldReturnTrue
    [x] testHasActiveChild_withInactiveChild_shouldReturnFalse
    [x] testToArray_withActiveChild_shouldReturnExpectedArray
    [x] testToArray_withoutChild_shouldReturnExpectedArray
    
  • Unit/Containers/MenuContainerTest

    [x] testGetMenuArray_withAddmenu_shouldReturnExpectedArray
    

@xemoe
Copy link
Author

xemoe commented Apr 10, 2016

Example getMenuArray() result

$menu = [
    'overview' => ['label' => 'Overview', 'active' => false, 'link' => '/', 'child' => []],
    'rawlog' => ['label' => 'Log Archive', 'active' => false, 'link' => false, 'child' => [
        'rawlog.syslog' => ['label' => 'Syslog', 'active' => false, 'link' => 'raw/syslog',],
        'rawlog.mail' => ['label' => 'Mail', 'active' => true, 'link' => 'raw/mail',],
    ]],
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment