Created
April 22, 2014 07:25
-
-
Save satomixx/11168488 to your computer and use it in GitHub Desktop.
[CakePHP 2.x] ComponentでConstructorを使う、ついでにShellからComponentを使うまとめ ref: http://qiita.com/tsumekoara/items/c91533c95b8132c9db8f
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
<?php | |
App::uses('Component', 'Controller'); | |
class AsagohanComponent extends Component { | |
const BURNER_ACCESSKEY = "hidarihajinaraok"; | |
const BURNER_SECRETKEY = "jikkurimawasu"; | |
const BURNER_REGION = "hidarihaji"; | |
private $_ochawan; | |
private $_owan; | |
private $_burner; | |
public function __construct(ComponentCollection $collection, $settings = array()) { | |
// Burnerオブジェクト作成 | |
try { | |
$this->_burner = Burner::factory(array( | |
'key' => self::ACCESS_KEY, | |
'secret' => self::SECRET_KEY, | |
'region' => self::REGION | |
))->get('burner'); | |
} catch (S3Exception $e) { | |
throw new CakeException($e, Configure::read('AsagohanErrorCode.cannot_use_burner')); | |
} | |
$this->_ochawan = "zakkokumai" | |
$this->_owan = 'omisoshiru' . $this->_ochawan; | |
parent::__construct($collection, $settings); | |
} | |
// Getter | |
public function getOchawan() { | |
return $this->_ochawan; | |
} | |
// Getter | |
public function getOwan() { | |
return $this->_owan; | |
} |
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
<?php | |
App::uses("ComponentCollection", "Controller"); | |
App::uses("AsagohanComponent", "Controller/Component"); | |
class NeokiShell extends AppShell { | |
public function startup() { | |
$collection = new ComponentCollection(); | |
$this->Asagohan = new AsagohanComponent($collection); | |
parent::startup(); | |
} | |
public function main() { | |
$gohannisuru = $this->Asagohan->getOchawan(); | |
$shirumono = $this->Asagohan->getOwan(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment