Skip to content

Commit ea04341

Browse files
author
Sergey Karavay
committed
Add documentation, no phpdoc errors.
Updates: - refactored build script; - added script for building documentation; - installed phpdoc; - improved sources with comments.
1 parent c2a0957 commit ea04341

File tree

264 files changed

+53733
-915
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

264 files changed

+53733
-915
lines changed

build/build.php build/data.php

+3-121
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
* Information about data files markup can be found at LDML documentation (Locale Data Markup Language) - http://unicode.org/reports/tr35/
1414
*
1515
* @author Sergey <Gino Pane> Karavay
16-
*
1716
*/
1817

18+
require 'shared/functions.php';
19+
1920
if (version_compare(PHP_VERSION, '5.6.0') > 0) {
2021
ini_set('default_charset', 'UTF-8');
2122
} else {
@@ -94,43 +95,6 @@ function displayHelp()
9495
exit(0);
9596
}
9697

97-
/**
98-
* Enable/Disable supporting output of some functions
99-
*/
100-
$disableOutput = false;
101-
102-
/**
103-
* Set flag of disabled output
104-
*/
105-
function disableOutput()
106-
{
107-
global $disableOutput;
108-
109-
$disableOutput = true;
110-
}
111-
112-
/**
113-
* Set flag of enabled output
114-
*/
115-
function enableOutput()
116-
{
117-
global $disableOutput;
118-
119-
$disableOutput = false;
120-
}
121-
122-
/**
123-
* Check output flag
124-
*
125-
* @return bool
126-
*/
127-
function outputEnabled()
128-
{
129-
global $disableOutput;
130-
131-
return $disableOutput == false;
132-
}
133-
13498
/**
13599
* World's most popular languages
136100
*
@@ -537,22 +501,6 @@ function showStatus($done, $total, $text = '', $size = 30)
537501
}
538502
}
539503

540-
/**
541-
* Custom error handler
542-
*
543-
* @param $errorNumber
544-
* @param $errorString
545-
* @param $errorFile
546-
* @param $errorLine
547-
* @throws Exception
548-
*/
549-
function handleError($errorNumber, $errorString, $errorFile, $errorLine)
550-
{
551-
if ($errorNumber == E_NOTICE || $errorNumber == E_WARNING) {
552-
throw new Exception("$errorString in $errorFile @ line $errorLine \n", $errorNumber);
553-
}
554-
}
555-
556504
/**
557505
* Handle errors from CLDR checkout
558506
*
@@ -580,32 +528,6 @@ function handleCldrCheckoutError($directory, $code, $output)
580528
}
581529
}
582530

583-
/**
584-
* Check existence, create directory and handle any possible error
585-
*
586-
* @param string $directory
587-
* @return bool
588-
* @throws Exception
589-
*/
590-
function createDirectory($directory = "")
591-
{
592-
if (outputEnabled()) {
593-
echo "Creating \"$directory\" folder... ";
594-
}
595-
596-
if (!is_dir($directory)) {
597-
if (mkdir($directory, 0777, false) === false) {
598-
throw new Exception("Failed to create \"$directory\"\n");
599-
}
600-
}
601-
602-
if (outputEnabled()) {
603-
echo "Done.\n";
604-
}
605-
606-
return true;
607-
}
608-
609531
/**
610532
* Extract currency fractions and region data
611533
*
@@ -1417,7 +1339,7 @@ function handleSingleLocaleData($locale, $localeFile)
14171339
}
14181340

14191341
/**
1420-
* Check file name existance and readability
1342+
* Check file name existence and readability
14211343
*
14221344
* @param $fileName
14231345
* @throws Exception
@@ -1697,32 +1619,6 @@ function saveJsonFile($data, $file, $jsonFlags = 0)
16971619
}
16981620
}
16991621

1700-
/**
1701-
* Delete object specified by its path from the filesystem
1702-
*
1703-
* @param $path
1704-
* @throws Exception
1705-
*/
1706-
function deleteFromFilesystem($path)
1707-
{
1708-
if (is_file($path)) {
1709-
if (unlink($path) === false) {
1710-
throw new Exception("Failed to delete file $path");
1711-
}
1712-
} else {
1713-
$contents = scandir($path);
1714-
if ($contents === false) {
1715-
throw new Exception("Failed to retrieve the file list of $path");
1716-
}
1717-
foreach (array_diff($contents, ['.', '..']) as $item) {
1718-
deleteFromFilesystem($path . DIRECTORY_SEPARATOR . $item);
1719-
}
1720-
if (rmdir($path) === false) {
1721-
throw new Exception("Failed to delete directory $path");
1722-
}
1723-
}
1724-
}
1725-
17261622
/**
17271623
* Clean-up sources directory after build
17281624
*/
@@ -1735,20 +1631,6 @@ function cleanUpSourceDirectory()
17351631
}
17361632
}
17371633

1738-
/**
1739-
* Clean-up destination directory before build
1740-
*/
1741-
function cleanUpDestinationDirectory()
1742-
{
1743-
if (is_dir(DESTINATION_GENERAL_DIR)) {
1744-
echo "Cleanup old general data folder... ";
1745-
deleteFromFilesystem(DESTINATION_DIR);
1746-
echo "Done.\n";
1747-
}
1748-
}
1749-
1750-
set_error_handler('handleError');
1751-
17521634
/**
17531635
* @var array Build result report
17541636
*/

