/** * Authorize API with credentials * * @param \Google_Auth_AssertionCredentials $cred */ public function authenticate(\Google_Auth_AssertionCredentials $cred) { $this->client = $client = new \Google_Client(); $sitename = $this->app['config']->get('general/sitename'); // @todo url::slugify() will be deprecated in 2.1 $this->client->setApplicationName(\utilphp\util::slugify($sitename)); if (isset($_SESSION['token_gapps'])) { $client->setAccessToken($_SESSION['token_gapps']); } $client->setClientId($this->config['ClientID']); $client->setAssertionCredentials($cred); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } $_SESSION[$this->getServiceSessionTk($cred->scopes)] = $client->getAccessToken(); return $this->client; }
/** * generate an url-friendly string from Node::name * @param Node $node * @return string */ public function slugify(Node $node) { return util::slugify($node->getName()); }
public function test_slugify() { $this->assertEquals('a-simple-title', util::slugify('A simple title')); $this->assertEquals('this-post-it-has-a-dash', util::slugify('This post -- it has a dash')); $this->assertEquals('123-1251251', util::slugify('123----1251251')); $this->assertEquals('one23-1251251', util::slugify('123----1251251', '-', true)); $this->assertEquals('a-simple-title', util::slugify('A simple title', '-')); $this->assertEquals('this-post-it-has-a-dash', util::slugify('This post -- it has a dash', '-')); $this->assertEquals('123-1251251', util::slugify('123----1251251', '-')); $this->assertEquals('one23-1251251', util::slugify('123----1251251', '-', true)); $this->assertEquals('a_simple_title', util::slugify('A simple title', '_')); $this->assertEquals('this_post_it_has_a_dash', util::slugify('This post -- it has a dash', '_')); $this->assertEquals('123_1251251', util::slugify('123----1251251', '_')); $this->assertEquals('one23_1251251', util::slugify('123----1251251', '_', true)); // Blank seperator test $this->assertEquals('asimpletitle', util::slugify('A simple title', '')); $this->assertEquals('thispostithasadash', util::slugify('This post -- it has a dash', '')); $this->assertEquals('1231251251', util::slugify('123----1251251', '')); $this->assertEquals('one231251251', util::slugify('123----1251251', '', true)); // Test old parameter ordering for backwards compatability error_reporting(E_ALL ^ E_USER_DEPRECATED); $this->assertEquals('one23-1251251', util::slugify('123----1251251', true)); $this->assertEquals('123-1251251', util::slugify('123----1251251', false)); }