Пример #1
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $fieldRepository = new FieldRepository(new Field());
     $categoryFieldRepository = new CategoryFieldRepository(new CategoryField());
     $memberFieldRepository = new MemberFieldRepository(new MemberField());
     $channelRepository = new ChannelRepository(new Channel(), $fieldRepository);
     $siteRepository = new SiteRepository(new Site());
     $uploadPrefRepository = new UploadPrefRepository(new UploadPref());
     $hydratorFactory = new HydratorFactory(Model::resolveConnection(Model::getGlobalConnection()), $siteRepository, $uploadPrefRepository, new Asset(), new File(), new GridCol(), new GridRow(), new MatrixCol(), new MatrixRow(), new PlayaEntry(), new RelationshipEntry());
     Category::setCategoryFieldRepository($categoryFieldRepository);
     Category::setChannelRepository($channelRepository);
     Member::setMemberFieldRepository($memberFieldRepository);
     Title::setChannelRepository($channelRepository);
     Title::setSiteRepository($siteRepository);
     Title::setHydratorFactory($hydratorFactory);
 }
Пример #2
0
 /**
  * Constructor
  *
  * Build all the dependencies
  *
  * @var array $config  an EE config array
  */
 public function __construct($config = array())
 {
     Carbon::setToStringFormat(Carbon::ISO8601);
     $this->singleton('config', function ($app) use($config) {
         return $config;
     });
     $this->bind('db', function ($app) {
         return Model::resolveConnection(Model::getGlobalConnection());
     });
     $this->singleton('Field', function ($app) {
         return new Field();
     });
     $this->singleton('FieldRepository', function ($app) {
         return new FieldRepository($app->make('Field'));
     });
     $this->singleton('Channel', function ($app) {
         $channel = new Channel();
         $channel->setFieldRepository($app->make('FieldRepository'));
         return $channel;
     });
     $this->singleton('Site', function ($app) {
         return new Site();
     });
     $this->singleton('UploadPref', function ($app) {
         return new UploadPref();
     });
     $this->singleton('CategoryField', function ($app) {
         return new CategoryField();
     });
     $this->singleton('MemberField', function ($app) {
         return new MemberField();
     });
     $this->singleton('CategoryFieldRepository', function ($app) {
         return new CategoryFieldRepository($app->make('CategoryField'));
     });
     $this->singleton('MemberFieldRepository', function ($app) {
         return new MemberFieldRepository($app->make('MemberField'));
     });
     $this->singleton('ChannelRepository', function ($app) {
         return new ChannelRepository($app->make('Channel'));
     });
     $this->singleton('SiteRepository', function ($app) {
         return new SiteRepository($app->make('Site'));
     });
     $this->singleton('UploadPrefRepository', function ($app) {
         if (isset($app['config']['upload_prefs'])) {
             return new ConfigUploadPrefRepository($app['config']['upload_prefs']);
         }
         return new UploadPrefRepository($app->make('UploadPref'));
     });
     $this->singleton('Asset', function ($app) {
         return new Asset();
     });
     $this->singleton('File', function ($app) {
         return new File();
     });
     $this->singleton('GridCol', function ($app) {
         return new GridCol();
     });
     $this->singleton('GridRow', function ($app) {
         return new GridRow();
     });
     $this->singleton('MatrixCol', function ($app) {
         return new MatrixCol();
     });
     $this->singleton('MatrixRow', function ($app) {
         return new MatrixRow();
     });
     $this->singleton('PlayaEntry', function ($app) {
         return new PlayaEntry();
     });
     $this->singleton('RelationshipEntry', function ($app) {
         return new RelationshipEntry();
     });
     $this->singleton('HydratorFactory', function ($app) {
         return new HydratorFactory($app->make('db'), $app->make('SiteRepository'), $app->make('UploadPrefRepository'), $app->make('Asset'), $app->make('File'), $app->make('GridCol'), $app->make('GridRow'), $app->make('MatrixCol'), $app->make('MatrixRow'), $app->make('PlayaEntry'), $app->make('RelationshipEntry'));
     });
     $this->singleton('Category', function ($app) {
         $category = new Category();
         $category->setCategoryFieldRepository($app->make('CategoryFieldRepository'));
         $category->setChannelRepository($app->make('ChannelRepository'));
         return $category;
     });
     $this->singleton('Member', function ($app) {
         $member = new Member();
         $member->setMemberFieldRepository($app->make('MemberFieldRepository'));
         return $member;
     });
     $this->singleton('Title', function ($app) {
         $app->make('Category');
         $app->make('Member');
         $title = new Title();
         $title->setChannelRepository($app->make('ChannelRepository'));
         $title->setSiteRepository($app->make('SiteRepository'));
         $title->setHydratorFactory($app->make('HydratorFactory'));
         return $title;
     });
     $this->singleton('Entry', function ($app) {
         $app->make('Title');
         $entry = new Entry();
         $entry->setFieldRepository($app->make('FieldRepository'));
         return $entry;
     });
 }
Пример #3
0
 /**
  * Convert a Category model into an array suitable for ee()->TMPL->parse_variables_row
  *
  * @param  Category $category
  * @param  boolean  $customFieldsEnabled
  * @param  string   $prefix
  * @return array
  */
 protected function categoryToVariables(Category $category, $customFieldsEnabled = false, $prefix = '')
 {
     $categoryUri = ee()->config->item('use_category_name') === 'y' ? '/' . ee()->config->item('reserved_category_word') . '/' . $category->cat_url_title : '/C' . $category->cat_id;
     $regex = '#' . preg_quote($categoryUri) . '(\\/|\\/P\\d+\\/?)?$#';
     $row = array($prefix . 'active' => (bool) preg_match($regex, ee()->uri->uri_string()), $prefix . 'category_description' => $category->cat_description, $prefix . 'category_id' => $category->cat_id, $prefix . 'parent_id' => $category->parent_id, $prefix . 'category_image' => $category->cat_image, $prefix . 'category_name' => $category->cat_name, $prefix . 'category_url_title' => $category->cat_url_title, $prefix . 'path' => array($categoryUri, array('path_variable' => true)));
     if ($customFieldsEnabled) {
         foreach ($category->getFields() as $field) {
             $row[$prefix . $field->field_name] = $category->{$field->field_name};
         }
     }
     return $row;
 }