Skip to content

Commit 08ceb35

Browse files
authored
Merge pull request #24 from codex-editor/rename
Rename repository. Add Exception Docs
2 parents 6d93e15 + 7704a98 commit 08ceb35

File tree

10 files changed

+130
-101
lines changed

10 files changed

+130
-101
lines changed

CodexEditor/CodexEditorException.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

CodexEditor/BlockHandler.php renamed to EditorJS/BlockHandler.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace CodexEditor;
3+
namespace EditorJS;
44

55
/**
66
* Class BlockHandler
77
*
8-
* @package CodexEditor
8+
* @package EditorJS
99
*/
1010
class BlockHandler
1111
{
@@ -30,7 +30,7 @@ class BlockHandler
3030
* @param \HTMLPurifier_Config $sanitizer
3131
* @param string $configuration
3232
*
33-
* @throws CodexEditorException
33+
* @throws EditorJSException
3434
*/
3535
public function __construct($configuration, $sanitizer)
3636
{
@@ -44,7 +44,7 @@ public function __construct($configuration, $sanitizer)
4444
* @param string $blockType
4545
* @param array $blockData
4646
*
47-
* @throws CodexEditorException
47+
* @throws EditorJSException
4848
*
4949
* @return bool
5050
*/
@@ -54,7 +54,7 @@ public function validateBlock($blockType, $blockData)
5454
* Default action for blocks that are not mentioned in a configuration
5555
*/
5656
if (!array_key_exists($blockType, $this->rules->tools)) {
57-
throw new CodexEditorException("Tool `$blockType` not found in the configuration");
57+
throw new EditorJSException("Tool `$blockType` not found in the configuration");
5858
}
5959

6060
$rule = $this->rules->tools[$blockType];
@@ -68,7 +68,7 @@ public function validateBlock($blockType, $blockData)
6868
* @param string $blockType
6969
* @param array $blockData
7070
*
71-
* @throws CodexEditorException
71+
* @throws EditorJSException
7272
*
7373
* @return array|bool
7474
*/
@@ -88,7 +88,7 @@ public function sanitizeBlock($blockType, $blockData)
8888
* @param array $rules
8989
* @param array $blockData
9090
*
91-
* @throws CodexEditorException
91+
* @throws EditorJSException
9292
*
9393
* @return bool
9494
*/
@@ -100,7 +100,7 @@ private function validate($rules, $blockData)
100100
foreach ($rules as $key => $value) {
101101
if (($key != BlockHandler::DEFAULT_ARRAY_KEY) && (isset($value['required']) ? $value['required'] : true)) {
102102
if (!isset($blockData[$key])) {
103-
throw new CodexEditorException("Not found required param `$key`");
103+
throw new EditorJSException("Not found required param `$key`");
104104
}
105105
}
106106
}
@@ -110,7 +110,7 @@ private function validate($rules, $blockData)
110110
*/
111111
foreach ($blockData as $key => $value) {
112112
if (!is_integer($key) && !isset($rules[$key])) {
113-
throw new CodexEditorException("Found extra param `$key`");
113+
throw new EditorJSException("Found extra param `$key`");
114114
}
115115
}
116116

@@ -133,7 +133,7 @@ private function validate($rules, $blockData)
133133
*/
134134
if (isset($rule['canBeOnly'])) {
135135
if (!in_array($value, $rule['canBeOnly'])) {
136-
throw new CodexEditorException("Option '$key' with value `$value` has invalid value. Check canBeOnly param.");
136+
throw new EditorJSException("Option '$key' with value `$value` has invalid value. Check canBeOnly param.");
137137
}
138138
}
139139

@@ -143,14 +143,14 @@ private function validate($rules, $blockData)
143143
switch ($elementType) {
144144
case 'string':
145145
if (!is_string($value)) {
146-
throw new CodexEditorException("Option '$key' with value `$value` must be string");
146+
throw new EditorJSException("Option '$key' with value `$value` must be string");
147147
}
148148
break;
149149

150150
case 'integer':
151151
case 'int':
152152
if (!is_integer($value)) {
153-
throw new CodexEditorException("Option '$key' with value `$value` must be integer");
153+
throw new EditorJSException("Option '$key' with value `$value` must be integer");
154154
}
155155
break;
156156

@@ -161,12 +161,12 @@ private function validate($rules, $blockData)
161161
case 'boolean':
162162
case 'bool':
163163
if (!is_bool($value)) {
164-
throw new CodexEditorException("Option '$key' with value `$value` must be boolean");
164+
throw new EditorJSException("Option '$key' with value `$value` must be boolean");
165165
}
166166
break;
167167

168168
default:
169-
throw new CodexEditorException("Unhandled type `$elementType`");
169+
throw new EditorJSException("Unhandled type `$elementType`");
170170
}
171171
}
172172

@@ -179,7 +179,7 @@ private function validate($rules, $blockData)
179179
* @param array $rules
180180
* @param array $blockData
181181
*
182-
* @throws CodexEditorException
182+
* @throws EditorJSException
183183
*
184184
* @return array
185185
*/

CodexEditor/ConfigLoader.php renamed to EditorJS/ConfigLoader.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace CodexEditor;
3+
namespace EditorJS;
44

55
/**
66
* Class ConfigLoader
77
*
8-
* @package CodexEditor
8+
* @package EditorJS
99
*/
1010
class ConfigLoader
1111
{
@@ -16,12 +16,12 @@ class ConfigLoader
1616
*
1717
* @param string $configuration – configuration data
1818
*
19-
* @throws CodexEditorException
19+
* @throws EditorJSException
2020
*/
2121
public function __construct($configuration)
2222
{
2323
if (empty($configuration)) {
24-
throw new CodexEditorException("Configuration data is empty");
24+
throw new EditorJSException("Configuration data is empty");
2525
}
2626

2727
$config = json_decode($configuration, true);
@@ -33,17 +33,17 @@ public function __construct($configuration)
3333
*
3434
* @param array $config
3535
*
36-
* @throws CodexEditorException
36+
* @throws EditorJSException
3737
*/
3838
private function loadTools($config)
3939
{
4040
if (!isset($config['tools'])) {
41-
throw new CodexEditorException('Tools not found in configuration');
41+
throw new EditorJSException('Tools not found in configuration');
4242
}
4343

4444
foreach ($config['tools'] as $toolName => $toolData) {
4545
if (isset($this->tools[$toolName])) {
46-
throw new CodexEditorException("Duplicate tool $toolName in configuration");
46+
throw new EditorJSException("Duplicate tool $toolName in configuration");
4747
}
4848

4949
$this->tools[$toolName] = $this->loadTool($toolData);

CodexEditor/CodexEditor.php renamed to EditorJS/EditorJS.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace CodexEditor;
3+
namespace EditorJS;
44

55
/**
6-
* Class CodexEditor
6+
* Class EditorJS
77
*
8-
* @package CodexEditor
8+
* @package EditorJS
99
*/
10-
class CodexEditor
10+
class EditorJS
1111
{
1212
/**
1313
* @var array $blocks - blocks classes
@@ -30,13 +30,13 @@ class CodexEditor
3030
public $sanitizer;
3131

3232
/**
33-
* CodexEditor constructor.
33+
* EditorJS constructor.
3434
* Splits JSON string to separate blocks
3535
*
3636
* @param string $json
3737
* @param mixed $configuration
3838
*
39-
* @throws CodexEditorException()
39+
* @throws EditorJSException()
4040
*/
4141
public function __construct($json, $configuration)
4242
{
@@ -47,7 +47,7 @@ public function __construct($json, $configuration)
4747
* Check if json string is empty
4848
*/
4949
if (empty($json)) {
50-
throw new CodexEditorException('JSON is empty');
50+
throw new EditorJSException('JSON is empty');
5151
}
5252

5353
/**
@@ -59,40 +59,40 @@ public function __construct($json, $configuration)
5959
* Handle decoding JSON error
6060
*/
6161
if (json_last_error()) {
62-
throw new CodexEditorException('Wrong JSON format: ' . json_last_error_msg());
62+
throw new EditorJSException('Wrong JSON format: ' . json_last_error_msg());
6363
}
6464

6565
/**
6666
* Check if data is null
6767
*/
6868
if (is_null($data)) {
69-
throw new CodexEditorException('Input is null');
69+
throw new EditorJSException('Input is null');
7070
}
7171

7272
/**
7373
* Count elements in data array
7474
*/
7575
if (count($data) === 0) {
76-
throw new CodexEditorException('Input array is empty');
76+
throw new EditorJSException('Input array is empty');
7777
}
7878

7979
/**
8080
* Check if blocks param is missing in data
8181
*/
8282
if (!isset($data['blocks'])) {
83-
throw new CodexEditorException('Field `blocks` is missing');
83+
throw new EditorJSException('Field `blocks` is missing');
8484
}
8585

8686

8787
if (!is_array($data['blocks'])) {
88-
throw new CodexEditorException('Blocks is not an array');
88+
throw new EditorJSException('Blocks is not an array');
8989
}
9090

9191
foreach ($data['blocks'] as $blockData) {
9292
if (is_array($blockData)) {
9393
array_push($this->blocks, $blockData);
9494
} else {
95-
throw new CodexEditorException('Block must be an Array');
95+
throw new EditorJSException('Block must be an Array');
9696
}
9797
}
9898

EditorJS/EditorJSException.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace EditorJS;
4+
5+
use Exception;
6+
7+
/**
8+
* Class EditorJSException
9+
*
10+
* Custom Exception which allows Editor errors catching
11+
*
12+
* @package EditorJS
13+
*/
14+
class EditorJSException extends Exception
15+
{
16+
}

0 commit comments

Comments
 (0)