定制 foolz/theme 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

foolz/theme

Composer 安装命令:

composer require foolz/theme

包简介

An opinionated theme system where even the views can be classes, and everything is a plugin.

README 文档

README

A theme system that abuses OOP to give you those features you've always dreamed of.

You will need PHP 5.4 for this to work. You can install it through Composer and Packagist.

What a mess!

Foolz\Theme works on top of Foolz\Plugin. This means it has built-in support for plugin-like stuff, that you can use or ignore at will. We use it to allow re-skinning and hooking links on the interface.

We created our own Theme system because other theme systems were nothing more than View managers, monolithic and raw.

This package aims to use a multi-level approach to themes, where you can go up and down in the system and build components at the very last moment - by interacting with the theme directly. The structure goes like this:

  • Loader
  • Theme
  • Builder -> Global Parameter Manager
  • View -> Local Parameter Manager

From the View you can bubble up to the Loader, grab the global parameters, enter other partials, and build them within the View.

Other features:

  • Child themes: Instead of having to duplicate the entire theme directory, you can extend another theme and fallback on its files. You can also extend from an extended theme, with no limit.
  • Asset Manager: compile LESS files on the fly.

Classes

Theme

The Theme object abstracts the content of the theme. These will be returned by the Loader, and you will be able to choose which to use.

  • $theme->createBuilder()

    Returns a new builder. It's used to create the HTML.

  • $theme->getAssetManager()

    Returns the asset manager. It's used to load and edit the content of the package that the user will download, like stylesheets and images.

Builder

The builder is used to create the HTML. It divides the job between layouts and partials, and provides a global parameter manager.

  • $builder->getTheme()

    Returns the Theme that generated this builder object.

  • $builder->getParamManager()

    Returns the parameter manager used to hold parameters for the views.

  • $builder->createLayout($view)

    • string $view - The name of the layout with underscores

    Sets the layout and returns the View object.

  • $builder->createPartial($name, $view)

    • string $name - A given name for the partial
    • string $view - The name of the layout with underscores

    Sets a partial with the given $name, and returns the View object.

  • $builder->getLayout()

    Returns the currently set Layout.

  • $builder->getPartial($name)

    • string $name - The given name of the partial

    Returns the partial with the given name.

  • $builder->build()

    Builds the entire HTML with the given parameters.

Parameter Manager

Parameter managers are used to consistently store variables for use in the theme. The Builder has a global one, and every View has a local one.

  • $pm->reset()

    Resets the object to its original state.

  • $pm->getParams()

    Returns an array of parameters.

  • $pm->getParam($key, $fallback = undefined)

    • string $key - The key for the value
    • mixed $fallback

    Returns the value stored with $key. The fallback is activated through func_num_args() so it works even when using null.

    Throws: \OutOfBoundsException - If the value was not set and a fallback is not available

  • $pm->setParam($key, $value)

    • string $key - The key for the value
    • mixed $value - The value

    Sets a parameter

  • $pm->setParams($array)

    • array $array - An array of parameters to set

    Takes an array and inserts every single parameter. Doesn't delete previous parameters.

View

The View returned by the Builder is usually a custom object extending \Foolz\Theme\View.

There's also a bunch of shortcuts to go to the above levels available (getBuilder, getBuilderParamManager, getTheme, getAssetManager)

It's compulsory to override the toString() method (not the __toString() magic method!) in order to output the HTML. This function should output HTML or return a string.

  • $view->toString()

    Called when the HTML must be generated. It should contain the classic HTML building logic. $this can be used. No manual output buffering is necessary.

  • $view->getType()

    Returns the type of View, either layout or partial.

  • $view->getView()

    Returns the name of the View.

  • $view->getParamManager()

    Returns the local parameter manager.

  • $view->build()

    Builds and caches the HTML. Returns the HTML.

  • $view->doBuild()

    Builds the HTML and stores it in a variable. Rebuilds the HTML every time it's called.

    CHAINABLE

foolz/theme 适用场景与选型建议

foolz/theme 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.74k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2012 年 12 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「theme」 「template」 「views」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 foolz/theme 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 foolz/theme 我们能提供哪些服务?
定制开发 / 二次开发

基于 foolz/theme 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.74k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 15
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 4
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2012-12-21