Skip to content

Commit 1a7a1b8

Browse files
committed
update doc content
1 parent cd7cf6f commit 1a7a1b8

File tree

22 files changed

+136
-128
lines changed

22 files changed

+136
-128
lines changed

src/app/console/command/command.component.html

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ <h3>Command-line syntax</h3>
2525
<thead>
2626
<tr>
2727
<th scope="col">Token</th>
28-
<th scope="col">Discription</th>
28+
<th scope="col">Description</th>
2929
</tr>
3030
</thead>
3131
<tbody>
@@ -86,23 +86,23 @@ <h3>Define commands</h3>
8686
&lcub;
8787
public static function main(array $args = [])
8888
&lcub;
89-
// define the root command.
90-
$rootcommand = new CommandLine('watch', 'Command-line that displays the time.');
91-
$rootcommand->addOption('--version', 'Display the version information.', '-v');
89+
// Defines the root command.
90+
$rootCommand = new CommandLine('watch', 'Command-line that displays the time.');
91+
$rootCommand->addOption('--version', 'Display the version information.', '-v');
9292

93-
$rootcommand->setHandler(function (object $sender, CommandEventArgs $args): void &lcub;
93+
$rootCommand->setHandler(function (object $sender, CommandEventArgs $args): void &lcub;
9494
$version = $args->get('--version');
9595
if ($version) &lcub;
96-
Console::writeline("watch command-line: v1.0.0");
96+
Console::writeLine("watch command-line: v1.0.0");
9797
return;
9898
}
9999

100-
Console::writeline("Try 'watch --help' to get information about the command's usage.");
100+
Console::writeLine("Try 'watch --help' to get information about the command's usage.");
101101
});
102102

103-
// define the child command.
103+
// Defines the child command.
104104
$subcommand = new CommandLine('time', 'Display the current time');
105-
$subcommand->addArgument('timezone', 'Define the time zome');
105+
$subcommand->addArgument('timezone', 'Define the time zone');
106106

107107
$subcommand->setHandler(function (object $sender, CommandEventArgs $args): void &lcub;
108108
$datetime = new DateTime('now');
@@ -111,22 +111,22 @@ <h3>Define commands</h3>
111111
$datetime->setTimezone(new DateTimeZone($timezone->Value));
112112
}
113113

114-
Console::writeline($datetime->format('H:i:s'));
114+
Console::writeLine($datetime->format('H:i:s'));
115115
}
116116

117-
// add the child command.
118-
$rootcommand->addCommand($subcommand);
117+
// Adds the child command.
118+
$rootCommand->addCommand($subcommand);
119119

120-
// parse the input, then invoke the command.
121-
$rootcommand->invoke($args);
120+
// Parsing the input, then invoking the command.
121+
$rootCommand->invoke($args);
122122
}
123123
}
124124
</code></pre>
125125
<blockquote class="alert alert-info">
126126
<b>Note:</b> You can run your command-line application by executing the bin file of your application <code>./bin/run</code>
127127
</blockquote>
128128
<p>
129-
In this example, we have renamed the bin files <code>./bin/run</code> and <code>./bin/run.bat</code> to match the name of the root command, and became <code>./bin/watch</code> and <code>./bin/watch.bat</code>
129+
In this example, we have renamed the bin files <code>./bin/run</code> and <code>./bin/run.bat</code> to <code>./bin/watch</code> and <code>./bin/watch.bat</code> to match the name of the root command.
130130
</p>
131131
<p>
132132
Now you can execute the command with a given time zone argument to get the current time of that zone.
@@ -138,7 +138,7 @@ <h5>Output</h5>
138138
<p>
139139
Or execute the command with the option <code>--version</code> to get the version information.
140140
</p>
141-
<pre><code class="language-shell">./bin/watch --verion</code></pre>
141+
<pre><code class="language-shell">./bin/watch --version</code></pre>
142142
<h5>Output</h5>
143143
<pre><code class="language-shell">watch command-line: v1.0.0</code></pre>
144144
</article>

src/app/core/asynchronous/asynchronous.component.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ <h3>Coroutine Task</h3>
2121
function readFileAsync(string $path): Task &lcub;
2222
// Creating and starting the task.
2323
$task = Task::run(function() use($path) &lcub;
24-
$result = null;
2524
$file = fopen($path, 'r');
26-
// Suspend and resume the task while the reading has not finished yet.
27-
do &lcub;
28-
yield;
29-
stream_set_blocking($file, false);
30-
$result .= $content = fgets($file);
25+
stream_set_blocking($file, false);
26+
$result = null;
27+
while (!feof($file)) &lcub;
28+
// Suspend and resume the task while the reading has not finished yet.
29+
$content = yield fread($file, 1024);
3130
if ($content === false) &lcub;
3231
// Throws an exception on failure.
3332
throw new \Exception("Unable to read from the file");
3433
}
35-
} while (!feof($file));
34+
$result .= $content;
35+
}
3636

