Example #1
0
 protected function __construct($attrs = null)
 {
     if (!$this->no_backend) {
         if (!$this->table) {
             $this->table = strtolower(Inflector::get()->pluralize(get_class($this)));
         }
         $this->db = DB::instance();
     }
     if (!$this->no_cache) {
         $this->cache = Cache::instance();
     }
     if (class_exists('\\Notifier')) {
         $this->notifier = \Notifier::instance();
     }
     if (defined('AWS_CONSUMER_KEY') && defined('AWS_CONSUMER_SECRET') && defined('AWS_BUCKET')) {
         if (!class_exists('\\Aws\\S3\\S3Client')) {
             throw new Exception("AWS S3 packaged is required");
         }
         $this->s3 = \Aws\S3\S3Client::factory(array('key' => AWS_CONSUMER_KEY, 'secret' => AWS_CONSUMER_SECRET));
     }
     $this->validator = ValidatorBase::instance();
     if ($attrs && is_numeric($attrs)) {
         // assume $attrs is id
         $this->findOne(array($this->primary_key => $attrs));
     } else {
         if ($attrs && is_array($attrs)) {
             if (!array_key_exists($this->primary_key, $attrs)) {
                 $this->validate($attrs);
             }
             // set the attrs
             $this->attrs = $attrs;
             $this->protectAttrs();
         }
     }
 }