These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | /** |
||
4 | * Initialization file for query printer functionality in the Semantic Maps extension |
||
5 | * |
||
6 | * @file SM_QueryPrinters.php |
||
7 | * @ingroup SemanticMaps |
||
8 | * |
||
9 | * @licence GNU GPL v2+ |
||
10 | * @author Jeroen De Dauw < [email protected] > |
||
11 | */ |
||
12 | |||
13 | if ( !defined( 'MEDIAWIKI' ) ) { |
||
14 | die( 'Not an entry point.' ); |
||
15 | } |
||
16 | |||
17 | $GLOBALS['wgHooks']['MappingFeatureLoad'][] = 'SMQueryPrinters::initialize'; |
||
18 | |||
19 | final class SMQueryPrinters { |
||
20 | |||
21 | /** |
||
22 | * Initialization function for Maps query printer functionality. |
||
23 | */ |
||
24 | public static function initialize() { |
||
25 | global $wgAutoloadClasses, $egMapsDefaultServices; |
||
26 | |||
27 | $wgAutoloadClasses['SMQueryHandler'] = __DIR__ . '/SM_QueryHandler.php'; |
||
28 | $wgAutoloadClasses['SMMapPrinter'] = __DIR__ . '/SM_MapPrinter.php'; |
||
29 | $wgAutoloadClasses['SMKMLPrinter'] = __DIR__ . '/SM_KMLPrinter.php'; |
||
30 | |||
31 | self::initFormat( 'kml', 'SMKMLPrinter' ); |
||
32 | |||
33 | foreach ( MapsMappingServices::getServiceIdentifiers() as $serviceIdentifier ) { |
||
34 | $service = MapsMappingServices::getServiceInstance( $serviceIdentifier ); |
||
35 | |||
36 | // Check if the service has a query printer. |
||
37 | $QPClass = $service->getFeature( 'qp' ); |
||
38 | |||
39 | // If the service has no QP, skipt it and continue with the next one. |
||
40 | if ( $QPClass === false ) { |
||
41 | continue; |
||
42 | } |
||
43 | |||
44 | // Initiate the format. |
||
45 | $aliases = $service->getAliases(); |
||
46 | |||
47 | // Add the 'map' result format if there are mapping services that have QP's loaded. |
||
48 | if ( $egMapsDefaultServices['qp'] == $serviceIdentifier ) { |
||
49 | $aliases[] = 'map'; |
||
50 | } |
||
51 | |||
52 | self::initFormat( $service->getName(), 'SMMapPrinter', $aliases ); |
||
53 | } |
||
54 | |||
55 | return true; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Add the result format for a mapping service or alias. |
||
60 | * |
||
61 | * @param string $format |
||
62 | * @param string $formatClass |
||
63 | * @param array $aliases |
||
64 | */ |
||
65 | private static function initFormat( $format, $formatClass, array $aliases = array() ) { |
||
66 | global $smwgResultAliases, $smwgResultFormats; |
||
67 | |||
68 | // Add the QP to SMW. |
||
69 | $smwgResultFormats[$format] = $formatClass; |
||
70 | |||
71 | $smwgResultAliases[$format] = $aliases; |
||
72 | } |
||
73 | |||
74 | } |
||
75 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.