aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2015-01-28 17:09:27 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2015-01-28 17:09:27 +0100
commite4788de51ecbf2773a043325965e10eb74b14e8f (patch)
treeca66ba084b27050ee336b93b82fbd55ac7f9fd3a
parent569f8d6851ea31b594fc5ccbcc11fe79dbdf2fa6 (diff)
downloadwallabag-e4788de51ecbf2773a043325965e10eb74b14e8f.tar.gz
wallabag-e4788de51ecbf2773a043325965e10eb74b14e8f.tar.zst
wallabag-e4788de51ecbf2773a043325965e10eb74b14e8f.zip
1st implementation of wallabag api, yeah
-rw-r--r--.gitignore44
-rw-r--r--app/AppKernel.php3
-rw-r--r--app/SymfonyRequirements.php739
-rw-r--r--app/check.php142
-rw-r--r--app/config/config.yml20
-rw-r--r--app/config/routing.yml11
-rw-r--r--app/config/routing_rest.yml4
-rw-r--r--src/.htaccess7
-rw-r--r--src/Wallabag/CoreBundle/Controller/ApiController.php21
-rw-r--r--src/Wallabag/CoreBundle/Controller/StaticController.php8
-rw-r--r--web/.htaccess56
11 files changed, 1039 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index 0beb08c1..64831800 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,24 +1,38 @@
1/app/SymfonyRequirements.php 1# Cache and logs (Symfony2)
2/app/bootstrap.php.cache
3/app/check.php
4/app/cache/* 2/app/cache/*
5/app/config/parameters.yml
6/app/logs/* 3/app/logs/*
7!app/cache/.gitkeep 4!app/cache/.gitkeep
8!app/logs/.gitkeep 5!app/logs/.gitkeep
9.idea 6
10.DS_Store 7# Cache and logs (Symfony3)
11.vagrant 8/var/cache/*
9/var/logs/*
10!var/cache/.gitkeep
11!var/logs/.gitkeep
12
13# Parameters
14/app/config/parameters.yml
15/app/config/parameters.ini
16
17# Managed by Composer
18/app/bootstrap.php.cache
19/var/bootstrap.php.cache
20/bin/*
21!bin/console
22!bin/symfony_requirements
12/vendor/ 23/vendor/
13 24
14/bin/ 25# Assets and user uploads
15!bin/install 26/web/bundles/
16!bin/test 27/web/uploads/
17!bin/symfony
18 28
19data/assets/* 29# PHPUnit
20data/db/poche.sqlite 30/app/phpunit.xml
31/phpunit.xml
21 32
22/web/.htaccess 33# Composer PHAR
34/composer.phar
23 35
24!.gitignore \ No newline at end of file 36# Data for wallabag
37data/assets/*
38data/db/poche.sqlite \ No newline at end of file
diff --git a/app/AppKernel.php b/app/AppKernel.php
index f0383038..e2db75a7 100644
--- a/app/AppKernel.php
+++ b/app/AppKernel.php
@@ -16,6 +16,9 @@ class AppKernel extends Kernel
16 new Symfony\Bundle\AsseticBundle\AsseticBundle(), 16 new Symfony\Bundle\AsseticBundle\AsseticBundle(),
17 new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), 17 new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
18 new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), 18 new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
19 new FOS\RestBundle\FOSRestBundle(),
20 new JMS\SerializerBundle\JMSSerializerBundle(),
21 new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
19 new Wallabag\CoreBundle\WallabagCoreBundle(), 22 new Wallabag\CoreBundle\WallabagCoreBundle(),
20 ); 23 );
21 24
diff --git a/app/SymfonyRequirements.php b/app/SymfonyRequirements.php
new file mode 100644
index 00000000..cbcf1c8e
--- /dev/null
+++ b/app/SymfonyRequirements.php
@@ -0,0 +1,739 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12/*
13 * Users of PHP 5.2 should be able to run the requirements checks.
14 * This is why the file and all classes must be compatible with PHP 5.2+
15 * (e.g. not using namespaces and closures).
16 *
17 * ************** CAUTION **************
18 *
19 * DO NOT EDIT THIS FILE as it will be overridden by Composer as part of
20 * the installation/update process. The original file resides in the
21 * SensioDistributionBundle.
22 *
23 * ************** CAUTION **************
24 */
25
26/**
27 * Represents a single PHP requirement, e.g. an installed extension.
28 * It can be a mandatory requirement or an optional recommendation.
29 * There is a special subclass, named PhpIniRequirement, to check a php.ini configuration.
30 *
31 * @author Tobias Schultze <http://tobion.de>
32 */
33class Requirement
34{
35 private $fulfilled;
36 private $testMessage;
37 private $helpText;
38 private $helpHtml;
39 private $optional;
40
41 /**
42 * Constructor that initializes the requirement.
43 *
44 * @param bool $fulfilled Whether the requirement is fulfilled
45 * @param string $testMessage The message for testing the requirement
46 * @param string $helpHtml The help text formatted in HTML for resolving the problem
47 * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
48 * @param bool $optional Whether this is only an optional recommendation not a mandatory requirement
49 */
50 public function __construct($fulfilled, $testMessage, $helpHtml, $helpText = null, $optional = false)
51 {
52 $this->fulfilled = (bool) $fulfilled;
53 $this->testMessage = (string) $testMessage;
54 $this->helpHtml = (string) $helpHtml;
55 $this->helpText = null === $helpText ? strip_tags($this->helpHtml) : (string) $helpText;
56 $this->optional = (bool) $optional;
57 }
58
59 /**
60 * Returns whether the requirement is fulfilled.
61 *
62 * @return bool true if fulfilled, otherwise false
63 */
64 public function isFulfilled()
65 {
66 return $this->fulfilled;
67 }
68
69 /**
70 * Returns the message for testing the requirement.
71 *
72 * @return string The test message
73 */
74 public function getTestMessage()
75 {
76 return $this->testMessage;
77 }
78
79 /**
80 * Returns the help text for resolving the problem
81 *
82 * @return string The help text
83 */
84 public function getHelpText()
85 {
86 return $this->helpText;
87 }
88
89 /**
90 * Returns the help text formatted in HTML.
91 *
92 * @return string The HTML help
93 */
94 public function getHelpHtml()
95 {
96 return $this->helpHtml;
97 }
98
99 /**
100 * Returns whether this is only an optional recommendation and not a mandatory requirement.
101 *
102 * @return bool true if optional, false if mandatory
103 */
104 public function isOptional()
105 {
106 return $this->optional;
107 }
108}
109
110/**
111 * Represents a PHP requirement in form of a php.ini configuration.
112 *
113 * @author Tobias Schultze <http://tobion.de>
114 */
115class PhpIniRequirement extends Requirement
116{
117 /**
118 * Constructor that initializes the requirement.
119 *
120 * @param string $cfgName The configuration name used for ini_get()
121 * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false,
122 or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement
123 * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false.
124 This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin.
125 Example: You require a config to be true but PHP later removes this config and defaults it to true internally.
126 * @param string|null $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived)
127 * @param string|null $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived)
128 * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
129 * @param bool $optional Whether this is only an optional recommendation not a mandatory requirement
130 */
131 public function __construct($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null, $optional = false)
132 {
133 $cfgValue = ini_get($cfgName);
134
135 if (is_callable($evaluation)) {
136 if (null === $testMessage || null === $helpHtml) {
137 throw new InvalidArgumentException('You must provide the parameters testMessage and helpHtml for a callback evaluation.');
138 }
139
140 $fulfilled = call_user_func($evaluation, $cfgValue);
141 } else {
142 if (null === $testMessage) {
143 $testMessage = sprintf('%s %s be %s in php.ini',
144 $cfgName,
145 $optional ? 'should' : 'must',
146 $evaluation ? 'enabled' : 'disabled'
147 );
148 }
149
150 if (null === $helpHtml) {
151 $helpHtml = sprintf('Set <strong>%s</strong> to <strong>%s</strong> in php.ini<a href="#phpini">*</a>.',
152 $cfgName,
153 $evaluation ? 'on' : 'off'
154 );
155 }
156
157 $fulfilled = $evaluation == $cfgValue;
158 }
159
160 parent::__construct($fulfilled || ($approveCfgAbsence && false === $cfgValue), $testMessage, $helpHtml, $helpText, $optional);
161 }
162}
163
164/**
165 * A RequirementCollection represents a set of Requirement instances.
166 *
167 * @author Tobias Schultze <http://tobion.de>
168 */
169class RequirementCollection implements IteratorAggregate
170{
171 private $requirements = array();
172
173 /**
174 * Gets the current RequirementCollection as an Iterator.
175 *
176 * @return Traversable A Traversable interface
177 */
178 public function getIterator()
179 {
180 return new ArrayIterator($this->requirements);
181 }
182
183 /**
184 * Adds a Requirement.
185 *
186 * @param Requirement $requirement A Requirement instance
187 */
188 public function add(Requirement $requirement)
189 {
190 $this->requirements[] = $requirement;
191 }
192
193 /**
194 * Adds a mandatory requirement.
195 *
196 * @param bool $fulfilled Whether the requirement is fulfilled
197 * @param string $testMessage The message for testing the requirement
198 * @param string $helpHtml The help text formatted in HTML for resolving the problem
199 * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
200 */
201 public function addRequirement($fulfilled, $testMessage, $helpHtml, $helpText = null)
202 {
203 $this->add(new Requirement($fulfilled, $testMessage, $helpHtml, $helpText, false));
204 }
205
206 /**
207 * Adds an optional recommendation.
208 *
209 * @param bool $fulfilled Whether the recommendation is fulfilled
210 * @param string $testMessage The message for testing the recommendation
211 * @param string $helpHtml The help text formatted in HTML for resolving the problem
212 * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
213 */
214 public function addRecommendation($fulfilled, $testMessage, $helpHtml, $helpText = null)
215 {
216 $this->add(new Requirement($fulfilled, $testMessage, $helpHtml, $helpText, true));
217 }
218
219 /**
220 * Adds a mandatory requirement in form of a php.ini configuration.
221 *
222 * @param string $cfgName The configuration name used for ini_get()
223 * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false,
224 or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement
225 * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false.
226 This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin.
227 Example: You require a config to be true but PHP later removes this config and defaults it to true internally.
228 * @param string $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived)
229 * @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived)
230 * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
231 */
232 public function addPhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null)
233 {
234 $this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, false));
235 }
236
237 /**
238 * Adds an optional recommendation in form of a php.ini configuration.
239 *
240 * @param string $cfgName The configuration name used for ini_get()
241 * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false,
242 or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement
243 * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false.
244 This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin.
245 Example: You require a config to be true but PHP later removes this config and defaults it to true internally.
246 * @param string $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived)
247 * @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived)
248 * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
249 */
250 public function addPhpIniRecommendation($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null)
251 {
252 $this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, true));
253 }
254
255 /**
256 * Adds a requirement collection to the current set of requirements.
257 *
258 * @param RequirementCollection $collection A RequirementCollection instance
259 */
260 public function addCollection(RequirementCollection $collection)
261 {
262 $this->requirements = array_merge($this->requirements, $collection->all());
263 }
264
265 /**
266 * Returns both requirements and recommendations.
267 *
268 * @return array Array of Requirement instances
269 */
270 public function all()
271 {
272 return $this->requirements;
273 }
274
275 /**
276 * Returns all mandatory requirements.
277 *
278 * @return array Array of Requirement instances
279 */
280 public function getRequirements()
281 {
282 $array = array();
283 foreach ($this->requirements as $req) {
284 if (!$req->isOptional()) {
285 $array[] = $req;
286 }
287 }
288
289 return $array;
290 }
291
292 /**
293 * Returns the mandatory requirements that were not met.
294 *
295 * @return array Array of Requirement instances
296 */
297 public function getFailedRequirements()
298 {
299 $array = array();
300 foreach ($this->requirements as $req) {
301 if (!$req->isFulfilled() && !$req->isOptional()) {
302 $array[] = $req;
303 }
304 }
305
306 return $array;
307 }
308
309 /**
310 * Returns all optional recommendations.
311 *
312 * @return array Array of Requirement instances
313 */
314 public function getRecommendations()
315 {
316 $array = array();
317 foreach ($this->requirements as $req) {
318 if ($req->isOptional()) {
319 $array[] = $req;
320 }
321 }
322
323 return $array;
324 }
325
326 /**
327 * Returns the recommendations that were not met.
328 *
329 * @return array Array of Requirement instances
330 */
331 public function getFailedRecommendations()
332 {
333 $array = array();
334 foreach ($this->requirements as $req) {
335 if (!$req->isFulfilled() && $req->isOptional()) {
336 $array[] = $req;
337 }
338 }
339
340 return $array;
341 }
342
343 /**
344 * Returns whether a php.ini configuration is not correct.
345 *
346 * @return bool php.ini configuration problem?
347 */
348 public function hasPhpIniConfigIssue()
349 {
350 foreach ($this->requirements as $req) {
351 if (!$req->isFulfilled() && $req instanceof PhpIniRequirement) {
352 return true;
353 }
354 }
355
356 return false;
357 }
358
359 /**
360 * Returns the PHP configuration file (php.ini) path.
361 *
362 * @return string|false php.ini file path
363 */
364 public function getPhpIniConfigPath()
365 {
366 return get_cfg_var('cfg_file_path');
367 }
368}
369
370/**
371 * This class specifies all requirements and optional recommendations that
372 * are necessary to run the Symfony Standard Edition.
373 *
374 * @author Tobias Schultze <http://tobion.de>
375 * @author Fabien Potencier <fabien@symfony.com>
376 */
377class SymfonyRequirements extends RequirementCollection
378{
379 const REQUIRED_PHP_VERSION = '5.3.3';
380
381 /**
382 * Constructor that initializes the requirements.
383 */
384 public function __construct()
385 {
386 /* mandatory requirements follow */
387
388 $installedPhpVersion = phpversion();
389
390 $this->addRequirement(
391 version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>='),
392 sprintf('PHP version must be at least %s (%s installed)', self::REQUIRED_PHP_VERSION, $installedPhpVersion),
393 sprintf('You are running PHP version "<strong>%s</strong>", but Symfony needs at least PHP "<strong>%s</strong>" to run.
394 Before using Symfony, upgrade your PHP installation, preferably to the latest version.',
395 $installedPhpVersion, self::REQUIRED_PHP_VERSION),
396 sprintf('Install PHP %s or newer (installed version is %s)', self::REQUIRED_PHP_VERSION, $installedPhpVersion)
397 );
398
399 $this->addRequirement(
400 version_compare($installedPhpVersion, '5.3.16', '!='),
401 'PHP version must not be 5.3.16 as Symfony won\'t work properly with it',
402 'Install PHP 5.3.17 or newer (or downgrade to an earlier PHP version)'
403 );
404
405 $this->addRequirement(
406 is_dir(__DIR__.'/../vendor/composer'),
407 'Vendor libraries must be installed',
408 'Vendor libraries are missing. Install composer following instructions from <a href="http://getcomposer.org/">http://getcomposer.org/</a>. '.
409 'Then run "<strong>php composer.phar install</strong>" to install them.'
410 );
411
412 $cacheDir = is_dir(__DIR__.'/../var/cache') ? __DIR__.'/../var/cache' : __DIR__.'/cache';
413
414 $this->addRequirement(
415 is_writable($cacheDir),
416 'app/cache/ or var/cache/ directory must be writable',
417 'Change the permissions of either "<strong>app/cache/</strong>" or "<strong>var/cache/</strong>" directory so that the web server can write into it.'
418 );
419
420 $logsDir = is_dir(__DIR__.'/../var/logs') ? __DIR__.'/../var/logs' : __DIR__.'/logs';
421
422 $this->addRequirement(
423 is_writable($logsDir),
424 'app/logs/ or var/logs/ directory must be writable',
425 'Change the permissions of either "<strong>app/logs/</strong>" or "<strong>var/logs/</strong>" directory so that the web server can write into it.'
426 );
427
428 $this->addPhpIniRequirement(
429 'date.timezone', true, false,
430 'date.timezone setting must be set',
431 'Set the "<strong>date.timezone</strong>" setting in php.ini<a href="#phpini">*</a> (like Europe/Paris).'
432 );
433
434 if (version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>=')) {
435 $timezones = array();
436 foreach (DateTimeZone::listAbbreviations() as $abbreviations) {
437 foreach ($abbreviations as $abbreviation) {
438 $timezones[$abbreviation['timezone_id']] = true;
439 }
440 }
441
442 $this->addRequirement(
443 isset($timezones[@date_default_timezone_get()]),
444 sprintf('Configured default timezone "%s" must be supported by your installation of PHP', @date_default_timezone_get()),
445 'Your default timezone is not supported by PHP. Check for typos in your <strong>php.ini</strong> file and have a look at the list of deprecated timezones at <a href="http://php.net/manual/en/timezones.others.php">http://php.net/manual/en/timezones.others.php</a>.'
446 );
447 }
448
449 $this->addRequirement(
450 function_exists('json_encode'),
451 'json_encode() must be available',
452 'Install and enable the <strong>JSON</strong> extension.'
453 );
454
455 $this->addRequirement(
456 function_exists('session_start'),
457 'session_start() must be available',
458 'Install and enable the <strong>session</strong> extension.'
459 );
460
461 $this->addRequirement(
462 function_exists('ctype_alpha'),
463 'ctype_alpha() must be available',
464 'Install and enable the <strong>ctype</strong> extension.'
465 );
466
467 $this->addRequirement(
468 function_exists('token_get_all'),
469 'token_get_all() must be available',
470 'Install and enable the <strong>Tokenizer</strong> extension.'
471 );
472
473 $this->addRequirement(
474 function_exists('simplexml_import_dom'),
475 'simplexml_import_dom() must be available',
476 'Install and enable the <strong>SimpleXML</strong> extension.'
477 );
478
479 if (function_exists('apc_store') && ini_get('apc.enabled')) {
480 if (version_compare($installedPhpVersion, '5.4.0', '>=')) {
481 $this->addRequirement(
482 version_compare(phpversion('apc'), '3.1.13', '>='),
483 'APC version must be at least 3.1.13 when using PHP 5.4',
484 'Upgrade your <strong>APC</strong> extension (3.1.13+).'
485 );
486 } else {
487 $this->addRequirement(
488 version_compare(phpversion('apc'), '3.0.17', '>='),
489 'APC version must be at least 3.0.17',
490 'Upgrade your <strong>APC</strong> extension (3.0.17+).'
491 );
492 }
493 }
494
495 $this->addPhpIniRequirement('detect_unicode', false);
496
497 if (extension_loaded('suhosin')) {
498 $this->addPhpIniRequirement(
499 'suhosin.executor.include.whitelist',
500 create_function('$cfgValue', 'return false !== stripos($cfgValue, "phar");'),
501 false,
502 'suhosin.executor.include.whitelist must be configured correctly in php.ini',
503 'Add "<strong>phar</strong>" to <strong>suhosin.executor.include.whitelist</strong> in php.ini<a href="#phpini">*</a>.'
504 );
505 }
506
507 if (extension_loaded('xdebug')) {
508 $this->addPhpIniRequirement(
509 'xdebug.show_exception_trace', false, true
510 );
511
512 $this->addPhpIniRequirement(
513 'xdebug.scream', false, true
514 );
515
516 $this->addPhpIniRecommendation(
517 'xdebug.max_nesting_level',
518 create_function('$cfgValue', 'return $cfgValue > 100;'),
519 true,
520 'xdebug.max_nesting_level should be above 100 in php.ini',
521 'Set "<strong>xdebug.max_nesting_level</strong>" to e.g. "<strong>250</strong>" in php.ini<a href="#phpini">*</a> to stop Xdebug\'s infinite recursion protection erroneously throwing a fatal error in your project.'
522 );
523 }
524
525 $pcreVersion = defined('PCRE_VERSION') ? (float) PCRE_VERSION : null;
526
527 $this->addRequirement(
528 null !== $pcreVersion,
529 'PCRE extension must be available',
530 'Install the <strong>PCRE</strong> extension (version 8.0+).'
531 );
532
533 if (extension_loaded('mbstring')) {
534 $this->addPhpIniRequirement(
535 'mbstring.func_overload',
536 create_function('$cfgValue', 'return (int) $cfgValue === 0;'),
537 true,
538 'string functions should not be overloaded',
539 'Set "<strong>mbstring.func_overload</strong>" to <strong>0</strong> in php.ini<a href="#phpini">*</a> to disable function overloading by the mbstring extension.'
540 );
541 }
542
543 /* optional recommendations follow */
544
545 $this->addRecommendation(
546 file_get_contents(__FILE__) === file_get_contents(__DIR__.'/../vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/skeleton/app/SymfonyRequirements.php'),
547 'Requirements file should be up-to-date',
548 'Your requirements file is outdated. Run composer install and re-check your configuration.'
549 );
550
551 $this->addRecommendation(
552 version_compare($installedPhpVersion, '5.3.4', '>='),
553 'You should use at least PHP 5.3.4 due to PHP bug #52083 in earlier versions',
554 'Your project might malfunction randomly due to PHP bug #52083 ("Notice: Trying to get property of non-object"). Install PHP 5.3.4 or newer.'
555 );
556
557 $this->addRecommendation(
558 version_compare($installedPhpVersion, '5.3.8', '>='),
559 'When using annotations you should have at least PHP 5.3.8 due to PHP bug #55156',
560 'Install PHP 5.3.8 or newer if your project uses annotations.'
561 );
562
563 $this->addRecommendation(
564 version_compare($installedPhpVersion, '5.4.0', '!='),
565 'You should not use PHP 5.4.0 due to the PHP bug #61453',
566 'Your project might not work properly due to the PHP bug #61453 ("Cannot dump definitions which have method calls"). Install PHP 5.4.1 or newer.'
567 );
568
569 $this->addRecommendation(
570 version_compare($installedPhpVersion, '5.4.11', '>='),
571 'When using the logout handler from the Symfony Security Component, you should have at least PHP 5.4.11 due to PHP bug #63379 (as a workaround, you can also set invalidate_session to false in the security logout handler configuration)',
572 'Install PHP 5.4.11 or newer if your project uses the logout handler from the Symfony Security Component.'
573 );
574
575 $this->addRecommendation(
576 (version_compare($installedPhpVersion, '5.3.18', '>=') && version_compare($installedPhpVersion, '5.4.0', '<'))
577 ||
578 version_compare($installedPhpVersion, '5.4.8', '>='),
579 'You should use PHP 5.3.18+ or PHP 5.4.8+ to always get nice error messages for fatal errors in the development environment due to PHP bug #61767/#60909',
580 'Install PHP 5.3.18+ or PHP 5.4.8+ if you want nice error messages for all fatal errors in the development environment.'
581 );
582
583 if (null !== $pcreVersion) {
584 $this->addRecommendation(
585 $pcreVersion >= 8.0,
586 sprintf('PCRE extension should be at least version 8.0 (%s installed)', $pcreVersion),
587 '<strong>PCRE 8.0+</strong> is preconfigured in PHP since 5.3.2 but you are using an outdated version of it. Symfony probably works anyway but it is recommended to upgrade your PCRE extension.'
588 );
589 }
590
591 $this->addRecommendation(
592 class_exists('DomDocument'),
593 'PHP-DOM and PHP-XML modules should be installed',
594 'Install and enable the <strong>PHP-DOM</strong> and the <strong>PHP-XML</strong> modules.'
595 );
596
597 $this->addRecommendation(
598 function_exists('mb_strlen'),
599 'mb_strlen() should be available',
600 'Install and enable the <strong>mbstring</strong> extension.'
601 );
602
603 $this->addRecommendation(
604 function_exists('iconv'),
605 'iconv() should be available',
606 'Install and enable the <strong>iconv</strong> extension.'
607 );
608
609 $this->addRecommendation(
610 function_exists('utf8_decode'),
611 'utf8_decode() should be available',
612 'Install and enable the <strong>XML</strong> extension.'
613 );
614
615 $this->addRecommendation(
616 function_exists('filter_var'),
617 'filter_var() should be available',
618 'Install and enable the <strong>filter</strong> extension.'
619 );
620
621 if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
622 $this->addRecommendation(
623 function_exists('posix_isatty'),
624 'posix_isatty() should be available',
625 'Install and enable the <strong>php_posix</strong> extension (used to colorize the CLI output).'
626 );
627 }
628
629 $this->addRecommendation(
630 class_exists('Locale'),
631 'intl extension should be available',
632 'Install and enable the <strong>intl</strong> extension (used for validators).'
633 );
634
635 if (class_exists('Collator')) {
636 $this->addRecommendation(
637 null !== new Collator('fr_FR'),
638 'intl extension should be correctly configured',
639 'The intl extension does not behave properly. This problem is typical on PHP 5.3.X x64 WIN builds.'
640 );
641 }
642
643 if (class_exists('Locale')) {
644 if (defined('INTL_ICU_VERSION')) {
645 $version = INTL_ICU_VERSION;
646 } else {
647 $reflector = new ReflectionExtension('intl');
648
649 ob_start();
650 $reflector->info();
651 $output = strip_tags(ob_get_clean());
652
653 preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches);
654 $version = $matches[1];
655 }
656
657 $this->addRecommendation(
658 version_compare($version, '4.0', '>='),
659 'intl ICU version should be at least 4+',
660 'Upgrade your <strong>intl</strong> extension with a newer ICU version (4+).'
661 );
662 }
663
664 $accelerator =
665 (extension_loaded('eaccelerator') && ini_get('eaccelerator.enable'))
666 ||
667 (extension_loaded('apc') && ini_get('apc.enabled'))
668 ||
669 (extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.enable'))
670 ||
671 (extension_loaded('Zend OPcache') && ini_get('opcache.enable'))
672 ||
673 (extension_loaded('xcache') && ini_get('xcache.cacher'))
674 ||
675 (extension_loaded('wincache') && ini_get('wincache.ocenabled'))
676 ;
677
678 $this->addRecommendation(
679 $accelerator,
680 'a PHP accelerator should be installed',
681 'Install and/or enable a <strong>PHP accelerator</strong> (highly recommended).'
682 );
683
684 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
685 $this->addRecommendation(
686 $this->getRealpathCacheSize() > 1000,
687 'realpath_cache_size should be above 1024 in php.ini',
688 'Set "<strong>realpath_cache_size</strong>" to e.g. "<strong>1024</strong>" in php.ini<a href="#phpini">*</a> to improve performance on windows.'
689 );
690 }
691
692 $this->addPhpIniRecommendation('short_open_tag', false);
693
694 $this->addPhpIniRecommendation('magic_quotes_gpc', false, true);
695
696 $this->addPhpIniRecommendation('register_globals', false, true);
697
698 $this->addPhpIniRecommendation('session.auto_start', false);
699
700 $this->addRecommendation(
701 class_exists('PDO'),
702 'PDO should be installed',
703 'Install <strong>PDO</strong> (mandatory for Doctrine).'
704 );
705
706 if (class_exists('PDO')) {
707 $drivers = PDO::getAvailableDrivers();
708 $this->addRecommendation(
709 count($drivers) > 0,
710 sprintf('PDO should have some drivers installed (currently available: %s)', count($drivers) ? implode(', ', $drivers) : 'none'),
711 'Install <strong>PDO drivers</strong> (mandatory for Doctrine).'
712 );
713 }
714 }
715
716 /**
717 * Loads realpath_cache_size from php.ini and converts it to int.
718 *
719 * (e.g. 16k is converted to 16384 int)
720 *
721 * @return int
722 */
723 protected function getRealpathCacheSize()
724 {
725 $size = ini_get('realpath_cache_size');
726 $size = trim($size);
727 $unit = strtolower(substr($size, -1, 1));
728 switch ($unit) {
729 case 'g':
730 return $size * 1024 * 1024 * 1024;
731 case 'm':
732 return $size * 1024 * 1024;
733 case 'k':
734 return $size * 1024;
735 default:
736 return (int) $size;
737 }
738 }
739}
diff --git a/app/check.php b/app/check.php
new file mode 100644
index 00000000..90bad4a7
--- /dev/null
+++ b/app/check.php
@@ -0,0 +1,142 @@
1<?php
2
3require_once dirname(__FILE__).'/SymfonyRequirements.php';
4
5$lineSize = 70;
6$symfonyRequirements = new SymfonyRequirements();
7$iniPath = $symfonyRequirements->getPhpIniConfigPath();
8
9echo_title('Symfony2 Requirements Checker');
10
11echo '> PHP is using the following php.ini file:'.PHP_EOL;
12if ($iniPath) {
13 echo_style('green', ' '.$iniPath);
14} else {
15 echo_style('warning', ' WARNING: No configuration file (php.ini) used by PHP!');
16}
17
18echo PHP_EOL.PHP_EOL;
19
20echo '> Checking Symfony requirements:'.PHP_EOL.' ';
21
22$messages = array();
23foreach ($symfonyRequirements->getRequirements() as $req) {
24 /** @var $req Requirement */
25 if ($helpText = get_error_message($req, $lineSize)) {
26 echo_style('red', 'E');
27 $messages['error'][] = $helpText;
28 } else {
29 echo_style('green', '.');
30 }
31}
32
33$checkPassed = empty($messages['error']);
34
35foreach ($symfonyRequirements->getRecommendations() as $req) {
36 if ($helpText = get_error_message($req, $lineSize)) {
37 echo_style('yellow', 'W');
38 $messages['warning'][] = $helpText;
39 } else {
40 echo_style('green', '.');
41 }
42}
43
44if ($checkPassed) {
45 echo_block('success', 'OK', 'Your system is ready to run Symfony2 projects', true);
46} else {
47 echo_block('error', 'ERROR', 'Your system is not ready to run Symfony2 projects', true);
48
49 echo_title('Fix the following mandatory requirements', 'red');
50
51 foreach ($messages['error'] as $helpText) {
52 echo ' * '.$helpText.PHP_EOL;
53 }
54}
55
56if (!empty($messages['warning'])) {
57 echo_title('Optional recommendations to improve your setup', 'yellow');
58
59 foreach ($messages['warning'] as $helpText) {
60 echo ' * '.$helpText.PHP_EOL;
61 }
62}
63
64echo PHP_EOL;
65echo_style('title', 'Note');
66echo ' The command console could use a different php.ini file'.PHP_EOL;
67echo_style('title', '~~~~');
68echo ' than the one used with your web server. To be on the'.PHP_EOL;
69echo ' safe side, please check the requirements from your web'.PHP_EOL;
70echo ' server using the ';
71echo_style('yellow', 'web/config.php');
72echo ' script.'.PHP_EOL;
73echo PHP_EOL;
74
75exit($checkPassed ? 0 : 1);
76
77function get_error_message(Requirement $requirement, $lineSize)
78{
79 if ($requirement->isFulfilled()) {
80 return;
81 }
82
83 $errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.' ').PHP_EOL;
84 $errorMessage .= ' > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.' > ').PHP_EOL;
85
86 return $errorMessage;
87}
88
89function echo_title($title, $style = null)
90{
91 $style = $style ?: 'title';
92
93 echo PHP_EOL;
94 echo_style($style, $title.PHP_EOL);
95 echo_style($style, str_repeat('~', strlen($title)).PHP_EOL);
96 echo PHP_EOL;
97}
98
99function echo_style($style, $message)
100{
101 // ANSI color codes
102 $styles = array(
103 'reset' => "\033[0m",
104 'red' => "\033[31m",
105 'green' => "\033[32m",
106 'yellow' => "\033[33m",
107 'error' => "\033[37;41m",
108 'success' => "\033[37;42m",
109 'title' => "\033[34m",
110 );
111 $supports = has_color_support();
112
113 echo($supports ? $styles[$style] : '').$message.($supports ? $styles['reset'] : '');
114}
115
116function echo_block($style, $title, $message)
117{
118 $message = ' '.trim($message).' ';
119 $width = strlen($message);
120
121 echo PHP_EOL.PHP_EOL;
122
123 echo_style($style, str_repeat(' ', $width).PHP_EOL);
124 echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT).PHP_EOL);
125 echo_style($style, str_pad($message, $width, ' ', STR_PAD_RIGHT).PHP_EOL);
126 echo_style($style, str_repeat(' ', $width).PHP_EOL);
127}
128
129function has_color_support()
130{
131 static $support;
132
133 if (null === $support) {
134 if (DIRECTORY_SEPARATOR == '\\') {
135 $support = false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI');
136 } else {
137 $support = function_exists('posix_isatty') && @posix_isatty(STDOUT);
138 }
139 }
140
141 return $support;
142}
diff --git a/app/config/config.yml b/app/config/config.yml
index d7c465db..f2f5f9f3 100644
--- a/app/config/config.yml
+++ b/app/config/config.yml
@@ -84,3 +84,23 @@ swiftmailer:
84 username: "%mailer_user%" 84 username: "%mailer_user%"
85 password: "%mailer_password%" 85 password: "%mailer_password%"
86 spool: { type: memory } 86 spool: { type: memory }
87
88fos_rest:
89 param_fetcher_listener: true
90 body_listener: true
91 format_listener: true
92 view:
93 view_response_listener: 'force'
94 formats:
95 xml: true
96 json : true
97 templating_formats:
98 html: true
99 force_redirects:
100 html: true
101 failed_validation: HTTP_BAD_REQUEST
102 default_engine: twig
103 routing_loader:
104 default_format: json
105
106nelmio_api_doc: ~ \ No newline at end of file
diff --git a/app/config/routing.yml b/app/config/routing.yml
index 95c224ab..a57311dc 100644
--- a/app/config/routing.yml
+++ b/app/config/routing.yml
@@ -4,4 +4,13 @@ app:
4 4
5homepage: 5homepage:
6 pattern: / 6 pattern: /
7 defaults: { _controller: WallabagCoreBundle:Entry:showUnread } \ No newline at end of file 7 defaults: { _controller: WallabagCoreBundle:Entry:showUnread }
8
9doc-api:
10 resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
11 prefix: /api/doc
12
13rest :
14 type : rest
15 resource : "routing_rest.yml"
16 prefix : /api \ No newline at end of file
diff --git a/app/config/routing_rest.yml b/app/config/routing_rest.yml
new file mode 100644
index 00000000..ecddbd36
--- /dev/null
+++ b/app/config/routing_rest.yml
@@ -0,0 +1,4 @@
1app_api :
2 type: rest
3 resource: "WallabagCoreBundle:Api"
4 name_prefix: api_ \ No newline at end of file
diff --git a/src/.htaccess b/src/.htaccess
new file mode 100644
index 00000000..fb1de45b
--- /dev/null
+++ b/src/.htaccess
@@ -0,0 +1,7 @@
1<IfModule mod_authz_core.c>
2 Require all denied
3</IfModule>
4<IfModule !mod_authz_core.c>
5 Order deny,allow
6 Deny from all
7</IfModule>
diff --git a/src/Wallabag/CoreBundle/Controller/ApiController.php b/src/Wallabag/CoreBundle/Controller/ApiController.php
new file mode 100644
index 00000000..ac06701c
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Controller/ApiController.php
@@ -0,0 +1,21 @@
1<?php
2
3namespace Wallabag\CoreBundle\Controller;
4
5use Nelmio\ApiDocBundle\Annotation\ApiDoc;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Wallabag\CoreBundle\Entity\Entries;
8
9class ApiController extends Controller
10{
11 /**
12 * @ApiDoc(
13 * resource=true,
14 * description="This is a demo method. Just remove it",
15 * )
16 */
17 public function getEntryAction()
18 {
19 return new Entries('Blobby');
20 }
21}
diff --git a/src/Wallabag/CoreBundle/Controller/StaticController.php b/src/Wallabag/CoreBundle/Controller/StaticController.php
index 0fd19d65..07931f58 100644
--- a/src/Wallabag/CoreBundle/Controller/StaticController.php
+++ b/src/Wallabag/CoreBundle/Controller/StaticController.php
@@ -17,4 +17,12 @@ class StaticController extends Controller
17 array() 17 array()
18 ); 18 );
19 } 19 }
20
21 /**
22 * @Route("/", name="homepage")
23 */
24 public function apiAction()
25 {
26 return $this->redirect($this->generateUrl('nelmio_api_doc_index'));
27 }
20} 28}
diff --git a/web/.htaccess b/web/.htaccess
new file mode 100644
index 00000000..b52e3ae6
--- /dev/null
+++ b/web/.htaccess
@@ -0,0 +1,56 @@
1# Use the front controller as index file. It serves as a fallback solution when
2# every other rewrite/redirect fails (e.g. in an aliased environment without
3# mod_rewrite). Additionally, this reduces the matching process for the
4# start page (path "/") because otherwise Apache will apply the rewriting rules
5# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
6DirectoryIndex app.php
7
8<IfModule mod_rewrite.c>
9 RewriteEngine On
10
11 # Determine the RewriteBase automatically and set it as environment variable.
12 # If you are using Apache aliases to do mass virtual hosting or installed the
13 # project in a subdirectory, the base path will be prepended to allow proper
14 # resolution of the app.php file and to redirect to the correct URI. It will
15 # work in environments without path prefix as well, providing a safe, one-size
16 # fits all solution. But as you do not need it in this case, you can comment
17 # the following 2 lines to eliminate the overhead.
18 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
19 RewriteRule ^(.*) - [E=BASE:%1]
20
21 # Sets the HTTP_AUTHORIZATION header removed by apache
22 RewriteCond %{HTTP:Authorization} .
23 RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
24
25 # Redirect to URI without front controller to prevent duplicate content
26 # (with and without `/app.php`). Only do this redirect on the initial
27 # rewrite by Apache and not on subsequent cycles. Otherwise we would get an
28 # endless redirect loop (request -> rewrite to front controller ->
29 # redirect -> request -> ...).
30 # So in case you get a "too many redirects" error or you always get redirected
31 # to the start page because your Apache does not expose the REDIRECT_STATUS
32 # environment variable, you have 2 choices:
33 # - disable this feature by commenting the following 2 lines or
34 # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
35 # following RewriteCond (best solution)
36 RewriteCond %{ENV:REDIRECT_STATUS} ^$
37 RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
38
39 # If the requested filename exists, simply serve it.
40 # We only want to let Apache serve files and not directories.
41 RewriteCond %{REQUEST_FILENAME} -f
42 RewriteRule .? - [L]
43
44 # Rewrite all other queries to the front controller.
45 RewriteRule .? %{ENV:BASE}/app.php [L]
46</IfModule>
47
48<IfModule !mod_rewrite.c>
49 <IfModule mod_alias.c>
50 # When mod_rewrite is not available, we instruct a temporary redirect of
51 # the start page to the front controller explicitly so that the website
52 # and the generated links can still be used.
53 RedirectMatch 302 ^/$ /app.php/
54 # RedirectTemp cannot be used instead
55 </IfModule>
56</IfModule>