-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate profiles, imap/smtp/feed server list to repository trait with…
… unique ID management to get rid of array index integer values mixing up when deleting entries
- Loading branch information
Showing
28 changed files
with
206 additions
and
1,567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,73 @@ | ||
<?php | ||
|
||
class Hm_BaseRepository extends Hm_Repository | ||
{ | ||
trait Hm_Repository { | ||
|
||
} | ||
protected static $name; | ||
protected static $user_config; | ||
protected static $session; | ||
protected static $entities; | ||
|
||
protected static function initRepo($name, $user_config, $session, &$entities) { | ||
self::$name = $name; | ||
self::$user_config = $user_config; | ||
self::$session = $session; | ||
self::$entities = &$entities; | ||
$initial = self::$user_config->get(self::$name, []); | ||
foreach ($initial as $entity) { | ||
self::add($entity, false); | ||
} | ||
} | ||
|
||
protected static function generateId() { | ||
return uniqid(); | ||
} | ||
|
||
public static function save() { | ||
self::$user_config->set(self::$name, self::$entities); | ||
self::$session->set('user_data', self::$user_config->dump()); | ||
} | ||
|
||
public static function add($entity, $save = true) { | ||
if (! array_key_exists('id', $entity)) { | ||
$entity['id'] = self::generateId(); | ||
} | ||
self::$entities[$entity['id']] = $entity; | ||
if ($save) { | ||
self::save(); | ||
} | ||
} | ||
|
||
public static function edit($id, $entity) { | ||
if (array_key_exists($id, self::$entities)) { | ||
self::$entities[$id] = $entity; | ||
self::save(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public static function del($id) { | ||
if (array_key_exists($id, self::$entities)) { | ||
unset(self::$entities[$id]); | ||
self::save(); | ||
return true; | ||
} | ||
return false; | ||
|
||
} | ||
|
||
public static function get($id) { | ||
if (array_key_exists($id, self::$entities)) { | ||
return self::$entities[$id]; | ||
} | ||
return false; | ||
} | ||
|
||
public static function getAll() { | ||
return self::$entities; | ||
} | ||
|
||
public static function count() { | ||
return count(self::$entities); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.