Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit974facf

Browse files
committed
Revert "Merge pull request#25 from webimpress/hotfix/21"
This reverts commit8e14178, reversingchanges made to09f5af9.Fixes#28
1 parent63eae0a commit974facf

File tree

2 files changed

+18
-130
lines changed

2 files changed

+18
-130
lines changed

‎src/ConfigResource.php‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,25 @@ public function patch($data, $tree = false)
110110
*/
111111
publicfunctionpatchKey($key,$value)
112112
{
113-
$this->patch([$key =>$value]);
113+
// Get local config file
114+
$config = [];
115+
if (file_exists($this->fileName)) {
116+
$config =include$this->fileName;
117+
if (!is_array($config)) {
118+
$config = [];
119+
}
120+
}
121+
$config =$this->replaceKey($key,$value,$config);
114122

115-
return$this->config;
123+
// Write to configuration file
124+
$this->writer->toFile($this->fileName,$config);
125+
$this->invalidateCache($this->fileName);
126+
127+
// Reseed configuration
128+
$this->config =$config;
129+
130+
// Return written values
131+
return$config;
116132
}
117133

118134
/**

‎test/ConfigResourceTest.php‎

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
usePHPUnit\Framework\TestCase;
1010
usestdClass;
1111
useZend\Config\Writer\PhpArray;
12-
useZend\Stdlib\ArrayUtils;
1312
useZF\Configuration\ConfigResource;
1413

1514
class ConfigResourceTestextends TestCase
@@ -87,8 +86,6 @@ public function testPatchListUpdatesFileWithMergedConfig()
8786
],
8887
'baz' =>'not what you think',
8988
];
90-
$writer =newPhpArray();
91-
$writer->toFile($this->file,$config);
9289
$configResource =newConfigResource($config,$this->file,$this->writer);
9390

9491
$patch = [
@@ -100,10 +97,8 @@ public function testPatchListUpdatesFileWithMergedConfig()
10097
$this->assertEquals($patch,$response);
10198

10299
$expected = [
103-
'foo' =>'bar',
104100
'bar' => [
105101
'baz' =>'UPDATED',
106-
'bat' =>'bogus',
107102
],
108103
'baz' =>'what you think',
109104
];
@@ -407,127 +402,4 @@ public function testDeleteNonexistentKeyShouldDoNothing()
407402
$test =include$this->file;
408403
$this->assertEquals($expected,$test);
409404
}
410-
411-
publicfunctionpatchKey()
412-
{
413-
return [
414-
'scalar-top-level' => [
415-
'top',
416-
'updated',
417-
['top' =>'updated']
418-
],
419-
420-
'overwrite-hash' => [
421-
'sub',
422-
'updated',
423-
['sub' =>'updated'],
424-
],
425-
426-
'nested-scalar' => [
427-
'sub.level',
428-
'updated',
429-
[
430-
'sub' => [
431-
'level' =>'updated',
432-
],
433-
],
434-
],
435-
'nested-list' => [
436-
'sub.list',
437-
['three','four'],
438-
[
439-
'sub' => [
440-
'list' => ['three','four'],
441-
],
442-
],
443-
],
444-
'nested-hash' => [
445-
'sub.hash.two',
446-
'updated',
447-
[
448-
'sub' => [
449-
'hash' => [
450-
'two' =>'updated',
451-
],
452-
],
453-
],
454-
],
455-
'overwrite-nested-null' => [
456-
'sub.null',
457-
'updated',
458-
[
459-
'sub' => [
460-
'null' =>'updated',
461-
],
462-
],
463-
],
464-
'overwrite-nested-object' => [
465-
'sub.object',
466-
'updated',
467-
[
468-
'sub' => [
469-
'object' =>'updated',
470-
],
471-
],
472-
],
473-
'merge-nested' => [
474-
'sub.hash',
475-
[
476-
'two' =>'two-updated',
477-
'three' =>'three-updated',
478-
],
479-
[
480-
'sub' => [
481-
'hash' => [
482-
'one' =>1,
483-
'two' =>'two-updated',
484-
'three' =>'three-updated',
485-
],
486-
],
487-
],
488-
],
489-
'add-new' => [
490-
'sub',
491-
['new' =>'added'],
492-
[
493-
'sub' => [
494-
'new' =>'added',
495-
],
496-
],
497-
],
498-
];
499-
}
500-
501-
/**
502-
* @dataProvider patchKey
503-
*
504-
* @param string $key
505-
* @param mixed $value
506-
* @param mixed $expected
507-
*/
508-
publicfunctiontestPatchKey($key,$value,$expected)
509-
{
510-
$config = [
511-
'top' =>'level',
512-
'sub' => [
513-
'level' =>2,
514-
'list' => [
515-
'one',
516-
'two',
517-
],
518-
'hash' => [
519-
'one' =>1,
520-
'two' =>2,
521-
],
522-
'null' =>null,
523-
'object' => stdClass::class,
524-
],
525-
];
526-
$writer =newPhpArray();
527-
$writer->toFile($this->file,$config);
528-
529-
$updated =$this->configResource->patchKey($key,$value);
530-
$expected = ArrayUtils::merge($config,$expected);
531-
$this->assertEquals($expected,$updated);
532-
}
533405
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp