承接 neirda24/liipthemeprovider 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

neirda24/liipthemeprovider

最新稳定版本:1.1.6

Composer 安装命令:

composer require neirda24/liipthemeprovider

包简介

Allow to create some custom providers for the theme list.

README 文档

README

SensioLabsInsight Scrutinizer Code Quality Latest Stable Version Total Downloads Latest Unstable Version License Dependency Status

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require neirda24/liipthemeprovider "~1"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Neirda\Bundle\LiipThemeProvider\LiipThemeProviderBundle(),
        );

        // ...
    }

    // ...
}

How to use it

Step 1: Create your provider class

<?php
// src/AppBundle/ThemeProvider

use Neirda\Bundle\LiipThemeProvider\ThemeProviderInterface;

// ...
class ThemeProvider implements ThemeProviderInterface
{
    /**
     * {@inheritdoc}
     */
    public function getThemeList()
    {
        // implement your logic here...
        // it should return an array event if it is empty
    }

    // ...
}

Step 2: Declare the service

Your service must be tagged with liip_theme_provider.theme_provider.

XML:

...

    <services>
        ...
        <service id="app.theme.provider" class="AppBundle\ThemeProvider\ThemeProvider">
            <tag name="liip_theme_provider.theme_provider" />
        </service>
        ...
    </services>
...

Done !!

Example

Create this class:

<?php
// src/AppBundle/ThemeProvider

use Neirda\Bundle\LiipThemeProvider\Theme\ThemeProviderInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

class ThemeProvider implements ThemeProviderInterface
{
    /**
     * @const THEMES_PATH
     */
    const THEMES_PATH = 'src/AppBundle/Resources/themes';

    /**
     * @var string
     */
    protected $rootDir;

    /**
     * @var null|array
     */
    protected $themeList = null;

    /**
     * Constructor.
     *
     * @param string $rootDir
     */
    public function __construct($rootDir)
    {
        $this->rootDir = $rootDir;
    }

    /**
     * {@inheritdoc}
     */
    public function getThemeList()
    {
        if (!is_array($this->themeList)) {
            $path   = rtrim($this->rootDir, '/') . '/' . ltrim(static::THEMES_PATH, '/');
            $themes = new Finder();
            $themes->directories()->depth('== 0')->in($path);
            $themeList = [];
            foreach ($themes as $theme) {
                /** @var SplFileInfo $theme */
                $themeList[] = $theme->getFilename();
            }

            $this->themeList = $themeList;
        }

        return $this->themeList;
    }
}

And declare your service:

xml

...
<services>
    <service id="app.theme.provider" class="AppBundle\Provider\ThemeProvider">
        <argument>%kernel.root_dir%/../</argument>
        <tag name="liip_theme_provider.theme_provider" />
    </service>
</services>
...

Now, all you have to do is just creating a new folder and it will be automatically added to the themes available.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-30