Test Failed
Push — master ( 0d729d...0caf32 )
by Sebastian
05:03
created

StyleSheet::vendorPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 8
rs 9.4285
1
<?php
2
/**
3
 * citeproc-php
4
 *
5
 * @link        http://github.com/seboettg/citeproc-php for the source repository
6
 * @copyright   Copyright (c) 2016 Sebastian Böttger.
7
 * @license     https://opensource.org/licenses/MIT
8
 */
9
10
namespace Seboettg\CiteProc;
11
12
use Seboettg\CiteProc\Exception\CiteProcException;
13
14
/**
15
 * Class StyleSheet
16
 *
17
 * Helper class for loading CSL styles and CSL locales
18
 *
19
 * @package Seboettg\CiteProc
20
 * @author Sebastian Böttger <[email protected]>
21
 */
22
class StyleSheet
23
{
24
25
    /**
26
     * Loads xml formatted CSL stylesheet of a given stylesheet name, e.g. "american-physiological-society" for
27
     * apa style.
28
     *
29
     * See in styles folder (which is included as git submodule) for all available style sheets
30
     *
31
     * @param string $styleName e.g. "american-physiological-society" for apa
32
     * @return string
33
     */
34
    public static function loadStyleSheet($styleName)
35
    {
36
        $stylesPath = self::vendorPath() . "/citation-style-language/styles/";
37
        return file_get_contents($stylesPath . $styleName . '.csl');
38
    }
39
40
    /**
41
     * Loads xml formatted locales of given language key
42
     *
43
     * @param string $langKey e.g. "en-US", or "de-CH"
44
     * @return string
45
     */
46
    public static function loadLocales($langKey)
47
    {
48
        $localesPath = self::vendorPath() . "/citation-style-language/locales/";
49
        return file_get_contents($localesPath . "locales-" . $langKey . '.xml');
50
    }
51
52
    /**
53
     * @return bool|string
54
     * @throws CiteProcException
55
     */
56
    private static function vendorPath()
57
    {
58
        include_once __DIR__ . '/../../../vendorPath.php';
59
        if (!($vendorPath = vendorPath())) {
60
            throw new CiteProcException('vendor path not found. Use composer to initialize your project');
61
        }
62
        return $vendorPath;
63
    }
64
}