build/docs.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/**
4+
* Script for updating of OpenWorld's documentation.
5+
*
6+
* There's no need to split the script into many files, that's why everything what it needs is placed in the same file.
7+
*
8+
* Initially Based on Punic's update-docs script (https://github.com/punic/punic)
9+
*
10+
* @author Sergey <Gino Pane> Karavay
11+
*/
12+
13+
require 'shared/functions.php';
14+
15+
define('ROOT_DIR', dirname(__DIR__));
16+
define('SOURCE_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'src');
17+
define('DESTINATION_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'docs');
18+
define('PHPDOC_PATH', ROOT_DIR . DIRECTORY_SEPARATOR .
19+
'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'phpdoc');
20+
21+
try {
22+
echo "Initializing... \n";
23+
24+
cleanUpDestinationDirectory();
25+
createDirectory(DESTINATION_DIR);
26+
27+
echo "Creating doc files... \n";
28+
29+
$output = array();
30+
exec(
31+
escapeshellarg(PHPDOC_PATH) .
32+
" -d " . escapeshellarg(SOURCE_DIR) .
33+
" -t " . escapeshellarg(DESTINATION_DIR) .
34+
" --template=\"responsive-twig\"" .
35+
" --title=\"Php Open World\"",
36+
$output,
37+
$rc
38+
);
39+
40+
if ($rc !== 0) {
41+
throw new Exception("PhpDocumentor failed:\n" . trim(implode("\n", $output)));
42+
}
43+
44+
echo "Done.\n";
45+
46+
exit(0);
47+
} catch (Exception $x) {
48+
echo $x->getMessage(), "\n";
49+
50+
exit(1);
51+
}

build/shared/functions.php

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
/**
3+
* Functions shared between build scripts
4+
*/
5+
6+
/**
7+
* Enable/Disable supporting output of some functions
8+
*/
9+
$disableOutput = false;
10+
11+
/**
12+
* Set flag of disabled output
13+
*/
14+
function disableOutput()
15+
{
16+
global $disableOutput;
17+
18+
$disableOutput = true;
19+
}
20+
21+
/**
22+
* Set flag of enabled output
23+
*/
24+
function enableOutput()
25+
{
26+
global $disableOutput;
27+
28+
$disableOutput = false;
29+
}
30+
31+
/**
32+
* Check output flag
33+
*
34+
* @return bool
35+
*/
36+
function outputEnabled()
37+
{
38+
global $disableOutput;
39+
40+
return $disableOutput == false;
41+
}
42+
43+
/**
44+
* Custom error handler
45+
*
46+
* @param $errorNumber
47+
* @param $errorString
48+
* @param $errorFile
49+
* @param $errorLine
50+
* @throws Exception
51+
*/
52+
function handleError($errorNumber, $errorString, $errorFile, $errorLine)
53+
{
54+
if ($errorNumber == E_NOTICE || $errorNumber == E_WARNING) {
55+
throw new Exception("$errorString in $errorFile @ line $errorLine \n", $errorNumber);
56+
}
57+
}
58+
59+
/**
60+
* Check existence, create directory and handle any possible error
61+
*
62+
* @param string $directory
63+
* @return bool
64+
* @throws Exception
65+
*/
66+
function createDirectory($directory = "")
67+
{
68+
if (outputEnabled()) {
69+
echo "Creating \"$directory\" folder... ";
70+
}
71+
72+
if (!is_dir($directory)) {
73+
if (mkdir($directory, 0777, false) === false) {
74+
throw new Exception("Failed to create \"$directory\"\n");
75+
}
76+
}
77+
78+
if (outputEnabled()) {
79+
echo "Done.\n";
80+
}
81+
82+
return true;
83+
}
84+
85+
/**
86+
* Delete object specified by its path from the filesystem
87+
*
88+
* @param $path
89+
* @throws Exception
90+
*/
91+
function deleteFromFilesystem($path)
92+
{
93+
if (is_file($path)) {
94+
if (unlink($path) === false) {
95+
throw new Exception("Failed to delete file $path");
96+
}
97+
} else {
98+
$contents = scandir($path);
99+
if ($contents === false) {
100+
throw new Exception("Failed to retrieve the file list of $path");
101+
}
102+
foreach (array_diff($contents, ['.', '..']) as $item) {
103+
deleteFromFilesystem($path . DIRECTORY_SEPARATOR . $item);
104+
}
105+
if (rmdir($path) === false) {
106+
throw new Exception("Failed to delete directory $path");
107+
}
108+
}
109+
}
110+
111+
/**
112+
* Clean-up destination directory before build
113+
*/
114+
function cleanUpDestinationDirectory()
115+
{
116+
if (is_dir(DESTINATION_DIR)) {
117+
echo "Cleanup old general data folder... ";
118+
deleteFromFilesystem(DESTINATION_DIR);
119+
echo "Done.\n";
120+
}
121+
}
122+
123+
set_error_handler('handleError');

composer.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@
2828
},
2929
"require-dev": {
3030
"phpunit/phpunit": "5.*",
31-
"squizlabs/php_codesniffer": "2.*"
31+
"squizlabs/php_codesniffer": "2.*",
32+
"phpdocumentor/phpdocumentor" : "2.*"
3233
},
3334
"autoload": {
3435
"psr-4": {
3536
"OpenWorld\\": "src/"
3637
}
37-
},
38-
"bin": [
39-
40-
]
38+
}
4139
}

0 commit comments

Comments
 (0)