Skip to content

Commit add32d6

Browse files
committed
and more code
1 parent f11ec72 commit add32d6

File tree

38 files changed

+301
-301
lines changed

38 files changed

+301
-301
lines changed

01/using_exceptions/protected/apis/lyrics/LyricsFinder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ function getText($songTitle)
2121
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
2222
$result = curl_exec($curl);
2323

24-
// if there is HTTP error we'll throw an exception if($result===false)
24+
// if there is HTTP error we'll throw an exception
25+
if($result===false)
2526
{
2627
$errorText = curl_error($curl);
2728
curl_close($url);

01/using_yii_events/index.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
$app = Yii::createWebApplication($config);
1414
Yii::app()->onBeginRequest = function($event)
1515
{
16-
// starting output buffering with gzip handler
17-
return ob_start("ob_gzhandler");
16+
// starting output buffering with gzip handler
17+
return ob_start("ob_gzhandler");
1818
};
1919
// attaching a handler to application end
2020
Yii::app()->onEndRequest = function($event)
2121
{
22-
// releasing output buffer
23-
return ob_end_flush();
22+
// releasing output buffer
23+
return ob_end_flush();
2424
};
2525
$app->run();
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
22
class MyEventHandler
33
{
4-
static function handleMissingTranslation($event)
5-
{
6-
// event class for this event is CMissingTranslationEvent
7-
// so we can get some info about the message
8-
$text = implode(\n”, array(
9-
'Language: '.$event->language,
10-
'Category:'.$event->category,
11-
'Message:'.$event->message
12-
));
13-
// sending email
14-
mail('[email protected]', 'Missing translation', $text);
15-
}
4+
static function handleMissingTranslation($event)
5+
{
6+
// event class for this event is CMissingTranslationEvent
7+
// so we can get some info about the message
8+
$text = implode("\n", array(
9+
'Language: '.$event->language,
10+
'Category:'.$event->category,
11+
'Message:'.$event->message
12+
));
13+
// sending email
14+
mail('[email protected]', 'Missing translation', $text);
15+
}
1616
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
class Notifier {
3-
function comment($event){
4-
$text = There was new comment from {$event->comment->author} on post {$event->post->title};
5-
mail('[email protected]', 'New comment', $text);
6-
}
3+
function comment($event){
4+
$text = "There was new comment from {$event->comment->author} on post {$event->post->title}";
5+
mail('[email protected]', 'New comment', $text);
6+
}
77
}

01/using_yii_events/protected/models/Post.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
// Use Gii to generate Post model and then add methods listed below:
44

55
class Post extends CActiveRecord {
6-
// custom method for adding a comment
7-
// to current post
8-
function addComment(Comment $comment){
9-
$comment->post_id = $this->id;
6+
// custom method for adding a comment
7+
// to current post
8+
function addComment(Comment $comment){
9+
$comment->post_id = $this->id;
1010

11-
// creating event class instance
12-
$event = new NewCommentEvent($this);
13-
$event->post = $this;
14-
$event->comment = $comment;
11+
// creating event class instance
12+
$event = new NewCommentEvent($this);
13+
$event->post = $this;
14+
$event->comment = $comment;
1515

16-
// triggering event
17-
$this->onNewComment($event);
18-
return $event->isValid;
19-
}
16+
// triggering event
17+
$this->onNewComment($event);
18+
return $event->isValid;
19+
}
2020

21-
// defining onNewComment event
22-
public function onNewComment($event) {
23-
// Event is actually triggered here. This way we can use
24-
// onNewComment method instead of raiseEvent.
25-
$this->raiseEvent('onNewComment', $event);
26-
}
21+
// defining onNewComment event
22+
public function onNewComment($event) {
23+
// Event is actually triggered here. This way we can use
24+
// onNewComment method instead of raiseEvent.
25+
$this->raiseEvent('onNewComment', $event);
26+
}
2727
}
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
<?php
22
class UserForm extends CFormModel
33
{
4-
public $firstName;
5-
public $lastName;
6-
public $fullName;
4+
public $firstName;
5+
public $lastName;
6+
public $fullName;
77

8-
public function rules()
9-
{
10-
return array(
11-
// First name and last name are required
12-
array('firstName, lastName', 'required'),
13-
);
14-
}
8+
public function rules()
9+
{
10+
return array(
11+
// First name and last name are required
12+
array('firstName, lastName', 'required'),
13+
);
14+
}
1515

16-
// $event argument here is CEvent instance that
17-
// was created passed when an event method was called.
18-
// This time it was happened inside of
19-
// CModel::afterValidate().
20-
function afterValidate()
21-
{
22-
// If this method was called then
23-
// the model is already filled
24-
// with data and data is valid
25-
// so we can use it safely:
26-
$this->fullName = $this->firstName.' '.$this->lastName;
16+
// $event argument here is CEvent instance that
17+
// was created passed when an event method was called.
18+
// This time it was happened inside of
19+
// CModel::afterValidate().
20+
function afterValidate()
21+
{
22+
// If this method was called then
23+
// the model is already filled
24+
// with data and data is valid
25+
// so we can use it safely:
26+
$this->fullName = $this->firstName.' '.$this->lastName;
2727

28-
// It's important to call parent class method
29-
// so all other event handlers are called
30-
return parent::afterValidate();
31-
}
28+
// It's important to call parent class method
29+
// so all other event handlers are called
30+
return parent::afterValidate();
31+
}
3232
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CREATE TABLE task (
2-
id INT AUTO_INCREMENT PRIMARY KEY,
3-
title VARCHAR(255) NOT NULL,
4-
done BOOLEAN DEFAULT 0
2+
id INT AUTO_INCREMENT PRIMARY KEY,
3+
title VARCHAR(255) NOT NULL,
4+
done BOOLEAN DEFAULT 0
55
);

03/working_with_json/schema.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CREATE TABLE `news` (
2-
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
3-
`created_on` int(11) unsigned NOT NULL,
4-
`title` varchar(255) NOT NULL,
5-
PRIMARY KEY (`id`)
2+
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
3+
`created_on` int(11) unsigned NOT NULL,
4+
`title` varchar(255) NOT NULL,
5+
PRIMARY KEY (`id`)
66
)

04/adding_captcha/protected/controllers/EmailController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public function actionIndex()
2727
$this->render('index', array(
2828
'model' => $model,
2929
'success' => $success,
30-
));
30+
));
3131
}
3232
}

04/adding_captcha/protected/models/EmailForm.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class EmailForm extends CFormModel
77
function rules(){
88
return array(
99
array('email', 'email'),
10-
array('verifyCode', 'captcha', 'allowEmpty'=> !CCaptcha::checkRequirements()),
11-
);
12-
}
10+
array('verifyCode', 'captcha', 'allowEmpty'=> !CCaptcha::checkRequirements()),
11+
);
12+
}
1313
}

0 commit comments

Comments
 (0)