unique() public static méthode

Returns a wrapper that memoizes the result of the given closure.
public static unique ( Closure $closure ) : Closure
$closure Closure Closure to wrap.
Résultat Closure Wrapper.
 /**
  *
  */
 public function testGetUnique()
 {
     $unique = Container::unique(function ($Container) {
         return new Containable();
     });
     $first = $unique($this->Container);
     $second = $unique($this->Container);
     $this->assertSame($first, $second);
 }
Exemple #2
0
 /**
  *	Sets the default properties.
  */
 public function __construct(array $properties = [])
 {
     $this->_properties = $properties + ['providers' => ESSENCE_DEFAULT_PROVIDERS, 'Cache' => Container::unique(function () {
         return new VolatileCacheEngine();
     }), 'HttpUserAgent' => 'Essence', 'Http' => Container::unique(function ($C) {
         $Http = function_exists('curl_init') ? new CurlHttpClient() : new NativeHttpClient();
         $Http->setUserAgent($C->get('HttpUserAgent'));
         return $Http;
     }), 'Dom' => Container::unique(function () {
         return new NativeDomParser();
     }), 'Log' => Container::unique(function () {
         return new NullLogger();
     }), 'Preparator' => Container::unique(function () {
         return new Preparator();
     }), 'OEmbed' => function ($C) {
         return new OEmbed($C->get('Http'), $C->get('Dom'), $C->get('Log'), $C->get('Preparator'));
     }, 'Vimeo' => function ($C) {
         return new Vimeo($C->get('Http'), $C->get('Dom'), $C->get('Log'), $C->get('Preparator'));
     }, 'YoutubePreparator' => Container::unique(function () {
         return new YoutubePreparator();
     }), 'Youtube' => function ($C) {
         return new Youtube($C->get('Http'), $C->get('Dom'), $C->get('Log'), $C->get('YoutubePreparator'));
     }, 'OpenGraph' => function ($C) {
         return new OpenGraph($C->get('Http'), $C->get('Dom'), $C->get('Log'), $C->get('Preparator'));
     }, 'BandcampPreparator' => Container::unique(function () {
         return new BandcampPreparator();
     }), 'Bandcamp' => function ($C) {
         return new OpenGraph($C->get('Http'), $C->get('Dom'), $C->get('Log'), $C->get('BandcampPreparator'));
     }, 'VinePreparator' => Container::unique(function () {
         return new VinePreparator();
     }), 'Vine' => function ($C) {
         return new OpenGraph($C->get('Http'), $C->get('Dom'), $C->get('Log'), $C->get('VinePreparator'));
     }, 'Collection' => function ($C) {
         $Collection = new Collection($C);
         $Collection->load($C->get('providers'));
         return $Collection;
     }, 'Essence' => function ($C) {
         return new Essence($C->get('Collection'), $C->get('Cache'), $C->get('Http'), $C->get('Dom'), $C->get('Log'));
     }];
 }
