-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
4,232 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,49 @@ | ||
# documentation | ||
Zephir Documentation | ||
<p align="center"> | ||
<a href="https://zephir-lang.com/" target="_blank"> | ||
<img src="https://assets.phalcon.io/zephir/zephir_logo-105x36.svg" height="100" alt="Zephir"/> | ||
</a> | ||
</p> | ||
|
||
# Zephir - Documentation site source | ||
|
||
This is the official documentation site source code. | ||
|
||
## How to try it out | ||
|
||
```sh | ||
$ git clone [email protected]:zephir-lang/documentation.git | ||
$ cd zephir-docs-app | ||
``` | ||
|
||
You will need to build a docker image, to be able to work with the documents locally. | ||
|
||
```sh | ||
docker build -t zephir-mike . | ||
``` | ||
|
||
Once the image is built, run the `./serve` command | ||
|
||
```sh | ||
$ ./serve | ||
``` | ||
|
||
This will get you in the dockerized environment. Launch the server by issuing the following command: | ||
|
||
```sh | ||
$ mkdocs serve | ||
``` | ||
|
||
Check the documents on your browser by visiting `http://localhost:8000/` | ||
|
||
|
||
|
||
### Easy way pull latest of all submodules | ||
## License | ||
|
||
This project is open-sourced software licensed under the MIT License. See the [LICENSE](https://github.com/zephir-lang/documentation/blob/master/LICENSE) file for more information. | ||
|
||
## Thank you | ||
|
||
A big thank you to: | ||
- [Cloudflare](https://cloudflare.com) for hosting the site | ||
- All of our supporters and users! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5.5|latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
|
||
# Arrays | ||
|
||
Array manipulation in Zephir provides a way to leverage PHP arrays. An array in Zephir corresponds to the concept of a [hash table][hash_table] in other programming languages. | ||
|
||
## Declaring Array Variables | ||
|
||
Array variables can be declared using the keywords `var` or `array`: | ||
|
||
```zephir | ||
var a = []; // array variable, its type can be changed | ||
array b = []; // array variable, its type cannot be changed across execution | ||
``` | ||
|
||
## Creating Arrays | ||
|
||
Arrays are created by enclosing elements in square brackets: | ||
|
||
##### Empty array | ||
|
||
```zephir | ||
let elements = []; | ||
``` | ||
|
||
##### Array with elements | ||
|
||
```zephir | ||
let elements = [1, 3, 4]; | ||
``` | ||
|
||
##### Array with elements of different types | ||
|
||
```zephir | ||
let elements = ["first", 2, true]; | ||
``` | ||
|
||
##### Multi-dimensional array | ||
|
||
```zephir | ||
let elements = [[0, 1], [4, 5], [2, 3]]; | ||
``` | ||
|
||
Zephir supports hashes or dictionaries, similar to PHP: | ||
|
||
##### Hash with string keys | ||
|
||
```zephir | ||
let elements = ["foo": "bar", "bar": "foo"]; | ||
``` | ||
|
||
##### Hash with numeric keys | ||
|
||
```zephir | ||
let elements = [4: "bar", 8: "foo"]; | ||
``` | ||
|
||
##### Hash with mixed string and numeric keys | ||
|
||
```zephir | ||
let elements = [4: "bar", "foo": 8]; | ||
``` | ||
|
||
## Updating arrays | ||
|
||
Arrays are updated using square brackets: | ||
|
||
##### String key | ||
|
||
```zephir | ||
let elements["foo"] = "bar"; | ||
``` | ||
|
||
##### Numeric key | ||
|
||
```zephir | ||
let elements[0] = "bar"; | ||
``` | ||
|
||
##### Multi-dimensional array | ||
|
||
```zephir | ||
let elements[0]["foo"] = "bar"; | ||
let elements["foo"][0] = "bar"; | ||
``` | ||
|
||
## Appending elements | ||
|
||
Elements can be appended at the end of the array: | ||
|
||
```zephir | ||
let elements[] = "bar"; | ||
``` | ||
|
||
## Reading elements from arrays | ||
|
||
Retrieve array elements using either string or numeric keys: | ||
|
||
##### Using the string key | ||
|
||
```zephir | ||
let foo = elements["foo"]; | ||
``` | ||
|
||
##### Using the numeric key | ||
|
||
```zephir | ||
let foo = elements[0]; | ||
``` | ||
|
||
[array]: https://www.php.net/manual/en/language.types.array.php | ||
[hash_table]: https://en.wikipedia.org/wiki/Hash_table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
:root { | ||
--md-primary-fg-color: #273646; | ||
--md-primary-fg-color--light: #4b6786; | ||
--md-primary-fg-color--dark: #0c1015; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "Zephir documentation", | ||
"icons": [ | ||
{ | ||
"src": "/assets/favicons/android-chrome-192x192.png", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "/assets/favicons/android-chrome-512x512.png", | ||
"sizes": "512x512", | ||
"type": "image/png" | ||
} | ||
], | ||
"theme_color": "#6f5499", | ||
"background_color": "#6f5499", | ||
"display": "standalone" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Built-In Methods | ||
|
||
As previously mentioned, Zephir strongly encourages object-oriented programming, allowing variables related to static types to be handled as objects. | ||
|
||
Consider the following two methods with the same functionality: | ||
|
||
```zephir | ||
public function binaryToHex(string s) -> string | ||
{ | ||
var o = "", n; char ch; | ||
for ch in range(0, strlen(s)) { | ||
let n = sprintf("%X", ch); | ||
if strlen(n) < 2 { | ||
let o .= "0" . n; | ||
} else { | ||
let o .= n; | ||
} | ||
} | ||
return o; | ||
} | ||
``` | ||
|
||
And: | ||
|
||
```zephir | ||
public function binaryToHex(string s) -> string | ||
{ | ||
var o = "", n; char ch; | ||
for ch in range(0, s->length()) { | ||
let n = ch->toHex(); | ||
if n->length() < 2 { | ||
let o .= "0" . n; | ||
} else { | ||
let o .= n; | ||
} | ||
} | ||
return o; | ||
} | ||
``` | ||
|
||
Both methods achieve the same result, but the second one embraces object-oriented programming. It's worth noting that calling methods on static-typed variables has no impact on performance, as Zephir internally transforms the code from the object-oriented version to the procedural version. | ||
|
||
## String | ||
|
||
Zephir provides several built-in methods for string manipulation: | ||
|
||
| Object-Oriented | Procedural | Description | | ||
|-------------------|------------------------|--------------------------------------------------------------------------------| | ||
| `s->format()` | `sprintf(s, "%s", x)` | Return a formatted string | | ||
| `s->index("foo")` | `strpos(s, "foo")` | Find the position of the first occurrence of a substring in a string | | ||
| `s->length()` | `strlen(s)` | Get string length | | ||
| `s->lower()` | `strtolower(s)` | Make a string lowercase | | ||
| `s->lowerfirst()` | `lcfirst(s)` | Make a string's first character lowercase | | ||
| `s->md5()` | `md5(s)` | Calculate the md5 hash of a string | | ||
| `s->sha1()` | `sha1(s)` | Calculate the sha1 hash of a string | | ||
| `s->trim()` | `trim(s)` | Strip whitespace (or other characters) from the beginning and end of a string | | ||
| `s->trimleft()` | `ltrim(s)` | Strip whitespace (or other characters) from the beginning of a string | | ||
| `s->trimright()` | `rtrim(s)` | Strip whitespace (or other characters) from the end of a string | | ||
| `s->upper()` | `strtoupper(s)` | Make a string uppercase | | ||
| `s->upperfirst()` | `ucfirst(s)` | Make a string's first character uppercase | | ||
|
||
## Array | ||
|
||
Zephir also offers built-in methods for array manipulation: | ||
|
||
| Object-Oriented | Procedural | Description | | ||
|-------------------|--------------------------|--------------------------------------------------------------------------| | ||
| `a->combine(b)` | `array_combine(a, b)` | Creates an array by using one array for keys and another for its values | | ||
| `a->diff()` | `array_diff(a)` | Computes the difference of arrays | | ||
| `a->flip()` | `array_flip(a)` | Exchanges all keys with their associated values in an array | | ||
| `a->hasKey()` | `array_key_exists(a)` | Checks if the given key or index exists in the array | | ||
| `a->intersect(b)` | `array_intersect(a, b)` | Computes the intersection of arrays | | ||
| `a->join(" ")` | `join(" ", a)` | Join array elements with a string | | ||
| `a->keys()` | `array_keys(a)` | Return all the keys or a subset of the keys of an array | | ||
| `a->merge(b)` | `array_merge(a, b)` | Merge one or more arrays | | ||
| `a->pad()` | `array_pad(a, b)` | Pad array to the specified length with a value | | ||
| `a->rev()` | `array_reverse(a)` | Return an array with elements in reverse order | | ||
| `a->reversed()` | `array_reverse(a)` | Return an array with elements in reverse order | | ||
| `a->split()` | `array_chunk(a)` | Split an array into chunks | | ||
| `a->values()` | `array_values(a)` | Return all the values of an array | | ||
| `a->walk()` | `array_walk(a)` | Apply a user supplied function to every member of an array | | ||
|
||
## Char | ||
|
||
For character manipulation, Zephir provides: | ||
|
||
| OO | Procedural | | ||
|----------------|----------------------| | ||
| `ch->toHex()` | `sprintf("%X", ch)` | | ||
|
||
## Integer | ||
|
||
For integer manipulation, Zephir includes: | ||
|
||
| OO | Procedural | | ||
|--------------|---------------| | ||
| `i->abs()` | `abs(i)` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Closures | ||
|
||
Zephir supports closures, also known as anonymous functions, which are PHP-compatible and can be seamlessly utilized in Zephir. These closures can be returned to the PHP userland. | ||
|
||
Consider the following example: | ||
|
||
```zephir | ||
namespace MyLibrary; | ||
class Functional | ||
{ | ||
public function map(array! data) | ||
{ | ||
return function(number) { | ||
return number * number; | ||
}; | ||
} | ||
} | ||
``` | ||
|
||
In this example, a closure is defined within the map method, taking a number as a parameter and returning its square. | ||
|
||
Closures can also be executed directly within Zephir and passed as parameters to other functions/methods: | ||
|
||
```zephir | ||
namespace MyLibrary; | ||
class Functional | ||
{ | ||
public function map(array! data) | ||
{ | ||
return data->map(function(number) { | ||
return number * number; | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
Here, the closure is employed within the map function, applying the defined transformation to each element of the array. | ||
|
||
Additionally, Zephir provides a concise syntax for defining closures: | ||
|
||
```zephir | ||
namespace MyLibrary; | ||
class Functional | ||
{ | ||
public function map(array! data) | ||
{ | ||
return data->map(number => number * number); | ||
} | ||
} | ||
``` | ||
|
||
The short syntax offers a more compact way to express closures, enhancing code readability. |
Oops, something went wrong.