You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							32 lines
						
					
					
						
							748 B
						
					
					
				
			
		
		
	
	
							32 lines
						
					
					
						
							748 B
						
					
					
				<?php | 
						|
 | 
						|
namespace common\modules\pages\repositories; | 
						|
 | 
						|
use common\modules\pages\entities\Page; | 
						|
use core\repositories\NotFoundException; | 
						|
 | 
						|
class PageRepository | 
						|
{ | 
						|
    public function get($id): Page | 
						|
    { | 
						|
        //if (!$page = Page::findOne($id)) { | 
						|
	    if (!$page = Page::find()->with('translations')->andWhere(['id' => $id])->one()) { | 
						|
            throw new NotFoundException('Page is not found.'); | 
						|
        } | 
						|
        return $page; | 
						|
    } | 
						|
 | 
						|
    public function save(Page $page): void | 
						|
    { | 
						|
        if (!$page->save()) { | 
						|
            throw new \RuntimeException('Saving error.'); | 
						|
        } | 
						|
    } | 
						|
 | 
						|
    public function remove(Page $page): void | 
						|
    { | 
						|
        if (!$page->delete()) { | 
						|
            throw new \RuntimeException('Removing error.'); | 
						|
        } | 
						|
    } | 
						|
} |