Skip to content

Commit 1b7ba55

Browse files
committed
feat: initial import
Provides the initial package definition: - Taskfile for recreating stubs - README and LICENSE files - Initial stubs based on 1.3.x version of ZendHQ - Composer definition, setup to prompt for dev installation
0 parents  commit 1b7ba55

File tree

8 files changed

+1479
-0
lines changed

8 files changed

+1479
-0
lines changed

.gitattributes

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.github/ export-ignore
2+
/.gitattributes export-ignore
3+
/.gitignore export-ignore
4+
/composer.lock export-ignore
5+
/phpcs.xml.dist export-ignore
6+
/phpunit.xml.dist export-ignore
7+
/Taskfile export-ignore

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor/
2+
composer.lock

LICENSE.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2023 Perforce Software Inc.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are met:
5+
6+
- Redistributions of source code must retain the above copyright notice, this
7+
list of conditions and the following disclaimer.
8+
9+
- Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
13+
- Neither the name of Perforce Software Inc. nor the names of its contributors may
14+
be used to endorse or promote products derived from this software without
15+
specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# zendtech/zendhq-ide-helpers
2+
3+
This package provides class stubs for the purpose of IDE autocompletion when programming to [ZendHQ](https://www.zend.com/products/zendphp-enterprise/zendhq) APIs.
4+
You should primarily include this only if you do not have ZendHQ installed in your local PHP installation, but need your production application code to be able to use ZendHQ PHP APIs.
5+
6+
## Installation
7+
8+
This package should be installed as a development package:
9+
10+
```
11+
composer require --dev zendtech/zendhq-ide-helpers
12+
```
13+
14+
> If you omit the `--dev` flag, Composer _will_ prompt you to see if you meant to install it as a development dependency.
15+
16+
## What's included
17+
18+
This package contains stubs for the following ZendHQ PHP APIs:
19+
20+
- [JobQueue](https://help.zend.com/zendphp/current/content/zendhq/zendhq_jobqueue_php_api.htm)
21+
22+
## Support
23+
24+
The stubs contained in this library are generated from PHP stubs included in the ZendHQ extension, and provided as-is.

Taskfile

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/bin/bash
2+
# This is a Taskfile
3+
# (https://medium.com/@adrian_cooney/introducing-the-taskfile-5ddfe7ed83bd)
4+
#
5+
# It is a plain-old-bashfile, with a few helper functions.
6+
# Each task should be a single function.
7+
# Tasks that have dependencies can call the other functions as part of their
8+
# work; you can also create meta-tasks that simply call other tasks.
9+
#
10+
# To provide detailed help for a given task, write a function named {task}_help.
11+
#
12+
# Functions prefixed with tf_ or suffixed with _help will be omitted from help listings.
13+
14+
set -e
15+
16+
## Color functions
17+
## Usage: {color} "arguments" "go" "here"
18+
## Use these to add color to your output.
19+
tf_print_in_color() {
20+
local color="$1"
21+
shift
22+
if [[ -z ${NO_COLOR+x} ]]; then
23+
printf "$color%b\e[0m\n" "$*";
24+
else
25+
printf "%b\n" "$*";
26+
fi
27+
}
28+
29+
tf_red() { tf_print_in_color "\e[31m" "$*"; }
30+
tf_green() { tf_print_in_color "\e[32m" "$*"; }
31+
tf_yellow() { tf_print_in_color "\e[33m" "$*"; }
32+
tf_blue() { tf_print_in_color "\e[34m" "$*"; }
33+
tf_magenta() { tf_print_in_color "\e[35m" "$*"; }
34+
tf_cyan() { tf_print_in_color "\e[36m" "$*"; }
35+
tf_bold() { tf_print_in_color "\e[1m" "$*"; }
36+
tf_underlined() { tf_print_in_color "\e[4m" "$*"; }
37+
tf_red_bold() { tf_print_in_color "\e[1;31m" "$*"; }
38+
tf_green_bold() { tf_print_in_color "\e[1;32m" "$*"; }
39+
tf_yellow_bold() { tf_print_in_color "\e[1;33m" "$*"; }
40+
tf_blue_bold() { tf_print_in_color "\e[1;34m" "$*"; }
41+
tf_magenta_bold() { tf_print_in_color "\e[1;35m" "$*"; }
42+
tf_cyan_bold() { tf_print_in_color "\e[1;36m" "$*"; }
43+
tf_red_underlined() { tf_print_in_color "\e[4;31m" "$*"; }
44+
tf_green_underlined() { tf_print_in_color "\e[4;32m" "$*"; }
45+
tf_yellow_underlined() { tf_print_in_color "\e[4;33m" "$*"; }
46+
tf_blue_underlined() { tf_print_in_color "\e[4;34m" "$*"; }
47+
tf_magenta_underlined() { tf_print_in_color "\e[4;35m" "$*"; }
48+
tf_cyan_underlined() { tf_print_in_color "\e[4;36m" "$*"; }
49+
50+
## Help function
51+
function help {
52+
if [[ $# -gt 0 ]]; then
53+
if [[ "$(LC_ALL=C type -t "$1_help")" == "function" ]]; then
54+
"$1_help"
55+
else
56+
tf_blue "No additional help found for task '$1'"
57+
fi
58+
else
59+
tf_green "Usage:"
60+
echo " $0 <task> <args>"
61+
echo
62+
tf_green "Available Tasks:"
63+
compgen -A function | cat -n | grep -v -P "^\s+\d+\s+tf_" | grep -v -P "_help\$" | sed -r -e "s/^[[:space:]]+[[:digit:]]+[[:space:]]+/ /"
64+
echo
65+
tf_green "Run '$0 help {task}' to get help on a given task"
66+
fi
67+
}
68+
69+
## Task functions
70+
71+
# Helper function - implode
72+
# - First argument is string to use when imploding
73+
# - All remaining arguments are the values to implode
74+
# - Specify an array using "${array[@]}" as a second argument
75+
function tf_implode {
76+
local d=${1-} f=${2-}
77+
if shift 2; then
78+
printf %s "$f" "${@/#/$d}"
79+
fi
80+
}
81+
82+
function stubs {
83+
local tmp
84+
local stub
85+
86+
if [[ -z "${GH_TOKEN}" ]]; then
87+
tf_red "Missing GH_TOKEN; please provide it in your env or as part of your command line invocation"
88+
exit 1
89+
fi
90+
91+
if ! command -v git; then
92+
tf_red "The 'git' command is required to use this task."
93+
exit 1
94+
fi
95+
96+
tmp="$(mktemp -d)"
97+
98+
tf_cyan "Cloning zendhq repo"
99+
git clone "https://oauth2:${GH_TOKEN}@github.com/perforce-zend/zendhq.git" "${tmp}/zendhq"
100+
101+
tf_cyan "Isolating stubs"
102+
mkdir -p "${tmp}/stubs"
103+
printf "<?php" > "${tmp}/stubs/stubs.php"
104+
for stub in "${tmp}"/zendhq/src/zendphp/ext/zendhq/jq/8.2/*.stub.php; do
105+
sed -E '/<\?php/d' < "${stub}" >> "${tmp}/stubs/stubs.php"
106+
done
107+
108+
# @todo Update stubs such that:
109+
# - JobQueue constructor argument has a default argument
110+
# - Annotations are added for the JobOptions and QueueDefinition classes
111+
# to detail the priority/output capture allowed values
112+
113+
tf_cyan "Copying stubs to package"
114+
cp -a "${tmp}/stubs/stubs.php" "src/"
115+
116+
tf_cyan "Cleanup"
117+
rm -rf "${tmp}"
118+
119+
tf_green "[DONE]"
120+
}
121+
122+
function stubs_help {
123+
tf_green "stubs"
124+
echo " Retrieve JQ PHP API stub files, prepare them for use, and copy them"
125+
echo " into the applications."
126+
echo ""
127+
echo " This command requires the GH_TOKEN env be present. it will be used"
128+
echo " to seed the oauth2 token for cloning from Zend by Perforce's zendhq repository."
129+
echo " It should only be run by maintainers."
130+
}
131+
132+
## Default task
133+
## Change this to call a different task by default
134+
function tf_default {
135+
help "$@"
136+
}
137+
138+
# Switch to the directory containing the Taskfile
139+
cd "$(dirname "$(realpath "$0")")"
140+
141+
"${@:-tf_default}"

composer.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "zendtech/zendhq-ide-helper",
3+
"description": "Provides class stubs for ZendHQ classes to help with IDE completion when the ZendHQ extension is not installed",
4+
"license": "BSD-3-Clause",
5+
"keywords": [
6+
"dev",
7+
"zendhq"
8+
],
9+
"require": {
10+
"php": "^7.2.0 || ~8.0.0 || ~8.1.0 || ~8.2.0"
11+
},
12+
"autoload": {
13+
"files": [
14+
"src/include.php"
15+
]
16+
}
17+
}

src/include.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
if (! class_exists(ZendHQ\JobQueue\Queue::class, false)) {
6+
require_once __DIR__ . '/stubs.php';
7+
}

0 commit comments

Comments
 (0)