Exemple #3
0
 /**
  *	Configures default providers.
  */
 protected function _setupProviders()
 {
     $this->configure(['23hq' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.23hq.com/23/oembed?format=json&url=:url');
     }), 'Animoto' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://animoto.com/oembeds/create?format=json&url=:url');
     }), 'Aol' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://on.aol.com/api?format=json&url=:url');
     }), 'App.net' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('https://alpha-api.app.net/oembed?format=json&url=:url');
     }), 'Bambuser' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://api.bambuser.com/oembed.json?url=:url');
     }), 'Bandcamp' => Container::unique(function ($C) {
         return $C->get('TwitterCardsProvider');
     }), 'Blip.tv' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://blip.tv/oembed?format=json&url=:url');
     }), 'Cacoo' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://cacoo.com/oembed.json?url=:url');
     }), 'CanalPlus' => Container::unique(function ($C) {
         return $C->get('OpenGraphProvider');
     }), 'Chirb.it' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://chirb.it/oembed.json?url=:url');
     }), 'CircuitLab' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('https://www.circuitlab.com/circuit/oembed?format=json&url=:url');
     }), 'Clikthrough' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://clikthrough.com/services/oembed?format=json&url=:url');
     }), 'CollegeHumorOEmbed' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.collegehumor.com/oembed.json?url=:url');
     }), 'CollegeHumorOpenGraph' => Container::unique(function ($C) {
         return $C->get('OpenGraphProvider');
     }), 'Coub' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://coub.com/api/oembed.json?url=:url');
     }), 'CrowdRanking' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://crowdranking.com/api/oembed.json?url=:url');
     }), 'DailyMile' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://api.dailymile.com/oembed?format=json&url=:url');
     }), 'Dailymotion' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.dailymotion.com/services/oembed?format=json&url=:url');
     }), 'Deviantart' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://backend.deviantart.com/oembed?format=json&url=:url');
     }), 'Dipity' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.dipity.com/oembed/timeline?format=json&url=:url');
     }), 'Dotsub' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('https://dotsub.com/services/oembed?format=json&url=:url');
     }), 'EdocrOEmbed' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.edocr.com/api/oembed?format=json&url=:url');
     }), 'EdocrTwitterCards' => Container::unique(function ($C) {
         return $C->get('TwitterCardsProvider');
     }), 'Flickr' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://flickr.com/services/oembed?format=json&url=:url');
     }), 'FunnyOrDie' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.funnyordie.com/oembed?format=json&url=:url');
     }), 'Gist' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('https://github.com/api/oembed?format=json&url=:url');
     }), 'Gmep' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('https://gmep.org/oembed.json?url=:url');
     }), 'HowCast' => Container::unique(function ($C) {
         return $C->get('OpenGraphProvider');
     }), 'Huffduffer' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://huffduffer.com/oembed?format=json&url=:url');
     }), 'Hulu' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.hulu.com/api/oembed.json?url=:url');
     }), 'Ifixit' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.ifixit.com/Embed?format=json&url=:url');
     }), 'Ifttt' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.ifttt.com/oembed?format=json&url=:url');
     }), 'Imgur' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://api.imgur.com/oembed?format=json&url=:url');
     }), 'InstagramOEmbed' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://api.instagram.com/oembed?format=json&url=:url');
     }), 'InstagramOpenGraph' => Container::unique(function ($C) {
         return $C->get('OpenGraphProvider');
     }), 'Jest' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.jest.com/oembed.json?url=:url');
     }), 'Justin.tv' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://api.justin.tv/api/embed/from_url.json?url=:url');
     }), 'Kickstarter' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.kickstarter.com/services/oembed?format=json&url=:url');
     }), 'Meetup' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('https://api.meetup.com/oembed?format=json&url=:url');
     }), 'Mixcloud' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.mixcloud.com/oembed?format=json&url=:url');
     }), 'Mobypicture' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://api.mobypicture.com/oEmbed?format=json&url=:url');
     }), 'Nfb' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.nfb.ca/remote/services/oembed?format=json&url=:url');
     }), 'Official.fm' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://official.fm/services/oembed?format=json&url=:url');
     }), 'Polldaddy' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://polldaddy.com/oembed?format=json&url=:url');
     }), 'PollEverywhere' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.polleverywhere.com/services/oembed?format=json&url=:url');
     }), 'Prezi' => Container::unique(function ($C) {
         return $C->get('OpenGraphProvider');
     }), 'Qik' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://qik.com/api/oembed.json?url=:url');
     }), 'Rdio' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.rdio.com/api/oembed?format=json&url=:url');
     }), 'Revision3' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://revision3.com/api/oembed?format=json&url=:url');
     }), 'Roomshare' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://roomshare.jp/en/oembed.json?&url=:url');
     }), 'Sapo' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://videos.sapo.pt/oembed?format=json&url=:url');
     }), 'Screenr' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.screenr.com/api/oembed.json?url=:url');
     }), 'Scribd' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.scribd.com/services/oembed?format=json&url=:url');
     }), 'Shoudio' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://shoudio.com/api/oembed?format=json&url=:url');
     }), 'Sketchfab' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://sketchfab.com/oembed?format=json&url=:url');
     }), 'SlideShare' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.slideshare.net/api/oembed/2?format=json&url=:url');
     }), 'SoundCloud' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://soundcloud.com/oembed?format=json&url=:url');
     }), 'SpeakerDeck' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('https://speakerdeck.com/oembed.json?url=:url');
     }), 'Spotify' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('https://embed.spotify.com/oembed?format=json&url=:url');
     }), 'TedOEmbed' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.ted.com/talks/oembed.json?url=:url');
     }), 'TedOpenGraph' => Container::unique(function ($C) {
         return $C->get('OpenGraphProvider');
     }), 'Twitter' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('https://api.twitter.com/1/statuses/oembed.json?url=:url');
     }), 'Ustream' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.ustream.tv/oembed?format=json&url=:url');
     }), 'Vhx' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://vhx.tv/services/oembed.json?url=:url');
     }), 'Viddler' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.viddler.com/oembed/?url=:url');
     }), 'Videojug' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.videojug.com/oembed.json?url=:url');
     }), 'Vimeo' => Container::unique(function ($C) {
         return $C->get('VimeoProvider')->setEndpoint('http://vimeo.com/api/oembed.json?url=:url');
     }), 'Vine' => Container::unique(function ($C) {
         return $C->get('TwitterCardsProvider');
     }), 'Wistia' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://fast.wistia.com/oembed?format=json&url=:url');
     }), 'WordPress' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://public-api.wordpress.com/oembed/1.0?format=json&for=me&url=:url');
     }), 'Yfrog' => Container::unique(function ($C) {
         return $C->get('OEmbedProvider')->setEndpoint('http://www.yfrog.com/api/oembed?format=json&url=:url');
     }), 'Youtube' => Container::unique(function ($C) {
         return $C->get('YoutubeProvider')->setEndpoint('http://www.youtube.com/oembed?format=json&url=:url');
     })]);
 }
Exemple #4
0
    /**
     *	Configures Essence's helpers.
     */
    protected function _setupEssence()
    {
        $this->configure(['Crawler' => Container::unique(function ($C) {
            return new Crawler($C->get('Collection'), $C->get('Dom'));
        }), 'Extractor' => Container::unique(function ($C) {
            return new Extractor($C->get('Collection'));
        }), 'Replacer.urlPattern' => '~
					(?<!=["\']) # avoids matching URLs in HTML attributes
					(?:https?:)//
					(?:www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)?
					(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+
					(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:\'"\\.,<>?«»“”‘’])
				~ix', 'Replacer' => Container::unique(function ($C) {
            $Replacer = new Replacer($C->get('Extractor'));
            $Replacer->setUrlPattern($C->get('Replacer.urlPattern'));
            return $Replacer;
        })]);
    }