Failed Conditions
Push — interwiki-remove-golucky ( 52fcdb...768be5 )
by Henry
12:48 queued 09:48
created

jquery.php ➔ jquery_out()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
1
<?php
2
3
use dokuwiki\Cache\Cache;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Cache.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
5
if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__) . '/../../');
6
if(!defined('NOSESSION')) define('NOSESSION', true); // we do not use a session or authentication here (better caching)
7
if(!defined('NL')) define('NL', "\n");
8
if(!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); // we gzip ourself here
9
require_once(DOKU_INC . 'inc/init.php');
10
11
// MAIN
12
header('Content-Type: application/javascript; charset=utf-8');
13
jquery_out();
14
15
/**
16
 * Delivers the jQuery JavaScript
17
 *
18
 * We do absolutely nothing fancy here but concatenating the different files
19
 * and handling conditional and gzipped requests
20
 *
21
 * uses cache or fills it
22
 */
23
function jquery_out() {
24
    $cache = new Cache('jquery', '.js');
25
    $files = array(
26
        DOKU_INC . 'lib/scripts/jquery/jquery.min.js',
27
        DOKU_INC . 'lib/scripts/jquery/jquery-ui.min.js',
28
        DOKU_INC . 'lib/scripts/jquery/jquery-migrate.min.js',
29
    );
30
    $cache_files = $files;
31
    $cache_files[] = __FILE__;
32
33
    // check cache age & handle conditional request
34
    // This may exit if a cache can be used
35
    $cache_ok = $cache->useCache(array('files' => $cache_files));
36
    http_cached($cache->cache, $cache_ok);
37
38
    $js = '';
39
    foreach($files as $file) {
40
        $js .= file_get_contents($file)."\n";
41
    }
42
    stripsourcemaps($js);
43
44
    http_cached_finish($cache->cache, $js);
45
}
46