From c3510620ad0718d2ab1f856e3a838360a5ade314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sun, 11 Oct 2015 16:54:21 +0200 Subject: PoC of rule-based tagging --- app/AppKernel.php | 1 + composer.json | 3 +- composer.lock | 777 ++++++++++++++++++++- src/Wallabag/CoreBundle/Helper/ContentProxy.php | 8 +- src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php | 82 +++ .../CoreBundle/Resources/config/services.yml | 14 + 6 files changed, 855 insertions(+), 30 deletions(-) create mode 100644 src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php diff --git a/app/AppKernel.php b/app/AppKernel.php index 2475fe16..1eacb348 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -29,6 +29,7 @@ class AppKernel extends Kernel new FOS\OAuthServerBundle\FOSOAuthServerBundle(), new Wallabag\UserBundle\WallabagUserBundle(), new Scheb\TwoFactorBundle\SchebTwoFactorBundle(), + new KPhoen\RulerZBundle\KPhoenRulerZBundle(), ); if (in_array($this->getEnvironment(), array('dev', 'test'))) { diff --git a/composer.json b/composer.json index b6a9c854..ceefab02 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,8 @@ "friendsofsymfony/oauth-server-bundle": "^1.4@dev", "scheb/two-factor-bundle": "~1.4", "grandt/phpepub": "~4.0", - "wallabag/php-mobi": "~1.0.0" + "wallabag/php-mobi": "~1.0.0", + "kphoen/rulerz-bundle": "dev-master" }, "require-dev": { "doctrine/doctrine-fixtures-bundle": "~2.2.0", diff --git a/composer.lock b/composer.lock index b7b5d142..b29ac98a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "a9ec461e17166dcda1563dd55f6ff861", + "hash": "657caf7a678eb246a7055756dfa47d5d", + "content-hash": "95a1be6941e76e6a72622f183f4c0425", "packages": [ { "name": "doctrine/annotations", @@ -1484,6 +1485,610 @@ ], "time": "2014-10-12 19:18:40" }, + { + "name": "hoa/compiler", + "version": "2.15.10.29", + "source": { + "type": "git", + "url": "https://github.com/hoaproject/Compiler.git", + "reference": "ec0849fd3c1472fbcd86c3c961981f0cfe1f8d39" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hoaproject/Compiler/zipball/ec0849fd3c1472fbcd86c3c961981f0cfe1f8d39", + "reference": "ec0849fd3c1472fbcd86c3c961981f0cfe1f8d39", + "shasum": "" + }, + "require": { + "hoa/core": "~2.0", + "hoa/file": "~0.0", + "hoa/iterator": "~1.0", + "hoa/math": "~0.0", + "hoa/regex": "~0.0", + "hoa/visitor": "~1.0" + }, + "require-dev": { + "hoa/json": "~1.0", + "hoa/test": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Hoa\\Compiler\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Ivan Enderlin", + "email": "ivan.enderlin@hoa-project.net" + }, + { + "name": "Hoa community", + "homepage": "http://hoa-project.net/" + } + ], + "description": "The Hoa\\Compiler library.", + "homepage": "http://hoa-project.net/", + "keywords": [ + "algebraic", + "ast", + "compiler", + "context-free", + "coverage", + "exhaustive", + "grammar", + "isotropic", + "language", + "lexer", + "library", + "ll1", + "llk", + "parser", + "pp", + "random", + "regular", + "rule", + "sampler", + "syntax", + "token", + "trace", + "uniform" + ], + "time": "2015-10-29 21:35:12" + }, + { + "name": "hoa/core", + "version": "2.15.11.09", + "source": { + "type": "git", + "url": "https://github.com/hoaproject/Core.git", + "reference": "5538b1e90e2c66c90df5cc45e03fb85d047be900" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hoaproject/Core/zipball/5538b1e90e2c66c90df5cc45e03fb85d047be900", + "reference": "5538b1e90e2c66c90df5cc45e03fb85d047be900", + "shasum": "" + }, + "require": { + "ext-spl": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "hoa/test": "~1.0" + }, + "suggest": { + "ext-mbstring": "ext/mbstring must be present (or a third implementation).", + "hoa/cli": "To use the `hoa` script." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Hoa\\Core\\": "." + }, + "files": [ + "Core.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Ivan Enderlin", + "email": "ivan.enderlin@hoa-project.net" + }, + { + "name": "Hoa community", + "homepage": "http://hoa-project.net/" + } + ], + "description": "The Hoa\\Core library.", + "homepage": "http://hoa-project.net/", + "keywords": [ + "consistency", + "core", + "data", + "event", + "library", + "listener", + "parameter", + "protocol" + ], + "time": "2015-11-09 06:51:06" + }, + { + "name": "hoa/file", + "version": "0.15.11.09", + "source": { + "type": "git", + "url": "https://github.com/hoaproject/File.git", + "reference": "f46fe552ff79cb6c93a2ff9c25cfbc134fbd57ee" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hoaproject/File/zipball/f46fe552ff79cb6c93a2ff9c25cfbc134fbd57ee", + "reference": "f46fe552ff79cb6c93a2ff9c25cfbc134fbd57ee", + "shasum": "" + }, + "require": { + "hoa/core": "~2.0", + "hoa/iterator": "~1.0", + "hoa/stream": "~0.0" + }, + "require-dev": { + "hoa/test": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Hoa\\File\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Ivan Enderlin", + "email": "ivan.enderlin@hoa-project.net" + }, + { + "name": "Hoa community", + "homepage": "http://hoa-project.net/" + } + ], + "description": "The Hoa\\File library.", + "homepage": "http://hoa-project.net/", + "keywords": [ + "Socket", + "directory", + "file", + "finder", + "library", + "link", + "temporary" + ], + "time": "2015-11-09 06:55:20" + }, + { + "name": "hoa/iterator", + "version": "1.15.10.29", + "source": { + "type": "git", + "url": "https://github.com/hoaproject/Iterator.git", + "reference": "a64ed9fd62579a34e4450134d6d1abdf77d54435" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hoaproject/Iterator/zipball/a64ed9fd62579a34e4450134d6d1abdf77d54435", + "reference": "a64ed9fd62579a34e4450134d6d1abdf77d54435", + "shasum": "" + }, + "require": { + "hoa/core": "~2.0" + }, + "require-dev": { + "hoa/test": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Hoa\\Iterator\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Ivan Enderlin", + "email": "ivan.enderlin@hoa-project.net" + }, + { + "name": "Hoa community", + "homepage": "http://hoa-project.net/" + } + ], + "description": "The Hoa\\Iterator library.", + "homepage": "http://hoa-project.net/", + "keywords": [ + "iterator", + "library" + ], + "time": "2015-10-29 21:37:16" + }, + { + "name": "hoa/math", + "version": "0.15.10.26", + "source": { + "type": "git", + "url": "https://github.com/hoaproject/Math.git", + "reference": "62631c65d9a4f1b8bb4c4a3d6cdff0e8971d684e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hoaproject/Math/zipball/62631c65d9a4f1b8bb4c4a3d6cdff0e8971d684e", + "reference": "62631c65d9a4f1b8bb4c4a3d6cdff0e8971d684e", + "shasum": "" + }, + "require": { + "hoa/compiler": "~2.0", + "hoa/core": "~2.0", + "hoa/iterator": "~1.0" + }, + "require-dev": { + "hoa/test": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Hoa\\Math\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Ivan Enderlin", + "email": "ivan.enderlin@hoa-project.net" + }, + { + "name": "Hoa community", + "homepage": "http://hoa-project.net/" + } + ], + "description": "The Hoa\\Math library.", + "homepage": "http://hoa-project.net/", + "keywords": [ + "arrangement", + "combination", + "combinatorics", + "counting", + "library", + "math", + "permutation", + "sampler", + "set" + ], + "time": "2015-10-26 15:22:52" + }, + { + "name": "hoa/regex", + "version": "0.15.08.13", + "source": { + "type": "git", + "url": "https://github.com/hoaproject/Regex.git", + "reference": "2ef8a77ef3885ca202fcd9c31a8e54c44cd04232" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hoaproject/Regex/zipball/2ef8a77ef3885ca202fcd9c31a8e54c44cd04232", + "reference": "2ef8a77ef3885ca202fcd9c31a8e54c44cd04232", + "shasum": "" + }, + "require": { + "hoa/core": "~2.0", + "hoa/math": "~0.0", + "hoa/ustring": "~3.0", + "hoa/visitor": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Hoa\\Regex\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Ivan Enderlin", + "email": "ivan.enderlin@hoa-project.net" + }, + { + "name": "Hoa community", + "homepage": "http://hoa-project.net/" + } + ], + "description": "The Hoa\\Regex library.", + "homepage": "http://hoa-project.net/", + "keywords": [ + "compiler", + "library", + "regex" + ], + "time": "2015-08-13 06:48:47" + }, + { + "name": "hoa/ruler", + "version": "1.15.11.09", + "source": { + "type": "git", + "url": "https://github.com/hoaproject/Ruler.git", + "reference": "9afc9ae032d40b6dc10bff85c9126cf516953925" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hoaproject/Ruler/zipball/9afc9ae032d40b6dc10bff85c9126cf516953925", + "reference": "9afc9ae032d40b6dc10bff85c9126cf516953925", + "shasum": "" + }, + "require": { + "hoa/compiler": "~2.0", + "hoa/core": "~2.0", + "hoa/file": "~0.0", + "hoa/visitor": "~1.0" + }, + "require-dev": { + "hoa/test": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Hoa\\Ruler\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Ivan Enderlin", + "email": "ivan.enderlin@hoa-project.net" + }, + { + "name": "Hoa community", + "homepage": "http://hoa-project.net/" + } + ], + "description": "The Hoa\\Ruler library.", + "homepage": "http://hoa-project.net/", + "keywords": [ + "library", + "ruler" + ], + "time": "2015-11-09 06:58:52" + }, + { + "name": "hoa/stream", + "version": "0.15.10.26", + "source": { + "type": "git", + "url": "https://github.com/hoaproject/Stream.git", + "reference": "011ab91d942f1d7096deade4c8a10fe57d51c5b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hoaproject/Stream/zipball/011ab91d942f1d7096deade4c8a10fe57d51c5b3", + "reference": "011ab91d942f1d7096deade4c8a10fe57d51c5b3", + "shasum": "" + }, + "require": { + "hoa/core": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Hoa\\Stream\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Ivan Enderlin", + "email": "ivan.enderlin@hoa-project.net" + }, + { + "name": "Hoa community", + "homepage": "http://hoa-project.net/" + } + ], + "description": "The Hoa\\Stream library.", + "homepage": "http://hoa-project.net/", + "keywords": [ + "Context", + "bucket", + "composite", + "filter", + "in", + "library", + "out", + "protocol", + "stream", + "wrapper" + ], + "time": "2015-10-22 06:30:43" + }, + { + "name": "hoa/ustring", + "version": "3.15.11.09", + "source": { + "type": "git", + "url": "https://github.com/hoaproject/Ustring.git", + "reference": "8506be4910212b1a2beb9014763a8a4fbd871001" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hoaproject/Ustring/zipball/8506be4910212b1a2beb9014763a8a4fbd871001", + "reference": "8506be4910212b1a2beb9014763a8a4fbd871001", + "shasum": "" + }, + "require": { + "hoa/core": "~2.0" + }, + "require-dev": { + "hoa/test": "~1.0" + }, + "suggest": { + "ext-iconv": "ext/iconv must be present (or a third implementation) to use Hoa\\Ustring::transcode().", + "ext-intl": "To get a better Hoa\\Ustring::toAscii() and Hoa\\Ustring::compareTo()." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Hoa\\Ustring\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Ivan Enderlin", + "email": "ivan.enderlin@hoa-project.net" + }, + { + "name": "Hoa community", + "homepage": "http://hoa-project.net/" + } + ], + "description": "The Hoa\\Ustring library.", + "homepage": "http://hoa-project.net/", + "keywords": [ + "library", + "search", + "string", + "unicode" + ], + "time": "2015-11-09 06:44:33" + }, + { + "name": "hoa/visitor", + "version": "1.15.08.17", + "source": { + "type": "git", + "url": "https://github.com/hoaproject/Visitor.git", + "reference": "e30bfff741f71979f6476a41548e34afe8053c67" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hoaproject/Visitor/zipball/e30bfff741f71979f6476a41548e34afe8053c67", + "reference": "e30bfff741f71979f6476a41548e34afe8053c67", + "shasum": "" + }, + "require": { + "hoa/core": "~2.0" + }, + "require-dev": { + "hoa/test": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Hoa\\Visitor\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Ivan Enderlin", + "email": "ivan.enderlin@hoa-project.net" + }, + { + "name": "Hoa community", + "homepage": "http://hoa-project.net/" + } + ], + "description": "The Hoa\\Visitor library.", + "homepage": "http://hoa-project.net/", + "keywords": [ + "library", + "structure", + "visit", + "visitor" + ], + "time": "2015-08-17 06:30:58" + }, { "name": "htmlawed/htmlawed", "version": "1.1.19", @@ -1532,21 +2137,21 @@ }, { "name": "incenteev/composer-parameter-handler", - "version": "v2.1.1", + "version": "v2.1.2", "source": { "type": "git", "url": "https://github.com/Incenteev/ParameterHandler.git", - "reference": "84a205fe80a46101607bafbc423019527893ddd0" + "reference": "d7ce7f06136109e81d1cb9d57066c4d4a99cf1cc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Incenteev/ParameterHandler/zipball/84a205fe80a46101607bafbc423019527893ddd0", - "reference": "84a205fe80a46101607bafbc423019527893ddd0", + "url": "https://api.github.com/repos/Incenteev/ParameterHandler/zipball/d7ce7f06136109e81d1cb9d57066c4d4a99cf1cc", + "reference": "d7ce7f06136109e81d1cb9d57066c4d4a99cf1cc", "shasum": "" }, "require": { "php": ">=5.3.3", - "symfony/yaml": "~2.0" + "symfony/yaml": "~2.3|~3.0" }, "require-dev": { "composer/composer": "1.0.*@dev", @@ -1579,7 +2184,7 @@ "keywords": [ "parameters management" ], - "time": "2015-06-03 08:27:03" + "time": "2015-11-10 17:04:01" }, { "name": "j0k3r/graby", @@ -1671,20 +2276,19 @@ }, { "name": "j0k3r/php-readability", - "version": "v1.0.8", + "version": "v1.0.9", "source": { "type": "git", "url": "https://github.com/j0k3r/php-readability.git", - "reference": "f71c3a419623f821c245e0a003edfbf2c67f278e" + "reference": "41d7440c6e6130bacd50808342fe566e28f536fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/j0k3r/php-readability/zipball/f71c3a419623f821c245e0a003edfbf2c67f278e", - "reference": "f71c3a419623f821c245e0a003edfbf2c67f278e", + "url": "https://api.github.com/repos/j0k3r/php-readability/zipball/41d7440c6e6130bacd50808342fe566e28f536fb", + "reference": "41d7440c6e6130bacd50808342fe566e28f536fb", "shasum": "" }, "require": { - "ext-tidy": ">=1.2", "php": ">=5.3.3" }, "type": "library", @@ -1730,7 +2334,7 @@ "extraction", "html" ], - "time": "2015-09-23 19:09:38" + "time": "2015-11-10 08:55:29" }, { "name": "j0k3r/safecurl", @@ -2057,6 +2661,124 @@ ], "time": "2013-12-05 14:36:11" }, + { + "name": "kphoen/rulerz", + "version": "0.14.0", + "source": { + "type": "git", + "url": "https://github.com/K-Phoen/rulerz.git", + "reference": "608649b148ffdf3437600cc0f450d59b0579148d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/K-Phoen/rulerz/zipball/608649b148ffdf3437600cc0f450d59b0579148d", + "reference": "608649b148ffdf3437600cc0f450d59b0579148d", + "shasum": "" + }, + "require": { + "hoa/ruler": "~1.0", + "php": ">=5.4", + "symfony/property-access": "~2.3" + }, + "require-dev": { + "behat/behat": "~3.0", + "coduo/phpspec-data-provider-extension": "~1.0,!=1.0.2", + "doctrine/orm": "~2.4", + "elasticsearch/elasticsearch": "~1.0", + "illuminate/database": "~5.0", + "mikey179/vfsstream": "~1.4", + "phpspec/phpspec": "~2.0", + "pomm-project/cli": "~2.0@dev", + "pomm-project/foundation": "~2.0@dev", + "pomm-project/model-manager": "~2.0.@dev", + "ruflin/elastica": "~1.0", + "vlucas/phpdotenv": "~2.1" + }, + "suggest": { + "doctrine/orm": "To execute rules as Doctrine queries", + "elasticsearch/elasticsearch": "To execute rules as Elasticsearch queries", + "kphoen/rulerz-spec-builder": "If you want a specification builder", + "pomm-project/model-manager": "To execute rules as Pomm queries" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "RulerZ\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kévin Gomez", + "email": "contact@kevingomez.fr" + } + ], + "description": "Powerful implementation of the Specification pattern", + "homepage": "https://github.com/K-Phoen/RulerZ", + "keywords": [ + "doctrine", + "specification" + ], + "time": "2015-10-31 20:54:37" + }, + { + "name": "kphoen/rulerz-bundle", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/K-Phoen/RulerZBundle.git", + "reference": "86148898a052e349f880537c20d8102f617ebc17" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/K-Phoen/RulerZBundle/zipball/86148898a052e349f880537c20d8102f617ebc17", + "reference": "86148898a052e349f880537c20d8102f617ebc17", + "shasum": "" + }, + "require": { + "kphoen/rulerz": "~0.1, >=0.13.0", + "symfony/framework-bundle": "~2.3", + "symfony/validator": "~2.3" + }, + "require-dev": { + "matthiasnoback/symfony-dependency-injection-test": "~0.7", + "mikey179/vfsstream": "~1.0", + "phpunit/phpunit": "~4.8" + }, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "KPhoen\\RulerZBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kévin Gomez", + "email": "contact@kevingomez.fr" + } + ], + "description": "Symfony2 Bundle for RulerZ", + "homepage": "https://github.com/K-Phoen/RulerZBundle", + "keywords": [ + "doctrine", + "ruler", + "rulerz", + "specification" + ], + "time": "2015-11-01 11:57:49" + }, { "name": "kriswallsmith/assetic", "version": "v1.3.1", @@ -3014,25 +3736,25 @@ }, { "name": "sensio/framework-extra-bundle", - "version": "v3.0.10", + "version": "v3.0.11", "source": { "type": "git", "url": "https://github.com/sensiolabs/SensioFrameworkExtraBundle.git", - "reference": "18fc2063c4d6569cdca47a39fbac32342eb65f3c" + "reference": "a79e205737b58d557c05caef6dfa8f94d8084bca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sensiolabs/SensioFrameworkExtraBundle/zipball/18fc2063c4d6569cdca47a39fbac32342eb65f3c", - "reference": "18fc2063c4d6569cdca47a39fbac32342eb65f3c", + "url": "https://api.github.com/repos/sensiolabs/SensioFrameworkExtraBundle/zipball/a79e205737b58d557c05caef6dfa8f94d8084bca", + "reference": "a79e205737b58d557c05caef6dfa8f94d8084bca", "shasum": "" }, "require": { "doctrine/common": "~2.2", - "symfony/framework-bundle": "~2.3" + "symfony/framework-bundle": "~2.3|~3.0" }, "require-dev": { - "symfony/expression-language": "~2.4", - "symfony/security-bundle": "~2.4" + "symfony/expression-language": "~2.4|~3.0", + "symfony/security-bundle": "~2.4|~3.0" }, "suggest": { "symfony/expression-language": "", @@ -3065,7 +3787,7 @@ "annotations", "controllers" ], - "time": "2015-08-03 11:59:27" + "time": "2015-10-28 15:47:04" }, { "name": "sensiolabs/security-checker", @@ -4516,16 +5238,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.8.16", + "version": "4.8.18", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "625f8c345606ed0f3a141dfb88f4116f0e22978e" + "reference": "fa33d4ad96481b91df343d83e8c8aabed6b1dfd3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/625f8c345606ed0f3a141dfb88f4116f0e22978e", - "reference": "625f8c345606ed0f3a141dfb88f4116f0e22978e", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fa33d4ad96481b91df343d83e8c8aabed6b1dfd3", + "reference": "fa33d4ad96481b91df343d83e8c8aabed6b1dfd3", "shasum": "" }, "require": { @@ -4584,7 +5306,7 @@ "testing", "xunit" ], - "time": "2015-10-23 06:48:33" + "time": "2015-11-11 11:32:49" }, { "name": "phpunit/phpunit-mock-objects", @@ -5118,7 +5840,8 @@ "minimum-stability": "dev", "stability-flags": { "friendsofsymfony/user-bundle": 20, - "friendsofsymfony/oauth-server-bundle": 20 + "friendsofsymfony/oauth-server-bundle": 20, + "kphoen/rulerz-bundle": 20 }, "prefer-stable": true, "prefer-lowest": false, diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 7fb41393..dc6e1184 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php @@ -13,10 +13,12 @@ use Wallabag\CoreBundle\Tools\Utils; class ContentProxy { protected $graby; + protected $tagger; - public function __construct(Graby $graby) + public function __construct(Graby $graby, RuleBasedTagger $tagger) { - $this->graby = $graby; + $this->graby = $graby; + $this->tagger = $tagger; } /** @@ -59,6 +61,8 @@ class ContentProxy $entry->setPreviewPicture($content['open_graph']['og_image']); } + $this->tagger->tag($entry); + return $entry; } } diff --git a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php new file mode 100644 index 00000000..012450b6 --- /dev/null +++ b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php @@ -0,0 +1,82 @@ +rulerz = $rulerz; + $this->tagRepository = $tagRepository; + } + + /** + * Add tags from rules defined by the user. + * + * @param Entry $entry Entry to tag. + */ + public function tag(Entry $entry) + { + $rules = $this->getRulesForUser($entry->getUser()); + + foreach ($rules as $rule) { + if (!$this->rulerz->satisfies($entry, $rule['rule'])) { + continue; + } + + foreach ($rule['tags'] as $label) { + $tag = $this->getTag($entry->getUser(), $label); + + $entry->addTag($tag); + } + } + } + + /** + * Fetch a tag for a user. + * + * @param User $user + * @param string $label The tag's label. + * + * @return Tag + */ + private function getTag(User $user, $label) + { + $tag = $this->tagRepository->findOneByLabelAndUserId($label, $user->getId()); + + if (!$tag) { + $tag = new Tag($user); + $tag->setLabel($label); + } + + return $tag; + } + + private function getRulesForUser(User $user) + { + return [ + [ + 'rule' => 'domainName = "github.com"', + 'tags' => ['github'], + ], + [ + 'rule' => 'readingTime >= 15', + 'tags' => ['long reading'], + ], + [ + 'rule' => 'readingTime <= 3 ', + 'tags' => ['short reading'], + ], + ]; + } +} diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 8e21b052..4cf46b33 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -53,6 +53,20 @@ services: class: Wallabag\CoreBundle\Helper\ContentProxy arguments: - @wallabag_core.graby + - @wallabag_core.rule_based_tagger + + wallabag_core.rule_based_tagger: + class: Wallabag\CoreBundle\Helper\RuleBasedTagger + arguments: + - @rulerz + - @wallabag_core.tag_repository + + wallabag_core.tag_repository: + class: Wallabag\CoreBundle\Repository\TagRepository + factory_service: doctrine.orm.default_entity_manager + factory_method: getRepository + arguments: + - WallabagCoreBundle:Tag wallabag_core.registration_confirmed: class: Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener -- cgit v1.2.3