Skip to content

Commit

Permalink
Merge 5fe8d01 into 1bba9f6
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Aug 19, 2018
2 parents 1bba9f6 + 5fe8d01 commit 4ba0768
Show file tree
Hide file tree
Showing 40 changed files with 1,267 additions and 775 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
*~
/vendor/
/build/
/composer.lock
/mouf
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: php
matrix:
include:
- php: 7.2
env: PREFER_LOWEST=""
- php: 7.1
env: PREFER_LOWEST=""
- php: 7.1
env: PREFER_LOWEST="--prefer-lowest"

before_script:
- composer update $PREFER_LOWEST --no-interaction
- mkdir -p build/logs
script:
- "./vendor/bin/phpunit"
- "./vendor/bin/composer-require-checker"
- composer cs-check
- composer phpstan
after_script:
- php vendor/bin/coveralls -v
- if [ "$COUSCOUS" = "true" ] ; then vendor/bin/couscous travis-auto-deploy --php-version=7.1 -vvv; fi
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![Latest Stable Version](https://poser.pugx.org/mouf/html.renderer/v/stable.svg)](https://packagist.org/packages/mouf/html.renderer) [![Total Downloads](https://poser.pugx.org/mouf/html.renderer/downloads.svg)](https://packagist.org/packages/mouf/html.renderer) [![Latest Unstable Version](https://poser.pugx.org/mouf/html.renderer/v/unstable.svg)](https://packagist.org/packages/mouf/html.renderer) [![License](https://poser.pugx.org/mouf/html.renderer/license.svg)](https://packagist.org/packages/mouf/html.renderer)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/thecodingmachine/html.renderer/badges/quality-score.png?b=1.3)](https://scrutinizer-ci.com/g/thecodingmachine/html.renderer/?branch=1.3)

What is this package?
=====================

Expand Down
47 changes: 37 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name" : "mouf/html.renderer",
"description" : "This package contains the rendering mechanism of the Mouf framework. It is a mechanism allowing packages/templates/developers to overload a default template for various HTML objects.",
"type" : "mouf-library",
"type" : "library",
"authors" : [{
"name" : "David Négrier",
"email" : "d.negrier@thecodingmachine.com",
Expand All @@ -15,22 +15,47 @@
"render"
],
"homepage" : "http://mouf-php.com/packages/mouf/html.renderer",
"license" : [
"MIT"
],
"license" : "MIT",
"require" : {
"mouf/utils.cache.apc-cache" : "~2.0",
"twig/twig" : "^1 || ^2",
"mouf/utils.cache.in-memory-cache" : "~1.0",
"php" : ">=5.4.4",
"php" : ">=7.1",
"mouf/html.htmlelement" : "~2.0",
"mouf/html.renderer.twig-extensions" : "~1.0"
"mouf/html.renderer.twig-extensions" : "^2",
"psr/simple-cache": "^1",
"psr/container": "^1",
"container-interop/service-provider": "^0.4",
"thecodingmachine/funky": "^1",
"mindplay/composer-locator": "^2.1.3",
"psr/http-server-middleware": "^1",
"thecodingmachine/middleware-list-universal-module": "^1.1.1"
},
"require-dev": {
"phpunit/phpunit": "^7.3.1",
"symfony/cache": "^4.1.3",
"phpstan/phpstan": "^0.10.3",
"thecodingmachine/phpstan-strict-rules": "^0.10.3",
"maglnet/composer-require-checker": "^1.0",
"mnapoli/simplex": "^0.5",
"thecodingmachine/twig-universal-module": "^1",
"thecodingmachine/symfony-cache-universal-module": "^1",
"squizlabs/php_codesniffer": "^3.3.1"
},
"autoload" : {
"psr-0" : {
"Mouf\\Html\\Renderer" : "src/"
"psr-4" : {
"Mouf\\Html\\Renderer\\" : "src/"
}
},
"autoload-dev" : {
"psr-4" : {
"Mouf\\Html\\Renderer\\" : "tests/"
}
},
"scripts": {
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"phpstan": "phpstan analyse src -c phpstan.neon --level=5 --no-progress -vvv"
},
"extra" : {
"mouf" : {
"install" : [{
Expand All @@ -54,5 +79,7 @@
}
]
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
17 changes: 8 additions & 9 deletions src/install.php → install.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

$rendererCacheService = InstallUtils::getOrCreateInstance("rendererCacheService", "Mouf\\Utils\\Cache\\InMemoryCache", $moufManager);
if ($moufManager->instanceExists("apcCacheService")) {
$rendererCacheService->getProperty("chainWith")->setValue($moufManager->getInstanceDescriptor("apcCacheService"));
$rendererCacheService->getProperty("chainWith")->setValue($moufManager->getInstanceDescriptor("apcCacheService"));
}

$customRenderer = InstallUtils::getOrCreateInstance("customRenderer", "Mouf\\Html\\Renderer\\FileBasedRenderer", $moufManager);
Expand All @@ -33,22 +33,21 @@
$defaultRenderer->getProperty("cacheService")->setValue($rendererCacheService);

if (!file_exists(ROOT_PATH.'src/templates')) {
$old = umask(0);
mkdir(ROOT_PATH.'src/templates', 0775, true);
// We add a default file in the templates directory in order to make sure the directory is commited in Git
// (Git does not support commiting empty directories)
file_put_contents(ROOT_PATH.'src/templates/README.txt', 'Templates directory
$old = umask(0);
mkdir(ROOT_PATH.'src/templates', 0775, true);
// We add a default file in the templates directory in order to make sure the directory is commited in Git
// (Git does not support commiting empty directories)
file_put_contents(ROOT_PATH.'src/templates/README.txt', 'Templates directory
===================
This directory contains the templates used to renderer compatible objects in your application.
If you are not familiar with Mouf template mechanism, please have a look at the documentation:
http://mouf-php.com/packages/mouf/html.renderer/README.md');
umask($old);
umask($old);
}

// Let's rewrite the MoufComponents.php file to save the component
$moufManager->rewriteMouf();

// Finally, let's continue the install
InstallUtils::continueInstall();
?>
21 changes: 21 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<ruleset name="Expressive Skeleton coding standard">
<description>Expressive Skeleton coding standard</description>

<!-- display progress -->
<arg value="p"/>
<arg name="colors"/>

<!-- inherit rules from: -->
<rule ref="PSR2"/>

<!-- Paths to check -->
<file>src</file>

<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="300"/>
<property name="absoluteLineLimit" value="500"/>
</properties>
</rule>
</ruleset>
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#parameters:
# ignoreErrors:
# - "#Instantiated class WeakRef not found.#"
includes:
- vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
28 changes: 28 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
79 changes: 79 additions & 0 deletions src/AbstractPackageRendererServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php


namespace Mouf\Html\Renderer;

use Interop\Container\ServiceProviderInterface;
use Psr\Container\ContainerInterface;
use Psr\SimpleCache\CacheInterface;

/**
* This class can be extended to implement easily a service provider that creates "package level" renderers.
*/
abstract class AbstractPackageRendererServiceProvider implements ServiceProviderInterface
{
/**
* Returns the path to the templates directory.
*
* @return string
*/
abstract public static function getTemplateDirectory(): string;

public static function getPriority(): int
{
return 0;
}

/**
* Returns a list of all container entries registered by this service provider.
*
* - the key is the entry name
* - the value is a callable that will return the entry, aka the **factory**
*
* Factories have the following signature:
* function(\Psr\Container\ContainerInterface $container)
*
* @return callable[]
*/
public function getFactories()
{
return [
'packageRenderer_'.static::getTemplateDirectory() => [static::class, 'createRenderer']
];
}

public static function createRenderer(ContainerInterface $container): FileBasedRenderer
{
return new FileBasedRenderer(static::getTemplateDirectory(), $container->get(CacheInterface::class), $container, $container->get(\Twig_Environment::class));
}

/**
* Returns a list of all container entries extended by this service provider.
*
* - the key is the entry name
* - the value is a callable that will return the modified entry
*
* Callables have the following signature:
* function(Psr\Container\ContainerInterface $container, $previous)
* or function(Psr\Container\ContainerInterface $container, $previous = null)
*
* About factories parameters:
*
* - the container (instance of `Psr\Container\ContainerInterface`)
* - the entry to be extended. If the entry to be extended does not exist and the parameter is nullable, `null` will be passed.
*
* @return callable[]
*/
public function getExtensions()
{
return [
'packageRenderers' => [static::class, 'extendPackageRenderersList']
];
}

public static function extendPackageRenderersList(ContainerInterface $container, \SplPriorityQueue $priorityQueue): \SplPriorityQueue
{
$priorityQueue->insert('packageRenderer_'.static::getTemplateDirectory(), static::getPriority());
return $priorityQueue;
}
}
26 changes: 26 additions & 0 deletions src/CanSetTemplateRendererInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/*
* Copyright (c) 2013 David Negrier
*
* See the file LICENSE.txt for copying permission.
*/

namespace Mouf\Html\Renderer;

/**
* Classes implementing this interface are renderer system that can accept an additional renderer
* (for the template renderer)
*
* @author David Négrier <david@mouf-php.com>
*/
interface CanSetTemplateRendererInterface extends RendererInterface
{
/**
* Sets the renderer associated to the template.
* There should be only one if these renderers.
* It is the role of the template to subscribe to this renderer.
*
* @param string $templateRendererInstanceName The name of the template renderer in the container
*/
public function setTemplateRendererInstanceName(string $templateRendererInstanceName): void;
}
Loading

0 comments on commit 4ba0768

Please sign in to comment.