3737
fclose($file);
3838
// Returns a result on success.
@@ -99,8 +99,8 @@ <h3>Async/Await Pattern</h3>
9999

100100
$readJsonAsync = async(function($path): string &lcub;
101101
$file = new FileStream($path, 'r');
102-
// await for the async reading to complete without blocking the outside scope.
103-
$json = await($file->readAsync($file->Lenth));
102+
// Await for the async reading to complete without blocking the outside scope.
103+
$json = await($file->readAsync($file->Length));
104104
$data = json_decode($json);
105105

106106
$file->close();
@@ -127,7 +127,7 @@ <h3>Async/Await Pattern</h3>
127127
public async_readJsonAsync(function($path): string
128128
&lcub;
129129
$file = new FileStream($path, 'r');
130-
$json = await($file->readAsync($file->Lenth));
130+
$json = await($file->readAsync($file->Length));
131131
$data = json_decode($json);
132132

133133
$file->close();

src/app/core/delegates/delegates.component.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h3>Defining the delegate</h3>
2222

2323
class MyDelegate extends Delegate
2424
&lcub;
25-
// Define the delegate signature.
25+
// Defining the delegate signature.
2626
public function myDelegate(array $args): string
2727
&lcub;
2828
// The body is left empty.
@@ -40,7 +40,7 @@ <h3>Defining the handler</h3>
4040

4141
class MyHandler
4242
&lcub;
43-
// Define a method with the same signature as the delegate.
43+
// Defining a method with the same signature as the delegate.
4444
public function handle(array $args): string
4545
&lcub;
4646
return serialize($args);
@@ -54,17 +54,17 @@ <h3>Using the delegate</h3>
5454
</p>
5555
<pre><code class="language-php">&lt;?php
5656

57-
// Register the method 'handle' of the Handler class
57+
// Associating the method 'handle' of the Handler class to the delegate.
5858
$myAction = new MyDelegate([new MyHandler(), 'handle']);
5959

60-
// Or register in-line closure function of the same signature
60+
// Or Associating in-line closure function of the same signature
6161
$myAction = new MyDelegate(function(array $args): string &lcub;
6262
return serialize($args);
6363
});
6464

6565
$args = ['value1', 'value2'];
6666

67-
// Invoke the delegate instance.
67+
// Invoking the delegate instance.
6868
$result = $myAction($args);
6969
</code></pre>
7070
<br>
@@ -76,7 +76,7 @@ <h4>Multicast Delegate</h4>
7676

7777
$myAction = new MyDelegate();
7878

79-
// register Handlers
79+
// Associating Handlers
8080
$myAction[] = [new MyHandler(), 'handle'];
8181
$myAction[] = function(array $args): string &lcub;
8282
return json_encode($args);
@@ -107,7 +107,7 @@ <h5>Event Handler</h5>
107107
<li><b>$args:</b> (<code>DevNet\System\Event\EventArgs</code>) represents the event arguments to be handled by the handler.</li>
108108
</ul>
109109
<p>
110-
The example below represents a <code>Button</code> class as a publisher with two events: The <code>click</code> and <code>keypress</code> events, which can be associated with event listners.
110+
The example below represents a <code>Button</code> class as a publisher with two events: The <code>click</code> and <code>keypress</code> events, which can be associated with event listeners.
111111
</p>
112112
<pre><code class="language-php">&lt;?php
113113

@@ -129,7 +129,7 @@ <h5>Event Handler</h5>
129129
$this->keypress = new EventHandler();
130130
}
131131

132-
public function addListner(string $event, callable $handler): void
132+
public function addListener(string $event, callable $handler): void
133133
&lcub;
134134
switch($event) &lcub;
135135
case 'click':
@@ -173,7 +173,7 @@ <h5>Event Handler</h5>
173173
$this->Title = $title;
174174
$this->MyButton = new Button("My button");
175175
// Subscribe to the click event.
176-
$this->MyButton->addListner('click', [$this, 'onMyButtonClick']);
176+
$this->MyButton->addListener('click', [$this, 'onMyButtonClick']);
177177
}
178178

179179
public function onMyButtonClick(object $sender, EventArgs $event): void

