Skip to content

Commit

Permalink
Refactor main class
Browse files Browse the repository at this point in the history
  • Loading branch information
orlov-alexey committed Jul 21, 2017
1 parent d4ae0f6 commit d08a3cd
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 157 deletions.
22 changes: 22 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 1,22 @@
<?php
$finder = PhpCsFixer\Finder::create()
->exclude(['tests', 'node_modules'])
->in([__DIR__]);
$config = PhpCsFixer\Config::create()
->setUsingCache(true)
->setRules([
'@Symfony' => true,
'phpdoc_align' => false,
'phpdoc_summary' => false,
'phpdoc_inline_tag' => false,
'pre_increment' => false,
'heredoc_to_nowdoc' => false,
'cast_spaces' => false,
'include' => false,
'phpdoc_no_package' => false,
'concat_space' => ['spacing' => 'one'],
'ordered_imports' => true,
'array_syntax' => ['syntax' => 'short'],
])
->setFinder($finder);
return $config;
1 change: 1 addition & 0 deletions .php_cs.cache
Original file line number Diff line number Diff line change
@@ -0,0 1 @@
{"php":"7.0.17","version":"2.3.1:v2.3.1#d5257f7433bb490299c4f300d95598fd911a8ab0","rules":{"binary_operator_spaces":{"align_double_arrow":false,"align_equals":false},"blank_line_after_opening_tag":true,"blank_line_before_return":true,"braces":{"allow_single_line_closure":true},"class_definition":{"singleLine":true},"concat_space":{"spacing":"one"},"declare_equal_normalize":true,"function_typehint_space":true,"hash_to_slash_comment":true,"lowercase_cast":true,"magic_constant_casing":true,"method_separation":true,"native_function_casing":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_consecutive_blank_lines":{"tokens":["curly_brace_block","extra","parenthesis_brace_block","square_brace_block","throw","use"]},"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_mixed_echo_print":{"use":"echo"},"no_multiline_whitespace_around_double_arrow":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_unneeded_control_parentheses":true,"no_unused_imports":true,"no_whitespace_before_comma_in_array":true,"no_whitespace_in_blank_line":true,"normalize_index_brace":true,"object_operator_without_whitespace":true,"php_unit_fqcn_annotation":true,"phpdoc_annotation_without_dot":true,"phpdoc_indent":true,"phpdoc_no_access":true,"phpdoc_no_alias_tag":true,"phpdoc_no_empty_return":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_return_self_reference":true,"phpdoc_scalar":true,"phpdoc_separation":true,"phpdoc_single_line_var_spacing":true,"phpdoc_to_comment":true,"phpdoc_trim":true,"phpdoc_types":true,"phpdoc_var_without_name":true,"protected_to_private":true,"return_type_declaration":true,"self_accessor":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_class_element_per_statement":true,"single_quote":true,"space_after_semicolon":true,"standardize_not_equals":true,"ternary_operator_spaces":true,"trailing_comma_in_multiline_array":true,"trim_array_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"blank_line_after_namespace":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true,"ordered_imports":true,"array_syntax":{"syntax":"short"}},"hashes":{"Broadcast.php":1713408020,"drivers\/RedisDriver.php":6960426,"SocketIoAsset.php":2171177918,"events\/EventSubInterface.php":2049167892,"events\/EventPolicyInterface.php":1340448374,"events\/EventInterface.php":3429058442,"events\/EventRoomInterface.php":837023941,"events\/EventPubInterface.php":2023684046,"EventManager.php":1502699749,"commands\/SocketIoCommand.php":2445214399}}
16 changes: 8 additions & 8 deletions Broadcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 2,17 @@

namespace yiicod\socketio;

use yiicod\socketio\drivers\RedisDriver;
use yiicod\socketio\events\EventPolicyInterface;
use yiicod\socketio\events\EventPubInterface;
use yiicod\socketio\events\EventRoomInterface;
use yiicod\socketio\events\EventSubInterface;
use Exception;
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\HtmlPurifier;
use yii\helpers\Json;
use yiicod\base\helpers\LoggerHelper;
use yiicod\base\helpers\LoggerMessage;
use yiicod\socketio\drivers\RedisDriver;
use yiicod\socketio\events\EventPolicyInterface;
use yiicod\socketio\events\EventPubInterface;
use yiicod\socketio\events\EventRoomInterface;
use yiicod\socketio\events\EventSubInterface;

/**
* Class Broadcast
Expand Down Expand Up @@ -67,7 67,7 @@ public static function on(string $event, array $data)

$event->handle($data);
} catch (Exception $e) {
Yii::error(LoggerHelper::log($e, Json::encode($data)));
Yii::error(LoggerMessage::log($e, Json::encode($data)));
}
}

Expand Down Expand Up @@ -112,7 112,7 @@ public static function emit(string $event, array $data)
]);
}
} catch (Exception $e) {
Yii::error(LoggerHelper::log($e));
Yii::error(LoggerMessage::log($e));
}
}

Expand Down
44 changes: 8 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 1,26 @@
Socket.io Yii extensions
========================

Use all power socket.io in your Yii 2 project.
Use all power of socket.io in your Yii 2 project.

Config
------

###### Install node npm packages
###### Install node additional npm
```bash
cd ~
curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh

npm install --prefix ./vendor/yiicod/yii2-socketio/server
cd common/packages/soketio/server
npm install
```

###### Console config
```php
'controllerMap' => [
'socketio' => [
'class' => \yiicod\socketio\commands\SocketIoCommand::class,
'server' => 'localhost:1367',
// If you use SSL, then uncomment and set params
//'ssl' => [
// key => 'path to key',
// cert => 'path to cert',
//]
'class' => \common\packages\socketio\commands\SocketIoCommand::class,
'server' => 'localhost:1367'
],
]
```
Expand All @@ -34,16 29,15 @@ Config
```php
'components' =>[
'broadcastEvents' => [
'class' => \yiicod\socketio\EventManager::class,
// If you use onse redis on more then one project
'class' => \common\packages\socketio\EventManager::class,
'nsp' => 'some_unique_key',
// Namespaces with events folders
'namespaces' => [
'app\socketio',
]
],
'broadcastDriver' => [
'class' => \yiicod\socketio\drivers\RedisDriver::class,
'class' => \common\packages\socketio\drivers\RedisDriver::class,
'hostname' => 'locahost',
'port' => 6379,
],
Expand All @@ -62,11 56,6 @@ Usage

###### Create publisher from server to client
```php
namespace app\socketio;

use yiicod\socketio\events\EventInterface;
use yiicod\socketio\events\EventSubInterface;

class CountEvent implements EventInterface, EventPubInterface
{
/**
Expand Down Expand Up @@ -107,11 96,6 @@ Usage

###### Create receiver from client to server
```php
namespace app\socketio;

use yiicod\socketio\events\EventInterface;
use yiicod\socketio\events\EventSubInterface;

class MarkAsReadEvent implements EventInterface, EventSubInterface
{
/**
Expand Down Expand Up @@ -153,12 137,6 @@ You can have publisher and receiver in one event. If you need check data from cl

###### Receiver with checking from client to server
```php
namespace app\socketio;

use yiicod\socketio\events\EventInterface;
use yiicod\socketio\events\EventSubInterface;
use yiicod\socketio\events\EventPolicyInterface;

class MarkAsReadEvent implements EventInterface, EventSubInterface, EventPolicyInterface
{
/**
Expand Down Expand Up @@ -200,12 178,6 @@ You can have publisher and receiver in one event. If you need check data from cl
Soket.io has room functionl. If you need it, you should implement:
- EventRoomInterface
```php
namespace app\socketio;

use yiicod\socketio\events\EventInterface;
use yiicod\socketio\events\EventPubInterface;
use yiicod\socketio\events\EventRoomInterface;

class CountEvent implements EventInterface, EventPubInterface, EventRoomInterface
{
/**
Expand Down
2 changes: 1 addition & 1 deletion SocketIoAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 11,7 @@
*/
class SocketIoAsset extends AssetBundle
{
public $sourcePath = '@common/packages/socketio/server/node_modules/socket.io-client/dist';
public $sourcePath = '@vendor/yiicod/yii2-socketio/server/node_modules/socket.io-client/dist';

public $js = ['socket.io.js'];

Expand Down
4 changes: 2 additions & 2 deletions commands/SocketIoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 2,13 @@

namespace yiicod\socketio\commands;

use yiicod\socketio\Broadcast;
use Symfony\Component\Process\Process;
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Console;
use yii\helpers\Json;
use yiicod\cron\commands\DaemonController;
use yiicod\socketio\Broadcast;

/**
* Class SocketIoCommand
Expand Down Expand Up @@ -92,7 92,7 @@ public function nodejs()
'port' => Broadcast::getDriver()->port,
'password' => Broadcast::getDriver()->password,
])),
'channels' => empty(Broadcast::channels()) ? 'some_unique_keys' : implode(',', Broadcast::channels()),
'channels' => implode(',', Broadcast::channels()),
'nsp' => Broadcast::getManager()->nsp,
'ssl' => empty($this->ssl) ? null : json_encode($this->ssl),
'runtime' => Yii::getAlias('@runtime/logs'),
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 11,7 @@
}
],
"require": {
"yiisoft/yii2": "*",
"yiicod/yii2-cron": "1.*",
"yiicod/yii2-base": "*",
"symfony/process": "~2.3|~3.0",
Expand Down
50 changes: 0 additions & 50 deletions server/bundles/connections-manager.js

This file was deleted.

Loading

0 comments on commit d08a3cd

Please sign in to comment.