src/app/core/extension/extension.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ <h3>Calling the extension method</h3>
6464
$employee->Salary = 25000;
6565
$tax = 0.15;
6666

67-
// calling the extension method as if it belongs to the employee instance.
67+
// Calling the extension method as if it belongs to the employee instance.
6868
$income = $employee->getIncome($tax);
6969

7070
print("Income: &lcub;$income}$"); // Income: 21250$

src/app/core/generics/generics.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h3>Generic type parameter</h3>
3333
use DevNet\System\Template;
3434
use DevNet\System\TypeTrait;
3535

36-
// Define the type parameter T as a type of the items in the collection.
36+
// Defines the type parameter T as a type of the items in the collection.
3737
#[Template('T')]
3838
class Collection implements IEnumerable
3939
&lcub;
@@ -49,7 +49,7 @@ <h3>Generic type parameter</h3>
4949

5050
private function add(#[Type('T')] $item): void
5151
&lcub;
52-
// Call the item wrapper as collable to get the item value.
52+
// Checking the the type of the arguments before using them.
5353
$this->checkArgumentTypes(func_get_args());
5454
$this->items[] = $item;
5555
}
@@ -102,7 +102,7 @@ <h3>Checking generic type</h3>
102102

103103
private Collection $employees;
104104

105-
// accept only the injection of an argument of type Collection&lt;Employee>
105+
// Accepting only the injection of an argument of type Collection&lt;Employee>
106106
public function __construct(#[Type(Collection::class, [Employee::class])] $employees)
107107
&lcub;
108108
$this->checkArgumentTypes(func_get_args());

src/app/core/linq/linq.component.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ <h3>Using LINQ extension methods</h3>
2222
</p>
2323
<pre><code class="language-php">&lt;?php
2424

25-
// declaring the Linq namespace to be able to use the extension methods with the ArrayList instance.
25+
// Declaring the Linq namespace to be able to use the extension methods with the ArrayList instance.
2626
use DevNet\System\Linq;
2727

28-
// creating ArrayList instance with generic type argument of Employee class.
28+
// Creating ArrayList instance with generic type argument of Employee class.
2929
$list = new ArrayList(Employee::class);
3030

31-
// assuming we have Employee class with constructor that initializes Id and Name properties.
31+
// Assuming we have Employee class with constructor that initializes Id and Name properties.
3232
$list[] = new Employee(1, 'bob');
3333
$list[] = new Employee(2, 'carol');
3434
$list[] = new Employee(3, 'ted');
@@ -48,7 +48,7 @@ <h6>Output:</h6>
4848
Last employee is ted with Id 6
4949
</code></pre>
5050
<br>
51-
<h5>Filtring</h5>
51+
<h5>Filtering</h5>
5252
<pre><code class="language-php">print("Employees with Id greater than 2\n");
5353

5454
$employees = $list->where(fn($employee) => $employee->Id > 2);
@@ -111,7 +111,7 @@ <h6>Output:</h6>
111111
</code></pre>
112112
<br>
113113
<h5>Paging</h5>
114-
<pre><code class="language-php">// skip first 2 employees then take just 3 from the rest of employees.
114+
<pre><code class="language-php">// Skips the first 2 employees then take just 3 from the rest of employees.
115115
$employees = $list->skip(2)->take(3);
116116

117117
foreach ($employees as $employee) &lcub;
@@ -129,18 +129,18 @@ <h5>Aggregating</h5>
129129
$max = $list->max(fn($employee) => $employee->Id);
130130
$min = $list->min(fn($employee) => $employee->Id);
131131

132-
print("Tolat employess => &lcub;$count}\n");
132+
print("Total employees => &lcub;$count}\n");
133133
print("Max employee Id => &lcub;$max}\n");
134134
print("Min employee Id => &lcub;$min}\n");
135135
</code></pre>
136136
<h6>Output:</h6>
137-
<pre><code class="language-shell">Tolat employess => 6
137+
<pre><code class="language-shell">Total employees => 6
138138
Max employee Id => 6
139139
Min employee Id => 1
140140
</code></pre>
141141
<br>
142142
<h5>Grouping</h5>
143-
<pre><code class="language-php">// create groups of employees share the same name.
143+
<pre><code class="language-php">// Creates a groups of employees share the same name.
144144
$groups = $list->groupBy(fn($employee) => $employee->Name);
145145

146146
foreach ($groups as $group) &lcub;

src/app/entity/query/query.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ <h3>Linq Query</h3>
4646
<code>EntitySet</code> implements the <code>IQueryable</code> interface so it can use LINQ (Language-Integrated Query) to query data from the database, which are chained methods that represent SQL operations, compiled by the database provider to be sent as a specific database query language (MySQL, SQLite, ...) and then to get the result set.
4747
</p>
4848
<blockquote class="alert alert-warning">
49-
<b>Importante:</b> Linq methods are extension methods, so to use this feature, you have to declare the use of the Linq namespace <code>DevNet\System\Linq</code> in every class or code that uses Linq methods with an instance of <code>EntitySet</code>.
49+
<b>Important:</b> Linq methods are extension methods, so to use this feature, you have to declare the use of the Linq namespace <code>DevNet\System\Linq</code> in every class or code that uses Linq methods with an instance of <code>EntitySet</code>.
5050
</blockquote>
5151
<br>
5252
<h4>Filtering Data</h4>

src/app/entity/start/start.component.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ <h4>Connection String</h4>
185185
<code>"//[username]:[password]@[host]:[port]/[database]?[option=value]"</code>
186186
</p>
187187
<br>
188-
<h3>Registing the EntityContext</h3>
188+
<h3>Registering the EntityContext</h3>
189189
<p>
190190
You can register Entity ORM as a reused service that will be injected into your application using the Extension method <code>ServiceCollectionExtensions::addEntityContext()</code> inside the method <code>WebHostBuilder::register()</code>, as shown in the following code example:
191191
</p>
@@ -226,6 +226,7 @@ <h3>Registing the EntityContext</h3>
226226

227227
use DevNet\Web\Endpoint\ActionController;
228228
use DevNet\Web\Endpoint\IActionResult;
229+
use DevNet\Web\Endpoint\Route;
229230
use Application\Models\BlogContext;
230231

231232
class BlogController extends ActionController
@@ -237,9 +238,10 @@ <h3>Registing the EntityContext</h3>
237238
$this->blog = $blog;
238239
}
239240

241+
#[Route("/")]
240242
public function index(): IActionResult
241243
&lcub;
242-
$this->view($this->blog->Posts);
244+
$this->view(['posts' => $this->blog->Posts]);
243245
}
244246
}
245247
</code></pre>

src/app/security/antiforgery/antiforgery.component.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ <h3>X-CSRF-TOKEN</h3>
7474
<p>
7575
After registering the Antiforgery service with the MVC web application, it will be injected into the view so that you can generate a token in the HTML form.
7676
</p>
77-
<pre><code class="language-php-template">&lt;form method="POST" action="/account/update/<?= $model->Id ?>">
78-
&lt;input type="text" name="username value="<?= $model->Username ?>" />
79-
&lt;input type="email" name="email" value="<?= $model->Email ?>" />
77+
<pre><code class="language-php-template">&lt;form method="POST" action="/account/update/<?= $user->Id ?>">
78+
&lt;input type="text" name="username value="<?= $user->Username ?>" />
79+
&lt;input type="email" name="email" value="<?= $user->Email ?>" />
8080
&lt;input type="hidden" name="X-CSRF-TOKEN" value="<?= $this->Antiforgery->getToken() ?>" />
8181
&lt;/form>
8282
</code></pre>
@@ -108,10 +108,10 @@ <h3>X-CSRF-TOKEN</h3>
108108
if (!$user) &lcub;
109109
Throw \Exception("page not found!", 404);
110110
}
111-
return $this->view($user);
111+
return $this->view(['user' => $user]);
112112
}
113113

114-
// add AntiForgery validation filter as an attribute.
114+
// Adds AntiForgery validation filter as an attribute.
115115
#[Validate]
116116
#[Route(path: '/account/update/&lcub;id}', method: 'POST')]
117117
public function update(int $id, User $form): IActionResult
@@ -158,7 +158,7 @@ <h3>X-XSRF-TOKEN</h3>
158158
}));
159159

160160
$routes.MapPost("/account/store", (function(HttpContext $context) &lcub;
161-
$form = $context->Resquest->Form;
161+
$form = $context->Request->Form;
162162
$user = new User();
163163
$user->Username = $form->getValue('username');
164164
$user->Password = password_hash($form->getValue('password'), PASSWORD_DEFAULT);
@@ -171,7 +171,7 @@ <h3>X-XSRF-TOKEN</h3>
171171
file_put_contents('path/to/data.json', $json);
172172
$context->Response->setStatusCode(200);
173173
})
174-
// add Antiforgery validation filter to the endpoint "/account/store".
174+
// Adds Antiforgery validation filter to the endpoint "/account/store".
175175
->addFilter(Validate::class);
176176
});</code></pre>
177177
<p>

0 commit comments

Comments
 (0)